1 |
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 |
2 |
--- smeserver-dhcpmanager-1.5-old/root/etc/e-smith/web/functions/dhcpd 2014-01-13 23:06:55.000000000 +0100 |
3 |
+++ smeserver-dhcpmanager-1.5/root/etc/e-smith/web/functions/dhcpd 2014-01-13 23:07:32.000000000 +0100 |
4 |
@@ -6,7 +6,7 @@ |
5 |
# navigation : 6000 6900 |
6 |
# |
7 |
# Copyright (c) 2003 Thierry Quaak thierry@quaak.net |
8 |
-# |
9 |
+# 2014 Stephane de Labrusse stephdl@de-labrusse.fr |
10 |
#---------------------------------------------------------------------- |
11 |
|
12 |
###Set NameSpace of Panel |
13 |
@@ -37,8 +37,12 @@ |
14 |
sub Message ($$); |
15 |
sub Global_WinPopup ($); |
16 |
sub Perform_Message ($); |
17 |
-sub Table_IP ($); |
18 |
+sub Table_IP ($$); |
19 |
sub Scan_Local_Network ($); |
20 |
+sub Del_all_Lease ($); |
21 |
+sub Perform_del_all_Lease ($); |
22 |
+sub Save_checkip ($); |
23 |
+ |
24 |
### Clear PATH and related environment variables so that calls to |
25 |
### external programs do not cause results to be tainted. See |
26 |
### "perlsec" manual page for details. |
27 |
@@ -75,7 +79,7 @@ |
28 |
my $q = new CGI; |
29 |
if (! grep (/^state$/, $q->param)){ Main_Display($q, '');} |
30 |
elsif ($q->param ('state') eq "main_display"){Main_Display ($q,'');} |
31 |
-elsif ($q->param ('state') eq "Refresh"){Table_IP ($q);} |
32 |
+elsif ($q->param ('state') eq "Refresh"){Table_IP ($q, '');} |
33 |
elsif ($q->param ('state') eq "main_save"){Main_Save ($q);} |
34 |
elsif ($q->param ('state') eq "del_lease"){Del_Lease ($q);} |
35 |
elsif ($q->param ('state') eq "perform_del_lease"){Perform_Del_Lease ($q);} |
36 |
@@ -84,9 +88,11 @@ |
37 |
elsif ($q->param ('state') eq "Global WinPopup"){Global_WinPopup ($q);} |
38 |
elsif ($q->param ('state') eq "message"){Message ($q,'');} |
39 |
elsif ($q->param ('state') eq "perform_message"){Perform_Message ($q);} |
40 |
-elsif ($q->param ('state') eq "Connected IP"){Table_IP ($q);} |
41 |
+elsif ($q->param ('state') eq "Connected IP"){Table_IP ($q,'');} |
42 |
elsif ($q->param ('state') eq "Scan your Network"){Scan_Local_Network ($q);} |
43 |
- |
44 |
+elsif ($q->param ('state') eq "Remove all entries"){Del_all_Lease ($q);} |
45 |
+elsif ($q->param ('state') eq "Remove all dhcp leases"){Perform_del_all_Lease ($q);} |
46 |
+elsif ($q->param ('state') eq 'Save/Restart'){Save_checkip ($q);} |
47 |
else{esmith::cgi::genStateError ($q, \%conf);} |
48 |
exit (0); |
49 |
|
50 |
@@ -127,30 +133,30 @@ |
51 |
#print $q->h3 ('Managing DHCP clients...'); |
52 |
|
53 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
54 |
- esmith::cgi::genWidgetRow ($q, "Always check status of computers in the panel \"Connected IP\" (No is much faster, need Save/Restart) ", |
55 |
+ 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) ", |
56 |
$q->popup_menu (-name => 'dhcp_check', |
57 |
-values => ['disabled', 'enabled'], |
58 |
-default => $sme_conf{'check'}, |
59 |
-labels => \%check)) ); |
60 |
|
61 |
- # Go to see table connected ip |
62 |
+ #see table connected ip -> Table_ip |
63 |
#print $q->p ; |
64 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
65 |
esmith::cgi::genTextRow ($q, |
66 |
- $q->p ('You may want to see all connected computer to the dhcpd server ?'))); |
67 |
+ $q->p ('Show all devices connected to the dhcp server :'))); |
68 |
print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Connected IP'))); |
69 |
|
70 |
- # Go to scan the local network |
71 |
+ # scan the local network with nmap |
72 |
#print $q->p ; |
73 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
74 |
esmith::cgi::genTextRow ($q, |
75 |
- $q->p ('You may want to scan your network to know how many hosts are up ?'))); |
76 |
+ $q->p ('Scan your network to show active devices :'))); |
77 |
print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Scan your Network'))); |
78 |
|
79 |
#Global Winpopup |
80 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
81 |
esmith::cgi::genTextRow ($q, |
82 |
- $q->p ('You may want to send a global WinPopup to all connected computer compatible with Net send protocol ?'))); |
83 |
+ $q->p ('Send a global WinPopup with Net send protocol to all connected devices using a compatible client'))); |
84 |
print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Global WinPopup'))); |
85 |
print $q->hidden (-name => 'liste_connected', -override => 1, -default => "@liste_connected"); |
86 |
|
87 |
@@ -284,8 +290,8 @@ |
88 |
my $dhcpd_dns2server = $q->param ('dhcp_dns2server'); |
89 |
my $dhcpd_gatewaycustom = $q->param ('dhcp_gatewaycustom'); |
90 |
my $dhcpd_gateway = $q->param ('dhcp_gateway'); |
91 |
+ |
92 |
###Update SME configuration dbase |
93 |
- ##Create object to spammassassin dbase |
94 |
my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); |
95 |
|
96 |
##Initiate get method --> create record object |
97 |
@@ -418,21 +424,9 @@ |
98 |
|
99 |
# - 4 expand templates |
100 |
# changed to new sme standard signal-event |
101 |
- #system ("/sbin/e-smith/expand-template", "/etc/dhcpd.conf", "") == 0 ; |
102 |
- |
103 |
- ###Rebuild spamassassin hooks into procmail and restart deamon |
104 |
- #system ("/etc/e-smith/events/actions/restart-dhcpd") == 0 |
105 |
- #or die ("Error occurred while restarting dhcpd.\n"); |
106 |
- #system ("/etc/init.d/dhcpd","restart") == 0 |
107 |
system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 |
108 |
or die ("Error occurred while restarting dhcpd.\n"); |
109 |
- ###Display processed message |
110 |
- esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings'); |
111 |
- print $q->h3('Operation status report...'); |
112 |
- print $q->p("Successfully saved settings.... DHCPd restarted !\n"); |
113 |
- print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
114 |
- " main DHCPd panel.\n"); |
115 |
- esmith::cgi::genFooter ($q); |
116 |
+ Main_Display($q, "Successfully saved settings" ); |
117 |
exit; |
118 |
} |
119 |
|
120 |
@@ -510,21 +504,17 @@ |
121 |
close(OUTFILE); |
122 |
|
123 |
# changed to new sme standard signal-event |
124 |
- ###Rebuild spamassassin hooks into procmail and restart deamon |
125 |
- #system ("/etc/e-smith/events/actions/restart-dhcpd") == 0 |
126 |
- #or die ("Error occurred while restarting dhcpd.\n"); |
127 |
- #system ("/etc/init.d/dhcpd","restart") == 0 |
128 |
- #or die ("Error occurred while restarting dhcpd.\n"); |
129 |
- system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 |
130 |
+ system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 |
131 |
or die ("Error occurred while restarting dhcpd.\n"); |
132 |
###Return action message |
133 |
- Main_Display($q, "Successfully deleted <B><i>$name at $ip</i></B> in dhcpd.leases. " ); |
134 |
+ #Main_Display($q, "Successfully deleted <B><i>$name at $ip</i></B> in dhcpd.leases. " ); |
135 |
+ Table_IP($q, "Successfully deleted <B><i>$name at $ip</i></B> in dhcpd.leases. " ); |
136 |
exit; |
137 |
} |
138 |
|
139 |
|
140 |
#=============================================================================== |
141 |
-#SUBROUTINE: procedure qui supprime un bail dans le dhcpd.leases |
142 |
+#SUBROUTINE: procedure qui valide les parametres de l'host eteint |
143 |
#=============================================================================== |
144 |
sub Wake_Up ($){ |
145 |
###Pull CGI object from parameters array |
146 |
@@ -574,9 +564,9 @@ |
147 |
#Send Wake Up to the station |
148 |
#Old version obsolete since 1.5.0 - system ("/usr/bin/wol","$mac") ; |
149 |
system ("/sbin/ether-wake","$mac") ; |
150 |
- |
151 |
###Return action message |
152 |
- Main_Display($q, "Successfully request to wake up <B><i>$name at $mac</i></B> . The computer may take time to wake up. " ); |
153 |
+ #Main_Display($q, "Successfully request to wake up <B><i>$name at $mac</i></B> . The computer may take time to wake up. " ); |
154 |
+ Table_IP($q, "Successfully request to wake up <B><i>$name at $mac</i></B> . The computer may take time to wake up. "); |
155 |
exit; |
156 |
} |
157 |
|
158 |
@@ -635,7 +625,8 @@ |
159 |
$work_line =~ s/^;//; |
160 |
$work_line =~ s/"//g; |
161 |
$work_line =~ s/;$//; |
162 |
- push(@liste_computer,$work_line) ; |
163 |
+ push(@liste_computer,$work_line) ; |
164 |
+ @liste_computer= sort(@liste_computer); |
165 |
} |
166 |
} |
167 |
close(FILE); |
168 |
@@ -692,12 +683,13 @@ |
169 |
foreach (@liste_connected){ |
170 |
system ("/etc/e-smith/events/actions/send-message","$_","$message2send") ; |
171 |
} |
172 |
- Main_Display($q, "Successfully sent message popup to <B>@liste_connected</B>. Warning, there is no garanty that the popup will appear on the remote computer. " ); |
173 |
+ #Main_Display($q, "Successfully sent message popup to <B>@liste_connected</B>. Warning, there is no garanty that the popup will appear on the remote computer. " ); |
174 |
+ Table_IP($q, "Successfully sent message popup to <B>@liste_connected</B>. Warning, there is no garanty that the popup will appear on the remote computer. " ); |
175 |
exit; |
176 |
} |
177 |
|
178 |
#=============================================================================== |
179 |
-#SUBROUTINE: |
180 |
+#SUBROUTINE: Win Popup for all connected hosts |
181 |
#=============================================================================== |
182 |
sub Global_WinPopup($){ |
183 |
|
184 |
@@ -708,9 +700,9 @@ |
185 |
} |
186 |
|
187 |
#=============================================================================== |
188 |
-#SUBROUTINE: Perform Table_IP of dhcp server |
189 |
+#SUBROUTINE: Create Table_IP of dhcp server |
190 |
#=============================================================================== |
191 |
-sub Table_IP ($) { |
192 |
+sub Table_IP ($$) { |
193 |
###Pull cgi object from parameters array |
194 |
my $q = shift; |
195 |
my @computer; |
196 |
@@ -739,32 +731,39 @@ |
197 |
print $q->p (''); |
198 |
print $q->startform (-method => 'POST', |
199 |
-action => $q->url (-absolute => 1)); |
200 |
- #print $q->hr; |
201 |
- #print $q->h3 ('Managing DHCP clients...'); |
202 |
- |
203 |
+ |
204 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
205 |
- esmith::cgi::genWidgetRow ($q, "Always check status of connected IP in the manager (No is much faster, need Save/Restart) ", |
206 |
+ esmith::cgi::genWidgetRow ($q, "Always check status of computers in the panel (No is much faster. Use Save/Restart below to activate your changes) ", |
207 |
$q->popup_menu (-name => 'dhcp_check', |
208 |
-values => ['disabled', 'enabled'], |
209 |
-default => $sme_conf{'check'}, |
210 |
-labels => \%check)) ); |
211 |
+ |
212 |
+ ##save checkip ('Saving modification and restart the daemon...') and go to sub Save_checkip :) |
213 |
+ #print $q->h3 ('Saving modification and restart the daemon...'); |
214 |
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
215 |
+ esmith::cgi::genTextRow ($q, |
216 |
+ $q->p ('After changing the check IP setting above, you must save and' . |
217 |
+ ' restart dhcpd.'))); |
218 |
+ |
219 |
+ print $q->Tr (esmith::cgi::genButtonRow ($q, |
220 |
+ $q->submit (-name => 'state', -value => 'Save/Restart'))); |
221 |
+ |
222 |
# Refresh Liste |
223 |
#print $q->p ; |
224 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
225 |
esmith::cgi::genTextRow ($q, |
226 |
- $q->p ('You may want to refresh this list ?'))); |
227 |
+ $q->p ('You may want to refresh this list ?'))) ; |
228 |
print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Refresh'))); |
229 |
|
230 |
#print $q->hr; |
231 |
- #print $q->h3 ('Saving modification and restart the daemon...'); |
232 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
233 |
esmith::cgi::genTextRow ($q, |
234 |
- $q->p ('After changing the check setting above, you must save and' . |
235 |
- ' restart dhcpd.'))); |
236 |
+ $q->p ('You may want to clean all dhcp leases below ?'))) ; |
237 |
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Remove all entries'))); |
238 |
+ |
239 |
|
240 |
- print $q->Tr (esmith::cgi::genButtonRow ($q, |
241 |
- $q->submit (-name => 'action', -value => 'Save/Restart'))); |
242 |
- print $q->hidden (-name => 'state', -override => 1, -default => 'main_save'); |
243 |
+ |
244 |
print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
245 |
" main DHCPd panel.\n"); |
246 |
|
247 |
@@ -774,13 +773,15 @@ |
248 |
print $q->table ({border => 1, cellspacing => 1, cellpadding => 4,nowarp => 1}); |
249 |
print $q->Tr (esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'IP')), |
250 |
esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Network Name')), |
251 |
- esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Status')), |
252 |
+ esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Status - click for WOL')), |
253 |
esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Start Date')), |
254 |
esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'End Date')), |
255 |
esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'MAC Address' . |
256 |
'</CENTER>')), |
257 |
); |
258 |
##9->netbios (ancien10)::8->mac address (ancien8)::0->ip:: |
259 |
+##it is possible you may adapt array number if more options/lines are added to the dhcpd.leases |
260 |
+##symptoms are a blank line in Table_IP |
261 |
foreach (@liste_computer){ |
262 |
@computer = split(/;/, $_) ; |
263 |
if ( $computer[0] ) { |
264 |
@@ -789,7 +790,7 @@ |
265 |
my $datefin = $computer[5] . "-" . $computer[6] ; |
266 |
$status = $q->a ({href => $q->url (-absolute => 1) . |
267 |
"?state=wake_up&MAC=" . $computer[8] . "&name=" . |
268 |
- $computer[9]}, '<font color="#AAAAAA">Not checked...</font>') ; |
269 |
+ $computer[9]}, '<font color="orange">Not Checked...</font>') ; |
270 |
if ( $sme_conf{'check'} =~ /enabled/ ) { |
271 |
use Net::Ping; |
272 |
my($ping_obj) = Net::Ping->new("icmp"); |
273 |
@@ -800,7 +801,7 @@ |
274 |
$computer[6] = substr($computer[6],0,5); |
275 |
if ($ping_obj->ping("$computer[0]")) { |
276 |
push(@liste_connected,$computer[9]) ; |
277 |
- $status = "<font color='green'>ON</font>" ; |
278 |
+ $status = "<font color='green'>Active Device</font>" ; |
279 |
#alimentation de la liste des connecté |
280 |
} |
281 |
else { $status = $q->a ({href => $q->url (-absolute => 1) . |
282 |
@@ -814,7 +815,7 @@ |
283 |
} |
284 |
print $q->Tr (esmith::cgi::genSmallCell ($q, "$computer[0]"), |
285 |
esmith::cgi::genSmallCell ($q, "$computer[9]"), |
286 |
- esmith::cgi::genSmallCell ($q, "$status" ), |
287 |
+ esmith::cgi::genSmallCell ($q, "<CENTER>" ."$status" ), |
288 |
esmith::cgi::genSmallCell ($q, "<CENTER>" . "$datedeb" . "</CENTER>"), |
289 |
esmith::cgi::genSmallCell ($q, "<CENTER>" . "$datefin" . "</CENTER>"), |
290 |
esmith::cgi::genSmallCell ($q, "$computer[8]"), |
291 |
@@ -839,7 +840,81 @@ |
292 |
esmith::cgi::genFooter ($q); |
293 |
exit; |
294 |
} |
295 |
+# |
296 |
+#=============================================================================== |
297 |
+#SUBROUTINE: procedure qui sauve le checkip de la subroutine Table_ip |
298 |
+#=============================================================================== |
299 |
+sub Save_checkip ($){ |
300 |
+ |
301 |
+ ##Pull CGI object from parameters array |
302 |
+ my $q = shift; |
303 |
+ |
304 |
+ ###Build Hash of config parameters to update from cgi submit |
305 |
+ my $dhcpd_check = $q->param ('dhcp_check'); |
306 |
+ |
307 |
+ ##Initiate get method --> create record object |
308 |
+ my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); |
309 |
+ |
310 |
+ my $sme_record = $dbh_sme->get('dhcpd'); |
311 |
+ |
312 |
+ $sme_record->set_prop('check' , $dhcpd_check); |
313 |
+ |
314 |
+ system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 |
315 |
+ or die ("Error occurred while restarting dhcpd.\n"); |
316 |
+ Table_IP($q, "Successfully saved checkip status " ); |
317 |
+ exit; |
318 |
+} |
319 |
+# |
320 |
+#=============================================================================== |
321 |
+#SUBROUTINE: procedure qui supprime tous les bail dans le dhcpd.leases |
322 |
+#=============================================================================== |
323 |
+sub Del_all_Lease ($){ |
324 |
+ ###Pull CGI object from parameters array |
325 |
+ $q = shift; |
326 |
+ |
327 |
+ ###Start Panel. |
328 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Removing all DHCP Lease'); |
329 |
+ print $q->h3('Remove all entries in dhcpd.leases may cause issues'); |
330 |
+ |
331 |
+ print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1)); |
332 |
+ |
333 |
+ |
334 |
+ |
335 |
+ print $q->p (" The lease file is a log-structured file - whenever a lease changes, the |
336 |
+ contents of that lease are written to the end of the file. "); |
337 |
+ print $q->p ("This means that it is entirely possible for there to be two |
338 |
+ or more declarations of the same lease in the lease file at the same |
339 |
+ time."); |
340 |
+ print $q->p ("In that case, the instance of that particular lease that |
341 |
+ appears last in the file is the one that is in effect."); |
342 |
+ |
343 |
+ print $q->p ($q->b ("Are you sure ?")); |
344 |
|
345 |
+ print $q->submit (-name => 'state', -value => 'Remove all dhcp leases'); |
346 |
+ |
347 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
348 |
+ " main DHCPd panel.\n"); |
349 |
+ |
350 |
+ print $q->endform; |
351 |
+ esmith::cgi::genFooter ($q); |
352 |
+ return; |
353 |
+ |
354 |
+} |
355 |
+# |
356 |
+#=============================================================================== |
357 |
+#SUBROUTINE: supprime tous les bail dans le dhcpd.leases |
358 |
+#=============================================================================== |
359 |
+sub Perform_del_all_Lease ($){ |
360 |
+ |
361 |
+ system ('/bin/echo "" > /var/lib/dhcpd/dhcpd.leases') ==0 |
362 |
+ or die ("Error occurred while removing all leases"); |
363 |
+ |
364 |
+ system ("/sbin/e-smith/signal-event","conf-dhcpmanager") == 0 |
365 |
+ or die ("Error occurred while restarting dhcpd.\n"); |
366 |
+ |
367 |
+ Table_IP($q, "Successfully deleted all entries in dhcpd.leases. " ); |
368 |
+ exit; |
369 |
+} |
370 |
|
371 |
#=============================================================================== |
372 |
#SUBROUTINE: Scan The Local Network |
373 |
@@ -850,7 +925,9 @@ |
374 |
my $nmap_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); |
375 |
my $mask = $nmap_sme->get_value('LocalNetmask'); |
376 |
my $network = $nmap_sme->get_prop('InternalInterface','Network'); |
377 |
- |
378 |
+ |
379 |
+#we start to calculate the method to find the cidr (we want to use network/cidr with nmap) |
380 |
+ |
381 |
sub dec2bin { |
382 |
my $str = unpack("B32", pack("N", shift)); |
383 |
return $str; |
384 |
@@ -881,14 +958,15 @@ |
385 |
return $cidr; |
386 |
} |
387 |
|
388 |
- |
389 |
+#Then lets go to calculate the cidr |
390 |
my $cidr = netmask2cidr($mask, $network); |
391 |
- |
392 |
+ |
393 |
+#ok go to use nmap with nmap -T4 -sP network/cidr |
394 |
print $q->p ; |
395 |
print $q->h3("Your subnet appears to be $cidr and your netmask is $mask, please wait\n"); |
396 |
print $q->p ; |
397 |
|
398 |
- foreach (`/usr/bin/nmap -T4 -sP $cidr| /bin/grep -E "finished|Host"| /bin/sed -e 's/Nmap/Scanning/g'`) { |
399 |
+ 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'`) { |
400 |
|
401 |
print $q->br($_);} |
402 |
|