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-03 23:18:37.000000000 +0100 |
3 |
+++ smeserver-dhcpmanager-1.5/root/etc/e-smith/web/functions/dhcpd 2014-01-05 12:38:35.000000000 +0100 |
4 |
@@ -23,7 +23,8 @@ |
5 |
use esmith::AccountsDB; |
6 |
use esmith::FormMagick; |
7 |
use Net::Ping; |
8 |
- |
9 |
+use esmith::util::network qw(:all); |
10 |
+use Socket qw( inet_aton ); |
11 |
|
12 |
###Declare function prototypes |
13 |
sub Main_Display ($$); |
14 |
@@ -36,7 +37,8 @@ |
15 |
sub Message ($$); |
16 |
sub Global_WinPopup ($); |
17 |
sub Perform_Message ($); |
18 |
- |
19 |
+sub Table_IP ($); |
20 |
+sub Scan_Local_Network ($); |
21 |
### Clear PATH and related environment variables so that calls to |
22 |
### external programs do not cause results to be tainted. See |
23 |
### "perlsec" manual page for details. |
24 |
@@ -73,7 +75,7 @@ |
25 |
my $q = new CGI; |
26 |
if (! grep (/^state$/, $q->param)){ Main_Display($q, '');} |
27 |
elsif ($q->param ('state') eq "main_display"){Main_Display ($q,'');} |
28 |
-elsif ($q->param ('state') eq "Refresh"){Main_Display ($q,'');} |
29 |
+elsif ($q->param ('state') eq "Refresh"){Table_IP ($q);} |
30 |
elsif ($q->param ('state') eq "main_save"){Main_Save ($q);} |
31 |
elsif ($q->param ('state') eq "del_lease"){Del_Lease ($q);} |
32 |
elsif ($q->param ('state') eq "perform_del_lease"){Perform_Del_Lease ($q);} |
33 |
@@ -82,6 +84,9 @@ |
34 |
elsif ($q->param ('state') eq "Global WinPopup"){Global_WinPopup ($q);} |
35 |
elsif ($q->param ('state') eq "message"){Message ($q,'');} |
36 |
elsif ($q->param ('state') eq "perform_message"){Perform_Message ($q);} |
37 |
+elsif ($q->param ('state') eq "Connected IP"){Table_IP ($q);} |
38 |
+elsif ($q->param ('state') eq "Scan your Network"){Scan_Local_Network ($q);} |
39 |
+ |
40 |
else{esmith::cgi::genStateError ($q, \%conf);} |
41 |
exit (0); |
42 |
|
43 |
@@ -118,90 +123,34 @@ |
44 |
print $q->p (''); |
45 |
print $q->startform (-method => 'POST', |
46 |
-action => $q->url (-absolute => 1)); |
47 |
- print $q->hr; |
48 |
- print $q->h3 ('Managing DHCP clients...'); |
49 |
+ #print $q->hr; |
50 |
+ #print $q->h3 ('Managing DHCP clients...'); |
51 |
|
52 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
53 |
- esmith::cgi::genWidgetRow ($q, "Always check status in the manager (No is much faster, need Save/Restart) ", |
54 |
+ esmith::cgi::genWidgetRow ($q, "Always check status of computers in the panel \"Connected IP\" (No is much faster, need Save/Restart) ", |
55 |
$q->popup_menu (-name => 'dhcp_check', |
56 |
-values => ['disabled', 'enabled'], |
57 |
-default => $sme_conf{'check'}, |
58 |
-labels => \%check)) ); |
59 |
- &Load_leases ($q) ; |
60 |
- if ( 2 > 1 ) { |
61 |
- print $q->p ($q->b ('')); |
62 |
- print $q->table ({border => 1, cellspacing => 1, cellpadding => 4,nowarp => 1}); |
63 |
- print $q->Tr (esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'IP')), |
64 |
- esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Network Name')), |
65 |
- esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Status')), |
66 |
- esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Start Date')), |
67 |
- esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'End Date')), |
68 |
- esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'MAC Address' . |
69 |
- '</CENTER>')), |
70 |
- ); |
71 |
-##9->netbios (ancien10)::8->mac address (ancien8)::0->ip:: |
72 |
- foreach (@liste_computer){ |
73 |
- @computer = split(/;/, $_) ; |
74 |
- if ( $computer[0] ) { |
75 |
- my $datedeb = $computer[2] . "-" . $computer[3] ; |
76 |
- my $datefin = $computer[5] . "-" . $computer[6] ; |
77 |
- $status = $q->a ({href => $q->url (-absolute => 1) . |
78 |
- "?state=wake_up&MAC=" . $computer[8] . "&name=" . |
79 |
- $computer[9]}, '<font color="#AAAAAA">Not checked...</font>') ; |
80 |
- if ( $sme_conf{'check'} =~ /enabled/ ) { |
81 |
- use Net::Ping; |
82 |
- my($ping_obj) = Net::Ping->new("icmp"); |
83 |
- $computer[9] = uc($computer[9]) ; |
84 |
- $computer[8] = uc($computer[8]) ; |
85 |
- # formatage des dates |
86 |
- $computer[3] = substr($computer[3],0,5); |
87 |
- $computer[6] = substr($computer[6],0,5); |
88 |
- if ($ping_obj->ping("$computer[0]")) { |
89 |
- push(@liste_connected,$computer[9]) ; |
90 |
- $status = "<font color='green'>ON</font>" ; |
91 |
- #alimentation de la liste des connecté |
92 |
- } |
93 |
- else { $status = $q->a ({href => $q->url (-absolute => 1) . |
94 |
- "?state=wake_up&MAC=" . $computer[8] . "&name=" . |
95 |
- $computer[9]}, '<font color="red">Wake-Up...</font>'); |
96 |
- } |
97 |
- } |
98 |
- else { |
99 |
- push(@liste_connected,$computer[9]) ; |
100 |
- } |
101 |
- print $q->Tr (esmith::cgi::genSmallCell ($q, "$computer[0]"), |
102 |
- esmith::cgi::genSmallCell ($q, "$computer[9]"), |
103 |
- esmith::cgi::genSmallCell ($q, "$status" ), |
104 |
- esmith::cgi::genSmallCell ($q, "<CENTER>" . "$datedeb" . "</CENTER>"), |
105 |
- esmith::cgi::genSmallCell ($q, "<CENTER>" . "$datefin" . "</CENTER>"), |
106 |
- esmith::cgi::genSmallCell ($q, "$computer[8]"), |
107 |
- esmith::cgi::genSmallCell ($q, |
108 |
- $q->a ({href => $q->url (-absolute => 1) |
109 |
- . "?state=del_lease&host=" . $computer[0] . "&name=" . |
110 |
- $computer[9]}, 'Remove...')), |
111 |
- esmith::cgi::genSmallCell ($q, |
112 |
- $q->a ({href => $q->url (-absolute => 1) |
113 |
- . "?state=message&name=" . $computer[9]}, 'WinPopup...')) |
114 |
- ); |
115 |
- } |
116 |
- } |
117 |
- print '</table>'; |
118 |
- } |
119 |
- else{ |
120 |
- print $q->p ($q->b ('There are no computer connected.')); |
121 |
- } |
122 |
|
123 |
- # Refresh Liste |
124 |
- print $q->p ; |
125 |
+ # Go to see table connected ip |
126 |
+ #print $q->p ; |
127 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
128 |
esmith::cgi::genTextRow ($q, |
129 |
- $q->p ('You may want to refresh this list ?'))); |
130 |
- print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Refresh'))); |
131 |
- |
132 |
+ $q->p ('You may want to see all connected computer to the dhcpd server ?'))); |
133 |
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Connected IP'))); |
134 |
+ |
135 |
+ # Go to scan the local network |
136 |
+ #print $q->p ; |
137 |
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
138 |
+ esmith::cgi::genTextRow ($q, |
139 |
+ $q->p ('You may want to scan your network to know how many hosts are up ?'))); |
140 |
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Scan your Network'))); |
141 |
+ |
142 |
#Global Winpopup |
143 |
print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
144 |
esmith::cgi::genTextRow ($q, |
145 |
- $q->p ('You may want to send a global WinPopup to all connected computer ?'))); |
146 |
+ $q->p ('You may want to send a global WinPopup to all connected computer compatible with Net send protocol ?'))); |
147 |
print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Global WinPopup'))); |
148 |
print $q->hidden (-name => 'liste_connected', -override => 1, -default => "@liste_connected"); |
149 |
|
150 |
@@ -335,41 +284,137 @@ |
151 |
my $dhcpd_dns2server = $q->param ('dhcp_dns2server'); |
152 |
my $dhcpd_gatewaycustom = $q->param ('dhcp_gatewaycustom'); |
153 |
my $dhcpd_gateway = $q->param ('dhcp_gateway'); |
154 |
- |
155 |
###Update SME configuration dbase |
156 |
##Create object to spammassassin dbase |
157 |
my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); |
158 |
|
159 |
##Initiate get method --> create record object |
160 |
- my $sme_record = $dbh_sme->get('dhcpd'); |
161 |
- |
162 |
- ##Set status of service: obsolete way |
163 |
-# $sme_record->set_prop('status'=>$dhcpd_status); |
164 |
-# $sme_record->set_prop('check'=>$dhcpd_check); |
165 |
-# $sme_record->set_prop('end'=>$dhcpd_end); |
166 |
-# $sme_record->set_prop('start'=>$dhcpd_start); |
167 |
-# $sme_record->set_prop('winscustom'=>$dhcpd_winscustom); |
168 |
-# $sme_record->set_prop('winsserver'=>$dhcpd_winsserver); |
169 |
-# $sme_record->set_prop('leasetime'=>$dhcpd_leasetime); |
170 |
-# $sme_record->set_prop('dnscustom'=>$dhcpd_dnscustom); |
171 |
-# $sme_record->set_prop('dns1server'=>$dhcpd_dns1server); |
172 |
-# $sme_record->set_prop('dns2server'=>$dhcpd_dns2server); |
173 |
-# $sme_record->set_prop('gatewaycustom'=>$dhcpd_gatewaycustom); |
174 |
-# $sme_record->set_prop('gateway'=>$dhcpd_gateway); |
175 |
+ my $sme_record = $dbh_sme->get('dhcpd'); |
176 |
+ #get localip of server |
177 |
+ my $local_ip = $dbh_sme->get_value('LocalIP'); |
178 |
|
179 |
##Set status of service |
180 |
$sme_record->set_prop('status', $dhcpd_status); |
181 |
$sme_record->set_prop('check' , $dhcpd_check); |
182 |
- $sme_record->set_prop('end', $dhcpd_end); |
183 |
- $sme_record->set_prop('start', $dhcpd_start); |
184 |
$sme_record->set_prop('winscustom', $dhcpd_winscustom); |
185 |
- $sme_record->set_prop('winsserver', $dhcpd_winsserver); |
186 |
$sme_record->set_prop('leasetime' , $dhcpd_leasetime); |
187 |
$sme_record->set_prop('dnscustom' , $dhcpd_dnscustom); |
188 |
- $sme_record->set_prop('dns1server' , $dhcpd_dns1server); |
189 |
- $sme_record->set_prop('dns2server' , $dhcpd_dns2server); |
190 |
$sme_record->set_prop('gatewaycustom' , $dhcpd_gatewaycustom); |
191 |
- $sme_record->set_prop('gateway' , $dhcpd_gateway); |
192 |
+ |
193 |
+ #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 |
194 |
+ if ($dhcpd_status eq "enabled") |
195 |
+ { |
196 |
+ if ( isValidIP ($dhcpd_start) && isValidIP ($dhcpd_end)) |
197 |
+ { |
198 |
+ #check if $dhcpd_start is greater than $dhcpd_end and if yes, display an error message. |
199 |
+ if (inet_aton($dhcpd_start) ge inet_aton($dhcpd_end)) |
200 |
+ { |
201 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS'); |
202 |
+ 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"); |
203 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
204 |
+ " main DHCPd panel.\n"); |
205 |
+ esmith::cgi::genFooter ($q); |
206 |
+ exit; |
207 |
+ } |
208 |
+ elsif ( ( (inet_aton($dhcpd_start) le inet_aton($local_ip) ) && ( inet_aton($dhcpd_end)) ge inet_aton($local_ip) ) ) |
209 |
+ { |
210 |
+ #display an error if the range of dhcp server include the ip of the server address |
211 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS'); |
212 |
+ 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"); |
213 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
214 |
+ " main DHCPd panel.\n"); |
215 |
+ esmith::cgi::genFooter ($q); |
216 |
+ exit; |
217 |
+ } |
218 |
+ else |
219 |
+ { |
220 |
+ #set value |
221 |
+ my $dhcpd_start = cleanIP($dhcpd_start); |
222 |
+ my $dhcpd_end = cleanIP($dhcpd_end); |
223 |
+ |
224 |
+ $sme_record->set_prop('end', $dhcpd_end); |
225 |
+ $sme_record->set_prop('start', $dhcpd_start); |
226 |
+ } |
227 |
+ } |
228 |
+ #if $dhcpd_start or $dhcpd_end are not valid ip then display an error |
229 |
+ else |
230 |
+ { |
231 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS'); |
232 |
+ print $q->h3("DHCP Server address : error....Incorrect IP $dhcpd_start and $dhcpd_end, Update unsuccessfull\n"); |
233 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
234 |
+ " main DHCPd panel.\n"); |
235 |
+ esmith::cgi::genFooter ($q); |
236 |
+ exit; |
237 |
+ } |
238 |
+ } |
239 |
+ |
240 |
+ #checkip to the winserver perform the save in DB configuration or display an error if value != of a valid ip |
241 |
+ if ($dhcpd_winscustom eq "enabled") |
242 |
+ { |
243 |
+ |
244 |
+ if ( isValidIP ($dhcpd_winsserver) ) |
245 |
+ { |
246 |
+ #set value |
247 |
+ my $dhcpd_winsserver = cleanIP($dhcpd_winsserver); |
248 |
+ $sme_record->set_prop('winsserver', $dhcpd_winsserver); |
249 |
+ } |
250 |
+ else |
251 |
+ { |
252 |
+ #if $dhcpd_winsserver is not valid ip then display an error |
253 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS'); |
254 |
+ print $q->h3("WINS Server address : error....Incorrect IP $dhcpd_winsserver, Update unsuccessfull\n"); |
255 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
256 |
+ " main DHCPd panel.\n"); |
257 |
+ esmith::cgi::genFooter ($q); |
258 |
+ exit; |
259 |
+ } |
260 |
+ } |
261 |
+ |
262 |
+ #checkip to the dnsserver custom, perform the save in DB configuration or display an error if value != of a valid ip |
263 |
+ if ($dhcpd_dnscustom eq "enabled") |
264 |
+ { |
265 |
+ #check if $dhcpd_dns1server and ( $dhcpd_dns2server are valid ip or $dhcpd_dns2server = null ) |
266 |
+ if ( isValidIP ($dhcpd_dns1server) && (isValidIP($dhcpd_dns2server) || ( $dhcpd_dns2server eq "") ) ) |
267 |
+ { |
268 |
+ #set value |
269 |
+ my $dhcpd_dns1server = cleanIP($dhcpd_dns1server); |
270 |
+ $sme_record->set_prop('dns1server' , $dhcpd_dns1server); |
271 |
+ my $dhcpd_dns2server = cleanIP($dhcpd_dns2server); |
272 |
+ $sme_record->set_prop('dns2server' , $dhcpd_dns2server); |
273 |
+ } |
274 |
+ else |
275 |
+ { |
276 |
+ ##if $dhcpd_dns1server or $dhcpd_dns2server are not valid ip then display an error |
277 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS'); |
278 |
+ print $q->h3("Custom DNS Server address : error....Incorrect IP $dhcpd_dns1server and $dhcpd_dns2server, Update unsuccessfull\n"); |
279 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
280 |
+ " main DHCPd panel.\n"); |
281 |
+ esmith::cgi::genFooter ($q); |
282 |
+ exit; |
283 |
+ } |
284 |
+ } |
285 |
+ |
286 |
+ #checkip to the gateway_custom perform the save in DB configuration or display an error if value != of a valid ip |
287 |
+ if ($dhcpd_gatewaycustom eq "enabled") |
288 |
+ { |
289 |
+ if ( isValidIP ($dhcpd_gateway) ) |
290 |
+ { |
291 |
+ #set value |
292 |
+ my $dhcpd_gateway = cleanIP($dhcpd_gateway); |
293 |
+ $sme_record->set_prop('gateway' , $dhcpd_gateway); |
294 |
+ } |
295 |
+ else |
296 |
+ { |
297 |
+ #if $dhcpd_gateway is not valid ip then display an error |
298 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings ERRORS'); |
299 |
+ print $q->h3("Gateway Custom Server address : error....Incorrect IP $dhcpd_gateway, Update unsuccessfull\n"); |
300 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
301 |
+ " main DHCPd panel.\n"); |
302 |
+ esmith::cgi::genFooter ($q); |
303 |
+ exit; |
304 |
+ } |
305 |
+ } |
306 |
+ |
307 |
|
308 |
# - 4 expand templates |
309 |
# changed to new sme standard signal-event |
310 |
@@ -385,7 +430,7 @@ |
311 |
esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'DHCPd Settings'); |
312 |
print $q->h3('Operation status report...'); |
313 |
print $q->p("Successfully saved settings.... DHCPd restarted !\n"); |
314 |
-print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
315 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
316 |
" main DHCPd panel.\n"); |
317 |
esmith::cgi::genFooter ($q); |
318 |
exit; |
319 |
@@ -513,7 +558,6 @@ |
320 |
print $q->endform; |
321 |
esmith::cgi::genFooter ($q); |
322 |
return; |
323 |
- |
324 |
} |
325 |
#=============================================================================== |
326 |
#SUBROUTINE: Perform wake UP |
327 |
@@ -574,7 +618,7 @@ |
328 |
|
329 |
#Suppression des retours chariot en fin de lignes. |
330 |
chomp $_ ; |
331 |
- |
332 |
+ |
333 |
#Chargement d'un tableau avec le contenu de la ligne. |
334 |
(@detail) = split(/ /, $_) ; |
335 |
|
336 |
@@ -663,3 +707,195 @@ |
337 |
exit; |
338 |
} |
339 |
|
340 |
+#=============================================================================== |
341 |
+#SUBROUTINE: Perform Table_IP of dhcp server |
342 |
+#=============================================================================== |
343 |
+sub Table_IP ($) { |
344 |
+ ###Pull cgi object from parameters array |
345 |
+ my $q = shift; |
346 |
+ my @computer; |
347 |
+ my $status ; |
348 |
+ |
349 |
+ ###Pull action message, if any, from parameters array |
350 |
+ my $action_message = shift; |
351 |
+ |
352 |
+ ###Retrieve SME configuration entry for dhcpd |
353 |
+ my $dbh_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); |
354 |
+ my %sme_conf = $dbh_sme->get('dhcpd')->props; |
355 |
+ |
356 |
+ ###Display Main Panel Title |
357 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Managing DHCP clients...'); |
358 |
+ |
359 |
+ ###Check to see if we just processed a panel action. If so, display |
360 |
+ ###action message and bail. |
361 |
+ if ($action_message) { |
362 |
+ print $q->h3 ('Operation status report...'); |
363 |
+ print $q->b ("$action_message"); |
364 |
+ } |
365 |
+ |
366 |
+ #------------------------------------------------------------ |
367 |
+ # Start DHCP client Panel |
368 |
+ #------------------------------------------------------------ |
369 |
+ print $q->p (''); |
370 |
+ print $q->startform (-method => 'POST', |
371 |
+ -action => $q->url (-absolute => 1)); |
372 |
+ #print $q->hr; |
373 |
+ #print $q->h3 ('Managing DHCP clients...'); |
374 |
+ |
375 |
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
376 |
+ esmith::cgi::genWidgetRow ($q, "Always check status of connected IP in the manager (No is much faster, need Save/Restart) ", |
377 |
+ $q->popup_menu (-name => 'dhcp_check', |
378 |
+ -values => ['disabled', 'enabled'], |
379 |
+ -default => $sme_conf{'check'}, |
380 |
+ -labels => \%check)) ); |
381 |
+ # Refresh Liste |
382 |
+ #print $q->p ; |
383 |
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
384 |
+ esmith::cgi::genTextRow ($q, |
385 |
+ $q->p ('You may want to refresh this list ?'))); |
386 |
+ print $q->Tr (esmith::cgi::genButtonRow ($q,$q->submit (-name => 'state',-value => 'Refresh'))); |
387 |
+ |
388 |
+ #print $q->hr; |
389 |
+ #print $q->h3 ('Saving modification and restart the daemon...'); |
390 |
+ print $q->table ({border => 0, cellspacing => 0, cellpadding => 4}, |
391 |
+ esmith::cgi::genTextRow ($q, |
392 |
+ $q->p ('After changing the check setting above, you must save and' . |
393 |
+ ' restart dhcpd.'))); |
394 |
+ |
395 |
+ print $q->Tr (esmith::cgi::genButtonRow ($q, |
396 |
+ $q->submit (-name => 'action', -value => 'Save/Restart'))); |
397 |
+ print $q->hidden (-name => 'state', -override => 1, -default => 'main_save'); |
398 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
399 |
+ " main DHCPd panel.\n"); |
400 |
+ |
401 |
+ &Load_leases ($q) ; |
402 |
+ if ( 2 > 1 ) { |
403 |
+ print $q->p ($q->b ('')); |
404 |
+ print $q->table ({border => 1, cellspacing => 1, cellpadding => 4,nowarp => 1}); |
405 |
+ print $q->Tr (esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'IP')), |
406 |
+ esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Network Name')), |
407 |
+ esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Status')), |
408 |
+ esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'Start Date')), |
409 |
+ esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'End Date')), |
410 |
+ esmith::cgi::genSmallCell ($q, $q->p ( '<center>' . 'MAC Address' . |
411 |
+ '</CENTER>')), |
412 |
+ ); |
413 |
+##9->netbios (ancien10)::8->mac address (ancien8)::0->ip:: |
414 |
+ foreach (@liste_computer){ |
415 |
+ @computer = split(/;/, $_) ; |
416 |
+ if ( $computer[0] ) { |
417 |
+ |
418 |
+ my $datedeb = $computer[2] . "-" . $computer[3] ; |
419 |
+ my $datefin = $computer[5] . "-" . $computer[6] ; |
420 |
+ $status = $q->a ({href => $q->url (-absolute => 1) . |
421 |
+ "?state=wake_up&MAC=" . $computer[8] . "&name=" . |
422 |
+ $computer[9]}, '<font color="#AAAAAA">Not checked...</font>') ; |
423 |
+ if ( $sme_conf{'check'} =~ /enabled/ ) { |
424 |
+ use Net::Ping; |
425 |
+ my($ping_obj) = Net::Ping->new("icmp"); |
426 |
+ $computer[9] = uc($computer[9]) ; |
427 |
+ $computer[8] = uc($computer[8]) ; |
428 |
+ # formatage des dates |
429 |
+ $computer[3] = substr($computer[3],0,5); |
430 |
+ $computer[6] = substr($computer[6],0,5); |
431 |
+ if ($ping_obj->ping("$computer[0]")) { |
432 |
+ push(@liste_connected,$computer[9]) ; |
433 |
+ $status = "<font color='green'>ON</font>" ; |
434 |
+ #alimentation de la liste des connecté |
435 |
+ } |
436 |
+ else { $status = $q->a ({href => $q->url (-absolute => 1) . |
437 |
+ "?state=wake_up&MAC=" . $computer[8] . "&name=" . |
438 |
+ $computer[9]}, '<font color="red">Wake-Up...</font>'); |
439 |
+ } |
440 |
+ } |
441 |
+ else { |
442 |
+ push(@liste_connected,$computer[9]) ; |
443 |
+ |
444 |
+ } |
445 |
+ print $q->Tr (esmith::cgi::genSmallCell ($q, "$computer[0]"), |
446 |
+ esmith::cgi::genSmallCell ($q, "$computer[9]"), |
447 |
+ esmith::cgi::genSmallCell ($q, "$status" ), |
448 |
+ esmith::cgi::genSmallCell ($q, "<CENTER>" . "$datedeb" . "</CENTER>"), |
449 |
+ esmith::cgi::genSmallCell ($q, "<CENTER>" . "$datefin" . "</CENTER>"), |
450 |
+ esmith::cgi::genSmallCell ($q, "$computer[8]"), |
451 |
+ esmith::cgi::genSmallCell ($q, |
452 |
+ $q->a ({href => $q->url (-absolute => 1) |
453 |
+ . "?state=del_lease&host=" . $computer[0] . "&name=" . |
454 |
+ $computer[9]}, 'Remove...')), |
455 |
+ esmith::cgi::genSmallCell ($q, |
456 |
+ $q->a ({href => $q->url (-absolute => 1) |
457 |
+ . "?state=message&name=" . $computer[9]}, 'WinPopup...')) |
458 |
+ ); |
459 |
+ } |
460 |
+ } |
461 |
+ print '</table>'; |
462 |
+ } |
463 |
+ else{ |
464 |
+ print $q->p ($q->b ('There are no computer connected.')); |
465 |
+ } |
466 |
+ |
467 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
468 |
+ " main DHCPd panel.\n"); |
469 |
+ esmith::cgi::genFooter ($q); |
470 |
+ exit; |
471 |
+} |
472 |
+ |
473 |
+ |
474 |
+#=============================================================================== |
475 |
+#SUBROUTINE: Scan The Local Network |
476 |
+#=============================================================================== |
477 |
+sub Scan_Local_Network ($q) { |
478 |
+ |
479 |
+ esmith::cgi::genHeaderNonCacheable ($q, \%conf, 'Scanning your network, the time needed depends of your subnet mask'); |
480 |
+ my $nmap_sme = esmith::ConfigDB->open('/home/e-smith/db/configuration'); |
481 |
+ my $mask = $nmap_sme->get_value('LocalNetmask'); |
482 |
+ my $network = $nmap_sme->get_prop('InternalInterface','Network'); |
483 |
+ |
484 |
+ sub dec2bin { |
485 |
+ my $str = unpack("B32", pack("N", shift)); |
486 |
+ return $str; |
487 |
+} |
488 |
+ |
489 |
+sub netmask2cidr { |
490 |
+ my ($mask, $network) = @_; |
491 |
+ my @octet = split (/\./, $mask); |
492 |
+ my @bits; |
493 |
+ my $binmask; |
494 |
+ my $binoct; |
495 |
+ my $bitcount=0; |
496 |
+ |
497 |
+ foreach (@octet) { |
498 |
+ $binoct = dec2bin($_); |
499 |
+ $binmask = $binmask . substr $binoct, -8; |
500 |
+ } |
501 |
+ |
502 |
+ # let's count the 1s |
503 |
+ @bits = split (//,$binmask); |
504 |
+ foreach (@bits) { |
505 |
+ if ($_ eq "1") { |
506 |
+ $bitcount++; |
507 |
+ } |
508 |
+ } |
509 |
+ |
510 |
+ my $cidr = $network . "/" . $bitcount; |
511 |
+ return $cidr; |
512 |
+} |
513 |
+ |
514 |
+ |
515 |
+ my $cidr = netmask2cidr($mask, $network); |
516 |
+ |
517 |
+ print $q->p ; |
518 |
+ print $q->h3("Your subnet appears to be $cidr and your netmask is $mask, please wait\n"); |
519 |
+ print $q->p ; |
520 |
+ |
521 |
+ foreach (`/usr/bin/nmap -T4 -sP $cidr| /bin/grep -E "finished|Host"| /bin/sed -e 's/Nmap/Scanning/g'`) { |
522 |
+ |
523 |
+ print $q->br($_);} |
524 |
+ |
525 |
+ print $q->p ; |
526 |
+ |
527 |
+ print $q->p("<b><a href=dhcpd>Click Here</a></b> to return to" . |
528 |
+ " main DHCPd panel.\n"); |
529 |
+ esmith::cgi::genFooter ($q); |
530 |
+ exit; |
531 |
+ } |