<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * This class provides PLESK client support
 *
 * @package    OSB
 * @subpackage Plugins/Plesk
 * @category   Plugins
 * @author     Deon George
 * @copyright  (c) 2010 Deon George
 * @license    http://dev.leenooks.net/license.html
 */
class Plesk_Client extends Plesk {
	private $_loaded = FALSE;

	// @todo Get these default "templates" values out of the DB
	private $_template = array(
		'gen_info'=>array(),
		'stat'=>array(),
		'permissions' => array(
			'cp_access'=>TRUE,
			'create_domains'=>FALSE,
			'manage_phosting'=>FALSE,
			'manage_php_safe_mode'=>FALSE,
			'manage_sh_access'=>FALSE,
			'manage_not_chroot_shell'=>FALSE,
			'manage_quota'=>TRUE,
			'manage_subdomains'=>TRUE,
			'manage_domain_aliases'=>FALSE,
			'manage_log'=>TRUE,
			'manage_anonftp'=>FALSE,
			'manage_crontab'=>FALSE,
			'change_limits'=>FALSE,
			'manage_dns'=>TRUE,
			'manage_webapps'=>FALSE,
			'manage_webstat'=>TRUE,
			'manage_maillists'=>TRUE,
			'manage_spamfilter'=>FALSE,
			'manage_virusfilter'=>FALSE,
			'allow_local_backups'=>FALSE,
			'allow_ftp_backups'=>TRUE,
			'remote_access_interface'=>FALSE,
			'site_builder'=>FALSE,
			'manage_performance'=>FALSE,
			'manage_dashboard'=>TRUE,
			'select_db_server'=>FALSE,
		),
		'limits' => array(
			'resource-policy'=>'notify',
			'max_dom'=>-1,
			'max_subdom'=>-1,
			'max_dom_aliases'=>-1,
			'disk_space_soft'=>-1,
			'disk_space'=>-1,
			'max_traffic_soft'=>-1,
			'max_traffic'=>-1,
			'max_wu'=>-1,
			'max_db'=>-1,
			'max_box'=>-1,
			'mbox_quota'=>51200000,
			'max_redir'=>-1,
			'max_mg'=>-1,
			'max_resp'=>-1,
			'max_maillists'=>-1,
			'max_webapps'=>0,
			'expiration'=>-1,
		),
		'ippool' => array(
			'111.67.13.20'=>'shared',
		),
	);

	/**
	 * Get a Client Configuration
	 */
	public function cmd_getclient(Model_Service $so) {
		$items = array_keys($this->_template);

		$client = $this->packet->add_node('client');
		$get = $client->add_node('get');
		$filter = $get->add_node('filter');
		$filter->add_node('login',$so->plugin()->host_username);
		$dataset = $get->add_node('dataset');
		foreach ($items as $k)
			$dataset->add_node($k);

		$result = $this->server_command($this->xml);

		if ($result->client->get->result->status->value() != 'ok')
			throw new Kohana_Exception('Unable to get PLESK Client data');
 
                foreach ($items as $k)
                        foreach ($result->get($k) as $a=>$b)
                                $this->_object[$k] = $this->collapse($b);

		$this->_loaded = TRUE;

		return $this;
	}

	public function loaded() {
		return $this->_loaded;
	}
}
?>
