2011-12-16 23:31:35 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
|
|
* This class provides Host Server functions
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage HostServer
|
|
|
|
* @category Controllers/Task
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Task_Host extends Controller_Task {
|
2012-06-26 14:28:18 +00:00
|
|
|
private $so; // Service Object
|
|
|
|
private $hpo; //Host Server Object
|
2011-12-16 23:31:35 +00:00
|
|
|
|
|
|
|
public function __construct(Request $request, Response $response) {
|
|
|
|
parent::__construct($request,$response);
|
|
|
|
|
|
|
|
// To make it easy for some methods, we'll load our service here
|
|
|
|
switch (Request::current()->action()) {
|
|
|
|
case 'getclient':
|
2012-04-17 10:50:06 +00:00
|
|
|
case 'getdomain':
|
2012-07-03 13:05:08 +00:00
|
|
|
case 'getdns':
|
2012-06-26 14:28:18 +00:00
|
|
|
case 'getreseller':
|
2012-04-17 10:50:06 +00:00
|
|
|
case 'gettraffic':
|
2011-12-16 23:31:35 +00:00
|
|
|
case 'provision':
|
2012-04-17 10:50:06 +00:00
|
|
|
$this->so = ORM::factory('service',$this->request->param('id'));
|
2011-12-16 23:31:35 +00:00
|
|
|
|
2012-04-17 10:50:06 +00:00
|
|
|
if (! $this->so->loaded())
|
|
|
|
throw new Kohana_Exception('Unknown service :sid',array(':sid'=>$this->request->param('id')));
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
$this->hpo = $this->so->plugin()->host_server->plugin();
|
2011-12-16 23:31:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 10:50:06 +00:00
|
|
|
public function save($index,$result) {
|
|
|
|
$p = $this->so->plugin();
|
|
|
|
|
|
|
|
// We need to use a new var to avoid Indirect modification of overloaded property errors.
|
|
|
|
$x = is_null($p->server_data) ? array() : $p->server_data;
|
|
|
|
$x[$p->host_server_id][$index] = serialize($result);
|
|
|
|
$p->server_data = $x;
|
|
|
|
|
|
|
|
$x = is_null($p->server_data_date) ? array() : $p->server_data_date;
|
|
|
|
$x[$p->host_server_id][$index] = time();
|
|
|
|
$p->server_data_date = $x;
|
|
|
|
|
|
|
|
return $p->save();
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
private function verify($index,$result,$save=TRUE) {
|
|
|
|
$p = $this->so->plugin();
|
|
|
|
|
|
|
|
if (! isset($p->server_data[$p->host_server_id][$index]) OR (md5($p->server_data[$p->host_server_id][$index]) != md5(serialize($result)))) {
|
|
|
|
if ($save)
|
|
|
|
$this->save('c',$result);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-16 23:31:35 +00:00
|
|
|
/**
|
|
|
|
* Get Client Details from Host Server
|
|
|
|
*/
|
|
|
|
public function action_getclient() {
|
2012-06-26 14:28:18 +00:00
|
|
|
$result = $this->hpo->cmd_getclient($this->so);
|
2012-04-17 10:50:06 +00:00
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
if ($result->loaded())
|
|
|
|
$this->verify('c',$result);
|
2012-04-17 10:50:06 +00:00
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
print_r($result);
|
2011-12-16 23:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Client Details from Host Server
|
|
|
|
*/
|
2012-04-17 10:50:06 +00:00
|
|
|
public function action_getdomain() {
|
2012-06-26 14:28:18 +00:00
|
|
|
$result = $this->hpo->cmd_getdomain($this->so);
|
2012-04-17 10:50:06 +00:00
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
if ($result->loaded())
|
|
|
|
$this->verify('d',$result);
|
2012-04-17 10:50:06 +00:00
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
print_r($result);
|
|
|
|
}
|
|
|
|
|
2012-07-03 13:05:08 +00:00
|
|
|
/**
|
|
|
|
* Get DNS Details from Host Server
|
|
|
|
*/
|
|
|
|
public function action_getdns() {
|
|
|
|
$result = $this->hpo->cmd_getdns($this->so,'/tmp/z');
|
|
|
|
|
|
|
|
#if ($result->loaded())
|
|
|
|
# $this->verify('d',$result);
|
|
|
|
|
|
|
|
print_r($result);
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
/**
|
|
|
|
* Get Reseller
|
|
|
|
*/
|
|
|
|
public function action_getreseller() {
|
|
|
|
$result = $this->hpo->cmd_getreseller($this->so);
|
|
|
|
|
|
|
|
print_r($result);
|
2012-04-17 10:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Domain Traffic
|
|
|
|
*/
|
|
|
|
public function action_gettraffic() {
|
2012-06-26 14:28:18 +00:00
|
|
|
$result = $this->hpo->cmd_gettraffic($this->so);
|
2011-12-16 23:31:35 +00:00
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
print_r($result);
|
2011-12-16 23:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List services that need to be provisioned
|
2012-06-26 14:28:18 +00:00
|
|
|
* @todo This needs to be reviewed for functionality
|
2011-12-16 23:31:35 +00:00
|
|
|
*/
|
|
|
|
public function action_provisionlist() {
|
|
|
|
$mode = $this->request->param('id');
|
|
|
|
$cats = array();
|
|
|
|
|
|
|
|
if ($mode)
|
|
|
|
$cats = ORM::factory('product_category')->list_bylistgroup($mode);
|
|
|
|
|
|
|
|
foreach (ORM::Factory('service')->list_provision()->find_all() as $so) {
|
|
|
|
$pc = array();
|
|
|
|
|
|
|
|
// Limit to show only those by the requested category.
|
|
|
|
if ($cats) {
|
2011-12-27 01:06:04 +00:00
|
|
|
if (! $so->product->avail_category OR ! preg_match('/^a:/',$so->product->avail_category))
|
2011-12-16 23:31:35 +00:00
|
|
|
continue;
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
$pc = unserialize($so->product->avail_category);
|
2011-12-16 23:31:35 +00:00
|
|
|
|
|
|
|
if (! array_intersect($pc,array_keys($cats)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $so->id();
|
|
|
|
|
|
|
|
switch ($mode) {
|
|
|
|
case 'host':
|
|
|
|
printf(' %s %s %s',$so->plugin(),$so->plugin()->host_server->name,$so->service_name());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-26 14:28:18 +00:00
|
|
|
* Provision a Hosting Service
|
2011-12-16 23:31:35 +00:00
|
|
|
*/
|
|
|
|
public function action_provision() {
|
2012-06-26 14:28:18 +00:00
|
|
|
$result = $this->hpo->provision($this->so);
|
2011-12-16 23:31:35 +00:00
|
|
|
print_r((string)$result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|