diff --git a/application/classes/lnapp/table.php b/application/classes/lnapp/table.php
index 32c42739..ca485ad3 100644
--- a/application/classes/lnapp/table.php
+++ b/application/classes/lnapp/table.php
@@ -41,7 +41,7 @@ class lnApp_Table {
if (! empty($option['button']))
$button = implode('',$option['button']);
else
- $button = '';
+ $button = Form::button('Submit','View/Edit',array('class'=>'form_button','type'=>'submit'));
Script::add(array(
'type'=>'stdin',
diff --git a/modules/affiliate/classes/model/affiliate.php b/modules/affiliate/classes/model/affiliate.php
index 15d1cb98..8464ea41 100644
--- a/modules/affiliate/classes/model/affiliate.php
+++ b/modules/affiliate/classes/model/affiliate.php
@@ -11,5 +11,9 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Affiliate extends ORMOSB {
+ // Relationships
+ protected $_belongs_to = array(
+ 'host_server_affiliate'=>array('far_key'=>'affiliate_id','foreign_key'=>'id'),
+ );
}
?>
diff --git a/modules/charge/views/charge/admin/add.php b/modules/charge/views/charge/admin/add.php
new file mode 100644
index 00000000..052395ad
--- /dev/null
+++ b/modules/charge/views/charge/admin/add.php
@@ -0,0 +1,37 @@
+
+
+ Account |
+ |
+
+
+ Service |
+ |
+
+
+ Sweep |
+ |
+
+
+ Quantity |
+ |
+
+
+ Amount |
+ |
+
+
+ Taxable |
+ |
+
+
+ Description |
+ |
+
+
+
+
+ Attributes |
+ |
+
+
+
diff --git a/modules/host/classes/controller/task/host.php b/modules/host/classes/controller/task/host.php
new file mode 100644
index 00000000..a6757137
--- /dev/null
+++ b/modules/host/classes/controller/task/host.php
@@ -0,0 +1,123 @@
+action()) {
+ case 'getclient':
+ case 'getservice':
+ case 'provision':
+ $sid = $this->request->param('id');
+
+ $hso = ORM::factory('service',$sid)->plugin()->host_server;
+ require Kohana::find_file('vendor',$hso->provision_plugin);
+ $this->hs = new $hso->provision_plugin($hso);
+
+ break;
+ }
+ }
+
+ /**
+ * Get Client Details from Host Server
+ */
+ public function action_getclient() {
+ $sid = $this->request->param('id');
+
+ print_r((string)$this->hs->get_client(ORM::factory('service',$sid)));
+ }
+
+ /**
+ * Get Client Details from Host Server
+ */
+ public function action_getservice() {
+ $sid = $this->request->param('id');
+
+ print_r((string)$this->hs->get_service(ORM::factory('service',$sid)));
+ }
+
+ /**
+ * List services that need to be provisioned
+ */
+ 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) {
+ if (! $so->product->avail_category_id OR ! preg_match('/^a:/',$so->product->avail_category_id))
+ continue;
+
+ $pc = unserialize($so->product->avail_category_id);
+
+ 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";
+ }
+ }
+
+ /**
+ * Add a domain for the client
+ *
+ * @param int $id Hosting ID (in OSB)
+ * @return unknown_type
+ */
+ public function action_provision() {
+ $sid = $this->request->param('id');
+ $so = ORM::factory('service',$sid);
+
+ // Provision Account
+ // @todo Need a test to see if an account alerady exists.
+/*
+ $result = $this->hs->add_client($so);
+ print_r((string)$result);
+
+ // Next need to get the ID from the account call to set the IP
+ $result = $this->hs->setip(35); // @todo change this number
+ print_r((string)$result);
+
+ // Provision Domain
+ $result = $this->hs->add_service($so);
+ print_r((string)$result);
+
+ // Set Limits
+ $result = $this->hs->setlimits($so);
+ print_r((string)$result);
+
+ // Next need to get the ID for the domain to disable mail
+ $result = $this->hs->disablemail(43);
+ print_r((string)$result);
+*/
+ }
+}
+?>
diff --git a/modules/host/classes/model/host/server.php b/modules/host/classes/model/host/server.php
index f7fc9f3b..83dfd23f 100644
--- a/modules/host/classes/model/host/server.php
+++ b/modules/host/classes/model/host/server.php
@@ -11,6 +11,9 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Host_Server extends ORMOSB {
+ // Host Server doesnt use the update column
+ protected $_updated_column = FALSE;
+
public function manage_button($u,$p,$d) {
$c = sprintf('Service_Host_%s',$this->provision_plugin);
if (! class_exists($c))
@@ -20,5 +23,12 @@ class Model_Host_Server extends ORMOSB {
return $po->manage_button($u,$p,$d);
}
+
+ public function config() {
+ if (! $this->provision_plugin_data)
+ throw new Kohana_Exception('No plugin configuration data');
+
+ return unserialize($this->provision_plugin_data);
+ }
}
?>
diff --git a/modules/host/classes/model/host/server/affiliate.php b/modules/host/classes/model/host/server/affiliate.php
new file mode 100644
index 00000000..ba9c66ca
--- /dev/null
+++ b/modules/host/classes/model/host/server/affiliate.php
@@ -0,0 +1,15 @@
+
diff --git a/modules/host/classes/model/service/plugin/host.php b/modules/host/classes/model/service/plugin/host.php
index 4a99f651..ffdfda28 100644
--- a/modules/host/classes/model/service/plugin/host.php
+++ b/modules/host/classes/model/service/plugin/host.php
@@ -51,6 +51,10 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
* to manage the domain.
*/
public function manage_button() {
+ // @todo Convert this to a Static_List display
+ if ($this->service->queue == 'PROVISION')
+ return _('To Be Provisioned');
+
return ($this->host_username AND $this->host_password) ? $this->host_server->manage_button($this->host_username,$this->host_password,$this->name()) : '';
}
}
diff --git a/modules/host/vendor/plesk.php b/modules/host/vendor/plesk.php
new file mode 100644
index 00000000..f6cc935d
--- /dev/null
+++ b/modules/host/vendor/plesk.php
@@ -0,0 +1,258 @@
+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,
+ );
+
+ // @todo Get this out of the DB
+ private $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,
+ );
+
+ // @todo Get this out of the DB
+ private $ippool = array(
+ '111.67.13.20'=>'shared',
+ );
+
+ private $curlopts = array(
+ CURLOPT_CONNECTTIMEOUT => 60,
+ CURLOPT_FAILONERROR => TRUE,
+ CURLOPT_FOLLOWLOCATION => FALSE,
+ CURLOPT_HEADER => FALSE,
+ CURLOPT_HTTPPROXYTUNNEL => FALSE,
+ CURLOPT_RETURNTRANSFER => TRUE,
+ CURLOPT_TIMEOUT => 30,
+ CURLOPT_SSL_VERIFYHOST => FALSE,
+ CURLOPT_SSL_VERIFYPEER => FALSE,
+ CURLOPT_VERBOSE => TRUE,
+ );
+
+ public function __construct(Model_Host_Server $hso) {
+ $this->hso = $hso;
+ $this->xml = XML::factory(null,'plesk');
+ $this->packet = $this->xml->add_node('packet','',array('version'=>$this->protocol));
+ }
+
+ private function server_command(XML $xml) {
+ $hs = $this->hso->config();
+
+ $request = Request::factory(sprintf('%s/%s',$this->hso->manage_url,$this->path))
+ ->method('POST');
+
+ $request->get_client()->options(Arr::merge($this->curlopts,array(
+ CURLOPT_HTTPHEADER => array(
+ 'HTTP_AUTH_LOGIN: '.$hs['user'],
+ 'HTTP_AUTH_PASSWD: '.$hs['pass'],
+ 'Content-Type: text/xml',
+ ),
+ CURLOPT_POSTFIELDS => $this->render($xml),
+ )));
+
+ $response = $request->execute();
+
+ return XML::factory(null,'plesk',$response->body());
+ }
+
+ /**
+ * Get a Client Configuration
+ */
+ public function get_client(Model_Service $so) {
+ $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');
+ $dataset->add_node('gen_info');
+ $dataset->add_node('stat');
+ $dataset->add_node('permissions');
+ $dataset->add_node('limits');
+ $dataset->add_node('ippool');
+
+ return $this->server_command($this->xml);
+ }
+
+ /**
+ * Get a Server Configuration
+ */
+ public function get_service(Model_Service $so) {
+ $client = $this->packet->add_node('domain');
+ $get = $client->add_node('get');
+ $filter = $get->add_node('filter');
+ $filter->add_node('domain-name',strtolower($so->name()));
+ $dataset = $get->add_node('dataset');
+ $dataset->add_node('hosting');
+ $dataset->add_node('limits');
+
+ return $this->server_command($this->xml);
+ }
+
+ /**
+ * Add a new client to the host server
+ */
+ public function add_client(Model_Service $so) {
+ $client_template = 'DefaultClient';
+ $reseller_id = $so->affiliate->host_server_affiliate->host_username;
+
+ $client = $this->packet->add_node('client');
+ $add = $client->add_node('add');
+ $gen_info = $add->add_node('gen_info');
+ $gen_info->add_node('cname',$so->account->company);
+ $gen_info->add_node('pname',sprintf('%s %s',$so->account->first_name,$so->account->last_name));
+
+ $gen_info->add_node('login',$so->plugin()->host_username);
+ $gen_info->add_node('passwd',$so->plugin()->host_password);
+
+ $gen_info->add_node('status',0);
+ $gen_info->add_node('email',$so->account->email);
+
+ if ($reseller_id)
+ $gen_info->add_node('owner-login',$reseller_id);
+
+ return $this->server_command($this->xml);
+ }
+
+ public function add_service(Model_Service $so) {
+ // @todo This should come from the DB.
+ $host_ip = '111.67.13.20';
+ $domain_template = 'Default Domain';
+
+ $domain = $this->packet->add_node('domain');
+ $add = $domain->add_node('add');
+ $gen_setup = $add->add_node('gen_setup');
+ $gen_setup->add_node('name',strtolower($so->name()));
+ $gen_setup->add_node('owner-login',$so->plugin()->host_username);
+ $gen_setup->add_node('htype','vrt_hst');
+ $gen_setup->add_node('ip_address',$host_ip);
+ $gen_setup->add_node('status','0');
+ $hosting = $add->add_node('hosting');
+ $vrt_host = $hosting->add_node('vrt_hst');
+ $property = $vrt_host->add_node('property');
+ $property->add_node('name','ftp_login');
+ $property->add_node('value',$so->plugin()->ftp_username);
+ $property = $vrt_host->add_node('property');
+ $property->add_node('name','ftp_password');
+ $property->add_node('value',$so->plugin()->ftp_password);
+ $vrt_host->add_node('ip_address',$host_ip);
+
+ $add->add_node('template-name',$domain_template);
+
+ return $this->server_command($this->xml);
+ }
+
+ // @todo not sure if this is actually working as desired
+ public function setlimits(Model_Service $so) {
+ $client = $this->packet->add_node('client');
+
+ // Permissions
+ $set = $client->add_node('set');
+ $filter = $set->add_node('filter');
+ $filter->add_node('login',$so->plugin()->host_username);
+ $values = $set->add_node('values');
+
+ $x = $values->add_node('permissions');
+ foreach ($this->permissions as $k=>$v) {
+ $l = $x->add_node('permission');
+ $l->add_node('name',$k);
+ $l->add_node('value',$v==TRUE?'true':'false');
+ }
+
+ // Limits
+ $set = $client->add_node('set');
+ $filter = $set->add_node('filter');
+ $filter->add_node('login',$so->plugin()->host_username);
+ $values = $set->add_node('values');
+
+ $x = $values->add_node('limits');
+ foreach ($this->limits as $k=>$v) {
+ $l = $x->add_node('limit');
+ $l->add_node('name',$k);
+ $l->add_node('value',$v);
+ }
+
+ return $this->server_command($this->xml);
+ }
+
+ public function setip($id) {
+ $client = $this->packet->add_node('client');
+ $ip = $client->add_node('ippool_add_ip');
+ $ip->add_node('client_id',$id);
+ foreach ($this->ippool as $k=>$v)
+ $ip->add_node('ip_address',$k);
+
+ return $this->server_command($this->xml);
+ }
+
+ public function disablemail($id) {
+ $client = $this->packet->add_node('mail');
+ $disable = $client->add_node('disable');
+ $disable->add_node('domain_id',$id);
+
+ return $this->server_command($this->xml);
+ }
+
+ private function render(XML $xml) {
+ return preg_replace('/<\/?plesk>/','',(string)$xml->render(FALSE));
+ }
+}
+?>
diff --git a/modules/host_server/classes/controller/hostserver.php b/modules/host_server/classes/controller/hostserver.php
deleted file mode 100644
index c7989207..00000000
--- a/modules/host_server/classes/controller/hostserver.php
+++ /dev/null
@@ -1,101 +0,0 @@
-addclient($ao);
-
- print_r(array('s'=>(string)$result,'r'=>(string)$result->add->result));
- }
-
- /**
- * Add a domain for the client
- *
- * @param int $id Hosting ID (in OSB)
- * @return unknown_type
- */
- public function action_plesk_adddomaintest($id) {
- $so = ORM::factory('service',$id);
-
- $plesk = new Plesk;
- $result = $plesk->adddomain($so);
-
- print_r(array('s'=>(string)$result,'r'=>(string)$result->add->result));
- }
-
- public function action_plesk_addclient($id) {
- }
-
- public function action_plesk_getclient($id) {
- $ao = ORM::factory('account',$id);
- $plesk = new Plesk;
- print_r($plesk->get_client($ao)->as_array());
- }
-
- public function action_plesk_getservice($id) {
- $so = ORM::factory('service',$id);
- $plesk = new Plesk;
-
- $result = $plesk->get_service($so);
- print_r(array('s'=>(string)$result,'r'=>(string)$result->get));
- }
-
- /**
- * Set the Limits for the client
- *
- * @param int $id Client ID (in plesk)
- * @return unknown_type
- */
- public function action_plesk_setlimits() {
- $plesk = new Plesk;
- $result = $plesk->setlimits();
-
- print_r(array('s'=>(string)$result,'r'=>(string)$result->set->result));
- }
-
- /**
- * Set the IP for the client
- *
- * @param int $id Client ID (in plesk)
- * @return unknown_type
- */
- public function action_plesk_setip($id) {
- $plesk = new Plesk;
- $result = $plesk->setip($id);
-
- print_r(array('s'=>(string)$result,'r'=>(string)$result->set));
- }
-
- /**
- * Disable mail for a domain
- *
- * @param int $id Domain ID (in plesk)
- * @return unknown_type
- */
- public function action_plesk_disablemail($id) {
- $plesk = new Plesk;
- $result = $plesk->disablemail($id);
-
- print_r(array('s'=>(string)$result,'r'=>(string)$result));
- }
-
- public function action_plesk_settraffic() {
- die();
- $plesk = new Plesk;
- $result = $plesk->set_traffic();
-
- print_r(array('s'=>(string)$result,'r'=>(string)$result));
- }
-}
-?>
diff --git a/modules/host_server/classes/plesk.php b/modules/host_server/classes/plesk.php
deleted file mode 100644
index 8042dfd7..00000000
--- a/modules/host_server/classes/plesk.php
+++ /dev/null
@@ -1,321 +0,0 @@
-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,
- );
-
- private $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,
- );
-
- private $ippool = array(
- '111.67.13.20'=>'shared',
- );
-
- public function addclient($account) {
- // @todo Remove this static definition
- $reseller_id = 'gtc-admin';
- $client_template = 'DefaultClient';
-
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- // Client Details
- $client = $packet->add_node('client');
- $add = $client->add_node('add');
- $gen_info = $add->add_node('gen_info');
- $gen_info->add_node('cname',$account->company);
- $gen_info->add_node('pname',sprintf('%s %s',$account->first_name,$account->last_name));
-
- $gen_info->add_node('login',$this->admin_id);
- $gen_info->add_node('passwd',$this->password);
-
- $gen_info->add_node('status',0);
- $gen_info->add_node('email',$account->email);
-
- if ($reseller_id)
- $gen_info->add_node('owner-login',$reseller_id);
-
- return $this->server_command($xml);
- }
-
- // @not developed
- public function setlimits() {
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- $client = $packet->add_node('client');
-
- // Permissions
- $set = $client->add_node('set');
- $filter = $set->add_node('filter');
- $filter->add_node('login',$this->admin_id);
- $values = $set->add_node('values');
-
- $x = $values->add_node('permissions');
- foreach ($this->permissions as $k=>$v) {
- $l = $x->add_node('permission');
- $l->add_node('name',$k);
- $l->add_node('value',$v==TRUE?'true':'false');
- }
-
- // Limits
- $set = $client->add_node('set');
- $filter = $set->add_node('filter');
- $filter->add_node('login',$this->admin_id);
- $values = $set->add_node('values');
-
- $x = $values->add_node('limits');
- foreach ($this->limits as $k=>$v) {
- $l = $x->add_node('limit');
- $l->add_node('name',$k);
- $l->add_node('value',$v);
- }
-
- return $this->server_command($xml);
- }
-
- public function setip($id) {
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- // IP Address
- $client = $packet->add_node('client');
- $ip = $client->add_node('ippool_add_ip');
- $ip->add_node('client_id',$id);
- foreach ($this->ippool as $k=>$v)
- $ip->add_node('ip_address',$k);
-
- return $this->server_command($xml);
- }
-
- public function disablemail($id) {
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- // IP Address
- $client = $packet->add_node('mail');
- $disable = $client->add_node('disable');
- $disable->add_node('domain_id',$id);
-
-echo (string)$xml;
- return $this->server_command($xml);
- }
-
- public function adddomain($service) {
- $host_ip = '111.67.13.20';
- $domain_template = 'Default Domain';
-
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- // Domain Details
- $domain = $packet->add_node('domain');
- $add = $domain->add_node('add');
- $gen_setup = $add->add_node('gen_setup');
- $gen_setup->add_node('name',$service->domain_name);
- $gen_setup->add_node('owner-login',$this->admin_id);
- $gen_setup->add_node('htype','vrt_hst');
- $gen_setup->add_node('ip_address',$host_ip);
- $gen_setup->add_node('status','0');
- $hosting = $add->add_node('hosting');
- $vrt_host = $hosting->add_node('vrt_hst');
- $property = $vrt_host->add_node('property');
- $property->add_node('name','ftp_login');
- $property->add_node('value',$service->host_username);
- $property = $vrt_host->add_node('property');
- $property->add_node('name','ftp_password');
- $property->add_node('value',$service->host_password);
- $vrt_host->add_node('ip_address',$host_ip);
-
- $add->add_node('template-name',$domain_template);
-
- return $this->server_command($xml);
- }
-
- private function render(XML $xml) {
- return preg_replace('/<\/?plesk>/','',(string)$xml->render(FALSE));
- }
-
- public function addclienttohost() {
- $LOGIN = 'admin';
- $PASSWD = 'w243550lp';
-
- $header = array(
- "HTTP_AUTH_LOGIN: " . $LOGIN,
- "HTTP_AUTH_PASSWD: " . $PASSWD,
- "HTTP_PRETTY_PRINT: TRUE",
- "Content-Type: text/xml",
- );
-
- return Remote::get(sprintf('https://%s/%s','w24-1-1.gthost.net:8443',$this->path),array(
- CURLOPT_SSL_VERIFYHOST => 0,
- CURLOPT_SSL_VERIFYPEER => FALSE,
- CURLOPT_HTTPHEADER => $header,
- CURLOPT_VERBOSE => TRUE,
- CURLOPT_POSTFIELDS => $this->render(),
- CURLOPT_RETURNTRANSFER => TRUE));
- }
-
- public function adddomaintohost($id) {
- $this->domain = ORM::factory('hostserver',$id);
- $this->domain_xml();
-
- }
-
- public function get_client($account) {
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- $client = $packet->add_node('client');
- $get = $client->add_node('get');
- $filter = $get->add_node('filter');
- $filter->add_node('login',$this->admin_id);
- $dataset = $get->add_node('dataset');
- $dataset->add_node('gen_info');
- $dataset->add_node('stat');
- $dataset->add_node('permissions');
- $dataset->add_node('limits');
- $dataset->add_node('ippool');
-
- return $this->server_command($xml);
- }
-
- public function get_service($service) {
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- $client = $packet->add_node('domain');
- $get = $client->add_node('get');
- $filter = $get->add_node('filter');
- // @todo this should not be required
- if ($service->domain_tld)
- $filter->add_node('domain-name',sprintf('%s.%s',$service->domain_name,$service->domain_tld));
- else
- $filter->add_node('domain-name',$service->domain_name);
- $dataset = $get->add_node('dataset');
- $dataset->add_node('hosting');
- $dataset->add_node('limits');
-
- return $this->server_command($xml);
- }
-
- private function server_command(XML $xml) {
- // @todo Configure this in OSB
- $LOGIN = 'admin';
- $PASSWD = 'w243550lp';
- $SERVER = 'w24-1-1.gthost.net';
- $PORT = 8443;
- $PROTO = 'https';
-
- $header = array(
- 'HTTP_AUTH_LOGIN: '.$LOGIN,
- 'HTTP_AUTH_PASSWD: '.$PASSWD,
- 'HTTP_PRETTY_PRINT: TRUE',
- 'Content-Type: text/xml',
- );
-
-//echo (string)$xml;
-//die();
- return XML::factory(null,'plesk',Remote::get(sprintf('%s://%s:%s/%s',$PROTO,$SERVER,$PORT,$this->path),array(
- CURLOPT_SSL_VERIFYHOST => 0,
- CURLOPT_SSL_VERIFYPEER => FALSE,
- CURLOPT_HTTPHEADER => $header,
- CURLOPT_VERBOSE => TRUE,
- CURLOPT_TIMEOUT => 40,
- CURLOPT_CONNECTTIMEOUT => 20,
- CURLOPT_POSTFIELDS => $this->render($xml),
- CURLOPT_RETURNTRANSFER => TRUE)));
- }
-
- public function set_traffic() {
- $xml = XML::factory(null,'plesk');
- $packet = $xml->add_node('packet','',array('version'=>$this->protocol));
-
- $domain = $packet->add_node('domain');
- $set = $domain->add_node('set');
- $filter = $set->add_node('filter');
-
-# foreach (array(
-# 'absmotorcycles.com.au'
-# ) as $domain) {
-# $filter->add_node('domain-name',$domain);
-# }
-
- $values = $set->add_node('values');
-
- // Limits
- $x = $values->add_node('limits');
- #foreach ($this->limits as $k=>$v) {
- $l = $x->add_node('limit');
- $l->add_node('name','max_traffic');
- $l->add_node('value',1500*1024*1024);
- $l = $x->add_node('limit');
- $l->add_node('name','max_traffic_soft');
- $l->add_node('value',1300*1024*1024);
- #}
-
-//echo (string)$xml;die();
- return $this->server_command($xml);
- }
-}
diff --git a/modules/invoice/views/invoice/user/email.php b/modules/invoice/views/invoice/user/email.php
index 5c1e6995..81ff34e5 100644
--- a/modules/invoice/views/invoice/user/email.php
+++ b/modules/invoice/views/invoice/user/email.php
@@ -132,11 +132,11 @@
- Total Invoice: |
+ Total This Invoice: |
total(TRUE); ?> |
- Total Outstanding: |
+ Total Outstanding This Account: |
account->invoices_due_total(NULL,TRUE); ?> |
diff --git a/modules/invoice/views/invoice/user/view.php b/modules/invoice/views/invoice/user/view.php
index ad1c2090..08eb0d48 100644
--- a/modules/invoice/views/invoice/user/view.php
+++ b/modules/invoice/views/invoice/user/view.php
@@ -131,11 +131,11 @@
- Total Invoice: |
+ Total This Invoice: |
total(TRUE); ?> |
- Total Outstanding: |
+ Total Outstanding This Account: |
account->invoices_due_total(NULL,TRUE); ?> |
diff --git a/modules/product/classes/model/product.php b/modules/product/classes/model/product.php
index d034edc4..fce47fde 100644
--- a/modules/product/classes/model/product.php
+++ b/modules/product/classes/model/product.php
@@ -131,14 +131,14 @@ class Model_Product extends ORMOSB {
* List the number of services using this product
*/
public function services_count() {
- return $this->service->find_all()->count();
+ return $this->service->where('active','=',1)->find_all()->count();
}
/**
* List the number of invoices using this product
*/
public function invoices_count() {
- return $this->invoice->find_all()->count();
+ return $this->invoice->where('status','=',1)->find_all()->count();
}
/**
diff --git a/modules/service/classes/controller/admin/service.php b/modules/service/classes/controller/admin/service.php
index f97145fb..bdd66417 100644
--- a/modules/service/classes/controller/admin/service.php
+++ b/modules/service/classes/controller/admin/service.php
@@ -517,7 +517,8 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
));
}
- public function action_update($id) {
+ public function action_update() {
+ $id = $this->request->param('id');
$so = ORM::factory('service',$id);
if (! $so->loaded())
diff --git a/modules/service/classes/controller/user/service.php b/modules/service/classes/controller/user/service.php
index 6c112037..94911777 100644
--- a/modules/service/classes/controller/user/service.php
+++ b/modules/service/classes/controller/user/service.php
@@ -43,6 +43,7 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
public function action_view() {
$output = '';
+ // Check if we are a table view
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('service_view','id');
diff --git a/modules/service/classes/model/service.php b/modules/service/classes/model/service.php
index b984e971..9d311170 100644
--- a/modules/service/classes/model/service.php
+++ b/modules/service/classes/model/service.php
@@ -9,10 +9,14 @@
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
+ *
+ * Fields:
+ * + queue: PROVISION (to be provisioned)
*/
class Model_Service extends ORMOSB {
// Relationships
protected $_has_one = array(
+ 'affiliate'=>array('far_key'=>'affiliate_id','foreign_key'=>'id'),
'service_billing'=>array('far_key'=>'account_billing_id','foreign_key'=>'id'),
);
protected $_has_many = array(
@@ -104,17 +108,24 @@ class Model_Service extends ORMOSB {
}
}
+ /**
+ * Enable the plugin to store data
+ */
public function admin_update() {
if (is_null($plugin = $this->plugin()))
return NULL;
else
- return $plugin->_admin_update();
+ return $plugin->admin_update();
}
/** LIST FUNCTIONS **/
+ private function _list_active() {
+ return $this->where('active','=',1);
+ }
+
public function list_active() {
- return $this->where('active','=','1')->find_all();
+ return $this->_list_active()->find_all();
}
public function list_bylistgroup($cat) {
@@ -138,14 +149,20 @@ class Model_Service extends ORMOSB {
* List services that need to be billed.
*/
public function list_invoicesoon() {
- $result = array();
+ // @todo This needs to be configurable
+ $days = 35;
- foreach ($this->list_active() as $so)
- // @todo This should be configurable (days)
- if (! $so->suspend_billing AND $so->date_next_invoice < time()+35*86400)
- array_push($result,$so);
+ return $this->_list_active()
+ ->where_open()->where('suspend_billing','IS',NULL)->or_where('suspend_billing','=','0')->where_close()
+ ->where('date_next_invoice','<',time()+$days*86400)
+ ->find_all();
+ }
- return $result;
+ /**
+ * List services that need to be provisioned
+ */
+ public function list_provision() {
+ return $this->_list_active()->where('queue','=','PROVISION');
}
}
?>
diff --git a/modules/ssl/classes/controller/admin/ssl.php b/modules/ssl/classes/controller/admin/ssl.php
new file mode 100644
index 00000000..d8dcea0b
--- /dev/null
+++ b/modules/ssl/classes/controller/admin/ssl.php
@@ -0,0 +1,59 @@
+TRUE,
+ 'update'=>TRUE,
+ );
+
+ public function action_list() {
+ Block::add(array(
+ 'title'=>_('SSL Services'),
+ 'body'=>Table::display(
+ ORM::factory('ssl_ca')->find_all(),
+ 25,
+ array(
+ 'id'=>array('label'=>'ID','url'=>'admin/ssl/update/'),
+ 'sign_cert'=>array('label'=>'Cert'),
+ 'issuer()'=>array('label'=>'Issuer'),
+ 'expires()'=>array('label'=>'Expires'),
+ ),
+ array(
+ 'page'=>TRUE,
+ 'type'=>'select',
+ 'form'=>'admin/ssl/update',
+ )),
+ ));
+ }
+
+ public function action_update() {
+ $id = $this->request->param('id');
+ $so = ORM::factory('ssl_ca',$id);
+
+ if (! $so->loaded())
+ Request::current()->redirect('welcome/index');
+
+ if ($_POST) {
+ if (! $so->values($_POST)->update()->saved())
+ throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
+ }
+
+ Block::add(array(
+ 'title'=>sprintf('%s %s:%s',_('Update SSL Service'),$so->id,$so->display('sign_cert')),
+ 'body'=>View::factory('ssl/admin/update')
+ ->set('so',$so)
+ ->set('mediapath',Route::get('default/media'))
+ ));
+ }
+}
+?>
diff --git a/modules/ssl/classes/controller/task/ssl.php b/modules/ssl/classes/controller/task/ssl.php
new file mode 100644
index 00000000..493e5015
--- /dev/null
+++ b/modules/ssl/classes/controller/task/ssl.php
@@ -0,0 +1,25 @@
+request->param('id');
+ $so = ORM::factory('service',$id);
+
+ $so->plugin()->renew();
+ }
+}
+?>
diff --git a/modules/ssl/classes/controller/user/ssl.php b/modules/ssl/classes/controller/user/ssl.php
new file mode 100644
index 00000000..5e0baa18
--- /dev/null
+++ b/modules/ssl/classes/controller/user/ssl.php
@@ -0,0 +1,51 @@
+FALSE,
+ );
+
+ public function action_download() {
+ $id = $_POST['sid'];
+ $so = ORM::factory('service',$id);
+
+ if (! $so->loaded())
+ Request::current()->redirect('welcome/index');
+
+ $passwd = $_POST['passwd'];
+ if (strlen($passwd) < Kohana::config('ssl.minpass_length')) {
+ SystemMessage::add(array(
+ 'title'=>_('Validation failed'),
+ 'type'=>'error',
+ 'body'=>_('Your requested password is too short.'),
+ ));
+
+ Request::current()->redirect('user/service/view/'.$so->id);
+ }
+
+ if (! $so->loaded() OR ! Auth::instance()->authorised($so->account_id,$so->affiliate_id)) {
+ $this->template->content = 'Unauthorised or doesnt exist?';
+ return FALSE;
+ }
+
+ $file = Kohana::config('config.tmpdir').'/'.$so->name().'.pkcs12';
+ openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts()));
+ $x = file_get_contents($file);
+ unlink($file);
+ $this->response->headers('Content-Type','application/pks12');
+ $this->response->headers('Content-Disposition','attachment; filename="'.basename($file).'"');
+ $this->response->body($x);
+ $this->auto_render = FALSE;
+ }
+}
+?>
diff --git a/modules/ssl/classes/model/product/plugin/ssl.php b/modules/ssl/classes/model/product/plugin/ssl.php
new file mode 100644
index 00000000..ac067e8c
--- /dev/null
+++ b/modules/ssl/classes/model/product/plugin/ssl.php
@@ -0,0 +1,23 @@
+set('po',$this);
+ }
+}
+?>
diff --git a/modules/ssl/classes/model/service/plugin/ssl.php b/modules/ssl/classes/model/service/plugin/ssl.php
new file mode 100644
index 00000000..61f98d81
--- /dev/null
+++ b/modules/ssl/classes/model/service/plugin/ssl.php
@@ -0,0 +1,145 @@
+array(),
+ );
+ protected $_has_one = array(
+ 'ssl_ca'=>array('far_key'=>'ssl_ca_id','foreign_key'=>'id'),
+ 'ssl'=>array('far_key'=>'ssl_id','foreign_key'=>'id'),
+ );
+
+ protected $_display_filters = array(
+ 'csr'=>array(
+ array('SSL::csrsubject',array(':value')),
+ ),
+ );
+
+ // Required abstract functions
+ public function service_view() {
+ return View::factory('service/user/plugin/ssl/view')
+ ->set('so',$this);
+ }
+
+ public function name() {
+ return $this->display('csr');
+ }
+
+ // @todo This needs to be validated for this model
+ public function product() {
+ if ($this->provided_adsl_plan_id)
+ return $this->adsl_plan;
+ else
+ return $this->service->product->plugin();
+ }
+
+ public function valid_from() {
+ return SSL::from($this->cert);
+ }
+
+ public function valid_to() {
+ return SSL::expire($this->cert);
+ }
+
+ public function serial_num() {
+ return SSL::serial($this->cert);
+ }
+
+ public function hash() {
+ return SSL::hash($this->cert);
+ }
+
+ public function version() {
+ return SSL::version($this->cert);
+ }
+
+ /**
+ * Get specific service details for use in other modules
+ * For Example: Invoice
+ *
+ * @todo Make the rendered items configurable
+ * @todo Change this method name, now that it is public
+ */
+ // @todo This needs to be validated for this model
+ public function _details($type) {
+ switch ($type) {
+ case 'invoice_detail_items':
+ return array(
+ _('Service Address')=>$this->service_address ? $this->display('service_address') : '>NotSet<',
+ _('Contract Until')=>$this->contract_date_end(),
+ );
+ break;
+ default:
+ return parent::$_details($type);
+ }
+ }
+
+ // @todo This needs to be validated for this model
+ public function admin_update() {
+ return View::factory('service/admin/plugin/ssl/update')
+ ->set('mediapath',Route::get('default/media'))
+ ->set('so',$this);
+ }
+
+ public function download_button() {
+ if (! preg_match('/client/',$this->ssl->extensions))
+ return '';
+
+ // @todo Do some password validation
+ $output = Form::open('user/ssl/download');
+ $output .= Form::hidden('sid',$this->service->id);
+ $output .= _('Choose a password').': '.Form::password('passwd','').'
';
+ $output .= Form::submit('download','Download',array('class'=>'form_button'));
+ return $output;
+ }
+
+ public function cacerts() {
+ $return = array();
+
+ $x = $this->ssl_ca_id;
+ while ($x) {
+ $sco = ORM::factory('ssl_ca',$x);
+ array_push($return,$sco->sign_cert);
+ $x = $sco->parent_ssl_ca_id;
+ }
+
+ return $return;
+ }
+
+ public function renew() {
+ $d = SSL::details($this->cert);
+ $ssl_conf = Kohana::config('ssl');
+
+ // If our certificate is not old enough skip
+ if ($d['validTo_time_t'] > time()+$ssl_conf['min_renew_days']*86400)
+ return FALSE;
+
+ $res = openssl_csr_sign($this->csr,$this->ssl_ca->sign_cert,$this->ssl_ca->sign_pk,$this->ssl->days,array(
+ 'config'=>$ssl_conf['config'],
+ 'x509_extensions'=>$this->ssl->extensions,
+ ),time());
+
+ if (openssl_x509_export($res,$cert)) {
+ $this->cert = $cert;
+ $this->save();
+
+ return TRUE;
+ } else
+ throw new Kohana_Exception('Error Creating SSL Certificate :error',array(':error'=>openssl_error_string()));
+ }
+}
+?>
diff --git a/modules/ssl/classes/model/ssl.php b/modules/ssl/classes/model/ssl.php
new file mode 100644
index 00000000..19fe9a75
--- /dev/null
+++ b/modules/ssl/classes/model/ssl.php
@@ -0,0 +1,16 @@
+
diff --git a/modules/ssl/classes/model/ssl/ca.php b/modules/ssl/classes/model/ssl/ca.php
new file mode 100644
index 00000000..b3c48696
--- /dev/null
+++ b/modules/ssl/classes/model/ssl/ca.php
@@ -0,0 +1,37 @@
+array(
+ array('SSL::subject',array(':value')),
+ ),
+ );
+
+ public function expires() {
+ return SSL::expire($this->sign_cert);
+ }
+
+ public function issuer() {
+ return SSL::issuer($this->sign_cert);
+ }
+}
+?>
diff --git a/modules/ssl/classes/ssl.php b/modules/ssl/classes/ssl.php
new file mode 100644
index 00000000..94fd3120
--- /dev/null
+++ b/modules/ssl/classes/ssl.php
@@ -0,0 +1,63 @@
+
diff --git a/modules/ssl/config/ssl.php b/modules/ssl/config/ssl.php
new file mode 100644
index 00000000..7df8df05
--- /dev/null
+++ b/modules/ssl/config/ssl.php
@@ -0,0 +1,23 @@
+ 7,
+
+ // Min password length for exports
+ 'minpass_length' => 4,
+
+ // Location to openssl config
+ 'config' => 'appliation/config/openssl.cnf',
+);
+?>
diff --git a/modules/ssl/views/product/plugin/ssl/feature_summary.php b/modules/ssl/views/product/plugin/ssl/feature_summary.php
new file mode 100644
index 00000000..c3b8a8a3
--- /dev/null
+++ b/modules/ssl/views/product/plugin/ssl/feature_summary.php
@@ -0,0 +1,11 @@
+
+
+
+ Validity Days |
+ display('days'); ?> |
+
+
+ Type |
+ display('extensions'); ?> |
+
+
diff --git a/modules/ssl/views/service/admin/plugin/ssl/update.php b/modules/ssl/views/service/admin/plugin/ssl/update.php
new file mode 100644
index 00000000..0e50472d
--- /dev/null
+++ b/modules/ssl/views/service/admin/plugin/ssl/update.php
@@ -0,0 +1,14 @@
+
+
+ CSR |
+ service->plugin()->csr,array('cols'=>64,'rows'=>13)); ?> |
+
+
+ PK |
+ service->plugin()->pk,array('cols'=>64,'rows'=>13)); ?> |
+
+
+ Cert |
+ service->plugin()->cert,array('cols'=>64,'rows'=>13)); ?> |
+
+
diff --git a/modules/ssl/views/service/user/plugin/ssl/view.php b/modules/ssl/views/service/user/plugin/ssl/view.php
new file mode 100644
index 00000000..76239ea4
--- /dev/null
+++ b/modules/ssl/views/service/user/plugin/ssl/view.php
@@ -0,0 +1,44 @@
+
+
+
+ Service Details |
+
+
+ |
+
+
+
+
+
+ Service Name |
+ display('csr'); ?> |
+
+
+ Valid From |
+ valid_from(); ?> |
+
+
+ Valid To |
+ valid_to(); ?> |
+
+
+ Serial Number |
+ serial_num(); ?> |
+
+
+ Version |
+ version(); ?> |
+
+
+ Hash |
+ hash(); ?> |
+
+
+ Certificate |
+ display('cert'); ?> |
+
+
+ |
+ download_button(); ?> |
+
+
diff --git a/modules/ssl/views/ssl/admin/update.php b/modules/ssl/views/ssl/admin/update.php
new file mode 100644
index 00000000..c8a2571c
--- /dev/null
+++ b/modules/ssl/views/ssl/admin/update.php
@@ -0,0 +1,41 @@
+
+
+
+ Subject |
+ sign_cert); ?> |
+
+
+ Issuer |
+ sign_cert); ?> |
+
+
+ Valid From |
+ sign_cert); ?> |
+
+
+ Valid To |
+ sign_cert); ?> |
+
+
+ Serial Num |
+ sign_cert); ?> |
+
+
+ Hash |
+ sign_cert); ?> |
+
+
+ Version |
+ sign_cert); ?> |
+
+
+ Private Key |
+ sign_pk,array('cols'=>64,'rows'=>13)); ?> |
+
+
+ Certificate |
+ sign_cert,array('cols'=>64,'rows'=>13)); ?> |
+
+