DOS|Proton
02-05-2005, 02:47 PM
I currently have this 1 link that, if visited, it reboots my server. I'm trying to make a php page with a button on there so when I hit the button, it executes the link to reboot my machine but instead of being redirected to that link after clicking the button, I'd like to remain on the page.
Is there some kind of special form command to do that so I don't get redirected to the link, I just stay on the same site but my machine is still rebooted?
Can someone provide me with a sample code to do so, using http://blalblahblah.com/reboot/xx.xx.xxx.xx as the reboot link?
Thanks
DOS|Proton
02-05-2005, 03:41 PM
Also, is there a way to make a certain page only accessible from 1 IP?
Tekerz
02-05-2005, 06:56 PM
<?
$allowed_ip = 111.111.111.11;
// IP of authorized user
$user_ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
// This will be IP of current user
if (isset($_POST['submit'])) {
// check if page form was submited
if ($allowed_ip == $user_ip) {
//insert reboot code here if it's a URL use Snoopy PHP class
$msg = "Yes";
}
else {
// IP didn't match so no reboot and redirect user somewhere safe
header ("location: http://www.someplace.com");
}}
?>
<html>
<head>
<title>Your Reboot Page</title>
</head>
<body>
<center>
<?
if ($msg == "Yes") {
echo "Reboot was executed!";
}
?>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<br>
<input type="submit" name="submit" value="REBOOT NOW">
<br>
</form>
</body>
</html>
So That should do it. If you the reboot script can't be added to this script you can use the Snoopy class to run the URL (for lack of a better term).
Just change the 111.111.111.11 to the IP address of the authorized user. And change the someplace.com to a page that you want to redirect the unauthorized users to. Other then that just name the what ever you want save it as PHP and you should be all set. Let me know if you need more help or have trouble.
Tekerz
02-05-2005, 07:18 PM
One thing just make sure to place the IP address for the 1st variable ($allowed_ip) in quotation marks as it will error out otherwise.
Good Luck.
Burhan
02-06-2005, 02:03 AM
The problem with that code (and others like it) is that the client IP cannot be detected reliably (proxies, different ISP restrictions, multiple IP addresses, etc.)
fastduke
02-06-2005, 02:35 PM
Originally posted by fyrestrtr
The problem with that code (and others like it) is that the client IP cannot be detected reliably (proxies, different ISP restrictions, multiple IP addresses, etc.)
Of course. But is this code for the masses or is it for something specific? I would probably go with some kind of authentication, but hey timtowtdi!
innova
02-07-2005, 12:40 PM
That is pretty scary. File this post under the 'not recommended under any circumstances' category :)