Changes

Jump to navigation Jump to search
Line 204: Line 204:  
use Data::Dumper;
 
use Data::Dumper;
 
use esmith::util;
 
use esmith::util;
 +
use esmith::HostsDB;
 
use esmith::AccountsDB;
 
use esmith::AccountsDB;
 
+
use Net::Ping;
our $db  = esmith::ConfigDB->open() or die("Unable to open Configuration DB");
+
use esmith::util::network qw(:all);
our %sme_conf = $db->get('dhcpd')->props;
+
use Socket qw( inet_aton );
our %smb_conf = $db->get('smb')->props;
  −
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.
 
</syntaxhighlight>Necessary library units are identified and Configuration databases opened and the hash to be used to communicate with the template files is initialised.
Line 224: Line 221:  
     #
 
     #
 
     my $c = shift;
 
     my $c = shift;
 +
    %dhcp_data = ();
 +
    #$dhcp_data{"first"} = 'dhcpd_DESCRIPTION';
 +
    do_display( $c, %dhcp_data );
 +
}
 +
 +
sub do_display {
 +
    #
 +
    # Front parameters page
 +
    #
 +
    my $c = shift;
 +
    $c->app->log->info( $c->log_req );
 +
    my $title = $c->l("dhcpd_DHCP manager");
 +
    my $modul = '';
 +
    my $trt  = "SETTINGS";
 +
our $db  = esmith::ConfigDB->open() or die("Unable to open Configuration DB");
 +
our %sme_conf = $db->get('dhcpd')->props;
 +
our %smb_conf = $db->get('smb')->props;
 +
    $dhcp_data{trt} = $trt;
 
     $dhcp_data{"status"} = [[$c->l('dhcpd_ENABLED'),'enabled'],
 
     $dhcp_data{"status"} = [[$c->l('dhcpd_ENABLED'),'enabled'],
 
                             [$c->l('dhcpd_DISABLED'),'disabled']
 
                             [$c->l('dhcpd_DISABLED'),'disabled']
Line 243: Line 258:  
$sme_conf{'gatewaycustom'} = 'disabled' ;
 
$sme_conf{'gatewaycustom'} = 'disabled' ;
 
}                           
 
}                           
    #$dhcp_data{"first"} = 'dhcpd_DESCRIPTION';
+
     # Accumulate parameters for Configuration DB
    do_display( $c, %dhcp_data );
  −
}
  −
 
  −
sub do_display {
  −
    #
  −
    # Front parameters page
  −
    #
  −
    my $c = shift;
  −
    $c->app->log->info( $c->log_req );
  −
    my $title = $c->l("dhcpd_DHCP manager");
  −
    my $modul = '';
  −
    my $trt  = "SETTINGS";
  −
    $dhcp_data{trt} = $trt;
  −
     # Accumulate parameters for Configuration DB
   
     $dhcp_data{'params'} = \%sme_conf;
 
     $dhcp_data{'params'} = \%sme_conf;
 
     $dhcp_data{'smbparams'} = \%smb_conf;   
 
     $dhcp_data{'smbparams'} = \%smb_conf;   
Line 265: Line 266:  
);
 
);
 
     $c->render( template => 'dhcpd' );
 
     $c->render( template => 'dhcpd' );
 +
}
    
sub do_leases {
 
sub do_leases {
Line 271: Line 273:  
#
 
#
 
my $c = shift;
 
my $c = shift;
     my $title = $c->l("dhcp_MANAGING_DHCP_CLIENT");
+
     my $title = $c->l("dhcpd_MANAGING_DHCP_CLIENT");
 
     my $modul = '';
 
     my $modul = '';
    my $trt  = "LEASES";
+
    my $trt  = "LEASES";
 
     $dhcp_data{trt} = $trt;
 
     $dhcp_data{trt} = $trt;
 
     $dhcp_data{"first"} = '';
 
     $dhcp_data{"first"} = '';
     $dhcp_data{"leases"} = get_leases_in_array();
+
     my @leases = get_leases_in_array($c);
     $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data );
+
    #print dumper @leases;
 +
    #$dhcp_data{"leases"} = \@leases;
 +
     $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data, leases=> \@leases );
 
     $c->render( template => 'dhcpd' );
 
     $c->render( template => 'dhcpd' );
 
}
 
}
     −
sub do_winpopup {
  −
#
  −
# call to win pop up
  −
#
  −
my $c = shift;
  −
    my $title = $c->l("dhcp_GLOBAL_WINPOPUP");
  −
    my $modul = '';
  −
    my $trt  = "WINPOPUP";
  −
    $dhcp_data{trt} = $trt;
  −
    $dhcp_data{"first"} = '';
  −
#..... get winpopup details
  −
    $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data );
  −
    $c->render( template => 'dhcpd' );
  −
}
  −
  −
sub do_scan {
  −
#
  −
# call to show scan results
  −
#
  −
my $c = shift;
  −
    my $title = $c->l("dhcp_SCANNING_NETWORK_TITLE");
  −
    my $modul = '';
  −
    my $trt  = "NETSCAN";
  −
    $dhcp_data{trt} = $trt;
  −
    $dhcp_data{"first"} = '';
  −
# ..... get scan results into dhcp_data
  −
dhcp_data{"scanresults"} = get_scan_results($c);
  −
    $c->stash( title => $title, modul => $modul, dhcp_data => \%dhcp_data );
  −
    $c->render( template => 'dhcpd' );
  −
}
  −
   
sub do_update_config {
 
sub do_update_config {
 
#
 
#
Line 323: Line 295:  
# else write into config DB, and...
 
# else write into config DB, and...
 
# signal-event and ...return ok
 
# signal-event and ...return ok
my $ret = update_config($c);
+
$dhcp_data{"success"} ="";
if ($ret == 'ok') {
+
my $ret = Main_Save($c);
dhcp_data{"success"}="dhcp_CONFIG_SAVED_OK";
+
if ($ret eq 'ok') {  
do_leases($c);
+
$dhcp_data{"success"}="dhcpd_SUCCESSFULLY_SAVED_SETTINGS";
}
+
} else {
else {dhcp_data{"error"}=$ret;}
+
$dhcp_data{"error"}=$ret;
    return ;
+
}
}
+
do_display($c);
 
  −
sub do_delete_all_leases {
  −
#
  −
# Delete all the specified lease
  −
# Called from button at top of leases list panel
  −
#
  −
my $c = shift;
  −
    my $ret = delete_all_leases($c);
  −
if ($ret == 'ok') {  
  −
dhcp_data{"success"}="dhcp_CONFIG_SAVED_OK";
  −
do_leases($c);
  −
}
  −
else {dhcp_data{"error"}=$ret;}
   
     return ;
 
     return ;
 
}
 
}
   −
sub do_delete_one_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') {
  −
dhcp_data{"success"}="dhcp_CONFIG_SAVED_OK";
  −
do_leases($c);
  −
}
  −
else {dhcp_data{"error"}=$ret;}
  −
    return ;
  −
}
  −
  −
sub update_config {
  −
my $c = shift;
  −
#...do it
  −
return "ok";
  −
}
  −
  −
sub delete_one_lease {
  −
my $c = shift;
  −
    # ...do it
  −
    return "ok";
  −
}
  −
  −
sub delete_all_leases {
  −
my $c = shift;
  −
    # ...do it
  −
    return "ok";
  −
}
  −
  −
sub get_leases_in_array {
  −
my $c = shift;
  −
my @leases = [];
  −
    # ...do it
  −
    return @leases;
  −
}
  −
  −
sub winpopup{
  −
my $c = shift;
  −
# Message in $c->param("winpopupmsg")
  −
    # .... do it
  −
    return "ok";
  −
}
  −
  −
1;
   
</syntaxhighlight>
 
</syntaxhighlight>
   Line 737: Line 643:     
=== The .lex File ===
 
=== The .lex File ===
 +
The .lex file (dhcpd_en.lex) contains just the mappings between the language independant messages and the actual messages (in this case in English):<syntaxhighlight lang="text">
 +
'dhcpd_DHCP manager' =>
 +
'DHCP Manager',
 +
'dhcpd_DHCPD_TITLE' =>
 +
'DHCP Manager',
 +
'dhcpd_DHCPD_SETTINGS_TITLE' =>
 +
'Settings of the DHCP server',
 +
'dhcpd_CONNECTED_IP' =>
 +
'Show DHCP Clients',
 +
'dhcpd_SCAN_YOUR_NETWORK' =>
 +
'Scan your network',
 +
'dhcpd_GLOBAL_WINPOPUP' =>
 +
'Send Global Netsend WinPopup',
 +
'dhcpd_CHECK_CLIENT_STATUS' =>
 +
'Always check the status of computers (Disabled is much faster)',
 +
 +
</syntaxhighlight>
    
=== The .pm File ===
 
=== The .pm File ===
 +
The corresponding .pm file is created by the installation procedure (see below).<syntaxhighlight lang="perl">
 +
package SrvMngr::I18N::Modules::Dhcpd::en;
 +
use strict;
 +
use warnings;
 +
use utf8;
 +
use Mojo::Base 'SrvMngr::I18N';
 +
 +
use SrvMngr::I18N::Modules::General::en;
 +
 +
my %lexicon = (
 +
'dhcpd_DHCP manager' =>
 +
'DHCP Manager',
 +
'dhcpd_DHCPD_TITLE' =>
 +
'DHCP Manager',
 +
'dhcpd_DHCPD_SETTINGS_TITLE' =>
 +
'Settings of the DHCP server',
 +
'dhcpd_CONNECTED_IP' =>
 +
'Show DHCP Clients',
 +
'dhcpd_SCAN_YOUR_NETWORK' =>
 +
'Scan your network',
 +
'dhcpd_GLOBAL_WINPOPUP' =>
 +
'Send Global Netsend WinPopup',
 +
'dhcpd_CHECK_CLIENT_STATUS' =>
 +
'Always check the status of computers (Disabled is much faster)',
 +
 +
</syntaxhighlight>The file is genuine perl and forms part of the program code for the package.
    
== (Re)Building the RPM==
 
== (Re)Building the RPM==

Navigation menu