- added multiserver-client-deploy-cron

- outsourcing Deploy() function from froxlorclient to client_deployer
This commit is contained in:
Michael Kaufmann (d00p)
2010-10-20 09:01:34 +00:00
parent 836b7fb056
commit 0c9ab91373
4 changed files with 166 additions and 54 deletions

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (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()
{
}
}

View File

@@ -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)