I am having some problems with php.  I have no idea why this script 
will not work.  When I open this form it comes up just fine.  I then 
try to prese "Reset", "Set HC" or "Set with NTP".  and the responce I 
get back is "did not run.$TimeSubmit".  and $TimeSubmit is one of 
those that I pressed.  It just never runs those parts of the case 
statment.  I have also tried using if-else.  Now the message Appears 
fine.  I am running this script on a debian linux with apache.  I 
will include the script below.  I have given the script rights to run 
as it's user so that It can run the commands requested.

#!/usr/bin/php4-cgi
<?php
    extract ( $_POST );
$lsdata = "did not run.$TimeSubmit";
switch ($TimeSubmit)
{
  case "Reset": $lsdate = shell_exec("hwclock --hctosys");
                                break;
  case "Set HC": $lsdate = shell_exec("hwclock --systohc");
                                 break;
  case "Set with NTP": $lsdate = shell_exec("ntpdate pool.ntp.date");
                                           break;
  case "Set Time": $Date = date("m/d/Y");
                   $lsdata = "date -s '$Date $Time'";
                   $lsdate = $lsdata."<br>".shell_exec
($lsdata)."<br>".shell_exec("date");
                   break;
  case "Set Date": $Time = date("g:i a");
                   $lsdata = "date -s '$Date $Time'";
                   $lsdate = $lsdata."<br>".shell_exec
($lsdata)."<br>".shell_exec("date");
                   break;
                   
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<h1>Time Info</h1>
<?php
$time = date("g:i a");
$date = date("m/d/Y");
$weekday = date("l");
print "The Time is $time.<br>";
print "The Date is $date.<br>";
print "It is a $weekday.<br>";
print "<text>$lsdata</text>";
// The following code grabs info from the network config file
$handle = fopen("/etc/network/interfaces","r");
if ($handle)
{
  while (!feof($handle))
  {
    $line = fgets($handle, 4096);
    if (strpos($line,"iface eth0")!==FALSE)
    {
       if (strpos($line,"dhcp"))
       {
         $dhcpinfo = "Using DHCP";
       }
       if (strpos($line,"static"))
       {
         $dhcpinfo = "Using STATIC";
       }
           while (!feof($handle))
           {
             $line = fgets($handle, 4096);
             if ((strpos($line,"iface"))&&($line=""))
                while (!feof($handle)) fgets($handle, 4096);
             if (strpos($line,"address"))
                list($data,$address) = sscanf($line,"%s %s");
             if (strpos($line,"netmask"))
                list($data,$netmask) = sscanf($line,"%s %s");
             if (strpos($line,"gateway"))
                list($data,$gateway) = sscanf($line,"%s %s");
           }
    }
  }
  fclose($handle);
}
else print "Open Failed";
?>
<form method="post" action="timeForm.php">
<div style="text-align: right;"> </div>
<table style="width: 50%; text-align: left;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: right;">TIME:&nbsp;
<?php print "<input name='Time' value = '$time'>"; ?></td>
<td style="vertical-align: top;"><input name="TimeSubmit"
value="Set Time" type="submit"></td>
</tr>
<tr>
<td style="vertical-align: top; text-align: right;">DATE:&nbsp;
<?php print "<input name='Date' value = '$date'>"; ?></td>
<td style="vertical-align: top;"><input name="TimeSubmit"
value="Set Date" type="submit"></td>
</tr>
<tr>
<td style="vertical-align: top; text-align: right;">ADDRESS:&nbsp;
<?php print "<input name='Address' value = '$address'>"; ?></td>
<td style="vertical-align: top;"><input name="TimeSubmit"
value="Use DHCP" type="submit"><br>
</td>
</tr>
<tr>
<td style="vertical-align: top; text-align: right;">NETMASK:<?php 
print "<input name='netmask' value = '$netmask'>"; ?></td>
<td style="vertical-align: top;"><?php print $dhcpinfo; ?><br>
</td>
</tr>
<tr>
<td style="vertical-align: top; text-align: right;">GATEWAY:<?php 
print "<input name='gateway' value = '$gateway'>"; ?></td>
<td style="vertical-align: top;"><input name="TimeSubmit"
value="Set as Static" type="submit"></td>
</tr>
</tbody>
</table>
<input name="TimeSubmit" value="Reset" type="submit">
<input name="TimeSubmit" value="Set HC" type="submit">
<input name="TimeSubmit" value="Set with NTP" type="submit">
</form>
</body>
</html>








Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/php-list/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to