The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Viewing/Stopping/Restarting Services from external webpage

Discussion in 'cPanel Developers' started by Budde, Aug 25, 2008.

  1. Budde

    Budde Registered

    Joined:
    Aug 25, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I'd like to view, start, stop or restart services from cpanel on an external page of my site, instead of going to cpanel.. Is this possible?
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    At this time, our XML-API does support restarting of services. Viewing service status can be done independently of our APIs.

    As for starting/stopping services, are you encountering any issues with your server that would make you desire to do this?
     
  3. Budde

    Budde Registered

    Joined:
    Aug 25, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I was just wondering, since I'd like to create a Services page that would allow certain people to stop, start or restart services.
     
  4. wsenter

    wsenter Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    88
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Texas
    Take a look into writing specific interfaces with php and curl. I've done it in the past for a few additional remote server functions (like add account/modify account etc..). I've included the code below to give you a starting point. You should be able to use php and curl to be able to create something you want. Again the following is just an example as to how php/curl works. It will not solve your problem without heavy modifications...

    Code:
    <?php 
    // start the session and pass the Session parameter
    session_start(); 
    header("Cache-control: private"); //IE 6 Fix
    
    ######### Set up basic variables #########
    $serverIPaddress="192.168.1.1:2087";
    $whmusername="root";
    $whmpassword="123456";
    $server="https://$whmusername:$whmpassword@$serverIPaddress";
    
    //set the username of the account you are working with
    $user = "bobby12";
    $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
    
    
    
    ######### Here are few example of many of the items that you could do with curl.  It will not execute until the very bottom #########
    
    //change user's password
    $url="$server/scripts/passwd?password=$passwd&domain=$user&user=$user";
    
    //enable shell access		
    $url="$server/scripts2/domanageshells?user=$user&shell=Enable+Jailed+Shell&user=$user";
    
    //bandlimit increase		
    $url="$server/scripts2/dolimitbw?user=$user&bwlimit=$bndwidth";
    		
    //suspend an account
    $url="$server/scripts2/suspendacct?domain=$user&user=$user&suspend-domain=Suspend&reason=";
    
    //UN-suspend an account
    $url="$server/scripts2/suspendacct?domain=$user&user=$user&unsuspend-domain=UnSuspend&reason=";
    
    //add front page extensions
    $url="$server/scripts/installfp?domain=$user&user=$user&submit-domain=Install";
    
    //remove front page extensions
    $url="$server/scripts/uninstallfp?domain=$user&user=$user&submit-domain=UnInstall";
    
    //modify the quota on the account		
    $url="$server/scripts/editquota?user=$user&quota=$quota";
    
    //add a domain pointer
    $url="$server/scripts/park?txtdomain=&domain=$domain&ndomain=$NewDomain";
    		
    //modify the account
    $url="$server/scripts/saveedituser?user=$user&BWLIMIT";
    $url.="=$BWLIMIT&FEATURELIST=$FEATURELIST&IP=$IP&OWNER";
    $url.="=$OWNER&PLAN=$PLAN&STARTDATE=$STARTDATE&DNS=$domain";
    $url.="&RS=$RS&LANG=english&newuser=$user&seeshell=$shell&MAXPOP";
    $url.="=$MAXPOP&MAXFTP=$MAXFTP&MAXLST=$MAXLST&MAXSUB=$MAXSUB&MAXSQL";
    $url.="=$MAXSQL&MAXPARK=$MAXPARK&MAXADDON=$MAXADDON";
    
    //generate a csr
     //need to replace spaces in all of the variables with the '+' sign
    $host = str_replace(" ","+",$host);
    $country = str_replace(" ","+",$country);
    $state = str_replace(" ","+",$state);
    $city = str_replace(" ","+",$city);
    $cod = str_replace(" ","+",$cod);
    $co = str_replace(" ","+",$co);
    $email = str_replace(" ","+",$email);
    $pass = str_replace(" ","+",$pass);
    $url="$server/scripts/gencrt?xemail=$xemail&host=$host&country";
    $url.="=$country&state=$state&city=$city&co=$co&cod=$cod&email=$email&pass=$pass";
    		
    ######### execute curl #########
    
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    $buffer = curl_exec($ch);
    curl_close($ch);
    
    ?>
    If you are not able to do this on your own and are looking to hire someone to do this then we could talk. I am a US based programmer that could do something for you. If so write out a very detailed list of what exactly you want it to do and/or look like and we will proceed from there.
     

Share This Page