From cb1aa5f1b8ad3bd0d9584ed026f46fda0fb4a7f0 Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Wed, 22 Aug 2012 12:19:06 -0400
Subject: [PATCH] - Added remoting functions for vhost subdomains - Added plugin for vhost subdomains to catch onafterinsert/update
---
interface/lib/plugins/sites_web_vhost_subdomain_plugin.inc.php | 67 ++++++++++++++++++++++
interface/lib/classes/remoting.inc.php | 69 +++++++++++++++++++++++
2 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/interface/lib/classes/remoting.inc.php b/interface/lib/classes/remoting.inc.php
index e5b1c98..2eff849 100644
--- a/interface/lib/classes/remoting.inc.php
+++ b/interface/lib/classes/remoting.inc.php
@@ -1474,6 +1474,75 @@
return $affected_rows;
}
+ // ----------------------------------------------------------------------------------------------------------
+
+ //* Get record details
+ public function sites_web_vhost_subdomain_get($session_id, $primary_id)
+ {
+ global $app;
+
+ if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
+ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+ return false;
+ }
+ $app->uses('remoting_lib');
+ $app->remoting_lib->loadFormDef('../sites/form/web_vhost_subdomain.tform.php');
+ return $app->remoting_lib->getDataRecord($primary_id);
+ }
+
+ //* Add a record
+ public function sites_web_vhost_subdomain_add($session_id, $client_id, $params)
+ {
+ global $app;
+ if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
+ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+ return false;
+ }
+
+ //* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
+ if($params['document_root'] == '') $params['document_root'] = '-';
+ if($params['system_user'] == '') $params['system_user'] = '-';
+ if($params['system_group'] == '') $params['system_group'] = '-';
+
+ //* 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;
+
+ $domain_id = $this->insertQuery('../sites/form/web_vhost_subdomain.tform.php',$client_id,$params, 'sites:web_vhost_subdomain:on_after_insert');
+ return $domain_id;
+ }
+
+ //* Update a record
+ public function sites_web_vhost_subdomain_update($session_id, $client_id, $primary_id, $params)
+ {
+ if(!$this->checkPerm($session_id, 'sites_web_subdomain_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;
+
+ $affected_rows = $this->updateQuery('../sites/form/web_vhost_subdomain.tform.php',$client_id,$primary_id,$params, 'sites:web_vhost_subdomain:on_after_insert');
+ return $affected_rows;
+ }
+
+ //* Delete a record
+ public function sites_web_vhost_subdomain_delete($session_id, $primary_id)
+ {
+ if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
+ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+ return false;
+ }
+ $affected_rows = $this->deleteQuery('../sites/form/web_vhost_subdomain.tform.php',$primary_id);
+ return $affected_rows;
+ }
+
// -----------------------------------------------------------------------------------------------
//* Get record details
diff --git a/interface/lib/plugins/sites_web_vhost_subdomain_plugin.inc.php b/interface/lib/plugins/sites_web_vhost_subdomain_plugin.inc.php
new file mode 100644
index 0000000..a302982
--- /dev/null
+++ b/interface/lib/plugins/sites_web_vhost_subdomain_plugin.inc.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * sites_web_domain_plugin plugin
+ *
+ * @author Marius Cramer <m.cramer@pixcept.de> pixcept KG 2012, copied and adapted from web_domain plugin by:
+ * @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
+ */
+
+class sites_web_vhost_subdomain_plugin {
+
+ var $plugin_name = 'sites_web_vhost_subdomain_plugin';
+ var $class_name = 'sites_web_vhost_subdomain_plugin';
+
+ // TODO: This function is a duplicate from the one in interface/web/sites/web_vhost_subdomain_edit.php
+ // There should be a single "token replacement" function to be called from modules and
+ // from the main code.
+ // Returna a "3/2/1" path hash from a numeric id '123'
+ function id_hash($id,$levels) {
+ $hash = "" . $id % 10 ;
+ $id /= 10 ;
+ $levels -- ;
+ while ( $levels > 0 ) {
+ $hash .= "/" . $id % 10 ;
+ $id /= 10 ;
+ $levels-- ;
+ }
+ return $hash;
+ }
+
+ /*
+ This function is called when the plugin is loaded
+ */
+ function onLoad() {
+ global $app;
+ //Register for the events
+ // both event call the same function as the things to do do not differ here
+ $app->plugin->registerEvent('sites:web_vhost_subdomain:on_after_insert','sites_web_vhost_subdomain_plugin','sites_web_vhost_subdomain_edit');
+ $app->plugin->registerEvent('sites:web_vhost_subdomain:on_after_update','sites_web_vhost_subdomain_plugin','sites_web_vhost_subdomain_edit');
+ }
+
+ /*
+ Function to create the sites_web_vhost_subdomain rule and insert it into the custom rules
+ */
+ function sites_web_vhost_subdomain_edit($event_name, $page_form) {
+ global $app, $conf;
+
+ // Get configuration for the web system
+ $app->uses("getconf");
+ $web_rec = $app->tform->getDataRecord($page_form->id);
+ $web_config = $app->getconf->get_server_config(intval($web_rec['server_id']),'web');
+
+ $parent_domain = $app->db->queryOneRecord("SELECT * FROM `web_domain` WHERE `domain_id` = '" . intval($web_rec['parent_domain_id']) . "'");
+
+ // Set the values for document_root, system_user and system_group
+ $system_user = $app->db->quote($parent_domain['system_user']);
+ $system_group = $app->db->quote($parent_domain['system_group']);
+ $document_root = $app->db->quote($parent_domain['document_root']);
+ $php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$web_rec['web_folder'],$web_config["php_open_basedir"]);
+ $php_open_basedir = str_replace("[website_domain]/web",$web_rec['domain'].'/'.$web_rec['web_folder'],$php_open_basedir);
+ $php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir);
+ $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
+ $htaccess_allow_override = $app->db->quote($parent_domain['allow_override']);
+
+ $sql = "UPDATE web_domain SET sys_groupid = ".intval($parent_domain['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
+ $app->db->query($sql);
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.1