-2

hey people . i want to start a free hosting site .i have a doamin name with unlimited sub-domains and unlimited space and email acounts and unlimited ftp accounts .
what i want to do is to write a code that creates a sub-domain and a folder with the name of the subdomain name . and an ftp account with an access to the directory which has the name of the sub-domain . and i want also when a user signs up , the user get a spacific amount of email accounts and and ftp account and a spacific webspace .
but all what i really can do is to create a login and signup systems and database to store the information but i dont know how to write a code that creates a directory and i dont know how to create a sub-domin from a php code as well as i dont know how to deal with ftp .
polease tell me how to do these stuff and if you know any link that can help me in this , please post it to me
thanks in advance .

4
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Awah Mohamed
0

Seriously, prince Awah, I do not mean to be rude.

I have seen several of your posts and very few of the actually contain the code. You ask for stuff that is readily available on the net. We are always here to help you out if you get stuck provided you take the initiative to start out the project yourself and reach a point you can go no further.

All the questions you have above are available online. If you had searched PHP.net for the directory code, you would find that PHP has a mkdir() command to create directories. Similarly for the others you can do the search yourself instead of asking us to do it for you.

0

this is a combination coding and sysadmin question. I have been coding in php professionally for over 5 years and consider myself a professional developer and I cannot say that I can do this with confidence, security wise.

I would recommend you do some research on open source software or even purchased software that will do this for you.

-1

okay , thanks . who said i didnt do research . i did research and i knew that i can create a directory in php through mkdir() but i didnt find anything that proves that anybody can create a subdomain through php . i didnt find any code or open souce software that can do this to me .
i foun this code but it doesnt work >or i think i didnt know how to use it
please give me feed back

<?php

###############################################################
# cPanel Subdomains Creator 1.1
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
#
# Can be used in 3 ways:
# 1. just open script in browser and fill the form
# 2. pass all info via url and form will not appear
# Sample: cpanel_subdomains.php?cpaneluser=USER&cpanelpass=PASSWORD&domain=DOMAIN&subdomain=SUBDOMAIN
# 3. list subdomains in file. In this case you must provide all the defaults below
#
# Note: you can omit any parameter, except "subdomain".
# When omitted, default value specified below will be taken
###############################################################

// cpanel user
define('CPANELUSER','user');

// cpanel password
define('CPANELPASS','pass');

// name of the subdomains list file.
// file format may be 1 column or 2 columns divided with semicilon (;)
// Example for two columns:
//   rootdomain1;subdomain1
//   rootdomain1;subdomain2
// Example for one columns:
//   subdomain1
//   subdomain2
define('INPUT_FILE','domains.txt');

// cPanel skin (mainly "x")
// Check http://www.zubrag.com/articles/determine-cpanel-skin.php
// to know it for sure
define('CPANEL_SKIN','x');

// Default domain (subdomains will be created for this domain)
// Will be used if not passed via parameter and not set in subdomains file
define('DOMAIN','');


/////////////// END OF INITIAL SETTINGS ////////////////////////
////////////////////////////////////////////////////////////////

function getVar($name, $def = '') {
  if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != ''))
    return $_REQUEST[$name];
  else 
    return $def;
}

$cpaneluser=getVar('cpaneluser', CPANELUSER);
$cpanelpass=getVar('cpanelpass', CPANELPASS);
$cpanel_skin = getVar('cpanelskin', CPANEL_SKIN);

if (isset($_REQUEST["subdomain"])) {
  // get parameters passed via URL or form, emulate string from file 
  $doms = array( getVar('domain', DOMAIN) . ";" . $_REQUEST["subdomain"]);
  if (getVar('domain', DOMAIN) == '') die("You must specify domain name");
}
else {
  // open file with domains list
  $doms = @file(INPUT_FILE);
  if (!$doms) {
    // file does not exist, show input form
    echo "
Cannot find input file with subdomains information. It is ok if you are not creating subdomains from file.<br>
Tip: leave field empty to use default value you have specified in the script's code.<br>
<form method='post'>
  Subdomain:<input name='subdomain'><br>
  Domain:<input name='domain'><br>
  cPanel User:<input name='cpaneluser'><br>
  cPanel Password:<input name='cpanelpass'><br>
  cPanel Skin:<input name='cpanelskin'><br>
  <input type='submit' value='Create Subdomain' style='border:1px solid black'>
</form>";
    die();
  }
}

// create subdomain
function subd($host,$port,$ownername,$passw,$request) {

  $sock = fsockopen('localhost',2082);
  if(!$sock) {
    print('Socket error');
    exit();
  }

  $authstr = "$ownername:$passw";
  $pass = base64_encode($authstr);
  $in = "GET $request\r\n";
  $in .= "HTTP/1.0\r\n";
  $in .= "Host:$host\r\n";
  $in .= "Authorization: Basic $pass\r\n";
  $in .= "\r\n";
 
  fputs($sock, $in);
  while (!feof($sock)) {
    $result .= fgets ($sock,128);
  }
  fclose( $sock );

  return $result;
}

foreach($doms as $dom) {
  $lines = explode(';',$dom);
  if (count($lines) == 2) {
    // domain and subdomain passed
    $domain = trim($lines[0]);
    $subd = trim($lines[1]);
  }
  else {
    // only subdomain passed
    $domain = getVar('domain', DOMAIN);
    $subd = trim($lines[0]);
  }
  // http://[domainhere]:2082/frontend/x/subdomain/doadddomain.html?domain=[subdomain here]&rootdomain=[domain here]
  $request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
  $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
  $show = strip_tags($result);
  echo $show;
}

?>
0

this is the error that i usually get


HTTP/1.1 404 Not Found Server: cpsrvd/11.26 Connection: close Content-type: text/html 404 Not Found Not Found The server was not able to find the document (./frontend/x/subdomain/doadddomain.html) you requested. Please check the url and try again. You might also want to report this error to your web hosting provider. cpaneld/11.26 Server at localhost

0

If you're going to build this to essentially sit on top of cPanel, there is an entire API for interacting with cPanel: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/XmlApi

The easiest way to do this would be to have reseller access to cPanel and create the individual user accounts using sudomain.domain.com as their domain name. Set their account limits using the API and that should be that. cPanel will take care of the quotas and bandwidth, as well as account restrictions. Users can then log into cPanel and configure ftp accounts and email accounts up until the max you impose.

It has been a long time since I've setup an account using a subdomain as the account's domain and I don't recall if there are any limitations to this or not.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.