Skip to content

Commit b1b26f0

Browse files
committed
merging differences between 'server' and 'interface'
1 parent c0069d7 commit b1b26f0

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

server/lib/classes/db_mysql.inc.php

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php
2+
/*
3+
* db_mysql.inc.php: ISPConfig mysql db interface
4+
*
5+
* Note! When making changes to this file, put a copy in both locations:
6+
* interface/lib/classes/db_mysql.inc.php
7+
* server/lib/classes/db_mysql.inc.php
8+
*/
9+
210
/*
311
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
412
All rights reserved.
@@ -140,6 +148,7 @@ public function _build_query_string($sQuery = '') {
140148
if($iPos2 !== false && ($iPos === false || $iPos2 <= $iPos)) {
141149
$sTxt = $this->escape($sValue);
142150

151+
$sTxt = str_replace('`', '', $sTxt);
143152
if(strpos($sTxt, '.') !== false) {
144153
$sTxt = preg_replace('/^(.+)\.(.+)$/', '`$1`.`$2`', $sTxt);
145154
$sTxt = str_replace('.`*`', '.*', $sTxt);
@@ -180,11 +189,11 @@ public function _build_query_string($sQuery = '') {
180189

181190

182191
/**#@+
183-
* @access private
184-
*/
192+
* @access private
193+
*/
185194
private function _setCharset() {
186-
mysqli_query($this->_iConnId, 'SET NAMES '.$this->dbCharset);
187-
mysqli_query($this->_iConnId, "SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'");
195+
$this->query('SET NAMES '.$this->dbCharset);
196+
$this->query("SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'");
188197
}
189198

190199
private function securityScan($string) {
@@ -693,6 +702,10 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
693702
public function datalogInsert($tablename, $insert_data, $index_field) {
694703
global $app;
695704

705+
// Check fields
706+
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
707+
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
708+
696709
if(is_array($insert_data)) {
697710
$key_str = '';
698711
$val_str = '';
@@ -728,6 +741,10 @@ public function datalogInsert($tablename, $insert_data, $index_field) {
728741
public function datalogUpdate($tablename, $update_data, $index_field, $index_value, $force_update = false) {
729742
global $app;
730743

744+
// Check fields
745+
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
746+
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
747+
731748
$old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
732749

733750
if(is_array($update_data)) {
@@ -759,6 +776,10 @@ public function datalogUpdate($tablename, $update_data, $index_field, $index_val
759776
public function datalogDelete($tablename, $index_field, $index_value) {
760777
global $app;
761778

779+
// Check fields
780+
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
781+
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
782+
762783
$old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
763784
$this->query("DELETE FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
764785
$new_rec = array();
@@ -776,6 +797,26 @@ public function datalogError($errormsg) {
776797
return true;
777798
}
778799

800+
//* get the current datalog status for the specified login (or currently logged in user)
801+
public function datalogStatus($login = '') {
802+
global $app;
803+
804+
$return = array('count' => 0, 'entries' => array());
805+
806+
if($login == '' && isset($_SESSION['s']['user'])) {
807+
$login = $_SESSION['s']['user']['username'];
808+
}
809+
810+
$result = $this->queryAllRecords("SELECT COUNT( * ) AS cnt, sys_datalog.action, sys_datalog.dbtable FROM sys_datalog, server WHERE server.server_id = sys_datalog.server_id AND sys_datalog.user = ? AND sys_datalog.datalog_id > server.updated GROUP BY sys_datalog.dbtable, sys_datalog.action", $login);
811+
foreach($result as $row) {
812+
if(!$row['dbtable'] || in_array($row['dbtable'], array('aps_instances', 'aps_instances_settings', 'mail_access', 'mail_content_filter'))) continue; // ignore some entries, maybe more to come
813+
$return['entries'][] = array('table' => $row['dbtable'], 'action' => $row['action'], 'count' => $row['cnt'], 'text' => $app->lng('datalog_status_' . $row['action'] . '_' . $row['dbtable'])); $return['count'] += $row['cnt'];
814+
}
815+
unset($result);
816+
817+
return $return;
818+
}
819+
779820

780821
public function freeResult($query)
781822
{
@@ -906,10 +947,10 @@ public function getTables($database_name = '') {
906947

907948
function tableInfo($table_name) {
908949

909-
global $go_api, $go_info;
950+
global $go_api, $go_info, $app;
910951
// Tabellenfelder einlesen
911952

912-
if($rows = $go_api->db->queryAllRecords('SHOW FIELDS FROM ??', $table_name)){
953+
if($rows = $app->db->queryAllRecords('SHOW FIELDS FROM ??', $table_name)){
913954
foreach($rows as $row) {
914955
$name = $row['Field'];
915956
$default = $row['Default'];
@@ -1011,7 +1052,7 @@ public function mapType($metaType, $typeValue) {
10111052
return 'char';
10121053
break;
10131054
case 'varchar':
1014-
if($typeValue < 1) die('Database failure: Lenght required for these data types.');
1055+
if($typeValue < 1) die('Database failure: Length required for these data types.');
10151056
return 'varchar('.$typeValue.')';
10161057
break;
10171058
case 'text':
@@ -1020,6 +1061,9 @@ public function mapType($metaType, $typeValue) {
10201061
case 'blob':
10211062
return 'blob';
10221063
break;
1064+
case 'date':
1065+
return 'date';
1066+
break;
10231067
}
10241068
}
10251069

0 commit comments

Comments
 (0)