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.

Automate login to directly edit a page

Discussion in 'General Discussion' started by rborg, Jul 19, 2005.

  1. rborg

    rborg Registered

    Joined:
    Jul 19, 2005
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I made various coding attempts to make php CURL log on to any cpanel page via code (i.e. automated login but not to necessarily just to access index page).

    In fact the whole point is to offer my clients direct access to edit a specific html page on their domain without giving them the actual cpanel username and pass by creating a custom log in page through which clients log on using a user name and password provided by me and then in turn the script would automatically log them on to the target url this time naturally using the cpanel user pass combination

    I am trying this out because 1. it is convenient to administer 2. it is a safe guard against customers who would really manage to mess things up if given direct cpanel access. 3. It is convenient for the customer too.


    The script I am testing is pasted at the end of this post.

    Testing and outcome so far:

    If the script is used on the following link I only get as far as the page's text because a login dialog still pops up twice (one for the stylesheet and one for the image if I figured out correctly)
    "http://www.manicmalta.com:2082/frontend/x/files/select.html?dir=/home/manicmal/www&file=20050117ira_losco.htm"

    Also if you click on a link within the page a login dialog still pops up.

    On the other hand if I access the page directly via browser and provide cpanel user and pass the page loads fine and links work well. No further log ins required.

    Then I also went one step further and attempted access to the editor directly by using this link "http://www.manicmalta.com:2082/frontend/x/files/htmledit.html?dir=/home/manicmal/www&file=20050117ira_losco.htm"

    In this case the page loads and works fine BUT when I try to save the changes I always get a 'page not found' error page.

    On the other hand if I access the page directly via browser and provide cpanel user and pass the page works fine and also saves well.



    Is there something I am missing or is there something better than curl perhaps?? Any replies / ideas would be greatly appreciated. Hope that this is useful for other admins too.


    The code:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_URL, "http://www.manicmalta.com:2082/frontend/x/files/select.html?dir=/home/manicmal/www&file=BOV_Opera_Festival_Malta.htm");
    curl_setopt($ch, CURLOPT_USERPWD,$dom_u.":".$dom_p);
    curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
    $data = curl_exec($ch);
    curl_close($ch);
     
  2. rborg

    rborg Registered

    Joined:
    Jul 19, 2005
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Automate login for direct access to sub functions

    If anybody comes close to anything of the sort as described in my previous post kindly let me know on rborg AT operamail DOT com. Thanks :confused:
     
  3. rborg

    rborg Registered

    Joined:
    Jul 19, 2005
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Re auto log in - Hiccups in possible solution

    :( Hope you can help me

    I read the post
    http://forums.cpanel.net/showthread...g+automatically

    because I am trying to do the following (my post):
    http://forums.cpanel.net/showthread...g+automatically

    I modified Ricardo's script as follows and I checked cookie for data and seems that something is being returned. (although I cannot find cookie with other cookies in IE temp internet files ... is this normal?)

    However when header goes to location I am still getting a log in dialog box


    <?php
    session_start();
    # Please Keep this comment
    # Ricardo Riet Correa
    # ricardo@riet.com.br


    #get user information from session
    //$login_user = array ( "user" => $_SESSION[usuario],
    //"pass" => $_SESSION[pasinfo]);

    $_SESSION[usuario] = "username";
    $_SESSION[pasinfo] = "password";
    $login_user = array ( "user" => $_SESSION[usuario], "pass" => $_SESSION[pasinfo]);


    #connect to host and send login info
    $host = 'manicmalta.com';
    $fp = fsockopen($host, 2082, $errno, $errstr, 3);
    $out = "POST /login/ HTTP/1.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\n";

    #brake login info and send to host
    while (list ($k, $v) = each ($login_user)) {
    if(strlen($content) != 0) $content .= "&";
    $content .= rawurlencode($k). "=" .rawurlencode($v);
    }

    #I this is not necessary
    $out .= "Content-Length: ".strlen($content)."\r\n\r\n";
    $out .= $content." \r\n";

    #send everyting out and get the return
    fputs($fp, $out);
    $data = '';
    while (!feof($fp)) {
    $data .= fgets($fp, 128);
    }
    fclose($fp);

    #look the result for the string Set-Cookie
    #and get the value
    $string_nedle = 'Set-Cookie: ';
    $inicio = strpos($data,$string_nedle);
    $inicio = $inicio + strlen($string_nedle);
    $end_position = strpos($data,';',$inicio);
    $end_pos = $end_position - $inicio;
    $cookie_string = substr($data, $inicio , $end_pos);

    #split the cookie in the =
    list($name, $value) = split ("=", $cookie_string);

    #set cookie with the session value
    setcookie ($name, $value,time()+3600, "/", ".manicmalta.com");
    //echo($cookie_string);

    #send the user browser to the correct page
    Header("Location: http://www.manicmalta.com:2082/");
     
Loading...

Share This Page