]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blobdiff - html/cgi-bin/wakeonlan.cgi
Merge branch 'master' into next
[people/mfischer/ipfire-2.x.git] / html / cgi-bin / wakeonlan.cgi
index 87d540cbbb5f9a6219ae86f9d5ae088356eed188..c3c4c6911b2fe085136eca316c84a85f62203575 100644 (file)
@@ -1,9 +1,23 @@
 #!/usr/bin/perl
-#
-# IPFire WakeOnLan-AddOn CGI
-#
-# This code is distributed under the terms of the GPL
-#
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 use strict;
 
@@ -34,6 +48,11 @@ my @wol_devices = ();
 our $datafile = "/var/ipfire/wakeonlan/clients.conf";
 &ReadConfig;
 
+my %color = ();
+my %mainsettings = ();
+&General::readhash("${General::swroot}/main/settings", \%mainsettings);
+&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
+
 my %netsettings = ();
 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 my %cgiparams = ();
@@ -67,7 +86,7 @@ if ( $cgiparams{'ACTION'} eq 'add' )
 
   unless( &General::validmac($cgiparams{'CLIENT_MAC'}) )
   {
-    $errormessage = $Lang::tr{'invalid mac address'}; 
+    $errormessage = $Lang::tr{'invalid mac address'};
     goto ADDEXIT;
   }
 
@@ -103,7 +122,7 @@ if ( $cgiparams{'ACTION'} eq 'update' )
 
   unless( &General::validmac($cgiparams{'CLIENT_MAC'}) )
   {
-    $errormessage = $Lang::tr{'invalid mac address'}; 
+    $errormessage = $Lang::tr{'invalid mac address'};
     goto UPDATEEXIT;
   }
 
@@ -152,7 +171,7 @@ if ( $cgiparams{'ACTION'} eq 'wakeup' )
 
   undef %cgiparams;
 
-  system("/usr/local/sbin/launch-ether-wake $mac $iface");
+  &General::system("/usr/sbin/etherwake", "-i", "$iface", "$mac");
 
   # make a box with info, 'refresh' to normal screen after 5 seconds
   if ( $refresh eq 'yes' )
@@ -213,7 +232,7 @@ else
 print <<END
 <table width='100%'>
 <tr>
-  <td width='15%' class='base'>$Lang::tr{'mac address'}:&nbsp;</td>
+  <td width='15%' class='base'>$Lang::tr{'mac address'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
   <td width='40%'><input type='text' name='CLIENT_MAC' value='$cgiparams{'CLIENT_MAC'}' size='25' /></td>
   <td width='10%' class='base'>$Lang::tr{'interface'}:&nbsp;</td>
   <td align='left'>
@@ -222,11 +241,11 @@ END
 ;
 
 print "<option value='green' $selected{'CLIENT_IFACE'}{'green'}>$Lang::tr{'green'}</option>";
-if (&haveBlueNet()) 
+if (&haveBlueNet())
 {
   print "<option value='blue' $selected{'CLIENT_IFACE'}{'blue'}>$Lang::tr{'blue'}</option>";
 }
-if (&haveOrangeNet()) 
+if (&haveOrangeNet())
 {
   print "<option value='orange' $selected{'CLIENT_IFACE'}{'orange'}>$Lang::tr{'orange'}</option>";
 }
@@ -237,20 +256,20 @@ print <<END
   </td>
 </tr>
 <tr>
-  <td width='15%' class='base'>$Lang::tr{'remark'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+  <td width='15%' class='base'>$Lang::tr{'remark'}:</td>
   <td colspan='4' align='left'><input type='text' name='CLIENT_COMMENT' value='$cgiparams{'CLIENT_COMMENT'}' size='40' /></td>
 </tr>
 </table>
+<br>
 <hr />
 <table width='100%'>
 <tr>
-  <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
-  <td width='55%' class='base'>$Lang::tr{'this field may be blank'}</td>
-  <td width='40%' align='center'>
+  <td class='base' valign='top'><img src='/blob.gif' alt='*' />$Lang::tr{'required field'}</td>
+  <td width='40%' align='right'>
 END
 ;
 
-if ( ($cgiparams{'ACTION'} eq 'edit') || ($cgiparams{'ACTION'} eq 'update') ) 
+if ( ($cgiparams{'ACTION'} eq 'edit') || ($cgiparams{'ACTION'} eq 'update') )
 {
   print "<input type='hidden' name='ID' value='$cgiparams{'ID'}' />\n";
   print "<input type='hidden' name='ACTION' value='update' />";
@@ -273,43 +292,47 @@ print "</form>\n";
 &Header::openbox('100%', 'left', "$Lang::tr{'current devices'}");
 
 print <<END
-<table width='100%'>
+<table width='100%' class='tbl'>
 <tr>
-<td align='center' width='20%'><b>$Lang::tr{'mac address'}</b></td>
-<td align='center' width='10%'><b>$Lang::tr{'interface'}</b></td>
-<td align='center' width='60%'><b>$Lang::tr{'remark'}</b></td>
-<td align='center' colspan='2'><b>$Lang::tr{'action'}</b></td>
+<th align='center' width='20%'><b>$Lang::tr{'mac address'}</b></th>
+<th align='center' width='10%'><b>$Lang::tr{'interface'}</b></th>
+<th align='center' width='60%'><b>$Lang::tr{'remark'}</b></th>
+<th align='center' colspan='2'><b>$Lang::tr{'action'}</b></th>
+<th></th>
 </tr>
 END
 ;
-
+my $col="";
 for $i ( 0 .. $#wol_devices )
 {
   my $wol_mac = $wol_devices[$i]{'MAC'};
   my $wol_iface = $wol_devices[$i]{'IFace'};
   my $wol_txt = &Header::cleanhtml($wol_devices[$i]{'Comment'});
 
-  if ( (($cgiparams{'ACTION'} eq 'edit') || ($cgiparams{'ACTION'} eq 'update')) && ($i == $cgiparams{'ID'}) ) 
+  if ( (($cgiparams{'ACTION'} eq 'edit') || ($cgiparams{'ACTION'} eq 'update')) && ($i == $cgiparams{'ID'}) )
   {
-    print "<tr bgcolor='${Header::colouryellow}'>";
+    print "<tr>";
+    $col="bgcolor='${Header::colouryellow}'";
   }
-  elsif ( $i % 2) 
+  elsif ( $i % 2)
   {
-    print "<tr bgcolor='$Header::table2colour'>";
+    print "<tr>";
+    $col="bgcolor='$color{'color20'}'";
   }
-  else 
+  else
   {
-    print "<tr bgcolor='$Header::table1colour'>";
+    print "<tr>";
+    $col="bgcolor='$color{'color22'}'";
   }
 
   print <<END
-<td align='center'>$wol_mac</td>
-<td align='center'>$Lang::tr{"$wol_iface"}</td>
-<td align='left'>$wol_txt</td>
-<td align='center'>
+<td align='center' $col>$wol_mac</td>
+<td align='center' $col>$Lang::tr{"$wol_iface"}</td>
+<td align='left' $col>$wol_txt</td>
+<td align='center' $col>
 END
 ;
-  if ( (($wol_iface eq 'blue') && ! &haveBlueNet()) 
+  if ( (($wol_iface eq 'blue') && ! &haveBlueNet())
     || (($wol_iface eq 'orange') && ! &haveOrangeNet()) )
   {
     # configured IFace (momentarily) not available -> now wakeup button/image
@@ -328,14 +351,14 @@ END
   }
   print <<END
 </td>
-<td align='center'>
+<td align='center' $col>
   <form method='post' name='frmb$i' action='$ENV{'SCRIPT_NAME'}'>
   <input type='hidden' name='ACTION' value='edit' />
   <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
   <input type='hidden' name='ID' value='$i' />
   </form>
 </td>
-<td align='center'>
+<td align='center' $col>
   <form method='post' name='frmc$i' action='$ENV{'SCRIPT_NAME'}'>
   <input type='hidden' name='ACTION' value='remove' />
   <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
@@ -361,7 +384,7 @@ sub ReadConfig
 {
   # datafileformat:
   #   ID,MAC,IFACE,,Comment
-  # 
+  #
   my @tmpfile = ();
   if ( open(FILE, "$datafile") )
   {
@@ -398,14 +421,14 @@ sub WriteConfig
     unless(&General::validmac($wol_devices[$i]{'MAC'})) { next; }
     unshift (@tmp_clients, uc($wol_devices[$i]{'MAC'}).",$wol_devices[$i]{'IFace'},,$wol_devices[$i]{'Comment'}");
   }
-  
+
   # sort tmp_clients on MAC
   @tmp_clients = sort ( @tmp_clients );
 
   open(FILE, ">$datafile") or die 'hosts datafile error';
 
   my $count = 0;
-  foreach $line (@tmp_clients) 
+  foreach $line (@tmp_clients)
   {
     print FILE "$count,$line\n";
     $count++;
@@ -422,18 +445,14 @@ sub WriteConfig
 #
 sub haveOrangeNet
 {
-  if ($netsettings{'CONFIG_TYPE'} == 1) {return 1;}
-  if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
-  if ($netsettings{'CONFIG_TYPE'} == 5) {return 1;}
-  if ($netsettings{'CONFIG_TYPE'} == 7) {return 1;}
+  if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;}
+  if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
   return 0;
 }
 
 sub haveBlueNet
 {
+  if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
   if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
-  if ($netsettings{'CONFIG_TYPE'} == 5) {return 1;}
-  if ($netsettings{'CONFIG_TYPE'} == 6) {return 1;}
-  if ($netsettings{'CONFIG_TYPE'} == 7) {return 1;}
   return 0;
 }