Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

remote reboot

tommycahirtommycahir Posts: 27Member
[b][red]This message was edited by tommycahir at 2004-1-29 10:4:47[/red][/b][hr]
i'm writing a cgi script that will allow the user to remotely reboot a server (could be running windows or linux).. i'm new to perl and havent got a clue on how to go about this any help would be greatly appreciated
i'm also using snmp as part of the script to retrive information about the device and if theres possibly any way of doing it that way it would be greatly appreciated also.
thanking you
tommy


Comments

  • JonathanJonathan Posts: 2,914Member
    Hi,

    : i'm writing a cgi script that will allow the user to remotely reboot
    : a server (could be running windows or linux).. i'm new to perl and
    : havent got a clue on how to go about this any help would be greatly
    : appreciated
    I'm assuming you mean reboot the machine that the CGI script runs on. Windows and Linux are somewhat different (technically). You have a few issues on either platform, which are mostly privilege related.

    Linux - normally only root can issue a reboot command, e.g.
    shutdown -r now
    There are ways to allow normal users to execute it, I can probably dig them up for you. Alternatively, you can have a cron job that fires every minute (as root) and runs a script that checks if a file has been created that means a reboot is needed. It then deletes the file and does the reboot. The reboot CGI script simply needs to put the file in the right place. That way you don't need to award any additional privileges to the user the CGI runs as, which is my eyes is desirable.

    Windows - you need to call the ExitWindows API. There'll most likely be a Perl module to do this. Drop by http://search.cpan.org/ and look at the Win32 modules. Again, their will probably be a privs issue. I don't do a lot of Win32 dev or sysadmin (only use it as a desktop OS) so I'm not entirely familiar with the best way of doing this.

    : i'm also using snmp as part of the script to retrive information
    : about the device and if theres possibly any way of doing it that way
    : it would be greatly appreciated also.
    Again, CPAN is your friend. A search for snmp on there shows up several modules. I haven't used any of them, but if you know your SNMP then you'll probably be able to pick out what you need. :-)

    Hope this helps,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • tommycahirtommycahir Posts: 27Member
    : Hi,
    :
    : : i'm writing a cgi script that will allow the user to remotely reboot
    : : a server (could be running windows or linux).. i'm new to perl and
    : : havent got a clue on how to go about this any help would be greatly
    : : appreciated
    : I'm assuming you mean reboot the machine that the CGI script runs on. Windows and Linux are somewhat different (technically). You have a few issues on either platform, which are mostly privilege related.
    :
    : Linux - normally only root can issue a reboot command, e.g.
    : shutdown -r now
    : There are ways to allow normal users to execute it, I can probably dig them up for you. Alternatively, you can have a cron job that fires every minute (as root) and runs a script that checks if a file has been created that means a reboot is needed. It then deletes the file and does the reboot. The reboot CGI script simply needs to put the file in the right place. That way you don't need to award any additional privileges to the user the CGI runs as, which is my eyes is desirable.
    :
    : Windows - you need to call the ExitWindows API. There'll most likely be a Perl module to do this. Drop by http://search.cpan.org/ and look at the Win32 modules. Again, their will probably be a privs issue. I don't do a lot of Win32 dev or sysadmin (only use it as a desktop OS) so I'm not entirely familiar with the best way of doing this.
    :
    : : i'm also using snmp as part of the script to retrive information
    : : about the device and if theres possibly any way of doing it that way
    : : it would be greatly appreciated also.
    : Again, CPAN is your friend. A search for snmp on there shows up several modules. I haven't used any of them, but if you know your SNMP then you'll probably be able to pick out what you need. :-)
    :
    : Hope this helps,
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :
    that helps at least it gives me some where to start from.. there is a disadvantage to it as the user could type in the ip address of any server they wish and the cron demon miten't be actually be running on it... ill have a look on cpan to see if i can find anything useful
    tanx for the help
    any thing else would be greatly appreciated
  • JonathanJonathan Posts: 2,914Member
    : that helps at least it gives me some where to start from.. there is
    : a disadvantage to it as the user could type in the ip address of any
    : server they wish and the cron demon miten't be actually be running
    : on it... ill have a look on cpan to see if i can find anything
    : useful
    Hang on a moment...I thought you wanted a way to reboot the server the CGI script was executing on...but now you're talking about entering an IP I fear that's not what you want to do. If you want to shut down a remote server...well, that's kinda more difficult. Guess you can always SSH into it as root and do the shutdown. There'll surely be an SSH module (Net::SSH I think, don't quote me on it).

    : tanx for the help
    : any thing else would be greatly appreciated
    I can offer you obscene poetry written in VB and haiku about UNIX?

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • tommycahirtommycahir Posts: 27Member
    : : that helps at least it gives me some where to start from.. there is
    : : a disadvantage to it as the user could type in the ip address of any
    : : server they wish and the cron demon miten't be actually be running
    : : on it... ill have a look on cpan to see if i can find anything
    : : useful
    : Hang on a moment...I thought you wanted a way to reboot the server the CGI script was executing on...but now you're talking about entering an IP I fear that's not what you want to do. If you want to shut down a remote server...well, that's kinda more difficult. Guess you can always SSH into it as root and do the shutdown. There'll surely be an SSH module (Net::SSH I think, don't quote me on it).
    :
    :sorry not being so clear with the spec. i trying not to use ssh if possible it a web based applic that loows the user to enter an ip address (host name) and the community name and the either choose to see how long the system was up for or to reboot the system.. the server could be anywhere and as long as you have the correct community name and the ip address then you couyld send the reboot command. i think i got a way for doing it in windows still not sure bout the unix servers though.. ill have a look for the ssh module to see if i could do it that way
    tanx for all the help

  • JonathanJonathan Posts: 2,914Member
    : sorry not being so clear with the spec. i trying not to use ssh if
    : possible it a web based applic that loows the user to enter an ip
    : address (host name) and the community name and the either choose to
    : see how long the system was up for or to reboot the system.. the
    : server could be anywhere and as long as you have the correct
    : community name and the ip address then you couyld send the reboot
    : command. i think i got a way for doing it in windows still not sure
    : bout the unix servers though.. ill have a look for the ssh module to
    : see if i could do it that way
    :
    If I'm seeing this right you have:-

    [code]
    User --> Web Server With CGI
    | |
    Server A Server B[/code]
    The user enters an IP address of one of the servers. This server is then connected to by the CGI script to request info and/or be sent a reboot instruction.

    The main issue is that the CGI has to have access details for the other servers, e.g. if it's a UNIX machine you'll normally need root privs to shut it down. The SSH module may well be your best bet for those. Windows, well...pleased you've got something there. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.