Advertisement
fanirisaldi

Cpanel

Apr 4th, 2018
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.31 KB | None | 0 0
  1. <?php
  2.   $cpanelhost = 'localhost';
  3.   $cpaneluser = 'root';
  4.   $cpanelpass = 'pass';
  5.   $cpaneltheme = 'justhost';
  6. function create_subdomain($domainName, $pathDomain, $rootDomain) {
  7.     //Generate URL for access the subdomain creation in cPanel through PHP
  8.     $buildRequest = "/frontend/".$cpaneltheme."/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $domainName . "&dir=".$_SERVER['DOCUMENT_ROOT']."/".$pathDomain;
  9.    
  10.     //Open the socket
  11.     $openSocket = fsockopen('localhost',2082);
  12.    
  13.     if(!$openSocket) {
  14.         //SHow error
  15.         return "Socket error";
  16.         exit();
  17.     }
  18.    
  19.     //Login Details
  20.     $authString = $cpaneluser . ":" . $cpanelpass;
  21.    
  22.     //Encrypt the Login Details
  23.     $authPass = base64_encode($authString);
  24.    
  25.     //Request to Server using GET method
  26.     $buildHeaders = "GET " . $buildRequest ."\r\n";
  27.    
  28.     //HTTP
  29.     $buildHeaders .= "HTTP/1.0\r\n";
  30.     //Define Host
  31.     $buildHeaders .= "Host:localhost\r\n";
  32.    
  33.     //Request Authorization
  34.     $buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
  35.     $buildHeaders .= "\r\n";
  36.    
  37.     //fputs
  38.     fputs($openSocket, $buildHeaders);
  39.     while(!feof($openSocket)) {
  40.     fgets($openSocket,128);
  41.     }
  42.     fclose($openSocket);
  43.    
  44.     //Return the New SUbdomain with full URL
  45.     $newDomain = "http://" . $domainName . "." . $rootDomain . "/";
  46.    
  47.     //return with Message
  48.     echo "Created subdomain ".$newDomain;
  49.   }
  50. ?>
  51.  
  52. <html>
  53. <head>
  54. <title> cPanel Subdomain Creator </title>
  55. </head>
  56.  
  57. <body>
  58.  
  59. <form name="subdomain" method="post" action="index.php">
  60.   <input type="text" name="subdomain" placeholder="Subdomain name" /> <br />
  61.   <input type="text" name="domain" placeholder="Your main domain name" /> <br />
  62.   <input type="text" name="path" placeholder="Enter Path" /> <br />
  63.   <input type="submit" name="submit" value="Create Subdomain"/>
  64. </form>
  65.  
  66.  
  67. <?php
  68. if (isset($_POST["submit"]) && !empty($_POST["subdomain"])) && !empty($_POST["domain"])) && !empty($_POST["path"])) {
  69.     echo "Please fill in the information.";    
  70. }else{  
  71.   $domainName = $_POST["subdomain"];
  72.   $pathDomain = $_POST["path"];
  73.   $rootDomain = $_POST["domain"];
  74. function create_subdomain($domainName, $pathDomain, $rootDomain) {
  75.     //Generate URL for access the subdomain creation in cPanel through PHP
  76.     $buildRequest = "/frontend/".$cpaneltheme."/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $domainName . "&dir=".$_SERVER['DOCUMENT_ROOT']."/".$pathDomain;
  77.    
  78.     //Open the socket
  79.     $openSocket = fsockopen('localhost',2082);
  80.    
  81.     if(!$openSocket) {
  82.         //SHow error
  83.         return "Socket error";
  84.         exit();
  85.     }
  86.    
  87.     //Login Details
  88.     $authString = $cpaneluser . ":" . $cpanelpass;
  89.    
  90.     //Encrypt the Login Details
  91.     $authPass = base64_encode($authString);
  92.    
  93.     //Request to Server using GET method
  94.     $buildHeaders = "GET " . $buildRequest ."\r\n";
  95.    
  96.     //HTTP
  97.     $buildHeaders .= "HTTP/1.0\r\n";
  98.     //Define Host
  99.     $buildHeaders .= "Host:localhost\r\n";
  100.    
  101.     //Request Authorization
  102.     $buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
  103.     $buildHeaders .= "\r\n";
  104.    
  105.     //fputs
  106.     fputs($openSocket, $buildHeaders);
  107.     while(!feof($openSocket)) {
  108.     fgets($openSocket,128);
  109.     }
  110.     fclose($openSocket);
  111.    
  112.     //Return the New SUbdomain with full URL
  113.     $newDomain = "http://" . $domainName . "." . $rootDomain . "/";
  114.    
  115.     //return with Message
  116.     echo "Created subdomain ".$newDomain;
  117.   }
  118. }
  119. ?>
  120.  
  121. </body>
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement