This is the old XigmaNAS forum in read only mode,
it will taken offline by the end of march 2021!



I like to aks Users and Admins to rewrite/take over important post from here into the new fresh main forum!
Its not possible for us to export from here and import it to the main forum!

Shut down server with php and curl script

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
aleatorvb
NewUser
NewUser
Posts: 12
Joined: 21 Nov 2012 00:45
Status: Offline

Shut down server with php and curl script

Post by aleatorvb »

Code: Select all

$ip='10.0.0.66';
$port='80';
$user='admin';
$pass='nas4free';

$ch=curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, 'shutdown_happy.cookies');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
echo 'First page...'."\n";
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,	true);
curl_setopt($ch, CURLOPT_URL, "http://".$ip.':'.$port.'/index.php');
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, false);
$result=curl_exec($ch);
if(stripos($result,'value="Login"')!==false){
	echo 'Loging in...'."\n";
	$result='';
	curl_setopt($ch, CURLOPT_URL, "http://".$ip.':'.$port.'/login.php');
	curl_setopt($ch, CURLOPT_POST, true); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$user.'&password='.$pass);
	$result=curl_exec($ch);
	curl_setopt($ch, CURLOPT_POST, false);
}
echo 'Shutdown page...'."\n";
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,	true);
curl_setopt($ch, CURLOPT_URL, "http://".$ip.':'.$port.'/shutdown.php');
$result=curl_exec($ch);
if(stripos($result,'authtoken')!==false){
	$start=stripos($result,'authtoken');
	$authtoken=substr($result,$start,75);
	$authtoken=str_replace('authtoken"','',$authtoken);
	$authtoken=str_replace('type="hidden"','',$authtoken);
	$authtoken=str_replace('value="','',$authtoken);
	$authtoken=str_replace('/>','',$authtoken);
	$authtoken=str_replace('"','',$authtoken);
	$authtoken=trim($authtoken);
	echo 'Token: '.$authtoken."\n";
	
	echo 'Shutting down... '."\n";
	curl_setopt($ch, CURLOPT_URL, "http://".$ip.':'.$port.'/shutdown.php');
	curl_setopt($ch, CURLOPT_POST, true); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, 'authtoken='.$authtoken.'&Submit=yes');
	$result=curl_exec($ch);
	
	if(stripos($result,'The system is halting now')!==false){
		echo 'Success'."\n";
		die(0);
	}else{
		die(2);
	}
}
die(1);
Hardware: 9.1.0.1 - Sandstorm (revision 847) | Intel Corporation DQ87PG | 6x 3TB WD Red drives in a raid-z2 storage |Services: CIFS, Nagios Client, SSH, BitTorrent, Bittorent Sync. Saturating a gigabyte link over cifs! :)

User avatar
kkd
Forum Moderator
Forum Moderator
Posts: 306
Joined: 08 May 2013 21:47
Location: Budapest, Hungary
Contact:
Status: Offline

Re: Shut down server with php and curl script

Post by kkd »

hi
why did u post that?
XigmaNAS x64-embedded | INTEL Intel(R) Core(TM) i3-2100 CPU @ 3.10GHz | 9216MiB RAM | X x YTB WD Red ZFS mirror compressed

aleatorvb
NewUser
NewUser
Posts: 12
Joined: 21 Nov 2012 00:45
Status: Offline

Re: Shut down server with php and curl script

Post by aleatorvb »

In case someone else needed it.
Hardware: 9.1.0.1 - Sandstorm (revision 847) | Intel Corporation DQ87PG | 6x 3TB WD Red drives in a raid-z2 storage |Services: CIFS, Nagios Client, SSH, BitTorrent, Bittorent Sync. Saturating a gigabyte link over cifs! :)

Post Reply

Return to “Scripts and shell tips”