remove some unused functions and migrated some more functions to PDO database class, refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-14 08:27:57 +01:00
parent 868b472b98
commit 12800b730d
23 changed files with 326 additions and 500 deletions

View File

@@ -1,49 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* 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 Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function getAdmins($limit_resource = '') {
global $db, $theme;
$additional_conditions = '';
$additional_conditions_array = array();
if(getSessionUserDetail('customers_see_all') != true)
{
$additional_conditions_array[] = '`adminid` = \'' . (int)getSessionUserDetail('adminid') . '\'';
}
if($limit_resource != '')
{
$additional_conditions_array[] = '(`' . $limit_resource . '_used` < `' . $limit_resource . '` OR `' . $limit_resource . '` = \'-1\')';
}
if(!empty($additional_conditions_array))
{
$additional_conditions = ' WHERE ' . implode(' AND ', $additional_conditions_array) . ' ';
}
$query = 'SELECT `adminid`, `loginname`, `name`, `firstname`, `company` FROM `' . TABLE_PANEL_ADMINS . '` ' . $additional_conditions . ' ORDER BY `name` ASC';
$result = $db->query($query);
$admins_array = array();
while($row = $db->fetch_array($result))
{
$admins_array[$row['adminid']] = getCorrectFullUserDetails($row) . ' (' . $row['loginname'] . ')';
}
return $admins_array;
}

View File

@@ -17,19 +17,16 @@
*
*/
function getCustomerDetail($customerid, $varname)
{
global $db, $theme;
function getCustomerDetail($customerid, $varname) {
$query = 'SELECT `' . $db->escape($varname) . '` FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `customerid` = \'' . (int)$customerid . '\'';
$customer = $db->query_first($query);
$customer_stmt = Database::prepare("
SELECT `' . $varname . '` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :customerid
");
$customer = Database::pexecute_first($customer_stmt, array('customerid' => $customerid));
if(isset($customer[$varname]))
{
if (isset($customer[$varname])) {
return $customer[$varname];
}
else
{
} else {
return false;
}
}

View File

@@ -1,21 +0,0 @@
<?php
/**
* returns the customer-id of a customer by given domain
*
* @param string $domain users domain
*
* @return int customers id
*/
function getCustomerIdByDomain($domain = null)
{
global $db, $theme;
$result = $db->query_first("SELECT `customerid` FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `domain` = '".$domain."'");
if(is_array($result)
&& isset($result['customerid'])
) {
return $result['customerid'];
}
return false;
}

View File

@@ -1,49 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* 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 Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function getCustomers($limit_resource = '')
{
global $db, $theme;
$additional_conditions = '';
$additional_conditions_array = array();
if(getSessionUserDetail('customers_see_all') != true)
{
$additional_conditions_array[] = '`adminid` = \'' . (int)getSessionUserDetail('adminid') . '\'';
}
if($limit_resource != '')
{
$additional_conditions_array[] = '(`' . $limit_resource . '_used` < `' . $limit_resource . '` OR `' . $limit_resource . '` = \'-1\')';
}
if(!empty($additional_conditions_array))
{
$additional_conditions = ' WHERE ' . implode(' AND ', $additional_conditions_array) . ' ';
}
$query = 'SELECT `customerid`, `loginname`, `name`, `firstname`, `company` FROM `' . TABLE_PANEL_CUSTOMERS . '` ' . $additional_conditions . ' ORDER BY `name` ASC';
$result = $db->query($query);
$customers_array = array();
while($row = $db->fetch_array($result))
{
$customers_array[$row['customerid']] = getCorrectFullUserDetails($row) . ' (' . $row['loginname'] . ')';
}
return $customers_array;
}

View File

@@ -17,24 +17,22 @@
*
*/
function getIpAddresses()
{
global $db, $theme;
$query = 'SELECT `id`, `ip`, `port` FROM `' . TABLE_PANEL_IPSANDPORTS . '` ORDER BY `ip` ASC, `port` ASC';
$result = $db->query($query);
function getIpAddresses() {
$result_stmt = Database::query("
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC
");
$system_ipaddress_array = array();
while($row = $db->fetch_array($result))
{
if(!isset($system_ipaddress_array[$row['ip']])
&& !in_array($row['ip'], $system_ipaddress_array))
{
if(filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (!isset($system_ipaddress_array[$row['ip']])
&& !in_array($row['ip'], $system_ipaddress_array)
) {
if (filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$row['ip'] = '[' . $row['ip'] . ']';
}
$system_ipaddress_array[$row['ip']] = $row['ip'];
}
}

View File

@@ -17,40 +17,48 @@
*
*/
function getIpPortCombinations($ssl = false)
{
global $db, $theme;
$additional_conditions = '';
function getIpPortCombinations($ssl = false) {
global $userinfo;
$additional_conditions_params = array();
$additional_conditions_array = array();
if(getSessionUserDetail('ip') != '-1')
{
$admin_ip = $db->query_first('SELECT `id`, `ip`, `port` FROM `' . TABLE_PANEL_IPSANDPORTS . '` WHERE `id` = \'' . (int)getSessionUserDetail('ip') . '\' ORDER BY `ip`, `port` ASC');
$additional_conditions_array[] = '`ip` = \'' . $admin_ip['ip'] . '\'';
unset($admin_ip);
}
if($ssl !== null)
{
$additional_conditions_array[] = '`ssl` = \'' . ( $ssl === true ? '1' : '0' ) . '\'';
}
if(!empty($additional_conditions_array))
{
$additional_conditions = ' WHERE ' . implode(' AND ', $additional_conditions_array) . ' ';
if ($userinfo['ip'] != '-1') {
$admin_ip_stmt = Database::prepare("
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = :ipid
");
$admin_ip = Database::pexecute_first($admin_ip_stmt, array('ipid' => $userinfo['ip']));
$additional_conditions_array[] = "`ip` = :adminip";
$additional_conditions_params['adminip'] = $admin_ip['ip'];
$admin_ip = null;
}
$query = 'SELECT `id`, `ip`, `port` FROM `' . TABLE_PANEL_IPSANDPORTS . '` ' . $additional_conditions . ' ORDER BY `ip` ASC, `port` ASC';
$result = $db->query($query);
if ($ssl !== null) {
$additional_conditions_array[] = "`ssl` = :ssl";
$additional_conditions_params['ssl'] = ($ssl === true ? '1' : '0' );
}
$additional_conditions = '';
if (count($additional_conditions_array) > 0) {
$additional_conditions = " WHERE " . implode(" AND ", $additional_conditions_array) . " ";
}
$result_stmt = Database::prepare("
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` " .
$additional_conditions . " ORDER BY `ip` ASC, `port` ASC
");
Database::pexecute($result_stmt, $additional_conditions_params);
$system_ipaddress_array = array();
while($row = $db->fetch_array($result))
{
if(filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
$row['ip'] = '[' . $row['ip'] . ']';
while($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$row['ip'] = '[' . $row['ip'] . ']';
}
$system_ipaddress_array[$row['id']] = $row['ip'] . ':' . $row['port'];
}
return $system_ipaddress_array;
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* 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 Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function getLanguages()
{
global $db, $theme;
$query = 'SELECT * FROM `' . TABLE_PANEL_LANGUAGE . '` ';
$result = $db->query($query);
$languages_array = array();
while($row = $db->fetch_array($result))
{
if(!isset($languages_array[$row['language']])
&& !in_array($row['language'], $languages_array))
{
$languages_array[$row['language']] = html_entity_decode($row['language']);
}
}
return $languages_array;
}

View File

@@ -7,12 +7,14 @@
*
* @return string customers loginname
*/
function getLoginNameByUid($uid = null)
{
global $db, $theme;
$result = $db->query_first("SELECT `loginname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `guid` = '".(int)$uid."'");
if(is_array($result)
function getLoginNameByUid($uid = null) {
$result_stmt = Database::prepare("
SELECT `loginname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `guid` = :guid
");
$result = Database::pexecute_first($result_stmt, array('guid' => $uid));
if (is_array($result)
&& isset($result['loginname'])
) {
return $result['loginname'];

View File

@@ -20,26 +20,20 @@
*
* @return array
*/
function getPhpConfigs()
{
global $db, $theme;
$query = 'SELECT * FROM `' . TABLE_PANEL_PHPCONFIGS . '` ';
$result = $db->query($query, false, true);
function getPhpConfigs() {
$result_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "`");
$result = Database::pexecute_first($result_stmt, null, false);
$configs_array = array();
// if the table does not yet exist, we just use the default php.ini
if(!$result)
{
if ($result == false) {
$configs_array[1] = 'Default php.ini';
}
else
{
while($row = $db->fetch_array($result))
{
if(!isset($configs_array[$row['id']])
&& !in_array($row['id'], $configs_array))
{
} else {
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (!isset($configs_array[$row['id']])
&& !in_array($row['id'], $configs_array)
) {
$configs_array[$row['id']] = html_entity_decode($row['description']);
}
}

View File

@@ -1,38 +0,0 @@
<?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
*
*/
/**
* 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, $theme;
if(isset($server_id)
&& is_numeric($server_id)
&& $server_id > 0
) {
return $server_id;
}
// return default (master)
return 0;
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* 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 Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function getSessionUserDetail($varname)
{
global $userinfo, $theme;
if(isset($userinfo[$varname]))
{
return $userinfo[$varname];
}
else
{
return false;
}
}

View File

@@ -27,16 +27,16 @@
* @author Florian Lippert <flo@syscp.org>
*/
function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '')
{
global $db, $settings, $theme;
function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '') {
if($type == '1'
|| $type == '3'
|| $type == '4'
|| $type == '5'
|| $type == '10')
{
global $settings;
if ($type == '1'
|| $type == '3'
|| $type == '4'
|| $type == '5'
|| $type == '10'
) {
// 4 = bind -> if bind disabled -> no task
if ($type == '4' && $settings['system']['bind_enable'] == '0') {
return;
@@ -44,50 +44,69 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
// 10 = quota -> if quota disabled -> no task
if ($type == '10' && $settings['system']['diskquota_enabled'] == '0') {
return;
}
$db->query('DELETE FROM `' . TABLE_PANEL_TASKS . '` WHERE `type`="' . $type . '"');
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`) VALUES ("' . $type . '")');
}
elseif($type == '2'
&& $param1 != ''
&& $param2 != ''
&& $param3 != ''
&& ($param4 == 0 || $param4 == 1)
}
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = :type
");
Database::pexecute($del_stmt, array('type' => $type));
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TASKS . "` SET `type` = :type
");
Database::pexecute($ins_stmt, array('type' => $type));
} elseif ($type == '2'
&& $param1 != ''
&& $param2 != ''
&& $param3 != ''
&& ($param4 == 0 || $param4 == 1)
) {
$data = Array();
$data = array();
$data['loginname'] = $param1;
$data['uid'] = $param2;
$data['gid'] = $param3;
$data['store_defaultindex'] = $param4;
$data = serialize($data);
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("2", "' . $db->escape($data) . '")');
}
elseif($type == '6'
&& $param1 != '')
{
$data = Array();
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TASKS . "` SET `type` = '2', `data` = :data
");
Database::pexecute($ins_stmt, array('data' => $data));
} elseif ($type == '6'
&& $param1 != ''
) {
$data = array();
$data['loginname'] = $param1;
$data = serialize($data);
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("6", "' . $db->escape($data) . '")');
}
elseif($type == '7'
&& $param1 != ''
&& $param2 != '')
{
$data = Array();
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TASKS . "` SET `type` = '6', `data` = :data
");
Database::pexecute($ins_stmt, array('data' => $data));
} elseif ($type == '7'
&& $param1 != ''
&& $param2 != ''
) {
$data = array();
$data['loginname'] = $param1;
$data['email'] = $param2;
$data = serialize($data);
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("7", "' . $db->escape($data) . '")');
}
elseif($type == '8'
&& $param1 != ''
&& $param2 != '')
{
$data = Array();
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TASKS . "` SET `type` = '7', `data` = :data
");
Database::pexecute($ins_stmt, array('data' => $data));
} elseif ($type == '8'
&& $param1 != ''
&& $param2 != ''
) {
$data = array();
$data['loginname'] = $param1;
$data['homedir'] = $param2;
$data = serialize($data);
$db->query('INSERT INTO `' . TABLE_PANEL_TASKS . '` (`type`, `data`) VALUES ("8", "' . $db->escape($data) . '")');
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TASKS . "` SET `type` = '8', `data` = :data
");
Database::pexecute($ins_stmt, array('data' => $data));
}
}

View File

@@ -15,23 +15,24 @@
*
*/
/*
* returns true or false whether a
* given domain id is the std-subdomain
* of a customer
/**
* returns true or false whether a given domain id
* is the std-subdomain of a customer
*
* @param int domain-id
* @param int domain-id
*
* @return boolean
* @return boolean
*/
function isCustomerStdSubdomain($did = 0)
{
global $db, $theme;
function isCustomerStdSubdomain($did = 0) {
if($did > 0)
{
$result = $db->query_first("SELECT `customerid` FROM `".TABLE_PANEL_CUSTOMERS."` WHERE `standardsubdomain` = '".(int)$did."'");
if(is_array($result)
if ($did > 0) {
$result_stmt = Database::prepare("
SELECT `customerid` FROM `".TABLE_PANEL_CUSTOMERS."`
WHERE `standardsubdomain` = :did
");
$result = Database::pexecute($result_stmt, array('did' => $did));
if (is_array($result)
&& isset($result['customerid'])
&& $result['customerid'] > 0
) {