Creating subdomain API

Discussion in 'General' started by dokov, Jan 17, 2014.

  1. dokov

    dokov New Member

    Hello.

    I am building an automated system for my team to be able to install a whole website with subdomain, database, files upload from git, etc.

    Currently I am stuck with the subdomain creation.
    I managed to create the subdomain, but some of the fields in the database for this subdomain are wrong. I compare the rows of a subdomain added by the web interface and by the API script. The differences are in the following columns:

    Correctly created domain (by web interface):
    • ip_address: *
    • ipv6_address: empty
    • vhost_type: name
    • document_root: /var/www/clients/client1/web1
    • web_folder: subdomains/mywebsite
    • system_user: web1
    • system_group: client1
    • php: php-fpm
    • ruby: empty
    • python: empty
    • perl: empty
    • redirect_type: NULL
    • redirect_path: NULL
    • ssl: empty
    • php_open_basedir: ..a long string with correct paths /var/www/clients/client1...


    Wrongly created domain (by API):
    • ip_address: NULL
    • ipv6_address: NULL
    • vhost_type: NULL
    • document_root: NULL
    • web_folder: NULL
    • system_user: NULL
    • system_group: NULL
    • php: y
    • ruby: n
    • python: n
    • perl: n
    • redirect_type: empty
    • redirect_path: empty
    • ssl: n
    • php_open_basedir: NULL

    Here is part of my PHP code which creates the subdomain:

    Code:
    $subdomain = 'test';
    $client_id = 1;
    $params = array(
    	'server_id' => 1,
    	'ip_address' => '*',
    	'ipv6_address' => '',
    	'domain' => $subdomain.'.mydomain.com',
    	'type' => 'vhostsubdomain',
    	'parent_domain_id' => 1,
    	'vhost_type' => 'name',
    	'document_root' => '/var/www/clients/client1/web1',
    	'web_folder' => 'subdomains/'.$subdomain,
    	'system_user' => '2',
    	'system_group' => '2',
    	'hd_quota' => 0,
    	'traffic_quota' => -1,
    	'cgi' => 'n',
    	'ssi' => 'n',
    	'suexec' => 'y',
    	'errordocs' => 1,
    	'is_subdomainwww' => 0,
    	'subdomain' => 'none',
    	'php' => 'php-fpm',
    	'ruby' => 'n',
    	'redirect_type' => null,
    	'redirect_path' => null,
    	'ssl' => 'n',
    	'ssl_state' => '',
    	'ssl_locality' => '',
    	'ssl_organisation' => '',
    	'ssl_organisation_unit' => '',
    	'ssl_country' => '',
    	'ssl_domain' => '',
    	'ssl_request' => '',
    	'ssl_cert' => '',
    	'ssl_bundle' => '',
    	'ssl_action' => '',
    	'stats_password' => '',
    	'stats_type' => 'awstats',
    	'allow_override' => 'All',
    	'apache_directives' => '',
    	'php_open_basedir' => '/var/www/clients/client1/web1/subdomains/'.$subdomain.':/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/'.$subdomain.'.mydomain.com/subdomains/'.$subdomain.':/srv/www/'.$subdomain.'.mydomain.com/subdomains/'.$subdomain.':/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/var/lib/roundcube:',
    	'custom_php_ini' => '',
    	'backup_interval' => '',
    	'backup_copies' => 1,
    	'active' => 'y',
    	'traffic_quota_lock' => 'n'
    	);
    
    try {
    	if ( $subdomain_id = $this->api->sites_web_subdomain_add($this->session_id, $client_id, $params) ) {
    		return $this->response('Subdomain with ID '.$subdomain_id.' created', self::RESPONSE_SUCCESS);
    	}
    	else {
    		return $this->response('Subdomain not created', self::RESPONSE_ERROR);
    	}
    } catch (SoapFault $e) {
    	echo $this->api->__getLastResponse();
    	$this->response('SOAP Error: '.$e->getMessage(), self::RESPONSE_ERROR);
    }
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Do you mean a subdomain or vhostsubdomain? The record that you posted for the interface looks as if you created a vhostsubdomain (subdomain as separate vhost) while your script creates a subdomain (which is basically a alias for the website).
     
  3. dokov

    dokov New Member

    Actually I need vhostsubdomain. I host websites on these subdomains.
    Am I using a wrong API function?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    for vhostsubdomain, use the function:

    sites_web_vhost_subdomain_add($session_id, $client_id, $params)
     
  5. dokov

    dokov New Member

    I don't see such function in the API docs.
    Can you please give me an example for $params array values.

    Thanks!
     
  6. dokov

    dokov New Member

    Thanks. I've managed to figure out the $params array myself.
    It works just great!

    In general the missing function in the docs made me ask for help ;)
    The API docs needs a huge update!
     
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, I know. While the api doc is missing functions, I'am missing time to update it :D But its on the todo list :)

    If you want to get a list of all available functions, take a look at the file /usr/local/ispconfig/interface/lib/classes/remoting.inc.php The fields for the params array are identical to the database fields of the corresponding database table.
     
  8. dokov

    dokov New Member

    Thank you so much for your fast and good response!
     

Share This Page