API Stats Modification

Discussion in 'Developers' Forum' started by abdi, Apr 1, 2013.

  1. abdi

    abdi Member

    Hello Till,

    After a through investigation I have noticed the following situation with the API.

    The API function (say)

    Code:
    $domain_record = sites_web_domain_get($session_id, $domain_id)
    Returns the entire record inclusive of the stats_password crypt-ed value.

    That might not be a problem, however it's:

    When updating any of the above returned record with say:
    Code:
    $domain_record['active'] = 'n';
    sites_web_domain_update($session_id, $client_id, $domain_id, $domain_record)
    
    The finely updated record will hold a crypt-ed, crypt-ed stats_password Thus killing or resetting the stats_password set originally to some Un-Known crypt-ed characters ...

    Do you see a problem there?

    Joseph
     
  2. abdi

    abdi Member

    Solution to the problem

    My suggested solution to that problem is as follows:

    In the API lib file "/usr/local/ispconfig/interface/lib/classes/remoting.inc.php"

    I have introduced a new variable called update_stats_password which a user should set to 1 if they wish to update a stats_password. Otherwise by default its removed from the array to avoid messing up the preset stats_password .

    Below is my updated function suggesting to be added to the next update if its OK.

    Code:
    //* Update a record
    	public function sites_web_domain_update($session_id, $client_id, $primary_id, $params)
        {
    		if(!$this->checkPerm($session_id, 'sites_web_domain_update')) {
    			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
    			return false;
    		}
    		
    		//* Set a few defaults for nginx servers
    		if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
    		if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
    		if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
    		if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
    		
    		//* Added by Abdi Joseph
    		if($params['update_stats_password'] != '1') unset($params['stats_password']);
    		
    		$affected_rows = $this->updateQuery('../sites/form/web_domain.tform.php',$client_id,$primary_id,$params);
    		return $affected_rows;
    	}
    
    Any suggestions or comments are welcome ...

    Abdi Joseph
     
    Last edited: Apr 1, 2013
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    The api function works fine, you just used it the wrong way. Like with all API functions you have to pass a empty password parameter when the password shall not be change don update. So the correct API usage wozld be:

    $domain_record['active'] = 'n';
    $domain_record['stats_password'] = '';
    sites_web_domain_update($session_id, $client_id, $domain_id, $domain_record)
     

Share This Page