Jump to content

need a little help with some php commands


stelthius

Recommended Posts

Hi Guys,

 

I have built a test script to restart a few services via php but i have hit a wall, the script doesnt seem to work, safe mode is off in php and im aware it isnt recommended using PHP to perform the actions i want to it perform if anyone has any better ( Safer ) solutions please let me know :D

 

Below is my code, can anyone tell me why it wont work please ?

 

<?php		
	if (isset($_GET['cmd'])){
		if ($_GET['cmd'] == 'restart') {
		passthru('shutdown -r -t 01');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'shutdown') {
		passthru('shutdown -s -t 01');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'restartapache') {
		passthru('net stop apache');
		passthru('net start apache');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'restartmysql') {
		passthru('net stop MySQL');
		passthru('net start MySQL');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
		if ($_GET['cmd'] == 'restartftp') {
		passthru('#');
		echo '<font color=red>'.$lang_serrestarted.'</font>';
		}
	}		

	ini_set('display_errors','0'); 

	function lookup_ports($hport,$hdomain) {
         	$fp = fsockopen($hdomain, $hport,$errno,$errstr, 4);
        	if (!$fp){
             	$data = "<font color=red size=4>*</font>";
         	} else {
             	$data = "<font color=green size=4>*</font>";
             	fclose($fp);
         	}
         return $data;
	}

              ?>
System Control<br>
<br>
Restart Server - <a href="?page=servercontrol&cmd=restart">Restart Server</a><br>
<br>
Shutdown Server - <a href="?page=servercontrol&cmd=shutdown">Shutdown Server</a><br />
<br />
Restart Apache - <a href="?page=servercontrol&cmd=apacherestart">Restart Apache</a><br />
<br />
Restart MySQL - <a href="?page=servercontrol&cmd=restartmysql">Restart MySQL</a><br />
<br />
Restart FTP - <a href="?page=servercontrol&cmd=restartftp">Restart FTP</a><br />

 

Any help or ideas is appretiated,

 

 

Thanks Rick

Firstly, you should be using elseif. Secondly, you may try using shell_exec().

 

Also, I don't think I've ever seen apache or mysql restarted in that manner. Try:

 

apache:

/etc/init.d/httpd restart

apache2ctl restart

apachectl restart

 

mysql:

/etc/init.d/mysqld restart

I'm not sure of your permissions, but try to do sudo /etc/init.d/httpd restart. if not you can always do stop and then start.'

 

Try each of those apache restarts, one of them is bound to work.

 

Actually I lied: /etc/init.d/apache restart :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.