Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/08/2013, 20:50
Avatar de adex
adex
 
Fecha de Ingreso: marzo-2002
Ubicación: Lima, Perú, América Latina
Mensajes: 445
Antigüedad: 22 años, 1 mes
Puntos: 0
Pregunta Creando subdominios con PHP

Hola. Tengo un sistema automatizado para crear subdominios por medio de un registro de usuarios con PHP y mySQL. Todo marcha bien, pero solo por un detalle que todas las carpeta se crean en la raíz:
Código:
/home/userhost/public_html/$id_usuario_subdominio
y lo que deseo es personalizar osea que la carpeta del subdonio vaya en otra carpeta, así de esta manera:

Código:
/home/userhost/public_html/$carpeta_categoria/$id_usuario_subdominio
Mi sistema se basa en este script:

Código PHP:
Ver original
  1. define('CPANELUSER','user');
  2. define('CPANELPASS','pass');
  3. define('INPUT_FILE','domains.txt'); // domain;sd
  4. define('CPANEL_SKIN','x');
  5. function getVar($name, $def = '') {
  6.   if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != ''))
  7.     return $_REQUEST[$name];
  8.   else
  9.     return $def;
  10. }
  11.  
  12. $cpaneluser=getVar('cpaneluser', CPANELUSER);
  13. $cpanelpass=getVar('cpanelpass', CPANELPASS);
  14. $cpanel_skin = getVar('cpanelskin', CPANEL_SKIN);
  15.  
  16. if (isset($_REQUEST["subdomain"])) {
  17.   $doms = array( getVar('domain', DOMAIN) . ";" . $_REQUEST["subdomain"]);
  18.   if (getVar('domain', DOMAIN) == '') die("You must specify domain name");
  19. }
  20. else {
  21.   $doms = @file(INPUT_FILE);
  22.   if (!$doms) {
  23.     echo "
  24. Cannot find input file with subdomains information. It is ok if you are not creating subdomains from file.<br>
  25. Tip: leave field empty to use default value you have specified in the script's code.<br>
  26. <form method='post'>
  27.  Subdomain:<input name='subdomain'><br>
  28.  Domain:<input name='domain'><br>
  29.  cPanel User:<input name='cpaneluser'><br>
  30.  cPanel Password:<input name='cpanelpass'><br>
  31.  cPanel Skin:<input name='cpanelskin'><br>
  32.  <input type='submit' value='Create Subdomain' style='border:1px solid black'>
  33. </form>";
  34.     die();
  35.   }
  36. }
  37.  
  38. // create subdomain
  39. function subd($host,$port,$ownername,$passw,$request) {
  40.  
  41.   $sock = fsockopen('localhost',2082);
  42.   if(!$sock) {
  43.     print('Socket error');
  44.     exit();
  45.   }
  46.  
  47.   $authstr = "$ownername:$passw";
  48.   $pass = base64_encode($authstr);
  49.   $in = "GET $request\r\n";
  50.   $in .= "HTTP/1.0\r\n";
  51.   $in .= "Host:$host\r\n";
  52.   $in .= "Authorization: Basic $pass\r\n";
  53.   $in .= "\r\n";
  54.  
  55.   fputs($sock, $in);
  56.   while (!feof($sock)) {
  57.     $result .= fgets ($sock,128);
  58.   }
  59.   fclose( $sock );
  60.  
  61.   return $result;
  62. }
  63. foreach($doms as $dom) {
  64.   $lines = explode(';',$dom);
  65.   if (count($lines) == 2) {
  66.     $domain = trim($lines[0]);
  67.     $subd = trim($lines[1]);
  68.   }
  69.   else {
  70.     $domain = getVar('domain', DOMAIN);
  71.     $subd = trim($lines[0]);
  72.   }
  73.   $request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
  74.   $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
  75.   $show = strip_tags($result);
  76.   echo $show;
  77. }

Gracias por todo.

Última edición por adex; 04/08/2013 a las 21:26