Re: How can I have PHP set the linux system date/time?
| From: | Marek Kilimajer | Date: | Thu, 13 Feb 2003 12:46:03 +0000 |
| Subject: | Re: How can I have PHP set the linux system date/time? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135432@lists.php.net to get a copy of this message | ||
$execString = "/usr/bin/sudo /bin/date ".$binDate."<BR>";
^^^^^I believe the problem is here Daevid Vincent wrote:
I'm not sure what I'm doing wrong... In changetime.php:$binDate = date ("mdhiY",mktime($hour,$minute,0,$month,$day,$year));$execString = "/usr/bin/sudo /bin/date ".$binDate."<BR>";
//echo $execString."<BR>"; exec($execString);And then in /etc/sudoers: nobody ALL=NOPASSWD: /bin/date If I run the command (as daevid) "/usr/bin/sudo /bin/date 011304042003" for example, it works fine. Apache is running as nobody it seems: [daevid=pts/6]4:10am@dev:{/www/htdocs}> ps aux | grep "httpd"root 590 0.0 1.5 4996 1988 ? S Feb12 0:00/www/bin/httpd -Dnobody 592 0.0 2.9 5396 3704 ? S Feb12 0:01/www/bin/httpd -Dnobody 593 0.0 3.0 5524 3804 ? S Feb12 0:00/www/bin/httpd -Dnobody 594 0.0 3.0 5556 3856 ? S Feb12 0:01/www/bin/httpd -D Sooooo.... What is the problem? Ideas?-----Original Message----- From: Marek Kilimajer [mailto:kilimajer@webglobe.sk] Sent: Thursday, February 13, 2003 3:43 AM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] How can I have PHP set the linux system date/time? You need root priviledges, that means /bin/date must run as root. You can use sudo Daevid Vincent wrote:Yep, I am trying to have a php web page change the linux system date/time, but obviously running into the snag that /bin/date, while "chmod 775" doesn't allow a user to set the date/time. Why is that, given the permissions? Sure it makes sense, but it'sannoying. Ideas onhow to circumvent this problem?must have-rwxr-xr-x 1 root root 26780 Jul 23 2001 /bin/dateSeems to me that anyone should be able to use it then right? Where is the "write" portion defined? The 'info date' page says, "Youappropriate privileges to set the system clock." But itdoesn't say whatthat is or how to change them. If anyone cares, here's a nice bit-o-code: <?php if ($year == "") $year = date("Y"); if ($month == "") $month = date("m"); if ($day == "") $day = date("d"); if ($hour == "") $hour = date("h"); if ($minute == "") $minute = date("i"); $NewDateTime = date ("m/d/Y H:i", mktime ($hour,$minute,0,$month,$day,$year)); $binDate = date ("mdhiY", mktime ($hour,$minute,0,$month,$day,$year)); exec("/bin/date ".$binDate); //TODO: um, yeah, how do you expect this to work? you have to be root to do this!!!! ?> <CENTER> <table border=0 class=componentBox> <TR><TD COLSPAN=8 class=Header>Change Time / Date</TD></TR> <TR> <FORM ACTION="<?=$SCRIPT_NAME?>" METHOD="POST"> <TD> <TABLE BORDER=0> <TR><TD class=Menu>New Date</TD><TD> <select name="month"> <?php for($i = 1; $i <= 12; $i++) { echo "<option"; if ($month == $i) echo " SELECTED"; printf(">%02d\n",$i); } ?> </select> / <select name="day"> <?php for($i = 1; $i <= 31; $i++) { echo "<option"; if ($day == $i) echo " SELECTED"; printf(">%02d\n",$i); } ?> </select> / <select name="year"> <option <?php if ($year == "2003") echo " SELECTED"; ?>>2003 <option <?php if ($year == "2004") echo " SELECTED"; ?>>2004 <option <?php if ($year == "2005") echo " SELECTED"; ?>>2005 <option <?php if ($year == "2006") echo " SELECTED"; ?>>2006 </select> </TR> <TR><TD class=Menu>New Time</TD><TD> <select name="hour"> <?php for($i = 0; $i <= 23; $i++) { echo "<option"; if ($hour == $i) echo " SELECTED"; printf(">%02d\n",$i); } ?> </select> : <select name="minute"> <?php for($i = 0; $i <= 59; $i++) { echo "<option"; if ($minute == $i) echo " SELECTED"; printf(">%02d\n",$i); } ?> </select> </TR> <TR><TD COLSPAN=2 ALIGN=RIGHT> <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Set Time / Date"class=button></TD></FORM></TR> </TABLE> </TD></TR></TABLE><p> <?php if (!checkdate($month,$day,$year)) print "\n<P><B>You entered an invalid date, so it was converted to ".$NewDateTime."</B><P>\n"; ?>