logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: Performing remote shutdown via perl cgi [SOLVED]
Author
gianni24



Joined: 23 Jan 2015
Posts: 5
Location: italy, bracciano

PostPosted: Mon 26 Jan '15 10:34    Post subject: Performing remote shutdown via perl cgi [SOLVED] Reply with quote

Hello everybody,
I'm new to this forum, and hope someone can help me and put me trough in solving this annoying problem.

I've got at home one server running various services, some home based intranet site, and one useful "home lan control" that allows me to check the status and control every computer on my lan. The computer is running Xp Pro sp3, and I've got Apache 2.2.1 32 bit installed, with no ssl. I'm planning to upgrade the OS to Windows 7 64bit, so I've build a second server with the new OS, and set up the same Apache version on it.

What's happening in short: I cannot use the system command c:\windows\system32\shutdown.exe trough apache because the system is returning this error:

ERROR_ENVVAR_NOT_FOUND

To make sure is not depending on apache version I've tried the same with Apache 2.2.1 32bit, Apache 2.2.1 64 and Apache 2.4.3 64 bit. I'v tried too on a second windows7 64 bit machine too, with same result. Obviously I've already set apache services to run as account with sufficient privileges (acqually is an admin account).

If someone want to help me please use this simple perl cgi:

Code:
$cmd="shutdown.exe /?";
$rc=`$cmd 2>&1`;
print "Content-type: text/html\n\n";
print "$cmd<br><pre>$rc</pre>";


On XP the result is the help page of the shutdown command, on Win7 the result is the text message associated with the error depicted above. Launching the offending script direclty from commandline gives good result in both OSs.

Any help would be appreciated, even alternatives to the use of shutdown.exe in order to shutdown or restart remote machines on my net.

Thank you so much for any help coming Smile


Last edited by gianni24 on Fri 30 Jan '15 9:19; edited 1 time in total
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 26 Jan '15 18:53    Post subject: Re: Performing remote shutdown via perl cgi Reply with quote

gianni24 wrote:
(acqually is an admin account


Actually, no it's not. It's just an account that is able to ask for Administrator privileges as needed. That was a big change beginning in Vista to help keep infections down. There is only one true admin account "Administrator" and is disabled by default.

You could turn off the UAC but I really would not advise doing that, it's an option however.

If it's a pro/ultimate version of 7 then you could always remote desktop in, right-click on the command prompt shortcut and choose "Run as Administrator" and then issue the command. This is what I do.
Back to top
gianni24



Joined: 23 Jan 2015
Posts: 5
Location: italy, bracciano

PostPosted: Tue 27 Jan '15 18:11    Post subject: Re: Performing remote shutdown via perl cgi Reply with quote

Quote:
Actually, no it's not. It's just an account that is able to ask for Administrator privileges as needed. That was a big change beginning in Vista to help keep infections down. There is only one true admin account "Administrator" and is disabled by default.


Thankyou for pointing this out. The user I'm using to run Apache is the user I use to log on the computer, is not administrator, but has admin privileges.

I've changed the owner of shutdown.exe to this user too.

Quote:
You could turn off the UAC but I really would not advise doing that, it's an option however.


I've tried turning off UAC with no joy.

Quote:
If it's a pro/ultimate version of 7 then you could always remote desktop in, right-click on the command prompt shortcut and choose "Run as Administrator" and then issue the command. This is what I do.


The OS is Windows 7 Professional sp1. The machine is headless so I log on to it ONLY trough rdp.

Wich command I'm supposed to run as admin? If you're suggesting running httpd from commandline I've tried too, same result.

Let me add this info: shutdown.exe is the ONLY command I need that's non working when launched under apache, I've tried many others and all of them are working fine.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Tue 27 Jan '15 19:21    Post subject: Re: Performing remote shutdown via perl cgi Reply with quote

gianni24 wrote:
Wich command I'm supposed to run as admin? If you're suggesting running httpd from commandline I've tried too, same result.


shutdown.exe
Back to top
gianni24



Joined: 23 Jan 2015
Posts: 5
Location: italy, bracciano

PostPosted: Wed 28 Jan '15 14:46    Post subject: Reply with quote

shutdown.exe is working fine from the commandline.

Furthermore the perl script I've put in the post is working too, if launched from commandline and not from apache.

The problem seems in effects to be related with some environment variable shutdown is searching for and NOT founding when executing through apache.

Unfortunately I've got no idea of which env variable shutdown is needing...
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Wed 28 Jan '15 16:15    Post subject: Reply with quote

Did you try the fullpath to shutdown.exe ?
Back to top
gianni24



Joined: 23 Jan 2015
Posts: 5
Location: italy, bracciano

PostPosted: Fri 30 Jan '15 8:38    Post subject: Reply with quote

James Blond wrote:
Did you try the fullpath to shutdown.exe ?


Yes sure, it make no difference.

Shutdown.exe starts under apache, but it can't find some env var (not telling me which one)...

I've used a script like this one to see env var avaliable at time of launch:

print ("Content-type: text/html\n\n");
print "<h1>variabili d'ambiente</h1>\n";
print "\$0 = $0<br>\n";
foreach $key (sort keys(%ENV)) {
print "\$ENV{'$key'} = $ENV{$key}<br>\n";
}

This script can be run from commandline and/or via apache. This are the results under xp and win7 sp1 64bit:

win7 commandline
Code:
Content-type: text/html

<h1>variabili d'ambiente</h1>
$0 = E:\siti\www\cgi\env.pl<br>
$ENV{'ALLUSERSPROFILE'} = C:\ProgramData<br>
$ENV{'APPDATA'} = C:\Users\gianni\AppData\Roaming<br>
$ENV{'CLIENTNAME'} = GIANNIV<br>
$ENV{'COMMONPROGRAMFILES'} = C:\Program Files (x86)\Common Files<br>
$ENV{'COMMONPROGRAMFILES(X86)'} = C:\Program Files (x86)\Common Files<br>
$ENV{'COMMONPROGRAMW6432'} = C:\Program Files\Common Files<br>
$ENV{'COMPUTERNAME'} = SERVA<br>
$ENV{'COMSPEC'} = C:\Windows\system32\cmd.exe<br>
$ENV{'FP_NO_HOST_CHECK'} = NO<br>
$ENV{'HOMEDRIVE'} = C:<br>
$ENV{'HOMEPATH'} = \Users\gianni<br>
$ENV{'LOCALAPPDATA'} = C:\Users\gianni\AppData\Local<br>
$ENV{'LOGONSERVER'} = \\SERVA<br>
$ENV{'NUMBER_OF_PROCESSORS'} = 4<br>
$ENV{'OS'} = Windows_NT<br>
$ENV{'PATH'} = C:\Windows\system32;C:\Program Files (x86)\ImageMagick;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\Wbem;C:\Windows;C:\Program Files (x86)\Perl\bin\<br>
$ENV{'PATHEXT'} = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC<br>
$ENV{'PROCESSOR_ARCHITECTURE'} = x86<br>
$ENV{'PROCESSOR_ARCHITEW6432'} = AMD64<br>
$ENV{'PROCESSOR_IDENTIFIER'} = AMD64 Family 16 Model 4 Stepping 3, AuthenticAMD<br>
$ENV{'PROCESSOR_LEVEL'} = 16<br>
$ENV{'PROCESSOR_REVISION'} = 0403<br>
$ENV{'PROGRAMDATA'} = C:\ProgramData<br>
$ENV{'PROGRAMFILES'} = C:\Program Files (x86)<br>
$ENV{'PROGRAMFILES(X86)'} = C:\Program Files (x86)<br>
$ENV{'PROGRAMW6432'} = C:\Program Files<br>
$ENV{'PROMPT'} = $P$G<br>
$ENV{'PSMODULEPATH'} = C:\Windows\system32\WindowsPowerShell\v1.0\Modules\<br>
$ENV{'PUBLIC'} = C:\Users\Public<br>
$ENV{'SESSIONNAME'} = RDP-Tcp#0<br>
$ENV{'SYSTEMDRIVE'} = C:<br>
$ENV{'SYSTEMROOT'} = C:\Windows<br>
$ENV{'TEMP'} = E:\Temp<br>
$ENV{'TMP'} = E:\Temp<br>
$ENV{'USERDOMAIN'} = Serva<br>
$ENV{'USERNAME'} = gianni<br>
$ENV{'USERPROFILE'} = C:\Users\gianni<br>
$ENV{'WINDIR'} = C:\Windows<br>
$ENV{'WINDOWS_TRACING_FLAGS'} = 3<br>
$ENV{'WINDOWS_TRACING_LOGFILE'} = C:\BVTBin\Tests\installpackage\csilogfile.log<br>
$ENV{'__COMPAT_LAYER'} = RunAsAdmin<br>


Win7 Apache
Code:
variabili d'ambiente
$0 = E:\siti\www\cgi\env.pl
$ENV{'COMSPEC'} = C:\Windows\system32\cmd.exe
$ENV{'DOCUMENT_ROOT'} = E:/siti/www
$ENV{'GATEWAY_INTERFACE'} = CGI/1.1
$ENV{'HTTP_ACCEPT'} = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
$ENV{'HTTP_ACCEPT_ENCODING'} = gzip, deflate
$ENV{'HTTP_ACCEPT_LANGUAGE'} = it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
$ENV{'HTTP_CONNECTION'} = keep-alive
$ENV{'HTTP_HOST'} = serva
$ENV{'HTTP_USER_AGENT'} = Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
$ENV{'PATH'} = C:\Windows\system32;C:\Program Files (x86)\ImageMagick;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\Wbem;C:\Windows;C:\Program Files (x86)\Perl\bin\
$ENV{'PATHEXT'} = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
$ENV{'QUERY_STRING'} =
$ENV{'REMOTE_ADDR'} = 127.0.0.1
$ENV{'REMOTE_PORT'} = 49176
$ENV{'REQUEST_METHOD'} = GET
$ENV{'REQUEST_URI'} = /cgi/env.pl
$ENV{'SCRIPT_FILENAME'} = E:/siti/www/cgi/env.pl
$ENV{'SCRIPT_NAME'} = /cgi/env.pl
$ENV{'SCRIPT_URI'} = http://serva/cgi/env.pl
$ENV{'SCRIPT_URL'} = /cgi/env.pl
$ENV{'SERVER_ADDR'} = 127.0.0.1
$ENV{'SERVER_ADMIN'} = gianni24@techie.com
$ENV{'SERVER_NAME'} = serva
$ENV{'SERVER_PORT'} = 80
$ENV{'SERVER_PROTOCOL'} = HTTP/1.1
$ENV{'SERVER_SIGNATURE'} =
$ENV{'SERVER_SOFTWARE'} = Apache/2.2.21 (Win64)
$ENV{'SYSTEMROOT'} = C:\Windows
$ENV{'WINDIR'} = C:\Windows
$ENV{'__COMPAT_LAYER'} = RunAsAdmin


Xp Commandline
Code:
Content-type: text/html

<h1>variabili d'ambiente</h1>
$0 = E:\siti\www\cgi\env.pl<br>
$ENV{'ALLUSERSPROFILE'} = C:\Documents and Settings\All Users<br>
$ENV{'APPDATA'} = C:\Documents and Settings\gianni\Dati applicazioni<br>
$ENV{'CLIENTNAME'} = Console<br>
$ENV{'COMMONPROGRAMFILES'} = C:\Programmi\File comuni<br>
$ENV{'COMPUTERNAME'} = MULO<br>
$ENV{'COMSPEC'} = C:\WINDOWS\system32\cmd.exe<br>
$ENV{'FP_NO_HOST_CHECK'} = NO<br>
$ENV{'HOMEDRIVE'} = C:<br>
$ENV{'HOMEPATH'} = \Documents and Settings\gianni<br>
$ENV{'LOGONSERVER'} = \\MULO<br>
$ENV{'NUMBER_OF_PROCESSORS'} = 4<br>
$ENV{'OS'} = Windows_NT<br>
$ENV{'PATH'} = C:\Programmi\ImageMagick;C:\PROGRA~1\ULTRAE~1;C:\Programmi\ATI Technologies\ATI.ACE\Core-Static;C:\WINDOWS\System32\Wbem;C:\WINDOWS;C:\WINDOWS\system32;C:\Programmi\Perl\bin\;C:\Programmi\CVSNT\<br>
$ENV{'PATHEXT'} = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH<br>
$ENV{'PROCESSOR_ARCHITECTURE'} = x86<br>
$ENV{'PROCESSOR_IDENTIFIER'} = x86 Family 16 Model 5 Stepping 2, AuthenticAMD<br>
$ENV{'PROCESSOR_LEVEL'} = 16<br>
$ENV{'PROCESSOR_REVISION'} = 0502<br>
$ENV{'PROGRAMFILES'} = C:\Programmi<br>
$ENV{'PROMPT'} = $P$G<br>
$ENV{'SESSIONNAME'} = Console<br>
$ENV{'SYSTEMDRIVE'} = C:<br>
$ENV{'SYSTEMROOT'} = C:\WINDOWS<br>
$ENV{'TEMP'} = E:\Temp<br>
$ENV{'TMP'} = E:\Temp<br>
$ENV{'USERDOMAIN'} = MULO<br>
$ENV{'USERNAME'} = gianni<br>
$ENV{'USERPROFILE'} = C:\Documents and Settings\gianni<br>
$ENV{'WINDIR'} = C:\WINDOWS<br>


Xp Apache
Code:
variabili d'ambiente
$0 = E:\siti\www\cgi\env.pl
$ENV{'COMSPEC'} = C:\WINDOWS\system32\cmd.exe
$ENV{'DOCUMENT_ROOT'} = E:/siti/www
$ENV{'GATEWAY_INTERFACE'} = CGI/1.1
$ENV{'HTTP_ACCEPT'} = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
$ENV{'HTTP_ACCEPT_ENCODING'} = gzip, deflate
$ENV{'HTTP_ACCEPT_LANGUAGE'} = it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
$ENV{'HTTP_CONNECTION'} = keep-alive
$ENV{'HTTP_HOST'} = xphost
$ENV{'HTTP_USER_AGENT'} = Mozilla/5.0 (Windows NT 5.1; rv:28.0) Gecko/20100101 Firefox/28.0
$ENV{'PATH'} = C:\Programmi\ImageMagick;C:\PROGRA~1\ULTRAE~1;C:\Programmi\ATI Technologies\ATI.ACE\Core-Static;C:\WINDOWS\System32\Wbem;C:\WINDOWS;C:\WINDOWS\system32;C:\Programmi\Perl\bin\;C:\Programmi\CVSNT\
$ENV{'PATHEXT'} = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
$ENV{'QUERY_STRING'} =
$ENV{'REMOTE_ADDR'} = 127.0.0.1
$ENV{'REMOTE_PORT'} = 1686
$ENV{'REQUEST_METHOD'} = GET
$ENV{'REQUEST_URI'} = /cgi/env.pl
$ENV{'SCRIPT_FILENAME'} = E:/siti/www/cgi/env.pl
$ENV{'SCRIPT_NAME'} = /cgi/env.pl
$ENV{'SCRIPT_URI'} = http://xphost/cgi/env.pl
$ENV{'SCRIPT_URL'} = /cgi/env.pl
$ENV{'SERVER_ADDR'} = 127.0.0.1
$ENV{'SERVER_ADMIN'} = gianni24@techie.com
$ENV{'SERVER_NAME'} = xphost
$ENV{'SERVER_PORT'} = 80
$ENV{'SERVER_PROTOCOL'} = HTTP/1.1
$ENV{'SERVER_SIGNATURE'} =
$ENV{'SERVER_SOFTWARE'} = Apache/2.2.21 (Win32)
$ENV{'SYSTEMROOT'} = C:\WINDOWS
$ENV{'WINDIR'} = C:\WINDOWS


Maybe you can get something out of it Smile


Last edited by gianni24 on Fri 30 Jan '15 9:40; edited 1 time in total
Back to top
gianni24



Joined: 23 Jan 2015
Posts: 5
Location: italy, bracciano

PostPosted: Fri 30 Jan '15 9:25    Post subject: Reply with quote

SOLVED

Thank you so much to help me to "activate" my brain.

After posting the former answer I've asked myself: "why I can't provide shutdown with the env var he need?"

I've compared the env var avaliable at commandline with the one avaliable via Apache. Then I've added (BEFORE calling shutdown) a "set" for all the missing variables, and this way the command was working!! After a little binary search COMPUTERNAME turned out to be the "offending" env var.

In short to fix the strange behaviour of shutdown I've added the following lines to my perl script, before calling it:

Code:
$name=`hostname`;
$name=~s@\n@@gs;
$ENV{'COMPUTERNAME'}=$name;


et voila' the script is working fine now!!

I've changed the subj of my first post adding [SOLVED] hope this can help someone else too!
Back to top


Reply to topic   Topic: Performing remote shutdown via perl cgi [SOLVED] View previous topic :: View next topic
Post new topic   Forum Index -> Other Software