📄 general.php
字号:
if (get_magic_quotes_runtime() > 0) $newline=stripslashes($newline);
if (trim(str_replace(';','',$newline)) != '' && !$ignore_line) $output=$db->Execute($newline);
$results++;
$string .= $newline.'<br />';
$return_output[]=$output;
if (zen_not_null($result) && !zen_check_exceptions($result, $line) ) $errors[]=$result;
// reset var's
$newline = '';
$keep_together=1;
$complete_line = false;
if ($ignore_line && !zen_check_exceptions($result, $line)) $ignored_count++;
$ignore_line=false;
// show progress bar
global $zc_show_progress;
if ($zc_show_progress=='yes') {
$counter++;
if ($counter/5 == (int)($counter/5)) echo '~ ';
if ($counter>200) {
echo '<br /><br />';
$counter=0;
}
if (function_exists('ob_flush')) @ob_flush();
@flush();
}
} //endif $complete_line
} //endif ! # or -
} // end foreach $lines
return array('queries'=> $results, 'string'=>$string, 'output'=>$return_output, 'ignored'=>($ignored_count), 'errors'=>$errors);
} //end function
function zen_db_prepare_input($string) {
if (is_string($string)) {
return trim(zen_sanitize_string(stripslashes($string)));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = zen_db_prepare_input($value);
}
return $string;
} else {
return $string;
}
}
function zen_sanitize_string($string) {
$string = ereg_replace(' +', ' ', $string);
return preg_replace("/[<>]/", '_', $string);
}
function zen_validate_email($email = "root@localhost.localdomain") {
$valid_address = true;
$user ="";
$domain="";
// split the e-mail address into user and domain parts
// need to update to trap for addresses in the format of "first@last"@someplace.com
// this method will most likely break in that case
list( $user, $domain ) = explode( "@", $email );
$valid_ip_form = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';
$valid_email_pattern = '^[a-z0-9]+[a-z0-9_\.\'\-]*@[a-z0-9]+[a-z0-9\.\-]*\.(([a-z]{2,6})|([0-9]{1,3}))$';
$space_check = '[ ]';
// strip beginning and ending quotes, if and only if both present
if( (ereg('^["]', $user) && ereg('["]$', $user)) ){
$user = ereg_replace ( '^["]', '', $user );
$user = ereg_replace ( '["]$', '', $user );
$user = ereg_replace ( $space_check, '', $user ); //spaces in quoted addresses OK per RFC (?)
$email = $user."@".$domain; // contine with stripped quotes for remainder
}
// if e-mail domain part is an IP address, check each part for a value under 256
if (ereg($valid_ip_form, $domain)) {
$digit = explode( ".", $domain );
for($i=0; $i<4; $i++) {
if ($digit[$i] > 255) {
$valid_address = false;
return $valid_address;
exit;
}
// stop crafty people from using internal IP addresses
if (($digit[0] == 192) || ($digit[0] == 10)) {
$valid_address = false;
return $valid_address;
exit;
}
}
}
if (!ereg($space_check, $email)) { // trap for spaces in
if ( eregi($valid_email_pattern, $email)) { // validate against valid e-mail patterns
$valid_address = true;
} else {
$valid_address = false;
return $valid_address;
exit;
}
}
// Verify e-mail has an associated MX and/or A record.
// Need alternate method to deal with Verisign shenanigans and with Windows Servers
// if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
// $valid_address = false;
// }
return $valid_address;
}
function zen_encrypt_password($plain) {
$password = '';
for ($i=0; $i<10; $i++) {
$password .= zen_rand();
}
$salt = substr(md5($password), 0, 2);
$password = md5($salt . $plain) . ':' . $salt;
return $password;
}
function zen_validate_password($plain, $encrypted) {
if (zen_not_null($plain) && zen_not_null($encrypted)) {
$stack = explode(':', $encrypted);
if (sizeof($stack) != 2) return false;
if (md5($stack[1] . $plain) == $stack[0]) {
return true;
}
}
return false;
}
function zen_rand($min = null, $max = null) {
static $seeded;
if (!isset($seeded)) {
mt_srand((double)microtime()*1000000);
$seeded = true;
}
if (isset($min) && isset($max)) {
if ($min >= $max) {
return $min;
} else {
return mt_rand($min, $max);
}
} else {
return mt_rand();
}
}
function zen_read_config_value($value) {
$files_array = array();
$string='';
$files_array[] = '../includes/configure.php';
if ($za_dir = @dir('../includes/' . 'extra_configures')) {
while ($zv_file = $za_dir->read()) {
if (strstr($zv_file, '.php')) {
//echo $zv_file.'<br>';
$files_array[] = $zv_file;
}
}
}
foreach ($files_array as $filename) {
if (!file_exists($filename)) continue;
//echo $filename . '!<br>';
$lines = file($filename);
foreach($lines as $line) { // read the configure.php file for specific variables
$def_string=array();
$def_string=explode("'",$line);
//define('CONSTANT','value');
//[1]=TABLE_CONSTANT
//[2]=,
//[3]=value
//[4]=);
//[5]=
if (isset($def_string[1]) && strtoupper($def_string[1]) == $value ) $string .= $def_string[3];
}//end foreach $line
}//end foreach $filename
return $string;
}
function zen_table_exists($tablename, $pre_install=false) {
global $db, $db_test;
if ($pre_install==true) {
$tables = $db_test->Execute("SHOW TABLES like '" . DB_PREFIX . $tablename . "'");
} else {
$tables = $db->Execute("SHOW TABLES like '" . DB_PREFIX . $tablename . "'");
}
if (ZC_UPG_DEBUG3==true) echo 'Table check ('.$tablename.') = '. $tables->RecordCount() .'<br>';
if ($tables->RecordCount() > 0) {
return true;
} else {
return false;
}
}
function zen_check_database_privs($priv='',$table='',$show_privs=false) {
//bypass for now ... will attempt to use with modifications in a new release later
if ($show_privs==true) return 'Not Checked|||Not Checked';
return true;
// end bypass
global $zdb_server, $zdb_user, $zdb_name;
if (!zen_not_null($zdb_server)) $zdb_server = zen_read_config_value('DB_SERVER');
if (!zen_not_null($zdb_user)) $zdb_user = zen_read_config_value('DB_SERVER_USERNAME');
if (!zen_not_null($zdb_name)) $zdb_name = zen_read_config_value('DB_DATABASE');
if (isset($_GET['nogrants']) || isset($_POST['nogrants']) ) return true; // bypass if flag set
//Display permissions, or check for suitable permissions to carry out a particular task
//possible outputs:
//GRANT ALL PRIVILEGES ON *.* TO 'xyz'@'localhost' WITH GRANT OPTION
//GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER ON *.* TO 'xyz'@'localhost' IDENTIFIED BY PASSWORD '2344'
//GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `db1`.* TO 'xyz'@'localhost'
//GRANT SELECT (id) ON db1.tablename TO 'xyz'@'localhost
global $db;
global $db_test;
$granted_privs_list='';
if (ZC_UPG_DEBUG3==true) echo '<br />Checking for priv: ['.(zen_not_null($priv) ? $priv : 'none specified').']<br />';
if (!defined('DB_SERVER')) define('DB_SERVER',$zdb_server);
if (!defined('DB_SERVER_USERNAME')) define('DB_SERVER_USERNAME',$zdb_user);
if (!defined('DB_DATABASE')) define('DB_DATABASE',$zdb_name);
$user = DB_SERVER_USERNAME."@".DB_SERVER;
if ($user == 'DB_SERVER_USERNAME@DB_SERVER' || DB_DATABASE=='DB_DATABASE') return true; // bypass if constants not set properly
$sql = "show grants for ".$user;
if (ZC_UPG_DEBUG3==true) echo $sql.'<br />';
if (is_object($db)) {
$result = $db->Execute($sql);
} elseif (is_object($db_test)) {
$result = $db_test->Execute($sql);
}
while (!$result->EOF) {
if (ZC_UPG_DEBUG3==true) echo $result->fields['Grants for '.$user].'<br />';
$grant_syntax = $result->fields['Grants for '.$user] . ' ';
$granted_privs = str_replace('GRANT ','',$grant_syntax); // remove "GRANT" keyword
$granted_privs = substr($granted_privs,0,strpos($granted_privs,' TO ')); //remove anything after the "TO" keyword
$granted_db = str_replace(array('`','\\'),'',substr($granted_privs,strpos($granted_privs,' ON ')+4) ); //remove backquote and find "ON" string
if (ZC_UPG_DEBUG3==true) echo 'privs_list = '.$granted_privs.'<br />';
if (ZC_UPG_DEBUG3==true) echo 'granted_db = '.$granted_db.'<br />';
$db_priv_ok += ($granted_db == '*.*' || $granted_db==DB_DATABASE.'.*' || $granted_db==DB_DATABASE.'.'.$table) ? true : false;
if (ZC_UPG_DEBUG3==true) echo 'db-priv-ok='.$db_priv_ok.'<br />';
if ($db_priv_ok) { // if the privs list pertains to the current database, or is *.*, carry on
$granted_privs = substr($granted_privs,0,strpos($granted_privs,' ON ')); //remove anything after the "ON" keyword
$granted_privs_list .= ($granted_privs_list=='') ? $granted_privs : ', '.$granted_privs;
$specific_priv_found = (zen_not_null($priv) && substr_count($granted_privs,$priv)==1);
if (ZC_UPG_DEBUG3==true) echo 'specific priv['.$priv.'] found ='.$specific_priv_found.'<br />';
if (ZC_UPG_DEBUG3==true) echo 'spec+db='.($specific_priv_found && $db_priv_ok == true).' ||| ';
if (ZC_UPG_DEBUG3==true) echo 'all+db='.($granted_privs == 'ALL PRIVILEGES' && $db_priv_ok==true).'<br /><br />';
if (($specific_priv_found && $db_priv_ok == true) || ($granted_privs == 'ALL PRIVILEGES' && $db_priv_ok==true)) {
return true; // privs found
}
} // endif $db_priv_ok
$result->MoveNext();
}
if ($show_privs) {
if (ZC_UPG_DEBUG3==true) echo 'LIST OF PRIVS='.$granted_privs_list.'<br />';
return $db_priv_ok . '|||'. $granted_privs_list;
} else {
return false; // if not found, return false
}
}
function zen_drop_index_command($param) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -