- first commit for upcoming multiserver-support :)
This commit is contained in:
@@ -63,8 +63,18 @@ function getFormOverviewGroupOutput($groupname, $groupdetails)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($fielddetails['disabled']) && $fielddetails['disabled'] == true)
|
||||
{
|
||||
$d = true;
|
||||
$option.='<span class="strikethrough">';
|
||||
} else {
|
||||
$d = false;
|
||||
}
|
||||
$option.= $lng['admin']['activated'].': ';
|
||||
$option.= makeyesno($fieldname, '1', '0', $settings[$fielddetails['settinggroup']][$fielddetails['varname']]);
|
||||
$option.= makeyesno($fieldname, '1', '0', $settings[$fielddetails['settinggroup']][$fielddetails['varname']], $d);
|
||||
if($d) {
|
||||
$option.='</span>';
|
||||
}
|
||||
$activated = (int)$settings[$fielddetails['settinggroup']][$fielddetails['varname']];
|
||||
}
|
||||
}
|
||||
|
||||
38
lib/functions/froxlor/function.getServerId.php
Normal file
38
lib/functions/froxlor/function.getServerId.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 Functions
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* this function checks whether $server_id (multi-server) is set
|
||||
* in userdata.inc.php and returns the value. If not set or invalid,
|
||||
* always return the id of the master (which is '0')
|
||||
*
|
||||
* @return int server_id of current server
|
||||
* @since 0.9.14-svn7
|
||||
*/
|
||||
function getServerId() {
|
||||
|
||||
global $server_id;
|
||||
|
||||
if(isset($server_id)
|
||||
&& is_numeric($server_id)
|
||||
&& $server_id > 0
|
||||
) {
|
||||
return $server_id;
|
||||
}
|
||||
// return default (master)
|
||||
return 0;
|
||||
}
|
||||
@@ -24,12 +24,18 @@
|
||||
* @param string Parameter 1
|
||||
* @param string Parameter 2
|
||||
* @param string Parameter 3
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @param string Parameter 4
|
||||
*
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
*/
|
||||
|
||||
function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '')
|
||||
{
|
||||
global $db, $settings;
|
||||
|
||||
// check for $server_id, if it's not set default to "master"
|
||||
$server_id = getServerId();
|
||||
|
||||
if($type == '1'
|
||||
|| $type == '3'
|
||||
@@ -37,8 +43,7 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|
||||
|| $type == '5')
|
||||
{
|
||||
$db->query('DELETE FROM `' . TABLE_PANEL_TASKS . '` WHERE `type`="' . $type . '"');
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`) VALUES ("' . $type . '")');
|
||||
$doupdate = true;
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `sid`) VALUES ("' . $type . '", "'.$server_id.'")');
|
||||
}
|
||||
elseif($type == '2'
|
||||
&& $param1 != ''
|
||||
@@ -52,8 +57,7 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|
||||
$data['gid'] = $param3;
|
||||
$data['store_defaultindex'] = $param4;
|
||||
$data = serialize($data);
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("2", "' . $db->escape($data) . '")');
|
||||
$doupdate = true;
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`, `sid`) VALUES ("2", "' . $db->escape($data) . '", "'.$server_id.'")');
|
||||
}
|
||||
elseif($type == '6'
|
||||
&& $param1 != '')
|
||||
@@ -61,8 +65,7 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|
||||
$data = Array();
|
||||
$data['loginname'] = $param1;
|
||||
$data = serialize($data);
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("6", "' . $db->escape($data) . '")');
|
||||
$doupdate = true;
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`, `sid`) VALUES ("6", "' . $db->escape($data) . '", "'.$server_id.'")');
|
||||
}
|
||||
elseif($type == '7'
|
||||
&& $param1 != ''
|
||||
@@ -72,8 +75,7 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|
||||
$data['loginname'] = $param1;
|
||||
$data['email'] = $param2;
|
||||
$data = serialize($data);
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("7", "' . $db->escape($data) . '")');
|
||||
$doupdate = true;
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`, `sid`) VALUES ("7", "' . $db->escape($data) . '", "'.$server_id.'")');
|
||||
}
|
||||
elseif($type == '8'
|
||||
&& $param1 != ''
|
||||
@@ -83,50 +85,6 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|
||||
$data['loginname'] = $param1;
|
||||
$data['homedir'] = $param2;
|
||||
$data = serialize($data);
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("8", "' . $db->escape($data) . '")');
|
||||
$doupdate = true;
|
||||
}
|
||||
|
||||
if($doupdate === true
|
||||
&& (int)$settings['system']['realtime_port'] !== 0
|
||||
&& function_exists('socket_create'))
|
||||
{
|
||||
$timeout = 15;
|
||||
//$socket = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
|
||||
if($socket !== false)
|
||||
{
|
||||
// create the request packet
|
||||
$packet = chr(0) . chr(1) . 'RUN' . chr(0);
|
||||
// UDP is connectionless, so we just send on it.
|
||||
//@socket_sendto($socket, $packet, strlen($packet), 0x100, '127.0.0.1', (int)$settings['system']['realtime_port']);
|
||||
|
||||
/*
|
||||
* this is for TCP-Connections
|
||||
*/
|
||||
$time = time();
|
||||
|
||||
while(!@socket_connect($socket, '127.0.0.1', (int)$settings['system']['realtime_port']))
|
||||
{
|
||||
$err = socket_last_error($socket);
|
||||
|
||||
if($err == 115
|
||||
|| $err == 114)
|
||||
{
|
||||
if((time() - $time) >= $timeout)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* close socket
|
||||
*/
|
||||
@socket_close($socket);
|
||||
}
|
||||
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`, `sid`) VALUES ("8", "' . $db->escape($data) . '", "'.$server_id.'")');
|
||||
}
|
||||
}
|
||||
|
||||
69
lib/functions/froxlor/function.versionInUpdate.php
Normal file
69
lib/functions/froxlor/function.versionInUpdate.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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 Functions
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* check whether the current version is
|
||||
* lower than the given version
|
||||
*
|
||||
* @param string $current_version current installed version of froxlor
|
||||
* @param string $version_to_check version to check for update
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function versionInUpdate($current_version, $version_to_check)
|
||||
{
|
||||
if (!isFroxlor()) {
|
||||
return true;
|
||||
}
|
||||
$pos_a = strpos($current_version, '-svn');
|
||||
$pos_b = strpos($version_to_check, '-svn');
|
||||
// if we compare svn-versions, we have to add -svn0 to the version
|
||||
// to compare it correctly
|
||||
if($pos_a === false && $pos_b !== false)
|
||||
{
|
||||
$current_version.= '-svn9999';
|
||||
}
|
||||
|
||||
return version_compare($current_version, $version_to_check, '<');
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether the current version is
|
||||
* lower than the given version
|
||||
* - without checking if this is Froxlor
|
||||
* because we need this in our loadSettings
|
||||
* functions and isFroxlor() needs settings
|
||||
* already
|
||||
*
|
||||
* @param string $current_version current installed version of froxlor
|
||||
* @param string $version_to_check version to check for update
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function compareFroxlorVersion($current_version, $version_to_check)
|
||||
{
|
||||
$pos_a = strpos($current_version, '-svn');
|
||||
$pos_b = strpos($version_to_check, '-svn');
|
||||
// if we compare svn-versions, we have to add -svn0 to the version
|
||||
// to compare it correctly
|
||||
if($pos_a === false && $pos_b !== false)
|
||||
{
|
||||
$current_version.= '-svn9999';
|
||||
}
|
||||
|
||||
return version_compare($current_version, $version_to_check, '<');
|
||||
}
|
||||
@@ -24,12 +24,18 @@
|
||||
* @param string Value which will be returned if user chooses yes
|
||||
* @param string Value which will be returned if user chooses no
|
||||
* @param string Value which is chosen by default
|
||||
* @param bool Whether this element is disabled or not (default: false)
|
||||
* @return string HTML Code
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
*/
|
||||
|
||||
function makeyesno($name, $yesvalue, $novalue = '', $yesselected = '')
|
||||
function makeyesno($name, $yesvalue, $novalue = '', $yesselected = '', $disabled = false)
|
||||
{
|
||||
global $lng;
|
||||
return '<select class="dropdown_noborder" name="' . $name . '"><option value="' . $yesvalue . '"' . ($yesselected ? ' selected="selected"' : '') . '>' . $lng['panel']['yes'] . '</option><option value="' . $novalue . '"' . ($yesselected ? '' : ' selected="selected"') . '>' . $lng['panel']['no'] . '</option></select>';
|
||||
|
||||
if($disabled) {
|
||||
$d = ' disabled="disabled"';
|
||||
}
|
||||
return '<select class="dropdown_noborder" name="' . $name . '"'.$d.'><option value="' . $yesvalue . '"' . ($yesselected ? ' selected="selected"' : '') . '>' . $lng['panel']['yes'] . '</option><option value="' . $novalue . '"' . ($yesselected ? '' : ' selected="selected"') . '>' . $lng['panel']['no'] . '</option></select>';
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
|
||||
function loadSettings(&$settings_data, $db)
|
||||
{
|
||||
global $version;
|
||||
|
||||
// multi-server-support, get the destination server id (master = 0)
|
||||
$server_id = getServerId();
|
||||
|
||||
$settings = array();
|
||||
|
||||
if(is_array($settings_data) && isset($settings_data['groups']) && is_array($settings_data['groups']))
|
||||
@@ -31,11 +36,49 @@ function loadSettings(&$settings_data, $db)
|
||||
{
|
||||
if(isset($field_details['settinggroup']) && isset($field_details['varname']) && isset($field_details['default']))
|
||||
{
|
||||
$row = $db->query_first('SELECT `settinggroup`, `varname`, `value` FROM `' . TABLE_PANEL_SETTINGS . '` WHERE `settinggroup` = \'' . $db->escape($field_details['settinggroup']) . '\' AND `varname` = \'' . $db->escape($field_details['varname']) . '\' ');
|
||||
$sql_query = 'SELECT
|
||||
`settinggroup`, `varname`, `value`
|
||||
FROM
|
||||
`' . TABLE_PANEL_SETTINGS . '`
|
||||
WHERE
|
||||
`settinggroup` = \'' . $db->escape($field_details['settinggroup']) . '\'
|
||||
AND
|
||||
`varname` = \'' . $db->escape($field_details['varname']) . '\' ';
|
||||
|
||||
// since 0.9.14-svn7 we have $server_id for multi-server-support
|
||||
// but versions before 0.9.14-svn7 don't have the `sid` field
|
||||
// in panel_settings, so only append the condition if we're on
|
||||
// 0.9.14-svn7 or higher
|
||||
if(compareFroxlorVersion('0.9.14-svn7', $version))
|
||||
{
|
||||
$sql_query_sid = 'AND `sid` = \''. (int)$server_id . '\' ';
|
||||
} else {
|
||||
$sql_query_sid = '';
|
||||
}
|
||||
|
||||
$row = $db->query_first($sql_query.$sql_query_sid);
|
||||
if(!empty($row))
|
||||
{
|
||||
$varvalue = $row['value'];
|
||||
}
|
||||
elseif($server_id > 0)
|
||||
{
|
||||
// if we're a client (server_id > 0)
|
||||
// and a setting is not found or not
|
||||
// needed for clients, we get it from
|
||||
// the master (server_id = 0)
|
||||
$sql_query_sid = 'AND `sid` = \'0\' ';
|
||||
$row = $db->query_first($sql_query.$sql_query_sid);
|
||||
if(!empty($row))
|
||||
{
|
||||
$varvalue = $row['value'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// default to array-default-value
|
||||
$varvalue = $field_details['default'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$varvalue = $field_details['default'];
|
||||
|
||||
@@ -20,8 +20,19 @@
|
||||
function saveSetting($settinggroup, $varname, $newvalue)
|
||||
{
|
||||
global $db;
|
||||
$query = 'UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = \'' . $db->escape($newvalue) . '\' WHERE `settinggroup` = \'' . $db->escape($settinggroup) . '\' AND `varname`=\'' . $db->escape($varname) . '\'';
|
||||
|
||||
// multi-server-support, get the destination server id (master = 0)
|
||||
$server_id = getServerId();
|
||||
|
||||
$query = 'UPDATE
|
||||
`' . TABLE_PANEL_SETTINGS . '`
|
||||
SET
|
||||
`value` = \'' . $db->escape($newvalue) . '\'
|
||||
WHERE
|
||||
`settinggroup` = \'' . $db->escape($settinggroup) . '\'
|
||||
AND
|
||||
`varname`=\'' . $db->escape($varname) . '\'
|
||||
AND
|
||||
`sid`=\''. (int)$server_id . '\' ';
|
||||
return $db->query($query);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user