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-13 23:06:55.000000000 +0100 +++ smeserver-dhcpmanager-1.5/root/etc/e-smith/web/functions/dhcpd 2014-01-13 23:07:32.000000000 +0100 @@ -6,7 +6,7 @@ # navigation : 6000 6900 # # Copyright (c) 2003 Thierry Quaak thierry@quaak.net -# +# 2014 Stephane de Labrusse stephdl@de-labrusse.fr #---------------------------------------------------------------------- ###Set NameSpace of Panel @@ -37,8 +37,12 @@ sub Message ($$); sub Global_WinPopup ($); sub Perform_Message ($); -sub Table_IP ($); +sub Table_IP ($$); sub Scan_Local_Network ($); +sub Del_all_Lease ($); +sub Perform_del_all_Lease ($); +sub Save_checkip ($); + ### 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. @@ -75,7 +79,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"){Table_IP ($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);} @@ -84,9 +88,11 @@ 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 "Connected IP"){Table_IP ($q,'');} elsif ($q->param ('state') eq "Scan your Network"){Scan_Local_Network ($q);} - +elsif ($q->param ('state') eq "Remove all entries"){Del_all_Lease ($q);} +elsif ($q->param ('state') eq "Remove all dhcp leases"){Perform_del_all_Lease ($q);} +elsif ($q->param ('state') eq 'Save/Restart'){Save_checkip ($q);} else{esmith::cgi::genStateError ($q, \%conf);} exit (0); @@ -127,30 +133,30 @@ #print $q->h3 ('Managing DHCP clients...'); print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, - esmith::cgi::genWidgetRow ($q, "Always check status of computers in the panel \"Connected IP\" (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. Use Save/Restart below to activate your changes) ", $q->popup_menu (-name => 'dhcp_check', -values => ['disabled', 'enabled'], -default => $sme_conf{'check'}, -labels => \%check)) ); - # Go to see table connected ip + #see table connected ip -> Table_ip #print $q->p ; print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, esmith::cgi::genTextRow ($q, - $q->p ('You may want to see all connected computer to the dhcpd server ?'))); + $q->p ('Show all devices connected to the dhcp server :'))); print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Connected IP'))); - # Go to scan the local network + # scan the local network with nmap #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 ?'))); + $q->p ('Scan your network to show active devices :'))); 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 compatible with Net send protocol ?'))); + $q->p ('Send a global WinPopup with Net send protocol to all connected devices using a compatible client'))); 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"); @@ -284,8 +290,8 @@ 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 @@ -418,21 +424,9 @@ # - 4 expand templates # changed to new sme standard signal-event - #system ("/sbin/e-smith/expand-template", "/etc/dhcpd.conf", "") == 0 ; - - ###Rebuild spamassassin hooks into procmail and restart deamon - #system ("/etc/e-smith/events/actions/restart-dhcpd") == 0 - #or die ("Error occurred while restarting dhcpd.\n"); - #system ("/etc/init.d/dhcpd","restart") == 0 system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 or die ("Error occurred while restarting dhcpd.\n"); - ###Display processed message - 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" . - " main DHCPd panel.\n"); - esmith::cgi::genFooter ($q); + Main_Display($q, "Successfully saved settings" ); exit; } @@ -510,21 +504,17 @@ close(OUTFILE); # changed to new sme standard signal-event - ###Rebuild spamassassin hooks into procmail and restart deamon - #system ("/etc/e-smith/events/actions/restart-dhcpd") == 0 - #or die ("Error occurred while restarting dhcpd.\n"); - #system ("/etc/init.d/dhcpd","restart") == 0 - #or die ("Error occurred while restarting dhcpd.\n"); - system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 + system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 or die ("Error occurred while restarting dhcpd.\n"); ###Return action message - Main_Display($q, "Successfully deleted $name at $ip in dhcpd.leases. " ); + #Main_Display($q, "Successfully deleted $name at $ip in dhcpd.leases. " ); + Table_IP($q, "Successfully deleted $name at $ip in dhcpd.leases. " ); exit; } #=============================================================================== -#SUBROUTINE: procedure qui supprime un bail dans le dhcpd.leases +#SUBROUTINE: procedure qui valide les parametres de l'host eteint #=============================================================================== sub Wake_Up ($){ ###Pull CGI object from parameters array @@ -574,9 +564,9 @@ #Send Wake Up to the station #Old version obsolete since 1.5.0 - system ("/usr/bin/wol","$mac") ; system ("/sbin/ether-wake","$mac") ; - ###Return action message - Main_Display($q, "Successfully request to wake up $name at $mac . The computer may take time to wake up. " ); + #Main_Display($q, "Successfully request to wake up $name at $mac . The computer may take time to wake up. " ); + Table_IP($q, "Successfully request to wake up $name at $mac . The computer may take time to wake up. "); exit; } @@ -635,7 +625,8 @@ $work_line =~ s/^;//; $work_line =~ s/"//g; $work_line =~ s/;$//; - push(@liste_computer,$work_line) ; + push(@liste_computer,$work_line) ; + @liste_computer= sort(@liste_computer); } } close(FILE); @@ -692,12 +683,13 @@ foreach (@liste_connected){ system ("/etc/e-smith/events/actions/send-message","$_","$message2send") ; } - Main_Display($q, "Successfully sent message popup to @liste_connected. Warning, there is no garanty that the popup will appear on the remote computer. " ); + #Main_Display($q, "Successfully sent message popup to @liste_connected. Warning, there is no garanty that the popup will appear on the remote computer. " ); + Table_IP($q, "Successfully sent message popup to @liste_connected. Warning, there is no garanty that the popup will appear on the remote computer. " ); exit; } #=============================================================================== -#SUBROUTINE: +#SUBROUTINE: Win Popup for all connected hosts #=============================================================================== sub Global_WinPopup($){ @@ -708,9 +700,9 @@ } #=============================================================================== -#SUBROUTINE: Perform Table_IP of dhcp server +#SUBROUTINE: Create Table_IP of dhcp server #=============================================================================== -sub Table_IP ($) { +sub Table_IP ($$) { ###Pull cgi object from parameters array my $q = shift; my @computer; @@ -739,32 +731,39 @@ 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) ", + esmith::cgi::genWidgetRow ($q, "Always check status of computers in the panel (No is much faster. Use Save/Restart below to activate your changes) ", $q->popup_menu (-name => 'dhcp_check', -values => ['disabled', 'enabled'], -default => $sme_conf{'check'}, -labels => \%check)) ); + + ##save checkip ('Saving modification and restart the daemon...') and go to sub Save_checkip :) + #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 IP setting above, you must save and' . + ' restart dhcpd.'))); + + print $q->Tr (esmith::cgi::genButtonRow ($q, + $q->submit (-name => 'state', -value => 'Save/Restart'))); + # 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 ?'))); + $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.'))); + $q->p ('You may want to clean all dhcp leases below ?'))) ; + print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Remove all entries'))); + - 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"); @@ -774,13 +773,15 @@ 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 ( '
' . 'Status - click for WOL')), 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:: +##it is possible you may adapt array number if more options/lines are added to the dhcpd.leases +##symptoms are a blank line in Table_IP foreach (@liste_computer){ @computer = split(/;/, $_) ; if ( $computer[0] ) { @@ -789,7 +790,7 @@ 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...') ; + $computer[9]}, 'Not Checked...') ; if ( $sme_conf{'check'} =~ /enabled/ ) { use Net::Ping; my($ping_obj) = Net::Ping->new("icmp"); @@ -800,7 +801,7 @@ $computer[6] = substr($computer[6],0,5); if ($ping_obj->ping("$computer[0]")) { push(@liste_connected,$computer[9]) ; - $status = "ON" ; + $status = "Active Device" ; #alimentation de la liste des connecté } else { $status = $q->a ({href => $q->url (-absolute => 1) . @@ -814,7 +815,7 @@ } print $q->Tr (esmith::cgi::genSmallCell ($q, "$computer[0]"), esmith::cgi::genSmallCell ($q, "$computer[9]"), - esmith::cgi::genSmallCell ($q, "$status" ), + esmith::cgi::genSmallCell ($q, "
" ."$status" ), esmith::cgi::genSmallCell ($q, "
" . "$datedeb" . "
"), esmith::cgi::genSmallCell ($q, "
" . "$datefin" . "
"), esmith::cgi::genSmallCell ($q, "$computer[8]"), @@ -839,7 +840,81 @@ esmith::cgi::genFooter ($q); exit; } +# +#=============================================================================== +#SUBROUTINE: procedure qui sauve le checkip de la subroutine Table_ip +#=============================================================================== +sub Save_checkip ($){ + + ##Pull CGI object from parameters array + my $q = shift; + + ###Build Hash of config parameters to update from cgi submit + my $dhcpd_check = $q->param ('dhcp_check'); + + ##Initiate get method --> create record object + my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); + + my $sme_record = $dbh_sme->get('dhcpd'); + + $sme_record->set_prop('check' , $dhcpd_check); + + system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 + or die ("Error occurred while restarting dhcpd.\n"); + Table_IP($q, "Successfully saved checkip status " ); + exit; +} +# +#=============================================================================== +#SUBROUTINE: procedure qui supprime tous les bail dans le dhcpd.leases +#=============================================================================== +sub Del_all_Lease ($){ + ###Pull CGI object from parameters array + $q = shift; + + ###Start Panel. + esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Removing all DHCP Lease'); + print $q->h3('Remove all entries in dhcpd.leases may cause issues'); + + print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1)); + + + + print $q->p (" The lease file is a log-structured file - whenever a lease changes, the + contents of that lease are written to the end of the file. "); + print $q->p ("This means that it is entirely possible for there to be two + or more declarations of the same lease in the lease file at the same + time."); + print $q->p ("In that case, the instance of that particular lease that + appears last in the file is the one that is in effect."); + + print $q->p ($q->b ("Are you sure ?")); + print $q->submit (-name => 'state', -value => 'Remove all dhcp leases'); + + print $q->p("Click Here to return to" . + " main DHCPd panel.\n"); + + print $q->endform; + esmith::cgi::genFooter ($q); + return; + +} +# +#=============================================================================== +#SUBROUTINE: supprime tous les bail dans le dhcpd.leases +#=============================================================================== +sub Perform_del_all_Lease ($){ + + system ('/bin/echo "" > /var/lib/dhcpd/dhcpd.leases') ==0 + or die ("Error occurred while removing all leases"); + + system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 + or die ("Error occurred while restarting dhcpd.\n"); + + Table_IP($q, "Successfully deleted all entries in dhcpd.leases. " ); + exit; +} #=============================================================================== #SUBROUTINE: Scan The Local Network @@ -850,7 +925,9 @@ 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'); - + +#we start to calculate the method to find the cidr (we want to use network/cidr with nmap) + sub dec2bin { my $str = unpack("B32", pack("N", shift)); return $str; @@ -881,14 +958,15 @@ return $cidr; } - +#Then lets go to calculate the cidr my $cidr = netmask2cidr($mask, $network); - + +#ok go to use nmap with nmap -T4 -sP network/cidr 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'`) { + foreach (`/usr/bin/nmap -T4 -sP $cidr| /bin/grep -E "scan|done"| /bin/sed -e 's/Nmap scan/- Scan/g'|/bin/sed -e 's/done/Done/g'|/bin/sed -e 's/Nmap//g'`) { print $q->br($_);}