From 0c9ab913734076b877597b42c8c5a89730cde6c0 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Wed, 20 Oct 2010 09:01:34 +0000 Subject: [PATCH] - added multiserver-client-deploy-cron - outsourcing Deploy() function from froxlorclient to client_deployer --- .../froxlorclient/class.froxlorclient.php | 55 +------- .../formfields/function.buildFormEx.php | 4 +- ...on_tasks.inc.multiserver.client_deploy.php | 127 ++++++++++++++++++ scripts/jobs/cron_tasks.php | 34 +++++ 4 files changed, 166 insertions(+), 54 deletions(-) create mode 100644 scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php diff --git a/lib/classes/froxlorclient/class.froxlorclient.php b/lib/classes/froxlorclient/class.froxlorclient.php index 191b7430..b9f4d44d 100644 --- a/lib/classes/froxlorclient/class.froxlorclient.php +++ b/lib/classes/froxlorclient/class.froxlorclient.php @@ -112,55 +112,6 @@ class froxlorclient return $result; } - /** - * This functions deploys the needed files - * to the client destination server - * - * @TODO - * - get information about what files need to be transfered - * - generate userdata.inc.php for client (db = master db) - */ - public function Deploy() - { - // get FroxlorSshTransport-object - $ssh = null; - try { - if($this->_getSetting('client', 'deploy_mode') !== null - && $this->_getSetting('client', 'deploy_mode') == 'pubkey' - ) { - $ssh = FroxlorSshTransport::usePublicKey( - $this->_getSetting('client', 'hostname'), - $this->_getSetting('client', 'ssh_port'), - $this->_getSetting('client', 'ssh_user'), - $this->_getSetting('client', 'ssh_pubkey'), - $this->_getSetting('client', 'ssh_privkey'), - $this->_getSetting('client', 'ssh_passphrase') - ); - } else if($this->_getSetting('client', 'deploy_mode') !== null) { - $ssh = FroxlorSshTransport::usePlainPassword( - $this->_getSetting('client', 'hostname'), - $this->_getSetting('client', 'ssh_port'), - $this->_getSetting('client', 'ssh_user'), - $this->_getSetting('client', 'ssh_passphrase') - ); - } else { - throw new Exception('NO_DEPLOY_METHOD_GIVEN'); - } - } catch (Exception $e) { - return $e->getMessage(); - } - - if($ssh instanceof FroxlorSshTransport) - { - /** - * @TODO implement me - */ - - // close the session - $ssh->close(); - } - } - /** * Insert new client to database */ @@ -300,7 +251,7 @@ class froxlorclient * * @return mixed or null if not found */ - private function _getSetting($_grp = '', $_var = '', $_grptrusted = false, $_vartrusted = false) + public function getSetting($_grp = '', $_var = '', $_grptrusted = false, $_vartrusted = false) { if($_grp != '' && $_var != '' @@ -337,7 +288,7 @@ class froxlorclient * @param bool $_vartrusted * @param bool $_valuetrusted */ - private function _setSetting($_grp = '', $_var = '', $_value = '', $_grptrusted = false, $_vartrusted = false, $_valuetrusted = false) + public function setSetting($_grp = '', $_var = '', $_value = '', $_grptrusted = false, $_vartrusted = false, $_valuetrusted = false) { if($_grp != '' && $_var != '' @@ -389,7 +340,7 @@ class froxlorclient { foreach($fv as $field => $value) { - $this->_setSetting($group, $field, $value, true, true, true); + $this->setSetting($group, $field, $value, true, true, true); } } } diff --git a/lib/functions/formfields/function.buildFormEx.php b/lib/functions/formfields/function.buildFormEx.php index 78c4a791..17c9f6d3 100644 --- a/lib/functions/formfields/function.buildFormEx.php +++ b/lib/functions/formfields/function.buildFormEx.php @@ -38,7 +38,7 @@ function buildFormEx($form, $part = '', $server_id = 0) { $fields .= getFormGroupOutput($groupname, $groupdetails); } - + if(validateFieldDefinition($groupdetails)) { // Prefetch form fields @@ -47,7 +47,7 @@ function buildFormEx($form, $part = '', $server_id = 0) $groupdetails['fields'][$fieldname] = array_merge_prefix($fielddetails, $fielddetails['type'], prefetchFormFieldData($fieldname, $fielddetails)); $form['groups'][$groupname]['fields'][$fieldname] = $groupdetails['fields'][$fieldname]; } - + // Collect form field output foreach($groupdetails['fields'] as $fieldname => $fielddetails) { diff --git a/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php b/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php new file mode 100644 index 00000000..b798bdd4 --- /dev/null +++ b/scripts/jobs/cron_tasks.inc.multiserver.client_deploy.php @@ -0,0 +1,127 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Cron + * @version $Id$ + */ + +/* + * This script prepares data for froxlor-clients (multserver-mode) + * and transfers them via ssh/scp to the destination-server + */ + +if(@php_sapi_name() != 'cli' +&& @php_sapi_name() != 'cgi' +&& @php_sapi_name() != 'cgi-fcgi') +{ + die('This script only works in the shell.'); +} + +class client_deployer +{ + /** + * object of froxlor-client + * @var froxlorclient + */ + private $_client = null; + + public function __construct($client = null) + { + $this->_client = $client; + } + + /** + * This functions deploys the needed files + * to the client destination server + * + * @return bool + */ + public function Deploy() + { + // get FroxlorSshTransport-object + $ssh = null; + if($this->_client->getSetting('client', 'deploy_mode') !== null + && $this->_client->getSetting('client', 'deploy_mode') == 'pubkey' + ) { + $ssh = FroxlorSshTransport::usePublicKey( + $this->_client->getSetting('client', 'hostname'), + $this->_client->getSetting('client', 'ssh_port'), + $this->_client->getSetting('client', 'ssh_user'), + $this->_client->getSetting('client', 'ssh_pubkey'), + $this->_client->getSetting('client', 'ssh_privkey'), + $this->_client->getSetting('client', 'ssh_passphrase') + ); + } + else if($this->_getSetting('client', 'deploy_mode') !== null) + { + $ssh = FroxlorSshTransport::usePlainPassword( + $this->_client->getSetting('client', 'hostname'), + $this->_client->getSetting('client', 'ssh_port'), + $this->_client->getSetting('client', 'ssh_user'), + $this->_client->getSetting('client', 'ssh_passphrase') + ); + } else { + throw new Exception('NO_DEPLOY_METHOD_GIVEN'); + } + + if($ssh instanceof FroxlorSshTransport) + { + /** + * @TODO implement me + */ + + // close the session + $ssh->close(); + } + } + + /** + * transfer the created archive to + * the destination host + * + * @return double amount of bytes transferd + */ + private function _transferArchive() + { + $archive = $this->_prepareFiles(); + } + + /** + * create an archive of all needed files listed + * in a list/xml file (@TODO) + * + * @return string path to the created archive + */ + private function _prepareFiles() + { + + /** + * create userdata file which + * has to be included to the archive + */ + $userdatafile = $this->_createUserdataFile(); + } + + /** + * create the userdata.inc.php file filled + * with necessary data, like database-host, + * username, etc. + * !!! don't forget to set $server_id to the correct value !!! + * + * @return string full path to the created file + */ + private function _createUserdataFile() + { + + } +} diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 665f3aaa..2a568168 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -25,6 +25,10 @@ require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.10.apache require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.15.apache_fcgid.php')); require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.20.lighttpd.php')); require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.25.lighttpd_fcgid.php')); +// only include if multiserver is enabled +if($settings['multiserver']['enabled']) { + require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.multiserver.client_deploy.php')); +} /** * LOOK INTO TASKS TABLE TO SEE IF THERE ARE ANY UNDONE JOBS @@ -375,6 +379,36 @@ while($row = $db->fetch_array($result_tasks)) } } } + + /** + * TYPE=9 -> deploy a Froxlor multiserver client to its destination + */ + elseif ($row['type'] == '9') + { + fwrite($debugHandler, ' cron_tasks: Task9 started - deploy a Froxlor multiserver client' . "\n"); + $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task9 started - deploy a Froxlor multiserver client'); + + if(is_array($row['data'])) + { + if(isset($row['data']['serverid'])) + { + /* + * get froxlor-client-object + */ + $client = froxlorclient::getInstance(null, $db, (int)$row['data']['serverid']); + /* + * create new deployer-object + */ + $deployer = new client_deployer($client); + /* + * deploy + * + * @TODO handle Exceptions + */ + $deployer->Deploy(); + } + } + } } if($db->num_rows($result_tasks) != 0)