#889 implement renumber in the web interface

This commit is contained in:
Oliver Gorwits
2022-07-19 22:34:54 +01:00
parent 3317128c41
commit e290d352b9
4 changed files with 54 additions and 1 deletions

View File

@@ -1,3 +1,9 @@
2.052009 - 2022-06-xx
[NEW FEATURES]
* #889 implement renumber in the web interface
2.052008 - 2022-06-12
[NEW FEATURES]

View File

@@ -7,7 +7,7 @@ use Dancer::Plugin::Auth::Extensible;
use NetAddr::IP qw/:rfc3021 :lower/;
use App::Netdisco::JobQueue 'jq_insert';
use App::Netdisco::Util::Device 'delete_device';
use App::Netdisco::Util::Device qw/delete_device renumber_device/;
sub add_job {
my ($action, $device, $subaction) = @_;
@@ -46,6 +46,21 @@ foreach my $action (@{ setting('job_prio')->{high} },
};
}
ajax qr{/ajax/control/admin/(?:\w+/)?renumber} => require_role setting('defanged_admin') => sub {
send_error('Missing device', 400) unless param('device');
send_error('Missing new IP', 400) unless param('newip');
my $device = NetAddr::IP->new(param('device'));
send_error('Bad device', 400)
if ! $device or $device->addr eq '0.0.0.0';
my $newip = NetAddr::IP->new(param('newip'));
send_error('Bad new IP', 400)
if ! $newip or $newip->addr eq '0.0.0.0';
return renumber_device( $device->addr, $newip->addr );
};
ajax qr{/ajax/control/admin/(?:\w+/)?delete} => require_role setting('defanged_admin') => sub {
send_error('Missing device', 400) unless param('device');

View File

@@ -219,6 +219,11 @@ td > form.nd_inline-form {
margin-bottom: 2px;
}
/* pull right admin buttons in the device details view */
.nd_pull-right-admin-button {
margin-right: 4px;
}
/* fix layout of form fields inside the (pseudo devices) table */
.nd_center-cell input {
margin-bottom: 0px;

View File

@@ -201,6 +201,10 @@
<button class="btn btn-danger btn-small pull-right"
data-toggle="modal" data-target="#nd_devdel" type="button">Delete</button>
<button class="btn btn-danger btn-small pull-right nd_pull-right-admin-button"
data-toggle="modal" data-target="#nd_devrenumber" type="button">Renumber</button>
<div id="nd_devdel" class="nd_modal nd_deep-horizon modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="nd_devdel-label" aria-hidden="true">
<div class="modal-header">
@@ -227,6 +231,29 @@
<button class="btn btn-danger nd_adminbutton" name="delete" data-dismiss="modal">Confirm</button>
</div>
</div>
<div id="nd_devrenumber" class="nd_modal nd_deep-horizon modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="nd_devrenumber-label" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="nd_devrenumber-label">Confirm Renumber: [% d.dns || d.ip | html_entity %]</h3>
</div>
<div class="modal-body">
<blockquote>
<ul>
<li><p>This action is run immediately</p></li>
<li><p>No check is made as to whether the new IP is reachable</p></li>
</ul>
</blockquote>
<textarea id="nd_devrenumber-newip" class="input-block-level" rows="1" data-form="renumber"
placeholder="Enter new IP address" name="newip"></textarea>
<input type="hidden" data-form="renumber" value="[% d.ip | html_entity %]" name="device"/>
</div>
<div class="modal-footer">
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn btn-danger nd_adminbutton" name="renumber" data-dismiss="modal">Confirm</button>
</div>
</div>
</td>
</tr>
[% END %]