make app portable through uri_base

This commit is contained in:
Oliver Gorwits
2012-01-15 23:09:43 +00:00
parent e2e032de18
commit c555fc9330
18 changed files with 59 additions and 54 deletions

View File

@@ -11,6 +11,11 @@ use Netdisco::Web::AuthN;
use Netdisco::Web::Search;
use Netdisco::Web::Device;
hook 'before_template' => sub {
my $tokens = shift;
$tokens->{uri_base} = request->base->path;
};
get '/' => sub {
template 'index';
};

View File

@@ -14,10 +14,10 @@
<td>[% row.alias %]</a>
<td>[% row.dns.remove(settings.domain_suffix) %]</a>
<td class="center_cell"><a class="nd_linkcell"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.port %]">[% row.port %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.port %]">[% row.port %]</a></td>
<td>[% row.device_port.name %]</td>
<td><a class="nd_linkcell"
href="/search?tab=node&q=[% row.subnet %]">[% row.subnet %]</a></td>
href="[% uri_base %]/search?tab=node&q=[% row.subnet %]">[% row.subnet %]</a></td>
</tr>
[% END %]
</tbody>

View File

@@ -8,7 +8,7 @@
<td>Location</td>
<td>
<a rel="twipsy" data-placement="above" data-offset="5" title="Find Similar Devices"
href="/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&location=[% d.location | uri %]">[% d.location %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&location=[% d.location | uri %]">[% d.location %]</a>
</td>
</tr>
<tr>
@@ -19,10 +19,10 @@
<td>Vendor / Model</td>
<td>
<a rel="twipsy" data-placement="above" data-offset="5" title="Find Similar Devices"
href="/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&vendor=[% d.vendor | uri %]">[% d.vendor %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&vendor=[% d.vendor | uri %]">[% d.vendor %]</a>
/
<a rel="twipsy" data-placement="above" data-offset="5" title="Find Similar Devices"
href="/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&model=[% d.model | uri %]">[% d.model %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&model=[% d.model | uri %]">[% d.model %]</a>
</td>
</tr>
<tr>
@@ -30,7 +30,7 @@
<td>[% d.os %] /
<a rel="twipsy" data-placement="above" data-offset="5"
title="Find Similar Devices"
href="/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&os_ver=[% d.os_ver | uri %]">[% d.os_ver %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.device %]&q=[% d.dns | uri %]&os_ver=[% d.os_ver | uri %]">[% d.os_ver %]</a>
</td>
</tr>
<tr>

View File

@@ -58,7 +58,7 @@
[% IF params.c_vlan %]
<td class="center_cell">
<a class="nd_linkcell"
href="/search?tab=vlan&q=[% row.vlan | uri %]">[% row.vlan | html_entity %]</a>
href="[% uri_base %]/search?tab=vlan&q=[% row.vlan | uri %]">[% row.vlan | html_entity %]</a>
</td>
[% END %]
[% IF params.c_vmember %]
@@ -69,7 +69,7 @@
[% SET count = 0 %]
[% FOREACH vlan IN row.tagged_vlans %]
[% SET output = output _
'<a href="/search?tab=vlan&q=' _ vlan.vlan _ '">' _ vlan.vlan _ '</a>' %]
'<a href="[% uri_base %]/search?tab=vlan&q=' _ vlan.vlan _ '">' _ vlan.vlan _ '</a>' %]
[% SET output = output _ ', ' IF NOT loop.last %]
[% SET count = count + 1 %]
[% END %]
@@ -85,28 +85,28 @@
<td>
[% IF row.remote_ip %]
[% IF row.neighbor %]
<a href="/device?tab=ports&ip=[% row.neighbor.ip | uri %]&q=[% row.remote_port | uri %]">
<a href="[% uri_base %]/device?tab=ports&ip=[% row.neighbor.ip | uri %]&q=[% row.remote_port | uri %]">
[% row.neighbor.dns.remove(settings.domain_suffix) || row.neighbor.ip %]
([% row.remote_port | html_entity %])</a>
[% ELSE %]
<span class="label important">n</span>
<a href="/search?tab=node&q=[% row.remote_ip | uri %]">[% row.remote_ip %] ([% row.remote_port %])
<a href="[% uri_base %]/search?tab=node&q=[% row.remote_ip | uri %]">[% row.remote_ip %] ([% row.remote_port %])
<br/>&nbsp; ([% row.remote_type %]) / ([% row.remote_id %])</a>
[% END %]
[% END %]
[% FOREACH node IN row.get_nodes(params.n_archived) %]
[% '<br/>' IF row.remote_ip OR NOT loop.first %]
[% '<span class="label warning">a</span> &nbsp;' IF NOT node.active %]
<a href="/search?tab=node&q=[% node.mac | uri %]">[% node.mac %]</a>
<a href="[% uri_base %]/search?tab=node&q=[% node.mac | uri %]">[% node.mac %]</a>
[% ' (' _ node.time_last _ ')' IF params.n_age %]
[% IF params.n_ip %]
[% FOREACH ip IN node.ips %]
<br/>&nbsp; [% '<span class="label warning">a</span> &nbsp;' IF NOT ip.active %]
[% SET dns = ip.dns %]
[% IF dns %]
<a href="/search?tab=node&q=[% ip.ip | uri %]">[% ip.dns %] ([% ip.ip %])</a>
<a href="[% uri_base %]/search?tab=node&q=[% ip.ip | uri %]">[% ip.dns %] ([% ip.ip %])</a>
[% ELSE %]
<a href="/search?tab=node&q=[% ip.ip | uri %]">[% ip.ip %]</a>
<a href="[% uri_base %]/search?tab=node&q=[% ip.ip | uri %]">[% ip.ip %]</a>
[% END %]
[% END %]
[% END %]

View File

@@ -14,7 +14,7 @@
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td><a href="/device?ip=[% row.ip %]">[% row.dns.remove(settings.domain_suffix) %]</a></td>
<td><a href="[% uri_base %]/device?ip=[% row.ip %]">[% row.dns.remove(settings.domain_suffix) %]</a></td>
<td>[% row.contact %]</td>
<td>[% row.location %]</td>
<td>[% row.name %]</td>

View File

@@ -17,12 +17,12 @@
[% WHILE (row = results.next) %]
<tr>
<td><a class="nd_linkcell"
href="/search?[% vars.query_defaults.node %]&q=[% row.mac | uri %]">[% row.mac %]</a></td>
href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% row.mac | uri %]">[% row.mac %]</a></td>
[% IF params.vendor %]
<td>[% row.oui.company %]</td>
[% END %]
<td>IP &rarr; MAC</td>
<td><a href="/search?[% vars.query_defaults.node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
<td><a href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
[% ' (' _ row.dns.remove(settings.domain_suffix) _ ')' IF row.dns %]
[% ' <span class="label warning">a</span>' IF NOT row.active %]
</td>
@@ -38,7 +38,7 @@
<td>&nbsp;</td>
[% END %]
<td>Switch Port</td>
<td><a href="/device?tab=ports&ip=[% node.switch | url %]&q=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
<td><a href="[% uri_base %]/device?tab=ports&ip=[% node.switch | url %]&q=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
[% ' <span class="label warning">a</span>' IF NOT node.active %]
</td>
@@ -55,7 +55,7 @@
<td>&nbsp;</td>
[% END %]
<td>MAC &rarr; IP</td>
<td><a href="/search?[% vars.query_defaults.node %]&q=[% nodeip.ip | uri %]">[% nodeip.ip %]</a>
<td><a href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% nodeip.ip | uri %]">[% nodeip.ip %]</a>
[% ' (' _ nodeip.dns.remove(settings.domain_suffix) _ ')' IF nodeip.dns %]
[% ' <span class="label warning">a</span>' IF NOT nodeip.active %]
</td>

View File

@@ -20,7 +20,7 @@
<td>
[% IF first_row %]
<a class="nd_linkcell"
href="/search?[% vars.query_defaults.node %]&q=[% row.mac | uri %]">[% row.mac %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% row.mac | uri %]">[% row.mac %]</a>
[% ELSE %]
&nbsp;
[% END %]
@@ -35,7 +35,7 @@
</td>
[% END %]
<td>MAC &rarr; IP</td>
<td><a href="/search?[% vars.query_defaults.node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
<td><a href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% row.ip | uri %]">[% row.ip %]</a>
[% ' (' _ row.dns.remove(settings.domain_suffix) _ ')' IF row.dns %]
[% ' <span class="label warning">a</span>' IF NOT row.active %]
</td>
@@ -51,7 +51,7 @@
<td>
[% IF first_row %]
<a class="nd_linkcell"
href="/search?[% vars.query_defaults.node %]&q=[% node.mac | uri %]">[% node.mac %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% node.mac | uri %]">[% node.mac %]</a>
[% ELSE %]
&nbsp;
[% END %]
@@ -66,7 +66,7 @@
</td>
[% END %]
<td>Switch Port</td>
<td><a href="/device?tab=ports&ip=[% node.switch | url %]&q=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
<td><a href="[% uri_base %]/device?tab=ports&ip=[% node.switch | url %]&q=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
[% ' (' _ node.device.dns.remove(settings.domain_suffix) _ ')' IF node.device.dns %]
[% ' <span class="label warning">a</span>' IF NOT node.active %]
</td>
@@ -82,7 +82,7 @@
<td>
[% IF first_row %]
<a class="nd_linkcell"
href="/search?[% vars.query_defaults.node %]&q=[% port.mac | uri %]">[% port.mac %]</a>
href="[% uri_base %]/search?[% vars.query_defaults.node %]&q=[% port.mac | uri %]">[% port.mac %]</a>
[% ELSE %]
&nbsp;
[% END %]
@@ -97,7 +97,7 @@
</td>
[% END %]
<td>Switch Port</td>
<td><a href="/device?tab=ports&ip=[% port.ip | url %]&q=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
<td><a href="[% uri_base %]/device?tab=ports&ip=[% port.ip | url %]&q=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
[% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %]
</td>
[% IF params.stamps %]

View File

@@ -11,7 +11,7 @@
[% WHILE (row = results.next) %]
<tr>
<td>[% row.name %]</td>
<td><a href="/device?tab=ports&ip=[% row.ip %]&q=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
<td><a href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.port %]">[% row.ip %] [ [% row.port %] ]</a>
[% ' (' _ row.device.dns.remove(settings.domain_suffix) _ ')' IF row.device.dns %]
</td>
<td>[% row.descr %]</td>

View File

@@ -13,17 +13,17 @@
[% WHILE (row = results.next) %]
<tr>
<td><a class="nd_linkcell nd_stealthlink"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.vlan.vlan %]</a></td>
<td><a class="nd_linkcell"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.dns %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.dns %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.vlan.description %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.model %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.model %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.os %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.os %]</a></td>
<td><a class="nd_linkcell nd_stealthlink"
href="/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
href="[% uri_base %]/device?tab=ports&ip=[% row.ip %]&q=[% row.vlan.vlan %]">[% row.vendor %]</a></td>
</tr>
[% END %]
</tbody>

View File

@@ -1,5 +1,5 @@
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="/device">
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="[% uri_base %]/device">
<input name="ip" value="[% params.ip %]" type="hidden"/>
<input name="q" value="[% params.q %]" type="hidden"/>
</form>

View File

@@ -1,5 +1,5 @@
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="/device">
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="[% uri_base %]/device">
<input name="ip" value="[% params.ip %]" type="hidden"/>
<input name="q" value="[% params.q %]" type="hidden"/>
</form>

View File

@@ -1,5 +1,5 @@
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="/device">
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="[% uri_base %]/device">
<input name="ip" value="[% params.ip %]" type="hidden"/>
<input name="q" value="[% params.q %]" type="hidden"/>
</form>

View File

@@ -1,5 +1,5 @@
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="/device">
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="[% uri_base %]/device">
<input name="tab" value="[% tab.id %]" type="hidden"/>
<input name="ip" value="[% params.ip %]" type="hidden"/>
<div class="clearfix">

View File

@@ -50,7 +50,7 @@
);
// submit the query and put results into the tab pane
$(target).load( '/ajax/content/device/' + tab + '?' + query,
$(target).load( '[% uri_base %]/ajax/content/device/' + tab + '?' + query,
function(response, status, xhr) {
if (status !== "success") {
$(target).html(
@@ -65,7 +65,7 @@
);
}
// looks good, update the bookmark for this search
$(mark).attr('href', '/device?' + query);
$(mark).attr('href', '[% uri_base %]/device?' + query);
// enable collapser on any large vlan lists
$('.nd_collapse_vlans').collapser({

View File

@@ -18,7 +18,7 @@
);
// submit the query and put results into the tab pane
$(target).load( '/ajax/content/search/' + tab + '?' + query,
$(target).load( '[% uri_base %]/ajax/content/search/' + tab + '?' + query,
function(response, status, xhr) {
if (status !== "success") {
$(target).html(
@@ -33,7 +33,7 @@
);
}
// looks good, update the bookmark for this search
$(mark).attr('href', '/search?' + query);
$(mark).attr('href', '[% uri_base %]/search?' + query);
}
);
}

View File

@@ -30,7 +30,7 @@
<h2>Welcome to Netdisco</h2>
<small>Netdisco is an Open Source web-based network management tool.</small>
[% IF NOT session.user %]
<form class="nd_loginform" method="post" action="/login">
<form class="nd_loginform" method="post" action="[% uri_base %]/login">
<div class="inline-inputs">
<input placeholder="Username" class="span2" name="username" type="text"/>
<input placeholder="Password" class="span2" name="password" type="password"/>

View File

@@ -11,12 +11,12 @@
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript" src="/javascripts/jquery-latest.min.js"></script>
<script type="text/javascript" src="/javascripts/jquery-collapser.min.js"></script>
<script type="text/javascript" src="/javascripts/bootstrap-alerts.js"></script>
<script type="text/javascript" src="/javascripts/bootstrap-twipsy.js"></script>
<script type="text/javascript" src="/javascripts/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="/javascripts/bootstrap-tabs.js"></script>
<script type="text/javascript" src="[% uri_base %]/javascripts/jquery-latest.min.js"></script>
<script type="text/javascript" src="[% uri_base %]/javascripts/jquery-collapser.min.js"></script>
<script type="text/javascript" src="[% uri_base %]/javascripts/bootstrap-alerts.js"></script>
<script type="text/javascript" src="[% uri_base %]/javascripts/bootstrap-twipsy.js"></script>
<script type="text/javascript" src="[% uri_base %]/javascripts/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="[% uri_base %]/javascripts/bootstrap-tabs.js"></script>
<script type="text/javascript">
$(document).ready(function() {
@@ -24,8 +24,8 @@
});
</script>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="[% uri_base %]/css/bootstrap.min.css">
<link rel="stylesheet" href="[% uri_base %]/css/style.css">
</head>
<body>
@@ -41,22 +41,22 @@
<div class="topbar" data-dropdown="dropdown">
<div class="topbar-inner">
<div class="container-fluid">
<a class="brand" href="/">Netdisco</a>
<a class="brand" href="[% uri_base %]/">Netdisco</a>
[% IF session.user %]
<ul class="nav">
<li><a href="/">Home</a></li>
<li><a href="[% uri_base %]/">Home</a></li>
[% IF more_dd.size %]
<li class="dropdown">
<a href="#" class="dropdown-toggle">More</a>
<ul class="dropdown-menu">
[% FOREACH title IN more_dd.keys.sort %]
<li><a href="[% more_dd.$title %]">[% title %]</a></li>
<li><a href="[% uri_base %][% more_dd.$title %]">[% title %]</a></li>
[% END %]
</ul>
</li> <!-- /dropdown -->
[% END %]
</ul>
<form method="get" action="/search">
<form method="get" action="[% uri_base %]/search">
<input placeholder="Search" class="span5" name="q" type="text"/>
</form>
<ul class="nav secondary-nav">
@@ -67,7 +67,7 @@
<a href="#" class="dropdown-toggle">[% session.user %]</a>
<ul class="dropdown-menu">
[% FOREACH item IN user_dd %]
<li><a href="[% item.link %]">[% item.title %]</a></li>
<li><a href="[% uri_base %][% item.link %]">[% item.title %]</a></li>
[% END %]
</ul>
</li> <!-- /dropdown -->

View File

@@ -4,7 +4,7 @@
<div class="tab-content">
[% FOREACH tab IN vars.tabs %]
<div id="[% tab.id %]_search" class="tab-pane [% 'active' IF params.tab == tab.id %]">
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="/search">
<form id="[% tab.id %]_form" class="nd_sidesearchform form-stacked" method="get" action="[% uri_base %]/search">
<div class="clearfix">
<input class="span3" name="q" value="[% params.q %]" type="text"/>
</div>