Create a website: sites_web_domain_add & webid

Discussion in 'Developers' Forum' started by vaio1, Dec 3, 2011.

  1. vaio1

    vaio1 ISPConfig Developer

    SOLVED: How-to create a website: sites_web_domain_add

    Hi guys,

    after a searching on the forum I have solved the creation of the website domain in this way:

    At the moment I have created this function and this works!

    IspConfig needs more documentation. The class declaration are not sufficient.

    Code:
    	/**
    	 * Create a new website
    	 * 
    	 * Executes the creation of new website in the IspConfig control panel
    	 * Note in order to not fail this command, it must meet the following requirements:
    	 * 
    	 * - The customer must be registered in the db.
    	 * - The parameters must be saved in the service detail (orderitems table)
    	 * 
    	 * @param      array      $task     Must be a valid task 
    	 * @return     mixed       True, or throw an Exception if failed.
    	 * @access     public
    	 */
    	public function create_website(array $task) {
    		// Connection to the SOAP system
    		$client = $this->Connect ();
    		
    		// Get all the customer information
    		$customer = Customers::getAllInfo ( $task ['customer_id'] );
    		
    		// Get the custom ISPConfig attribute set in the customer control panel 
    		if (!empty($customer ['CustomersAttributesValues'] [0] ['CustomersAttributes'] ['var']) && $customer ['CustomersAttributesValues'] [0] ['CustomersAttributes'] ['var'] == "client_id" && ! empty ( $customer ['CustomersAttributesValues'] [0] ['value'] ) && is_numeric ( $customer ['CustomersAttributesValues'] [0] ['value'] )) {
    			$clientId = $customer ['CustomersAttributesValues'] [0] ['value']; // External ISPConfig ClientID
    			$record = $client->client_get ( $this->getSession (), $clientId );
    			if ($record == false) {
    				$clientId = self::create_client($task);
    				$client = $this->Connect (); 	// Open again the Connection to the SOAP system previously closed
    			}
    			
    			// Get the service details
    			$service = OrdersItems::getAllInfo($task['orderitem_id']);
    			
    			if(!empty($service)){
    				// Get the Json encoded parameters in the task
    				$parameters = json_decode ( $task ['parameters'], true );
    	
    				// Get the domain
    				if(!empty($service['Orders']['OrdersItemsDomains'][0]['Domains'])){
    					$domain = $service['Orders']['OrdersItemsDomains'][0]['Domains']['domain'] . "." . $service['Orders']['OrdersItemsDomains'][0]['Domains']['tld'];
    	
    					$params = array(
    							'server_id' => 1,
    							'ip_address' => '',
    							'domain' => $domain,
    							'type' => 'vhost',
    							'parent_domain_id' => 0,
    							'vhost_type' => 'name',
    							'hd_quota' => $parameters['webspace'],
    							'traffic_quota' => $parameters['bandwidth'],
    							'cgi' => 'y',
    							'ssi' => 'y',
    							'suexec' => 'y',
    							'errordocs' => 1,
    							'is_subdomainwww' => 1,
    							'subdomain' => '',
    							'php' => 'y',
    							'ruby' => 'n',
    							'redirect_type' => '',
    							'redirect_path' => '',
    							'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' => 'webalizer',
    							'backup_interval' => '',
    							'backup_copies' => 1,
    							'active' => 'y',
    							'traffic_quota_lock' => 'n',
    	                        'system_user' =>'web1', 
    	                        'allow_override' =>'All', 
    	                        'custom_php_ini' =>'',  
    	                        'apache_directives' => ''
    						);
    					
    				}
    				
    				$websiteId = $client->sites_web_domain_add($this->getSession(), $clientId, $params, $readonly = false);
    			}
    		}
    		// Logout from the IspConfig Remote System
    		$client->logout($this->getSession ());
    		
    		return $websiteId;
    		
    	}
    
     
    Last edited: Dec 3, 2011
  2. till

    till Super Moderator

    There is a example script for every function of the remote API available in the examples folder.
     
  3. vaio1

    vaio1 ISPConfig Developer

    Hi Till,

    the problem is not the way to call the methods but the meaning of every single paramenter. Anyway we are creating our inteface using all the documentation in the samples, the api docs and the forum but sometimes we find some difficulty to understand some parameter and its action if used in the api call.

    anyway thanks for the project and the support.
     

Share This Page