diff -Nur smeserver-dhcpmanager-1.5-old/root/etc/e-smith/web/functions/dhcpd smeserver-dhcpmanager-1.5/root/etc/e-smith/web/functions/dhcpd
--- smeserver-dhcpmanager-1.5-old/root/etc/e-smith/web/functions/dhcpd 2014-01-03 23:18:37.000000000 +0100
+++ smeserver-dhcpmanager-1.5/root/etc/e-smith/web/functions/dhcpd 2014-01-05 12:38:35.000000000 +0100
@@ -23,7 +23,8 @@
use esmith::AccountsDB;
use esmith::FormMagick;
use Net::Ping;
-
+use esmith::util::network qw(:all);
+use Socket qw( inet_aton );
###Declare function prototypes
sub Main_Display ($$);
@@ -36,7 +37,8 @@
sub Message ($$);
sub Global_WinPopup ($);
sub Perform_Message ($);
-
+sub Table_IP ($);
+sub Scan_Local_Network ($);
### Clear PATH and related environment variables so that calls to
### external programs do not cause results to be tainted. See
### "perlsec" manual page for details.
@@ -73,7 +75,7 @@
my $q = new CGI;
if (! grep (/^state$/, $q->param)){ Main_Display($q, '');}
elsif ($q->param ('state') eq "main_display"){Main_Display ($q,'');}
-elsif ($q->param ('state') eq "Refresh"){Main_Display ($q,'');}
+elsif ($q->param ('state') eq "Refresh"){Table_IP ($q);}
elsif ($q->param ('state') eq "main_save"){Main_Save ($q);}
elsif ($q->param ('state') eq "del_lease"){Del_Lease ($q);}
elsif ($q->param ('state') eq "perform_del_lease"){Perform_Del_Lease ($q);}
@@ -82,6 +84,9 @@
elsif ($q->param ('state') eq "Global WinPopup"){Global_WinPopup ($q);}
elsif ($q->param ('state') eq "message"){Message ($q,'');}
elsif ($q->param ('state') eq "perform_message"){Perform_Message ($q);}
+elsif ($q->param ('state') eq "Connected IP"){Table_IP ($q);}
+elsif ($q->param ('state') eq "Scan your Network"){Scan_Local_Network ($q);}
+
else{esmith::cgi::genStateError ($q, \%conf);}
exit (0);
@@ -118,90 +123,34 @@
print $q->p ('');
print $q->startform (-method => 'POST',
-action => $q->url (-absolute => 1));
- print $q->hr;
- print $q->h3 ('Managing DHCP clients...');
+ #print $q->hr;
+ #print $q->h3 ('Managing DHCP clients...');
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
- esmith::cgi::genWidgetRow ($q, "Always check status in the manager (No is much faster, need Save/Restart) ",
+ esmith::cgi::genWidgetRow ($q, "Always check status of computers in the panel \"Connected IP\" (No is much faster, need Save/Restart) ",
$q->popup_menu (-name => 'dhcp_check',
-values => ['disabled', 'enabled'],
-default => $sme_conf{'check'},
-labels => \%check)) );
- &Load_leases ($q) ;
- if ( 2 > 1 ) {
- print $q->p ($q->b (''));
- print $q->table ({border => 1, cellspacing => 1, cellpadding => 4,nowarp => 1});
- print $q->Tr (esmith::cgi::genSmallCell ($q, $q->p ( '
' . 'IP')),
- esmith::cgi::genSmallCell ($q, $q->p ( '' . 'Network Name')),
- esmith::cgi::genSmallCell ($q, $q->p ( '' . 'Status')),
- esmith::cgi::genSmallCell ($q, $q->p ( '' . 'Start Date')),
- esmith::cgi::genSmallCell ($q, $q->p ( '' . 'End Date')),
- esmith::cgi::genSmallCell ($q, $q->p ( '' . 'MAC Address' .
- '')),
- );
-##9->netbios (ancien10)::8->mac address (ancien8)::0->ip::
- foreach (@liste_computer){
- @computer = split(/;/, $_) ;
- if ( $computer[0] ) {
- my $datedeb = $computer[2] . "-" . $computer[3] ;
- my $datefin = $computer[5] . "-" . $computer[6] ;
- $status = $q->a ({href => $q->url (-absolute => 1) .
- "?state=wake_up&MAC=" . $computer[8] . "&name=" .
- $computer[9]}, 'Not checked...') ;
- if ( $sme_conf{'check'} =~ /enabled/ ) {
- use Net::Ping;
- my($ping_obj) = Net::Ping->new("icmp");
- $computer[9] = uc($computer[9]) ;
- $computer[8] = uc($computer[8]) ;
- # formatage des dates
- $computer[3] = substr($computer[3],0,5);
- $computer[6] = substr($computer[6],0,5);
- if ($ping_obj->ping("$computer[0]")) {
- push(@liste_connected,$computer[9]) ;
- $status = "ON" ;
- #alimentation de la liste des connecté
- }
- else { $status = $q->a ({href => $q->url (-absolute => 1) .
- "?state=wake_up&MAC=" . $computer[8] . "&name=" .
- $computer[9]}, 'Wake-Up...');
- }
- }
- else {
- push(@liste_connected,$computer[9]) ;
- }
- print $q->Tr (esmith::cgi::genSmallCell ($q, "$computer[0]"),
- esmith::cgi::genSmallCell ($q, "$computer[9]"),
- esmith::cgi::genSmallCell ($q, "$status" ),
- esmith::cgi::genSmallCell ($q, "" . "$datedeb" . ""),
- esmith::cgi::genSmallCell ($q, "" . "$datefin" . ""),
- esmith::cgi::genSmallCell ($q, "$computer[8]"),
- esmith::cgi::genSmallCell ($q,
- $q->a ({href => $q->url (-absolute => 1)
- . "?state=del_lease&host=" . $computer[0] . "&name=" .
- $computer[9]}, 'Remove...')),
- esmith::cgi::genSmallCell ($q,
- $q->a ({href => $q->url (-absolute => 1)
- . "?state=message&name=" . $computer[9]}, 'WinPopup...'))
- );
- }
- }
- print '';
- }
- else{
- print $q->p ($q->b ('There are no computer connected.'));
- }
- # Refresh Liste
- print $q->p ;
+ # Go to see table connected ip
+ #print $q->p ;
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
esmith::cgi::genTextRow ($q,
- $q->p ('You may want to refresh this list ?')));
- print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Refresh')));
-
+ $q->p ('You may want to see all connected computer to the dhcpd server ?')));
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Connected IP')));
+
+ # Go to scan the local network
+ #print $q->p ;
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
+ esmith::cgi::genTextRow ($q,
+ $q->p ('You may want to scan your network to know how many hosts are up ?')));
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Scan your Network')));
+
#Global Winpopup
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
esmith::cgi::genTextRow ($q,
- $q->p ('You may want to send a global WinPopup to all connected computer ?')));
+ $q->p ('You may want to send a global WinPopup to all connected computer compatible with Net send protocol ?')));
print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Global WinPopup')));
print $q->hidden (-name => 'liste_connected', -override => 1, -default => "@liste_connected");
@@ -335,41 +284,137 @@
my $dhcpd_dns2server = $q->param ('dhcp_dns2server');
my $dhcpd_gatewaycustom = $q->param ('dhcp_gatewaycustom');
my $dhcpd_gateway = $q->param ('dhcp_gateway');
-
###Update SME configuration dbase
##Create object to spammassassin dbase
my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration');
##Initiate get method --> create record object
- my $sme_record = $dbh_sme->get('dhcpd');
-
- ##Set status of service: obsolete way
-# $sme_record->set_prop('status'=>$dhcpd_status);
-# $sme_record->set_prop('check'=>$dhcpd_check);
-# $sme_record->set_prop('end'=>$dhcpd_end);
-# $sme_record->set_prop('start'=>$dhcpd_start);
-# $sme_record->set_prop('winscustom'=>$dhcpd_winscustom);
-# $sme_record->set_prop('winsserver'=>$dhcpd_winsserver);
-# $sme_record->set_prop('leasetime'=>$dhcpd_leasetime);
-# $sme_record->set_prop('dnscustom'=>$dhcpd_dnscustom);
-# $sme_record->set_prop('dns1server'=>$dhcpd_dns1server);
-# $sme_record->set_prop('dns2server'=>$dhcpd_dns2server);
-# $sme_record->set_prop('gatewaycustom'=>$dhcpd_gatewaycustom);
-# $sme_record->set_prop('gateway'=>$dhcpd_gateway);
+ my $sme_record = $dbh_sme->get('dhcpd');
+ #get localip of server
+ my $local_ip = $dbh_sme->get_value('LocalIP');
##Set status of service
$sme_record->set_prop('status', $dhcpd_status);
$sme_record->set_prop('check' , $dhcpd_check);
- $sme_record->set_prop('end', $dhcpd_end);
- $sme_record->set_prop('start', $dhcpd_start);
$sme_record->set_prop('winscustom', $dhcpd_winscustom);
- $sme_record->set_prop('winsserver', $dhcpd_winsserver);
$sme_record->set_prop('leasetime' , $dhcpd_leasetime);
$sme_record->set_prop('dnscustom' , $dhcpd_dnscustom);
- $sme_record->set_prop('dns1server' , $dhcpd_dns1server);
- $sme_record->set_prop('dns2server' , $dhcpd_dns2server);
$sme_record->set_prop('gatewaycustom' , $dhcpd_gatewaycustom);
- $sme_record->set_prop('gateway' , $dhcpd_gateway);
+
+ #checkip to the dhcpserver, perform the save in DB configuration or display an error if value != of a valid ip or if dhcp_start is greater than dhcp_end
+ if ($dhcpd_status eq "enabled")
+ {
+ if ( isValidIP ($dhcpd_start) && isValidIP ($dhcpd_end))
+ {
+ #check if $dhcpd_start is greater than $dhcpd_end and if yes, display an error message.
+ if (inet_aton($dhcpd_start) ge inet_aton($dhcpd_end))
+ {
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS');
+ print $q->h3("DHCP Server : error....Incorrect range of IPs, the DHCP Start \($dhcpd_start\) is greater than the DHCP End \($dhcpd_end\), Update unsuccessfull\n");
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }
+ elsif ( ( (inet_aton($dhcpd_start) le inet_aton($local_ip) ) && ( inet_aton($dhcpd_end)) ge inet_aton($local_ip) ) )
+ {
+ #display an error if the range of dhcp server include the ip of the server address
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS');
+ print $q->h3("DHCP Server : error....Incorrect range of IPs, the range of IP address allocation must not include the server address\($local_ip\), Update unsuccessfull\n");
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }
+ else
+ {
+ #set value
+ my $dhcpd_start = cleanIP($dhcpd_start);
+ my $dhcpd_end = cleanIP($dhcpd_end);
+
+ $sme_record->set_prop('end', $dhcpd_end);
+ $sme_record->set_prop('start', $dhcpd_start);
+ }
+ }
+ #if $dhcpd_start or $dhcpd_end are not valid ip then display an error
+ else
+ {
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS');
+ print $q->h3("DHCP Server address : error....Incorrect IP $dhcpd_start and $dhcpd_end, Update unsuccessfull\n");
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }
+ }
+
+ #checkip to the winserver perform the save in DB configuration or display an error if value != of a valid ip
+ if ($dhcpd_winscustom eq "enabled")
+ {
+
+ if ( isValidIP ($dhcpd_winsserver) )
+ {
+ #set value
+ my $dhcpd_winsserver = cleanIP($dhcpd_winsserver);
+ $sme_record->set_prop('winsserver', $dhcpd_winsserver);
+ }
+ else
+ {
+ #if $dhcpd_winsserver is not valid ip then display an error
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS');
+ print $q->h3("WINS Server address : error....Incorrect IP $dhcpd_winsserver, Update unsuccessfull\n");
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }
+ }
+
+ #checkip to the dnsserver custom, perform the save in DB configuration or display an error if value != of a valid ip
+ if ($dhcpd_dnscustom eq "enabled")
+ {
+ #check if $dhcpd_dns1server and ( $dhcpd_dns2server are valid ip or $dhcpd_dns2server = null )
+ if ( isValidIP ($dhcpd_dns1server) && (isValidIP($dhcpd_dns2server) || ( $dhcpd_dns2server eq "") ) )
+ {
+ #set value
+ my $dhcpd_dns1server = cleanIP($dhcpd_dns1server);
+ $sme_record->set_prop('dns1server' , $dhcpd_dns1server);
+ my $dhcpd_dns2server = cleanIP($dhcpd_dns2server);
+ $sme_record->set_prop('dns2server' , $dhcpd_dns2server);
+ }
+ else
+ {
+ ##if $dhcpd_dns1server or $dhcpd_dns2server are not valid ip then display an error
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS');
+ print $q->h3("Custom DNS Server address : error....Incorrect IP $dhcpd_dns1server and $dhcpd_dns2server, Update unsuccessfull\n");
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }
+ }
+
+ #checkip to the gateway_custom perform the save in DB configuration or display an error if value != of a valid ip
+ if ($dhcpd_gatewaycustom eq "enabled")
+ {
+ if ( isValidIP ($dhcpd_gateway) )
+ {
+ #set value
+ my $dhcpd_gateway = cleanIP($dhcpd_gateway);
+ $sme_record->set_prop('gateway' , $dhcpd_gateway);
+ }
+ else
+ {
+ #if $dhcpd_gateway is not valid ip then display an error
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS');
+ print $q->h3("Gateway Custom Server address : error....Incorrect IP $dhcpd_gateway, Update unsuccessfull\n");
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }
+ }
+
# - 4 expand templates
# changed to new sme standard signal-event
@@ -385,7 +430,7 @@
esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings');
print $q->h3('Operation status report...');
print $q->p("Successfully saved settings.... DHCPd restarted !\n");
-print $q->p("Click Here to return to" .
+ print $q->p("Click Here to return to" .
" main DHCPd panel.\n");
esmith::cgi::genFooter ($q);
exit;
@@ -513,7 +558,6 @@
print $q->endform;
esmith::cgi::genFooter ($q);
return;
-
}
#===============================================================================
#SUBROUTINE: Perform wake UP
@@ -574,7 +618,7 @@
#Suppression des retours chariot en fin de lignes.
chomp $_ ;
-
+
#Chargement d'un tableau avec le contenu de la ligne.
(@detail) = split(/ /, $_) ;
@@ -663,3 +707,195 @@
exit;
}
+#===============================================================================
+#SUBROUTINE: Perform Table_IP of dhcp server
+#===============================================================================
+sub Table_IP ($) {
+ ###Pull cgi object from parameters array
+ my $q = shift;
+ my @computer;
+ my $status ;
+
+ ###Pull action message, if any, from parameters array
+ my $action_message = shift;
+
+ ###Retrieve SME configuration entry for dhcpd
+ my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration');
+ my %sme_conf = $dbh_sme->get('dhcpd')->props;
+
+ ###Display Main Panel Title
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Managing DHCP clients...');
+
+ ###Check to see if we just processed a panel action. If so, display
+ ###action message and bail.
+ if ($action_message) {
+ print $q->h3 ('Operation status report...');
+ print $q->b ("$action_message");
+ }
+
+ #------------------------------------------------------------
+ # Start DHCP client Panel
+ #------------------------------------------------------------
+ print $q->p ('');
+ print $q->startform (-method => 'POST',
+ -action => $q->url (-absolute => 1));
+ #print $q->hr;
+ #print $q->h3 ('Managing DHCP clients...');
+
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
+ esmith::cgi::genWidgetRow ($q, "Always check status of connected IP in the manager (No is much faster, need Save/Restart) ",
+ $q->popup_menu (-name => 'dhcp_check',
+ -values => ['disabled', 'enabled'],
+ -default => $sme_conf{'check'},
+ -labels => \%check)) );
+ # Refresh Liste
+ #print $q->p ;
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
+ esmith::cgi::genTextRow ($q,
+ $q->p ('You may want to refresh this list ?')));
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Refresh')));
+
+ #print $q->hr;
+ #print $q->h3 ('Saving modification and restart the daemon...');
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4},
+ esmith::cgi::genTextRow ($q,
+ $q->p ('After changing the check setting above, you must save and' .
+ ' restart dhcpd.')));
+
+ print $q->Tr (esmith::cgi::genButtonRow ($q,
+ $q->submit (-name => 'action', -value => 'Save/Restart')));
+ print $q->hidden (-name => 'state', -override => 1, -default => 'main_save');
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+
+ &Load_leases ($q) ;
+ if ( 2 > 1 ) {
+ print $q->p ($q->b (''));
+ print $q->table ({border => 1, cellspacing => 1, cellpadding => 4,nowarp => 1});
+ print $q->Tr (esmith::cgi::genSmallCell ($q, $q->p ( '' . 'IP')),
+ esmith::cgi::genSmallCell ($q, $q->p ( '' . 'Network Name')),
+ esmith::cgi::genSmallCell ($q, $q->p ( '' . 'Status')),
+ esmith::cgi::genSmallCell ($q, $q->p ( '' . 'Start Date')),
+ esmith::cgi::genSmallCell ($q, $q->p ( '' . 'End Date')),
+ esmith::cgi::genSmallCell ($q, $q->p ( '' . 'MAC Address' .
+ '')),
+ );
+##9->netbios (ancien10)::8->mac address (ancien8)::0->ip::
+ foreach (@liste_computer){
+ @computer = split(/;/, $_) ;
+ if ( $computer[0] ) {
+
+ my $datedeb = $computer[2] . "-" . $computer[3] ;
+ my $datefin = $computer[5] . "-" . $computer[6] ;
+ $status = $q->a ({href => $q->url (-absolute => 1) .
+ "?state=wake_up&MAC=" . $computer[8] . "&name=" .
+ $computer[9]}, 'Not checked...') ;
+ if ( $sme_conf{'check'} =~ /enabled/ ) {
+ use Net::Ping;
+ my($ping_obj) = Net::Ping->new("icmp");
+ $computer[9] = uc($computer[9]) ;
+ $computer[8] = uc($computer[8]) ;
+ # formatage des dates
+ $computer[3] = substr($computer[3],0,5);
+ $computer[6] = substr($computer[6],0,5);
+ if ($ping_obj->ping("$computer[0]")) {
+ push(@liste_connected,$computer[9]) ;
+ $status = "ON" ;
+ #alimentation de la liste des connecté
+ }
+ else { $status = $q->a ({href => $q->url (-absolute => 1) .
+ "?state=wake_up&MAC=" . $computer[8] . "&name=" .
+ $computer[9]}, 'Wake-Up...');
+ }
+ }
+ else {
+ push(@liste_connected,$computer[9]) ;
+
+ }
+ print $q->Tr (esmith::cgi::genSmallCell ($q, "$computer[0]"),
+ esmith::cgi::genSmallCell ($q, "$computer[9]"),
+ esmith::cgi::genSmallCell ($q, "$status" ),
+ esmith::cgi::genSmallCell ($q, "" . "$datedeb" . ""),
+ esmith::cgi::genSmallCell ($q, "" . "$datefin" . ""),
+ esmith::cgi::genSmallCell ($q, "$computer[8]"),
+ esmith::cgi::genSmallCell ($q,
+ $q->a ({href => $q->url (-absolute => 1)
+ . "?state=del_lease&host=" . $computer[0] . "&name=" .
+ $computer[9]}, 'Remove...')),
+ esmith::cgi::genSmallCell ($q,
+ $q->a ({href => $q->url (-absolute => 1)
+ . "?state=message&name=" . $computer[9]}, 'WinPopup...'))
+ );
+ }
+ }
+ print '';
+ }
+ else{
+ print $q->p ($q->b ('There are no computer connected.'));
+ }
+
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+}
+
+
+#===============================================================================
+#SUBROUTINE: Scan The Local Network
+#===============================================================================
+sub Scan_Local_Network ($q) {
+
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Scanning your network, the time needed depends of your subnet mask');
+ my $nmap_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration');
+ my $mask = $nmap_sme->get_value('LocalNetmask');
+ my $network = $nmap_sme->get_prop('InternalInterface','Network');
+
+ sub dec2bin {
+ my $str = unpack("B32", pack("N", shift));
+ return $str;
+}
+
+sub netmask2cidr {
+ my ($mask, $network) = @_;
+ my @octet = split (/\./, $mask);
+ my @bits;
+ my $binmask;
+ my $binoct;
+ my $bitcount=0;
+
+ foreach (@octet) {
+ $binoct = dec2bin($_);
+ $binmask = $binmask . substr $binoct, -8;
+ }
+
+ # let's count the 1s
+ @bits = split (//,$binmask);
+ foreach (@bits) {
+ if ($_ eq "1") {
+ $bitcount++;
+ }
+ }
+
+ my $cidr = $network . "/" . $bitcount;
+ return $cidr;
+}
+
+
+ my $cidr = netmask2cidr($mask, $network);
+
+ print $q->p ;
+ print $q->h3("Your subnet appears to be $cidr and your netmask is $mask, please wait\n");
+ print $q->p ;
+
+ foreach (`/usr/bin/nmap -T4 -sP $cidr| /bin/grep -E "finished|Host"| /bin/sed -e 's/Nmap/Scanning/g'`) {
+
+ print $q->br($_);}
+
+ print $q->p ;
+
+ print $q->p("Click Here to return to" .
+ " main DHCPd panel.\n");
+ esmith::cgi::genFooter ($q);
+ exit;
+ }