diff options
author | Mark Wells <mark@freeside.biz> | 2013-12-10 20:08:43 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-12-10 20:08:43 -0800 |
commit | a4c1077430ac3b053c30084dcf76c54be45dca08 (patch) | |
tree | 2f225a7519cc9f0f83b4b7b99986b99cdb37f2e3 /httemplate | |
parent | c27f80ec10180391d00286bf50dfbf09a96c1b00 (diff) |
Designate forbidden address ranges, #25530
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/addr_range.html | 66 | ||||
-rw-r--r-- | httemplate/edit/addr_range.html | 27 | ||||
-rw-r--r-- | httemplate/edit/elements/edit.html | 21 | ||||
-rw-r--r-- | httemplate/edit/process/addr_range.html | 22 | ||||
-rw-r--r-- | httemplate/elements/menu.html | 4 | ||||
-rw-r--r-- | httemplate/misc/delete-addr_range.html | 21 |
6 files changed, 161 insertions, 0 deletions
diff --git a/httemplate/browse/addr_range.html b/httemplate/browse/addr_range.html new file mode 100644 index 000000000..d657f32ec --- /dev/null +++ b/httemplate/browse/addr_range.html @@ -0,0 +1,66 @@ +<& elements/browse.html, + 'title' => 'Address Ranges', + 'name_singular' => 'address range', + 'html_init' => $html_init, + 'html_foot' => $html_foot, + 'query' => { 'table' => 'addr_range', + 'order_by' => $order_by, + }, + 'count_query' => "SELECT count(*) from addr_range", + 'header' => [ 'From', + '', # the dash + 'To', + 'Status', + # would be nice to show whether any addresses in the + # range are assigned, but that's ugly + ], + 'fields' => [ 'start', + sub { '–' }, + 'end', + 'desc', + ], + 'links' => [ + [ '#' ], + '', + [ '#' ], + ], + 'link_onclicks' => [ $edit_link, + '', + $edit_link, + '', + ], +&> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration'); +# addr_ranges are ALWAYS global, else there will be chaos + +my $order_by = "ORDER BY inet(start)"; # Pg-ism +# though we could also make the field itself inet-type... +# this would simplify a lot of things. + +my $html_init = include('/elements/error.html'); + +my $edit_link = sub { + my $addr_range = shift; + include('/elements/popup_link_onclick.html', + action => $p.'edit/addr_range.html?rangenum='. + $addr_range->rangenum, + actionlabel => 'Edit address range', + width => 650, + height => 420, + ); +}; + +my $add_link = include('/elements/popup_link_onclick.html', + action => $p.'edit/addr_range.html', + actionlabel => 'Edit address range', + width => 650, + height => 420, +); + +my $html_foot = qq!<A HREF="#" onclick="$add_link"> +<I>Add a new address range</I></A>!; + +</%init> diff --git a/httemplate/edit/addr_range.html b/httemplate/edit/addr_range.html new file mode 100644 index 000000000..68efa5d79 --- /dev/null +++ b/httemplate/edit/addr_range.html @@ -0,0 +1,27 @@ +<& elements/edit.html, + 'name_singular' => 'address range', + 'popup' => 1, + 'table' => 'addr_range', + 'labels' => { 'start' => 'From', + 'end' => 'To', + 'status' => 'Status', + 'rangenum'=> 'Range', + }, + 'fields' => [ 'start', + 'end', + { field => 'status', + type => 'select', + labels => \%FS::addr_range::status_desc, + options => [ sort { $a cmp $b } + keys(%FS::addr_range::status_desc) ], + disable_empty => 1, + }, + ], + 'delete_url' => $p.'misc/delete-addr_range.html', +&> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration'); + +</%init> diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 9e27f2a4c..16d0817eb 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -108,6 +108,9 @@ Example: # overrides default popurl(1)."process/$table.html" 'post_url' => popurl(1).'process/something', + # optional link to delete this object; primary key will be appended + 'delete_url' => $p.'misc/delete-something.html?', + #we're in a popup (no title/menu/searchboxes) 'popup' => 1, @@ -211,6 +214,7 @@ Example: % ); % } + <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html', $title, include( '/elements/menubar.html', @menubar ), @@ -773,6 +777,23 @@ Example: : "Add ". ($opt{'name'} || $opt{'name_singular'}) %>" > +% if ( $opt{'delete_url'} and $object->get($pkey) ) { +% my $delete_msg = 'Delete this '. +% ($opt{'name_singular'} || $opt{'name'}); +% my $delete_url = $opt{'delete_url'}; +% $delete_url .= '?' unless $delete_url =~ /\?/; +% $delete_url .= $object->get($pkey); + <SCRIPT TYPE="text/javascript"> + function confirm_delete() { + if(confirm(<% $delete_msg . '?' |js_string %>)) { + window.location.href = <% $delete_url |js_string %>; + } + } + </SCRIPT> + <INPUT TYPE = "button" + VALUE = "<% $delete_msg |h %>" + onclick = "confirm_delete()"> +% } % } </FORM> diff --git a/httemplate/edit/process/addr_range.html b/httemplate/edit/process/addr_range.html new file mode 100644 index 000000000..6b05d23a5 --- /dev/null +++ b/httemplate/edit/process/addr_range.html @@ -0,0 +1,22 @@ +<& elements/process.html, + 'table' => 'addr_range', + 'popup_reload' => 'Address range changed', + 'precheck_callback' => sub { + my ($cgi) = @_; + my $start = NetAddr::IP->new($cgi->param('start'), 0) + or return 'Illegal or empty (IP address) start: '.$cgi->param('start'); + if ( length($cgi->param('end')) ) { + my $end = NetAddr::IP->new($cgi->param('end'), 0) + or return 'Illegal or empty (IP address) end: '.$cgi->param('end'); + if ( $end < $start ) { + ($start, $end) = ($end, $start); + $cgi->param('end', $end->addr); + $cgi->param('start', $start->addr); + } + $cgi->param('length', $end - $start + 1); + } else { + $cgi->param('length', 1); + } + ''; + }, +&> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index b4fff2285..2ae216c5c 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -508,6 +508,10 @@ tie my %config_broadband, 'Tie::IxHash', 'Routers' => [ $fsurl.'browse/router.cgi', 'Broadband access routers' ], 'Address blocks' => [ $fsurl.'browse/addr_block.cgi', 'Manage address blocks and block assignments to broadband routers' ], ; +if ( $curuser->access_right('Broadband global configuration') ) { + $config_broadband{'Address ranges'} = + [ $fsurl.'browse/addr_range.html', 'Designate special address ranges' ]; +} tie my %config_phone, 'Tie::IxHash', 'View/Edit phone device types' => [ $fsurl.'browse/part_device.html', 'Phone device types' ], diff --git a/httemplate/misc/delete-addr_range.html b/httemplate/misc/delete-addr_range.html new file mode 100644 index 000000000..c6310e9b1 --- /dev/null +++ b/httemplate/misc/delete-addr_range.html @@ -0,0 +1,21 @@ +% if ( $error ) { +<& /elements/errorpage-popup.html, $error &> +% } else { +<& /elements/header-popup.html, "Address range deleted" &> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> +</BODY> +</HTML> +% } +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Broadband global configuration'); + +my ($rangenum) = $cgi->keywords; +$rangenum =~ /^\d+$/ or die "bad rangenum '$rangenum'"; +my $addr_range = FS::addr_range->by_key($rangenum); +die "unknown rangenum $rangenum" unless $addr_range; +my $error = $addr_range->delete; +</%init> |