- first commit for upcoming multiserver-support :)
This commit is contained in:
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, '<');
|
||||
}
|
||||
Reference in New Issue
Block a user