All links and redirects are now relative

WARNING - this might break. We'll revert this commit if so.
The rationale is for those using proxies where the host name is not proxied
on, as in Apache's ProxyPreserveHost.
RFC2161 does not permit relative Location: header, but an upcoming revision
stil in-draft will apparently allow relative spec. I believe all browsers to
support relative Location: headers already.
This commit is contained in:
Oliver Gorwits
2013-03-04 21:40:43 +00:00
parent 9848de5c26
commit e3c0ae3554
6 changed files with 21 additions and 10 deletions

View File

@@ -13,10 +13,11 @@
* Remove Daemon's job queue DBIC schema from user config * Remove Daemon's job queue DBIC schema from user config
* Add log messages to the Daemon * Add log messages to the Daemon
* Use Path::Class for path and file name construction consistently * Use Path::Class for path and file name construction consistently
* Avoid use of DNS when looking up devices in DB by IP * All links and redirects are now relative
[BUG FIXES] [BUG FIXES]
* Avoid use of DNS when looking up devices in DB by IP
* Search by device port MAC no longer fatal * Search by device port MAC no longer fatal
* URI and HTML escape template variables * URI and HTML escape template variables

View File

@@ -43,7 +43,7 @@ hook 'before_template' => sub {
if request->base->path ne '/'; if request->base->path ne '/';
# allow portable dynamic content # allow portable dynamic content
$tokens->{uri_for} = \&uri_for; $tokens->{uri_for} = sub { uri_for(@_)->path_query() };
# allow very long lists of ports # allow very long lists of ports
$Template::Directive::WHILE_MAX = 10_000; $Template::Directive::WHILE_MAX = 10_000;

View File

@@ -22,23 +22,26 @@ hook 'before' => sub {
}; };
post '/login' => sub { post '/login' => sub {
status(302);
if (param('username') and param('password')) { if (param('username') and param('password')) {
my $user = schema('netdisco')->resultset('User')->find(param('username')); my $user = schema('netdisco')->resultset('User')->find(param('username'));
if ($user) { if ($user) {
my $sum = Digest::MD5::md5_hex(param('password')); my $sum = Digest::MD5::md5_hex(param('password'));
if ($sum and $sum eq $user->password) { if ($sum and $sum eq $user->password) {
session(user => $user->username); session(user => $user->username);
redirect uri_for('/inventory'); header(Location => uri_for('/inventory')->path_query());
return; return;
} }
} }
} }
redirect uri_for('/', {failed => 1}); header(Location => uri_for('/', {failed => 1})->path_query());
}; };
get '/logout' => sub { get '/logout' => sub {
session->destroy; session->destroy;
redirect uri_for('/', {logout => 1}); status(302);
header(Location => uri_for('/', {logout => 1})->path_query());
}; };
true; true;

View File

@@ -94,7 +94,9 @@ get '/device' => sub {
}); });
if (!defined $dev) { if (!defined $dev) {
return redirect uri_for('/', {nosuchdevice => 1}); status(302);
header(Location => uri_for('/', {nosuchdevice => 1})->path_query());
return;
} }
params->{'tab'} ||= 'details'; params->{'tab'} ||= 'details';

View File

@@ -64,7 +64,11 @@ get '/search' => sub {
my $s = schema('netdisco'); my $s = schema('netdisco');
if (not param('tab')) { if (not param('tab')) {
if (not $q) { return redirect uri_for('/') } if (not $q) {
status(302);
header(Location => uri_for('/')->path_query());
return;
}
# pick most likely tab for initial results # pick most likely tab for initial results
if ($q =~ m/^\d+$/) { if ($q =~ m/^\d+$/) {
@@ -76,11 +80,13 @@ get '/search' => sub {
if ($nd and $nd->count) { if ($nd and $nd->count) {
if ($nd->count == 1) { if ($nd->count == 1) {
# redirect to device details for the one device # redirect to device details for the one device
return redirect uri_for('/device', { status(302);
header(Location => uri_for('/device', {
tab => 'details', tab => 'details',
q => ($nd->first->dns || $nd->first->ip), q => ($nd->first->dns || $nd->first->ip),
f => '', f => '',
}); })->path_query());
return;
} }
# multiple devices # multiple devices

1
TODO
View File

@@ -12,7 +12,6 @@ FRONTEND
* reports page * reports page
* reports plugin(s) * reports plugin(s)
* (jeneric) device module tab * (jeneric) device module tab
* remove host from uri_for includes
* duplicate requests problem? * duplicate requests problem?
DAEMON DAEMON