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.

Making Redirect urls

Discussion in 'cPanel Developers' started by PHPEcono, Nov 19, 2008.

  1. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys,
    I am trying to creat an automated redirect url maker script ...

    This is whati did so fare

    $cpuser = '***'; // cPanel username
    $cppass = '***'; // cPanel password
    $cpdomain = 'blessingstairs.org'; // cPanel domain
    $cpskin = 'x3'; // cPanel skin

    $cp="http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mime/addredirect.html?type=permanent&domain=blessingstairs.org&path=tv/$num&url=$_POST&rdwww=0"; $f = fopen("$cp", "r"... whats keeping him from doing it automaticly?
     
  2. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    hmm ... looks like if it was working manualy it's because i had an active session open in cpanel. When my sessions expired i started having

    Functions in cPanel / WHM are available only directly through the cPanel and WHM interfaces or through our XML API. It appears that this request is coming from a referring site and might be malicious.

    What would be the correct code for this using the XML API?
     
  3. 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
    That page has the following API1 code in it:

    Code:
    <cpanel Mime="add_redirect($FORM{'path'},$FORM{'type'},$FORM{'url'},$FORM{'domain'},$FORM{'wildcard'},$FORM{'rdwww'
    })">
    
    The Mime=" indicates this is an API1 function. You can find information on calling this API1 function from the XML API at:

    http://cpanel.net/plugins/xmlapi/cpanel.html

    So you'll wind up with something resembling:

    Code:
    /xml-api/cpanel?user=[COLOR="Red"]username[/COLOR]&xmlin=<cpanelaction><module>Mime</module><func>add_redirect</func><apiversion>1</apiversion><args>[COLOR="Red"]path[/COLOR]</args><args>[COLOR="Red"]type[/COLOR]</args><args>[COLOR="Red"]url[/COLOR]</args><args>[COLOR="Red"]domain[/COLOR]</args><args>[COLOR="Red"]wildcard[/COLOR]</args><args>[COLOR="Red"]rdwww[/COLOR]</args></cpanelaction> 
    Of course, substituting the variables (shown in red) as necessary
     
  4. 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
    ** Moved thread to the developer forum **
     
  5. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Thx for your help.
    Now i get this error:

    Code:
    Warning: fopen(http://*****.org:2082/xml-api/cpanel?user=****&xmlin=<cpanelaction><module>Mime</module><func>add_redirect</func><apiversion>1</apiversion><args>tv/-345389974</args><args>permanent</args><args>http://www.voanews.com/wm/voa/sca/pash/pash1400vb.asx</args><args>blessingstairs.org</args><args></args><args></args><args>rdwww</args>0</cpanelaction>) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 401 Access Denied Still Working in /home/blesmpm/public_html/site/tvadmin.php on line 336
    
    The response:
    <cpanelresult><module>Mime</module><func>add_redirect</func><type>event</type><source>internal</source><apiversion>1</apiversion><data><result><fatalerror>[a fatal error or timeout occurred while processing this directive]</fatalerror><fatalerror>[a fatal error or timeout occurred while processing this directive]</fatalerror>
    
    My code is:
    $cp="http://$cpdomain:2082/xml-api/cpanel?user=$cpuser&xmlin=<cpanelaction><module>Mime</module><func>add_redirect</func><apiversion>1</apiversion><args>tv/$num</args><args>permanent</args><args>$_POST[url]</args><args>blessingstairs.org</args><args></args><args></args><args>rdwww</args>0</cpanelaction>";
    
    $f = fopen("$cp", "r");
    I had the same error using http://***.org/tv/$num as path
     
    #5 PHPEcono, Nov 19, 2008
    Last edited by a moderator: Nov 19, 2008
  6. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    PHPEcono,
    While the fopen() function states to be able to support HTTP auth, you'll probably have better luck with using curl:

    which I use for this type of thing when doing this in php...

    Disclaimer:
    I'm not a PHP Dev, if there are any errors above, my apologies.
     
  7. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Thx :) I am gona give it a try
     
  8. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Nah i am steel having troble with this ...

    PHP:
    $username '***';
    $password '***';
    $host '***.org

    $request = "/xml-api/cpanel?user=$username&xmlin=<cpanelaction><module>Mime</module><func>add_redirect</func><apiversion>1</apiversion><args>http://blessingstairs.org/tv/$num</args><args>permanent</args><args>$_POST[url]</args><args>blessingstairs.org</args><args>0</args><args>0</args></cpanelaction>";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, "http://$host:2082" . $request);  
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

    $result = curl_exec($ch);  
    curl_close($ch);
    echo $result;
    I get the same error

    Mime
    add_redirect
    event internal
    1
    [a fatal error or timeout occurred while processing this directive]
    [a fatal error or timeout occurred while processing this directive]
     
  9. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    PHPEcono,
    What's in /usr/local/cpanel/logs/error_log when this query is made?
     
  10. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    I never got the xml-api code to work so i tryed the one i posted at first and solved the autentification problem using the curl method. Works like a charme now. Thx for the help!

    WORKING CODE:

    $request = "/frontend/x3/mime/addredirect.html?type=permanent&domain=***.org&path=tv/$num&url=$_POST&rdwww=0"; $ch = curl_init(); c...$result = curl_exec($ch); curl_close($ch);
     
  11. 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
     
  12. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Of course but to use it, we need a working code :p
    I never got pass the error above.

    If you have a better solution go a head ;-)
     
  13. 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
    Our developers are working on a solution to this malfunctioning API call. From what I see, it should be propagating into the builds soon. Internal Case 15186

    I'll update this forum thread once I see it in the changelogs, so you can monitor this as well.
     
  14. 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
    This issue has been resolved in builds 31971 and later. Please let me know if this issue persists after updating.
     
  15. PHPEcono

    PHPEcono Active Member

    Joined:
    Apr 3, 2006
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    nice work guys i will give it a try and let you know
     
    #15 PHPEcono, Jan 7, 2009
    Last edited: Jan 7, 2009
  16. fanfavorite

    fanfavorite Active Member

    Joined:
    Jun 1, 2008
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    1
    I could be wrong, but isn't it supposed to be port 2086 (unsecure) or 2087 (secure) using the XML-API because it is run through WHM or do the actual cpanel calls allow through cpanels 2082 and 2083 ports?
     
  17. 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
    With regards to the XML-API (including API1 and API2 calls made via the XML-API), that is run through WHM (ports 2086/2087 as you stated).
     
Loading...

Share This Page