- added functions to get/set client settings
- added function for deployment of FroxlorClients
This commit is contained in:
@@ -74,9 +74,6 @@ class froxlorclient
|
||||
$this->settings = $settings;
|
||||
$this->cid = $cid;
|
||||
|
||||
// initialize data array
|
||||
$this->_initData();
|
||||
|
||||
// read data from database
|
||||
$this->_readData();
|
||||
}
|
||||
@@ -100,6 +97,40 @@ class froxlorclient
|
||||
return self::$clients[$_cid];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data in database
|
||||
*/
|
||||
@@ -188,8 +219,8 @@ class froxlorclient
|
||||
public function Set($_var = '', $_value = '', $_vartrusted = false, $_valuetrusted = false)
|
||||
{
|
||||
if($_var != ''
|
||||
&& $_value != '')
|
||||
{
|
||||
&& $_value != ''
|
||||
) {
|
||||
if(!$_vartrusted)
|
||||
{
|
||||
$_var = htmlspecialchars($_var);
|
||||
@@ -205,13 +236,79 @@ class froxlorclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize data-array
|
||||
* set a value in the internal settings array
|
||||
*
|
||||
* @param string $_var
|
||||
* @param string $_value
|
||||
* @param bool $_vartrusted
|
||||
* @param bool $_valuetrusted
|
||||
*/
|
||||
private function _initData()
|
||||
private function _getSetting($_var = '', $_vartrusted = false)
|
||||
{
|
||||
$this->Set('name', '', true, true);
|
||||
$this->Set('ip', '', true, true);
|
||||
$this->Set('enabled', '0', true, true);
|
||||
if($_var != '')
|
||||
{
|
||||
if(!$_vartrusted)
|
||||
{
|
||||
$_var = htmlspecialchars($_var);
|
||||
}
|
||||
|
||||
if(isset($this->c_data['settings'][$_var]))
|
||||
{
|
||||
return $this->c_data['settings'][$_var];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set a value in the internal settings array
|
||||
*
|
||||
* @param string $_var
|
||||
* @param string $_value
|
||||
* @param bool $_vartrusted
|
||||
* @param bool $_valuetrusted
|
||||
*/
|
||||
private function _setSetting($_var = '', $_value = '', $_vartrusted = false, $_valuetrusted = false)
|
||||
{
|
||||
if($_var != ''
|
||||
&& $_value != ''
|
||||
) {
|
||||
if(!$_vartrusted)
|
||||
{
|
||||
$_var = htmlspecialchars($_var);
|
||||
}
|
||||
|
||||
if(!$_valuetrusted)
|
||||
{
|
||||
$_value = htmlspecialchars($_value);
|
||||
}
|
||||
|
||||
if(!is_array($this->c_data['settings'])) {
|
||||
$this->c_data['settings'] = array();
|
||||
}
|
||||
|
||||
$this->c_data['settings'][$_var] = $_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read client settings from database
|
||||
*/
|
||||
private function _readSettings()
|
||||
{
|
||||
if(isset($this->cid)
|
||||
&& $this->cid != - 1
|
||||
) {
|
||||
$_settings = $this->db->query_first("SELECT * FROM `".TABLE_PANEL_SETTINGS."` WHERE `sid` = '".(int)$this->cid."'");
|
||||
|
||||
foreach($_settings as $field => $value)
|
||||
{
|
||||
$this->_setSetting($field, $value, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,12 +317,14 @@ class froxlorclient
|
||||
private function _readData()
|
||||
{
|
||||
if(isset($this->cid)
|
||||
&& $this->cid != - 1)
|
||||
{
|
||||
&& $this->cid != - 1
|
||||
) {
|
||||
$_client = $this->db->query_first('SELECT * FROM `' . TABLE_FROXLOR_CLIENTS . '` WHERE `id` = "' . $this->cid . '"');
|
||||
$this->Set('name', $_client['name'], true, true);
|
||||
$this->Set('ip', $_client['ip'], true, true);
|
||||
$this->Set('enabled', $_client['enabled'], true, true);
|
||||
|
||||
foreach($_client as $field => $value)
|
||||
{
|
||||
$this->Set($field, $value, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,9 +127,9 @@ class FroxlorSshTransport
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for plain password auth
|
||||
*
|
||||
*
|
||||
* @param string $ip ip toremote server
|
||||
* @param string $ip ip to remote server
|
||||
* @param string $port remote port
|
||||
* @param string $username ssh username
|
||||
* @param string $password ssh password
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
<?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 Panel
|
||||
* @version $Id$
|
||||
*
|
||||
* This file is for demonstration purpose and should NEVER be enabled
|
||||
* in a live enviroment.
|
||||
*
|
||||
* @version SVN: $Id: class.FroxlorModule.php 1167 2010-06-22 11:46:34Z d00p $
|
||||
*/
|
||||
exit();
|
||||
|
||||
@@ -43,4 +56,3 @@ $transport = FroxlorSshTransport::usePublicKey("test.froxlor.org", 22, "testUser
|
||||
* Clean up and finish.
|
||||
*/
|
||||
$transport->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user