Line 164: |
Line 164: |
| # name : dhcpman2, method : get, url : /dhcpman2, ctlact : Dhcpman#do_winpopup | | # name : dhcpman2, method : get, url : /dhcpman2, ctlact : Dhcpman#do_winpopup |
| # name : dhcpman3, method : get, url : /dhcpman3, ctlact : Dhcpman#do_scan | | # name : dhcpman3, method : get, url : /dhcpman3, ctlact : Dhcpman#do_scan |
− | # name : dhcpman4, method : get, url : /dhcpman4, ctlact : Dhcpman#do_del_lease | + | # name : dhcpman4, method : get, url : /dhcpman4, ctlact : Dhcpman#do_delete_lease |
− | # name : dhcpman5, method : get, url : /dhcpman5, ctlact : Dhcpman#update_config | + | # name : dhcpman5, method : get, url : /dhcpman5, ctlact : Dhcpman#do_update_config |
| # | | # |
| # routes : end | | # routes : end |
Line 174: |
Line 174: |
| | | |
| === Perl Main and sub-routines === | | === Perl Main and sub-routines === |
| + | <syntaxhighlight lang="perl"> |
| + | use strict; |
| + | use warnings; |
| + | use Mojo::Base 'Mojolicious::Controller'; |
| + | |
| + | use constant FALSE => 0; |
| + | use constant TRUE => 1; |
| + | |
| + | use Locale::gettext; |
| + | use SrvMngr::I18N; |
| + | use SrvMngr qw(theme_list init_session); |
| + | |
| + | use Data::Dumper; |
| + | use esmith::util; |
| + | use esmith::AccountsDB; |
| + | |
| + | our $db = esmith::ConfigDB->open() or die("Unable to open Configuration DB"); |
| + | our $adb = esmith::AccountsDB->open() or die("Unable to open accounts DB"); |
| + | |
| + | my %dhcp_data = (); |
| + | |
| + | </syntaxhighlight>Necessary library units are identified and Configuration databases opened and the hash to be used to communicate with the template files is initialised. |
| + | |
| + | As can be seen from the routing tables the following routines are specified to be the receipt of control depending on the web page user. |
| + | |
| + | In simplified terms these are the routines (as before currently untested):<syntaxhighlight lang="perl"> |
| + | sub main { |
| + | # |
| + | # Initial page - full summary of parameters etc |
| + | # Initial para from the Wiki. |
| + | # |
| + | my $c = shift; |
| + | $ddc_data{"first"} = 'dhcp_DESCRIPTION'; |
| + | do_display( $c, %dhcp_data ); |
| + | } |
| + | |
| + | sub do_display { |
| + | # |
| + | # Front parameters page |
| + | # |
| + | my $c = shift; |
| + | # Accumulate parameters for Configuration DB |
| + | # ..... |
| + | $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data ); |
| + | $c->render( template => 'dhcpman' ); |
| + | |
| + | sub do_leases { |
| + | # |
| + | # Show a table of the leases |
| + | # |
| + | my $c = shift; |
| + | $ddc_data{"first"} = 'dhcp_LEASES'; |
| + | $ddc_data{"leases") = get_leases_in_array(); |
| + | $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data ); |
| + | $c->render( template => 'dhcpman' ); |
| + | } |
| + | |
| + | |
| + | sub do_winpopup { |
| + | # |
| + | # call to win pop up |
| + | # |
| + | my $c = shift; |
| + | #..... get winpopup details |
| + | $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data ); |
| + | $c->render( template => 'dhcpman' ); |
| + | } |
| + | |
| + | sub do_scan { |
| + | # |
| + | # call to show scan results |
| + | # |
| + | my $c = shift; |
| + | # ..... get scan results |
| + | $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data ); |
| + | $c->render( template => 'dhcpman' ); |
| + | } |
| + | |
| + | sub do_update_config { |
| + | # |
| + | # Update config dhcp parameters |
| + | # called through form submit. |
| + | # |
| + | my $c = shift; |
| + | # Input results are in $c->param(<fieldname>). |
| + | # If parameters do not validate, then return error message. |
| + | # else write into config DB, and... |
| + | # signal-event and ...return ok |
| + | my $ret = update_config($c); |
| + | if ($ret == 'ok') do_display($c); |
| + | return |
| + | } |
| + | |
| + | sub do_delete_lease { |
| + | # |
| + | # Delete the specified lease |
| + | # Called from link in table of leases |
| + | # |
| + | my $c = shift; |
| + | # Lease in $c->param("lease") |
| + | # Validate - if not return error message |
| + | # delete it |
| + | # If deletion not ok return message |
| + | # else return "ok" |
| + | my $ret = delete_lease($c); |
| + | if ($ret == "ok") do_display($c); |
| + | return |
| + | } |
| + | |
| + | sub update_config { |
| + | my $c = shift; |
| + | #...do it |
| + | return "ok"; |
| + | } |
| + | |
| + | sub delete_lease { |
| + | my $c = shift; |
| + | # ...do it |
| + | return "ok"; |
| + | } |
| + | </syntaxhighlight> |
| | | |
| ==The Template Files (dhcpman.html.ep and partials)== | | ==The Template Files (dhcpman.html.ep and partials)== |