@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | function sn_db_connect($external_db_settings = null) { |
77 | 77 | $this->db_disconnect(); |
78 | 78 | |
79 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
79 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
80 | 80 | $this->dbsettings = $external_db_settings; |
81 | 81 | } |
82 | 82 | |
83 | - if(empty($this->dbsettings)) { |
|
83 | + if (empty($this->dbsettings)) { |
|
84 | 84 | $this->load_db_settings(); |
85 | 85 | } |
86 | 86 | |
87 | 87 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
88 | - if(!empty($this->dbsettings)) { |
|
88 | + if (!empty($this->dbsettings)) { |
|
89 | 89 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
90 | 90 | $this->driver = new $driver_name(); |
91 | 91 | $this->db_prefix = $this->dbsettings['prefix']; |
92 | 92 | |
93 | 93 | $this->connected = $this->connected || $this->driver_connect(); |
94 | 94 | |
95 | - if($this->connected) { |
|
95 | + if ($this->connected) { |
|
96 | 96 | $this->table_list = $this->db_get_table_list(); |
97 | 97 | // TODO Проверка на пустоту |
98 | 98 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | function driver_connect() { |
107 | 107 | global $debug; |
108 | 108 | |
109 | - if(!is_object($this->driver)) { |
|
109 | + if (!is_object($this->driver)) { |
|
110 | 110 | $debug->error_fatal('DB Error - No driver for MySQL found!'); |
111 | 111 | } |
112 | 112 | |
113 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
113 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
114 | 114 | $debug->error_fatal('DB Error - WRONG MySQL driver!'); |
115 | 115 | } |
116 | 116 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | function db_disconnect() { |
121 | - if($this->connected) { |
|
121 | + if ($this->connected) { |
|
122 | 122 | $this->connected = !$this->driver_disconnect(); |
123 | 123 | $this->connected = false; |
124 | 124 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
130 | 130 | global $numqueries, $debug, $config; |
131 | 131 | |
132 | - if(!is_string($table)) { |
|
132 | + if (!is_string($table)) { |
|
133 | 133 | $fetch = $table; |
134 | 134 | } |
135 | 135 | |
136 | - if(!$this->connected) { |
|
136 | + if (!$this->connected) { |
|
137 | 137 | $this->sn_db_connect(); |
138 | 138 | } |
139 | 139 | |
@@ -142,30 +142,30 @@ discard block |
||
142 | 142 | $skip_query_check ? $this->security_query_check_bad_words($query) : false; |
143 | 143 | |
144 | 144 | $sql = $query; |
145 | - if(strpos($sql, '{{') !== false) { |
|
146 | - foreach($this->table_list as $tableName) { |
|
145 | + if (strpos($sql, '{{') !== false) { |
|
146 | + foreach ($this->table_list as $tableName) { |
|
147 | 147 | $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - if($config->debug) { |
|
151 | + if ($config->debug) { |
|
152 | 152 | $numqueries++; |
153 | 153 | $arr = debug_backtrace(); |
154 | - $file = end(explode('/',$arr[0]['file'])); |
|
154 | + $file = end(explode('/', $arr[0]['file'])); |
|
155 | 155 | $line = $arr[0]['line']; |
156 | 156 | $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>"); |
157 | 157 | } |
158 | 158 | |
159 | - if(defined('DEBUG_SQL_COMMENT')) { |
|
159 | + if (defined('DEBUG_SQL_COMMENT')) { |
|
160 | 160 | $backtrace = debug_backtrace(); |
161 | 161 | $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
162 | 162 | |
163 | 163 | $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
164 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
164 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
165 | 165 | $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
166 | 166 | } |
167 | 167 | |
168 | - if(defined('DEBUG_SQL_ERROR')) { |
|
168 | + if (defined('DEBUG_SQL_ERROR')) { |
|
169 | 169 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
170 | 170 | $debug->add_to_array($sql_comment); |
171 | 171 | // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql)); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $sql = $sql_commented; |
174 | 174 | } |
175 | 175 | |
176 | - $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error()."<br />$sql<br />",'SQL Error'); |
|
176 | + $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error() . "<br />$sql<br />", 'SQL Error'); |
|
177 | 177 | |
178 | 178 | return $fetch ? $this->db_fetch($sqlquery) : $sqlquery; |
179 | 179 | } |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | // TODO Заменить это на новый логгер |
184 | 184 | global $config, $is_watching, $user, $debug; |
185 | 185 | |
186 | - if(!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array)) |
|
186 | + if (!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array)) |
|
187 | 187 | { |
188 | - if(!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
188 | + if (!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
189 | 189 | $is_watching = true; |
190 | 190 | $msg = "\$query = \"{$query}\"\n\r"; |
191 | - if(!empty($_POST)) { |
|
192 | - $msg .= "\n\r" . dump($_POST,'$_POST'); |
|
191 | + if (!empty($_POST)) { |
|
192 | + $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
193 | 193 | } |
194 | - if(!empty($_GET)) { |
|
195 | - $msg .= "\n\r" . dump($_GET,'$_GET'); |
|
194 | + if (!empty($_GET)) { |
|
195 | + $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
196 | 196 | } |
197 | 197 | $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
198 | 198 | $is_watching = false; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | function security_query_check_bad_words($query) { |
205 | 205 | global $user, $dm_change_legit, $mm_change_legit; |
206 | 206 | |
207 | - switch(true) { |
|
207 | + switch (true) { |
|
208 | 208 | case stripos($query, 'RUNCATE TABL') != false: |
209 | 209 | case stripos($query, 'ROP TABL') != false: |
210 | 210 | case stripos($query, 'ENAME TABL') != false: |
@@ -215,33 +215,33 @@ discard block |
||
215 | 215 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
216 | 216 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
217 | 217 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
218 | - $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
218 | + $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
219 | 219 | $report .= ">Database Inforamation\n"; |
220 | - $report .= "\tID - ".$user['id']."\n"; |
|
221 | - $report .= "\tUser - ".$user['username']."\n"; |
|
222 | - $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
223 | - $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
224 | - $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
225 | - $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
226 | - $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
227 | - $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
228 | - $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
229 | - $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
220 | + $report .= "\tID - " . $user['id'] . "\n"; |
|
221 | + $report .= "\tUser - " . $user['username'] . "\n"; |
|
222 | + $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
223 | + $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
224 | + $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
225 | + $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
226 | + $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
227 | + $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
228 | + $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
229 | + $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
230 | 230 | $report .= "\n"; |
231 | 231 | |
232 | 232 | $report .= ">Query Information\n"; |
233 | - $report .= "\tQuery - ".$query."\n"; |
|
233 | + $report .= "\tQuery - " . $query . "\n"; |
|
234 | 234 | $report .= "\n"; |
235 | 235 | |
236 | 236 | $report .= ">\$_SERVER Information\n"; |
237 | - $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
238 | - $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
239 | - $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
240 | - $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
241 | - $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
242 | - $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
243 | - $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
244 | - $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
237 | + $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
238 | + $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
239 | + $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
240 | + $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
241 | + $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
242 | + $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
243 | + $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
244 | + $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
245 | 245 | |
246 | 246 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
247 | 247 | |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | $prefix_length = strlen($this->db_prefix); |
262 | 262 | |
263 | 263 | $tl = array(); |
264 | - while($row = $this->db_fetch($query)) { |
|
265 | - foreach($row as $table_name) { |
|
266 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
264 | + while ($row = $this->db_fetch($query)) { |
|
265 | + foreach ($row as $table_name) { |
|
266 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
267 | 267 | $table_name = substr($table_name, $prefix_length); |
268 | - } elseif($prefixed_only) { |
|
268 | + } elseif ($prefixed_only) { |
|
269 | 269 | continue; |
270 | 270 | } |
271 | 271 | // $table_name = str_replace($db_prefix, '', $table_name); |