enhanced pdo database class; migrated admin_logger and admin_traffic
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
define('AREA', 'admin');
|
define('AREA', 'admin');
|
||||||
|
|
||||||
/**
|
|
||||||
* Include our init.php, which manages Sessions, Language etc.
|
|
||||||
*/
|
|
||||||
require('./lib/init.php');
|
require('./lib/init.php');
|
||||||
|
|
||||||
if ($page == 'log'
|
if ($page == 'log'
|
||||||
@@ -37,21 +34,23 @@ if ($page == 'log'
|
|||||||
$paging = new paging($userinfo, $db, TABLE_PANEL_LOG, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']);
|
$paging = new paging($userinfo, $db, TABLE_PANEL_LOG, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']);
|
||||||
$paging->sortfield = 'date';
|
$paging->sortfield = 'date';
|
||||||
$paging->sortorder = 'desc';
|
$paging->sortorder = 'desc';
|
||||||
$result = $db->query('SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit());
|
$result_stmt = Database::query('
|
||||||
$paging->setEntries($db->num_rows($result));
|
SELECT * FROM `' . TABLE_PANEL_LOG . '` ' . $paging->getSqlWhere(false) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit()
|
||||||
|
);
|
||||||
|
$paging->setEntries(Database::num_rows());
|
||||||
$sortcode = $paging->getHtmlSortCode($lng);
|
$sortcode = $paging->getHtmlSortCode($lng);
|
||||||
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
|
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
|
||||||
$searchcode = $paging->getHtmlSearchCode($lng);
|
$searchcode = $paging->getHtmlSearchCode($lng);
|
||||||
$pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s);
|
$pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s);
|
||||||
$clog = array();
|
$clog = array();
|
||||||
|
|
||||||
while ($row = $db->fetch_array($result)) {
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
|
||||||
if (!isset($clog[$row['action']])
|
if (!isset($clog[$row['action']])
|
||||||
|| !is_array($clog[$row['action']])
|
|| !is_array($clog[$row['action']])
|
||||||
) {
|
) {
|
||||||
$clog[$row['action']] = array();
|
$clog[$row['action']] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$clog[$row['action']][$row['logid']] = $row;
|
$clog[$row['action']][$row['logid']] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,17 +134,19 @@ if ($page == 'log'
|
|||||||
}
|
}
|
||||||
|
|
||||||
eval("echo \"" . getTemplate('logger/logger') . "\";");
|
eval("echo \"" . getTemplate('logger/logger') . "\";");
|
||||||
|
|
||||||
} elseif ($action == 'truncate') {
|
} elseif ($action == 'truncate') {
|
||||||
|
|
||||||
if (isset($_POST['send'])
|
if (isset($_POST['send'])
|
||||||
&& $_POST['send'] == 'send'
|
&& $_POST['send'] == 'send'
|
||||||
) {
|
) {
|
||||||
$yesterday = time() - (60 * 10);
|
$truncatedate = time() - (60 * 10);
|
||||||
|
$trunc_stmt = Database::prepare("
|
||||||
/* (60*60*24); */
|
DELETE FROM `" . TABLE_PANEL_LOG . "` WHERE `date` < :trunc"
|
||||||
|
);
|
||||||
$db->query("DELETE FROM `" . TABLE_PANEL_LOG . "` WHERE `date` < '" . $yesterday . "'");
|
Database::pexecute($trunc_stmt, array('trunc' => $truncatedate));
|
||||||
$log->logAction(ADM_ACTION, LOG_WARNING, 'truncated the system-log (mysql)');
|
$log->logAction(ADM_ACTION, LOG_WARNING, 'truncated the system-log (mysql)');
|
||||||
redirectTo($filename, Array('page' => $page, 's' => $s));
|
redirectTo($filename, array('page' => $page, 's' => $s));
|
||||||
} else {
|
} else {
|
||||||
ask_yesno('logger_reallytruncate', $filename, array('page' => $page, 'action' => $action), TABLE_PANEL_LOG);
|
ask_yesno('logger_reallytruncate', $filename, array('page' => $page, 'action' => $action), TABLE_PANEL_LOG);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,25 +18,22 @@
|
|||||||
|
|
||||||
define('AREA', 'admin');
|
define('AREA', 'admin');
|
||||||
|
|
||||||
/**
|
|
||||||
* Include our init.php, which manages Sessions, Language etc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
require ("./lib/init.php");
|
require ("./lib/init.php");
|
||||||
|
|
||||||
if($action == 'logout')
|
if ($action == 'logout') {
|
||||||
{
|
$logout_stmt = Database::prepare("
|
||||||
$db->query("DELETE FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `userid` = '" . (int)$userinfo['adminid'] . "' AND `adminsession` = '1'");
|
DELETE FROM `" . TABLE_PANEL_SESSIONS . "`
|
||||||
|
WHERE `userid` = :adminid
|
||||||
|
AND `adminsession` = '1'"
|
||||||
|
);
|
||||||
|
Database::pexecute($logout_stmt, array('adminid' => $userinfo['adminid']));
|
||||||
redirectTo('index.php');
|
redirectTo('index.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_POST['id']))
|
if (isset($_POST['id'])) {
|
||||||
{
|
|
||||||
$id = intval($_POST['id']);
|
$id = intval($_POST['id']);
|
||||||
}
|
} elseif(isset($_GET['id'])) {
|
||||||
elseif(isset($_GET['id']))
|
|
||||||
{
|
|
||||||
$id = intval($_GET['id']);
|
$id = intval($_GET['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,44 +53,69 @@ $months = array(
|
|||||||
'12' => 'dec',
|
'12' => 'dec',
|
||||||
);
|
);
|
||||||
|
|
||||||
if($page == 'overview' || $page == 'customers')
|
if ($page == 'overview' || $page == 'customers') {
|
||||||
{
|
|
||||||
if($action == 'su' && $id != 0)
|
|
||||||
{
|
|
||||||
$result = $db->query_first("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid`='" . (int)$id . "' " . ($userinfo['customers_see_all'] ? '' : " AND `adminid` = '" . (int)$userinfo['adminid'] . "' "));
|
|
||||||
|
|
||||||
if($result['loginname'] != '')
|
if ($action == 'su' && $id != 0) {
|
||||||
{
|
|
||||||
$result = $db->query_first("SELECT * FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `userid`='" . (int)$userinfo['userid'] . "'");
|
$result_stmt = Database::prepare("
|
||||||
|
SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
||||||
|
WHERE `customerid` = :id" .
|
||||||
|
($userinfo['customers_see_all'] ? '' : " AND `adminid` = :adminid")
|
||||||
|
);
|
||||||
|
Database::pexecute($result_stmt, array('id' => $id, 'adminid' => $userinfo['adminid']));
|
||||||
|
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($result['loginname'] != '') {
|
||||||
|
$result2_stmt = Database::prepare("
|
||||||
|
SELECT * FROM `" . TABLE_PANEL_SESSIONS . "`
|
||||||
|
WHERE `userid` = :id"
|
||||||
|
);
|
||||||
|
Database::pexecute($result2_stmt, array('id' => $userinfo['userid']));
|
||||||
|
$result2 = $result2_stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$s = md5(uniqid(microtime(), 1));
|
$s = md5(uniqid(microtime(), 1));
|
||||||
$db->query("INSERT INTO `" . TABLE_PANEL_SESSIONS . "` (`hash`, `userid`, `ipaddress`, `useragent`, `lastactivity`, `language`, `adminsession`) VALUES ('" . $db->escape($s) . "', '" . (int)$id . "', '" . $db->escape($result['ipaddress']) . "', '" . $db->escape($result['useragent']) . "', '" . time() . "', '" . $db->escape($result['language']) . "', '0')");
|
$ins_stmt = Database::prepare("
|
||||||
redirectTo('customer_traffic.php', Array(
|
INSERT INTO `" . TABLE_PANEL_SESSIONS . "` SET
|
||||||
's' => $s
|
`hash` = :hash,
|
||||||
));
|
`userid` = :id,
|
||||||
}
|
`ipaddress` = :ip,
|
||||||
else
|
`useragent` = :ua,
|
||||||
{
|
`lastactivity` = :la,
|
||||||
redirectTo('index.php', Array(
|
`language` = :lang,
|
||||||
'action' => 'login'
|
`adminsession` = '0'
|
||||||
));
|
");
|
||||||
|
$ins_data = array(
|
||||||
|
'hash' => $s,
|
||||||
|
'id' => $id,
|
||||||
|
'ip' => $result['ipaddress'],
|
||||||
|
'ua' => $result['useragent'],
|
||||||
|
'la' => time(),
|
||||||
|
'lang' => $result['language']
|
||||||
|
);
|
||||||
|
Database::pexecute($ins_stmt, $ins_data);
|
||||||
|
|
||||||
|
redirectTo('customer_traffic.php', array('s' => $s));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
redirectTo('index.php', array('action' => 'login'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$customerview = 1;
|
$customerview = 1;
|
||||||
$stats_tables = '';
|
$stats_tables = '';
|
||||||
$minyear = $db->query_first("SELECT `year` FROM `". TABLE_PANEL_TRAFFIC . "` ORDER BY `year` ASC LIMIT 1");
|
$minyear_stmt = Database::query("SELECT `year` FROM `". TABLE_PANEL_TRAFFIC . "` ORDER BY `year` ASC LIMIT 1");
|
||||||
if (!isset($minyear['year']) || $minyear['year'] == 0)
|
$minyear = $minyear_stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
{
|
|
||||||
|
if (!isset($minyear['year']) || $minyear['year'] == 0) {
|
||||||
$maxyears = 0;
|
$maxyears = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$maxyears = date("Y") - $minyear['year'];
|
$maxyears = date("Y") - $minyear['year'];
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($years = 0; $years<=$maxyears; $years++) {
|
for ($years = 0; $years<=$maxyears; $years++) {
|
||||||
|
|
||||||
$overview['year'] = date("Y")-$years;
|
$overview['year'] = date("Y")-$years;
|
||||||
$overview['type'] = $lng['traffic']['customer'];
|
$overview['type'] = $lng['traffic']['customer'];
|
||||||
$domain_list = '';
|
$domain_list = '';
|
||||||
$customer_name_list = $db->query("SELECT `customerid`,`company`,`name`,`firstname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `deactivated`='0'" . ($userinfo['customers_see_all'] ? '' : " AND `adminid` = '" . (int)$userinfo['adminid'] . "' ") . " ORDER BY name");
|
|
||||||
$totals = array(
|
$totals = array(
|
||||||
'jan' => 0,
|
'jan' => 0,
|
||||||
'feb' => 0,
|
'feb' => 0,
|
||||||
@@ -108,7 +130,18 @@ if($page == 'overview' || $page == 'customers')
|
|||||||
'nov' => 0,
|
'nov' => 0,
|
||||||
'dec' => 0,
|
'dec' => 0,
|
||||||
);
|
);
|
||||||
while($customer_name = $db->fetch_array($customer_name_list)) {
|
|
||||||
|
$customer_name_list_stmt = Database::prepare("
|
||||||
|
SELECT `customerid`,`company`,`name`,`firstname`
|
||||||
|
FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
||||||
|
WHERE `deactivated`='0'" .
|
||||||
|
($userinfo['customers_see_all'] ? '' : " AND `adminid` = :id") . "
|
||||||
|
ORDER BY name"
|
||||||
|
);
|
||||||
|
Database::pexecute($customer_name_list_stmt, array('id' => $userinfo['adminid']));
|
||||||
|
|
||||||
|
while($customer_name = $customer_name_list_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
|
||||||
$virtual_host = array(
|
$virtual_host = array(
|
||||||
'name' => ($customer_name['company'] == '' ? $customer_name['name'] . ", " . $customer_name['firstname'] : $customer_name['company']),
|
'name' => ($customer_name['company'] == '' ? $customer_name['name'] . ", " . $customer_name['firstname'] : $customer_name['company']),
|
||||||
'customerid' => $customer_name['customerid'],
|
'customerid' => $customer_name['customerid'],
|
||||||
@@ -126,8 +159,15 @@ if($page == 'overview' || $page == 'customers')
|
|||||||
'dec' => '-',
|
'dec' => '-',
|
||||||
);
|
);
|
||||||
|
|
||||||
$traffic_list = $db->query("SELECT month, SUM(http+ftp_up+ftp_down+mail)*1024 AS traffic FROM `" . TABLE_PANEL_TRAFFIC . "` WHERE year = " . (date("Y")-$years) . " AND `customerid` = '" . $customer_name['customerid'] . "' GROUP BY month ORDER BY month");
|
$traffic_list_stmt = Database::prepare("
|
||||||
while($traffic_month = $db->fetch_array($traffic_list)) {
|
SELECT month, SUM(http+ftp_up+ftp_down+mail)*1024 AS traffic
|
||||||
|
FROM `" . TABLE_PANEL_TRAFFIC . "`
|
||||||
|
WHERE year = :year AND `customerid` = :id
|
||||||
|
GROUP BY month ORDER BY month"
|
||||||
|
);
|
||||||
|
Database::pexecute($traffic_list_stmt, array('year' => (date("Y")-$years), 'id' => $customer_name['customerid']));
|
||||||
|
|
||||||
|
while ($traffic_month = $traffic_list_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$virtual_host[$months[(int)$traffic_month['month']]] = size_readable($traffic_month['traffic'], 'GiB', 'bi', '%01.'.(int)$settings['panel']['decimal_places'].'f %s');
|
$virtual_host[$months[(int)$traffic_month['month']]] = size_readable($traffic_month['traffic'], 'GiB', 'bi', '%01.'.(int)$settings['panel']['decimal_places'].'f %s');
|
||||||
$totals[$months[(int)$traffic_month['month']]] += $traffic_month['traffic'];
|
$totals[$months[(int)$traffic_month['month']]] += $traffic_month['traffic'];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class Database {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function __callStatic($name, $args) {
|
public static function __callStatic($name, $args) {
|
||||||
$callback = array(self::getDB(self::$_needroot), $name);
|
$callback = array(self::getDB(), $name);
|
||||||
$result = null;
|
$result = null;
|
||||||
try {
|
try {
|
||||||
$result = call_user_func_array($callback, $args );
|
$result = call_user_func_array($callback, $args );
|
||||||
@@ -127,7 +127,7 @@ class Database {
|
|||||||
*
|
*
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
private static function getDB($root = false) {
|
private static function getDB() {
|
||||||
|
|
||||||
if (!extension_loaded('pdo') || in_array("mysql", PDO::getAvailableDrivers()) == false) {
|
if (!extension_loaded('pdo') || in_array("mysql", PDO::getAvailableDrivers()) == false) {
|
||||||
self::_showerror(new Exception("The php PDO extension or PDO-MySQL driver is not available"));
|
self::_showerror(new Exception("The php PDO extension or PDO-MySQL driver is not available"));
|
||||||
@@ -143,7 +143,7 @@ class Database {
|
|||||||
require FROXLOR_INSTALL_DIR."/lib/userdata.inc.php";
|
require FROXLOR_INSTALL_DIR."/lib/userdata.inc.php";
|
||||||
|
|
||||||
// le format
|
// le format
|
||||||
if ($root = true
|
if (self::$_needroot == true
|
||||||
&& isset($sql['root_user'])
|
&& isset($sql['root_user'])
|
||||||
&& isset($sql['root_password'])
|
&& isset($sql['root_password'])
|
||||||
&& (!isset($sql_root) || !is_array($sql_root))
|
&& (!isset($sql_root) || !is_array($sql_root))
|
||||||
@@ -154,7 +154,7 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// either root or unprivileged user
|
// either root or unprivileged user
|
||||||
if ($root) {
|
if (self::$_needroot) {
|
||||||
$user = $sql_root[self::$_dbserver]['user'];
|
$user = $sql_root[self::$_dbserver]['user'];
|
||||||
$password = $sql_root[self::$_dbserver]['password'];
|
$password = $sql_root[self::$_dbserver]['password'];
|
||||||
$host = $sql_root[self::$_dbserver]['host'];
|
$host = $sql_root[self::$_dbserver]['host'];
|
||||||
|
|||||||
Reference in New Issue
Block a user