common.lib.php

来自「php绿色服务器,让大家试用greenamp」· PHP 代码 · 共 1,687 行 · 第 1/5 页

PHP
1,687
字号
            }            // And finally the path could be already set from REQUEST_URI            if (empty($url['path'])) {                if (!empty($_SERVER['PATH_INFO'])) {                    $path = parse_url($_SERVER['PATH_INFO']);                } else {                    // PHP_SELF in CGI often points to cgi executable, so use it as last choice                    $path = parse_url($_SERVER['PHP_SELF']);                }                $url['path'] = $path['path'];                unset($path);            }        }        // Make url from parts we have        $cfg['PmaAbsoluteUri'] = $url['scheme'] . '://';        // Was there user information?        if (!empty($url['user'])) {            $cfg['PmaAbsoluteUri'] .= $url['user'];            if (!empty($url['pass'])) {                $cfg['PmaAbsoluteUri'] .= ':' . $url['pass'];            }            $cfg['PmaAbsoluteUri'] .= '@';        }        // Add hostname        $cfg['PmaAbsoluteUri'] .= $url['host'];        // Add port, if it not the default one        if (!empty($url['port']) && (($url['scheme'] == 'http' && $url['port'] != 80) || ($url['scheme'] == 'https' && $url['port'] != 443))) {            $cfg['PmaAbsoluteUri'] .= $url['port'];        }        // And finally path, without script name        $cfg['PmaAbsoluteUri'] .= substr($url['path'], 0, strrpos($url['path'], '/') + 1);        unset($url);        // We display the warning by default, but not if it is disabled thru        // via the $cfg['PmaAbsoluteUri_DisableWarning'] variable.        // This is intended for sysadmins that actually want the default        // behaviour of auto-detection due to their setup.        // See the mailing list message:        // http://sourceforge.net/mailarchive/forum.php?thread_id=859093&forum_id=2141        if ($cfg['PmaAbsoluteUri_DisableWarning'] == FALSE) {            $display_pmaAbsoluteUri_warning = 1;        }    } else {        // The URI is specified, however users do often specify this        // wrongly, so we try to fix this.        // Adds a trailing slash et the end of the phpMyAdmin uri if it        // does not exist.        if (substr($cfg['PmaAbsoluteUri'], -1) != '/') {            $cfg['PmaAbsoluteUri'] .= '/';        }        // If URI doesn't start with http:// or https://, we will add        // this.        if (substr($cfg['PmaAbsoluteUri'], 0, 7) != 'http://' && substr($cfg['PmaAbsoluteUri'], 0, 8) != 'https://') {            if (!empty($_SERVER)) {                $SERVER_ARRAY = '_SERVER';            } else {                $SERVER_ARRAY = 'GLOBALS';            } // end if            if (isset(${$SERVER_ARRAY}['HTTPS'])) {                $HTTPS = ${$SERVER_ARRAY}['HTTPS'];            }            $cfg['PmaAbsoluteUri']          = ((!empty($HTTPS) && strtolower($HTTPS) != 'off') ? 'https' : 'http') . ':'                                            . (substr($cfg['PmaAbsoluteUri'], 0, 2) == '//' ? '' : '//')                                            . $cfg['PmaAbsoluteUri'];        }    }    $dblist       = array();    /**     * Gets the valid servers list and parameters     */    foreach ($cfg['Servers'] AS $key => $val) {        // Don't use servers with no hostname        if ( ($val['connect_type'] == 'tcp') && empty($val['host'])) {            unset($cfg['Servers'][$key]);        }        // Final solution to bug #582890        // If we are using a socket connection        // and there is nothing in the verbose server name        // or the host field, then generate a name for the server        // in the form of "Server 2", localized of course!        if ( ($val['connect_type'] == 'socket') && empty($val['host']) && empty($val['verbose']) ) {            $cfg['Servers'][$key]['verbose'] = $GLOBALS['strServer'] . $key;            $val['verbose']                  = $GLOBALS['strServer'] . $key;        }    }    if (empty($server) || !isset($cfg['Servers'][$server]) || !is_array($cfg['Servers'][$server])) {        $server = $cfg['ServerDefault'];    }    /**     * If no server is selected, make sure that $cfg['Server'] is empty (so     * that nothing will work), and skip server authentication.     * We do NOT exit here, but continue on without logging into any server.     * This way, the welcome page will still come up (with no server info) and     * present a choice of servers in the case that there are multiple servers     * and '$cfg['ServerDefault'] = 0' is set.     */    if ($server == 0) {        $cfg['Server'] = array();    }    /**     * Otherwise, set up $cfg['Server'] and do the usual login stuff.     */    else if (isset($cfg['Servers'][$server])) {        $cfg['Server'] = $cfg['Servers'][$server];        /**         * Loads the proper database interface for this server         */        require_once('./libraries/database_interface.lib.php');        // Gets the authentication library that fits the $cfg['Server'] settings        // and run authentication        // (for a quick check of path disclosure in auth/cookies:)        $coming_from_common = TRUE;        require_once('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php');        if (!PMA_auth_check()) {            PMA_auth();        } else {            PMA_auth_set_user();        }        // Check IP-based Allow/Deny rules as soon as possible to reject the        // user        // Based on mod_access in Apache:        // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup        // Look at: "static int check_dir_access(request_rec *r)"        // Robbat2 - May 10, 2002        if (isset($cfg['Server']['AllowDeny']) && isset($cfg['Server']['AllowDeny']['order'])) {            require_once('./libraries/ip_allow_deny.lib.php');            $allowDeny_forbidden         = FALSE; // default            if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {                $allowDeny_forbidden     = TRUE;                if (PMA_allowDeny('allow')) {                    $allowDeny_forbidden = FALSE;                }                if (PMA_allowDeny('deny')) {                    $allowDeny_forbidden = TRUE;                }            } else if ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {                if (PMA_allowDeny('deny')) {                    $allowDeny_forbidden = TRUE;                }                if (PMA_allowDeny('allow')) {                    $allowDeny_forbidden = FALSE;                }            } else if ($cfg['Server']['AllowDeny']['order'] == 'explicit') {                if (PMA_allowDeny('allow')                    && !PMA_allowDeny('deny')) {                    $allowDeny_forbidden = FALSE;                } else {                    $allowDeny_forbidden = TRUE;                }            } // end if... else if... else if            // Ejects the user if banished            if ($allowDeny_forbidden) {               PMA_auth_fails();            }            unset($allowDeny_forbidden); //Clean up after you!        } // end if        // The user can work with only some databases        if (isset($cfg['Server']['only_db']) && $cfg['Server']['only_db'] != '') {            if (is_array($cfg['Server']['only_db'])) {                $dblist   = $cfg['Server']['only_db'];            } else {                $dblist[] = $cfg['Server']['only_db'];            }        } // end if        $bkp_track_err = @ini_set('track_errors', 1);        // Try to connect MySQL with the control user profile (will be used to        // get the privileges list for the current user but the true user link        // must be open after this one so it would be default one for all the        // scripts)        if ($cfg['Server']['controluser'] != '') {            $dbh = PMA_DBI_connect($cfg['Server']['controluser'], $cfg['Server']['controlpass']);        } // end if ... else        // Pass #1 of DB-Config to read in master level DB-Config will go here        // Robbat2 - May 11, 2002        // Connects to the server (validates user's login)        $userlink = PMA_DBI_connect($cfg['Server']['user'], $cfg['Server']['password']);        if (empty($dbh)) {            $dbh = $userlink;        }        // Pass #2 of DB-Config to read in user level DB-Config will go here        // Robbat2 - May 11, 2002        @ini_set('track_errors', $bkp_track_err);        unset($bkp_track_err);        /**         * SQL Parser code         */        require_once('./libraries/sqlparser.lib.php');        /**         * SQL Validator interface code         */        require_once('./libraries/sqlvalidator.lib.php');        // if 'only_db' is set for the current user, there is no need to check for        // available databases in the "mysql" db        $dblist_cnt = count($dblist);        if ($dblist_cnt) {            $true_dblist  = array();            $is_show_dbs  = TRUE;            $dblist_asterisk_bool = FALSE;            for ($i = 0; $i < $dblist_cnt; $i++) {                // The current position                if ($dblist[$i] == '*' && $dblist_asterisk_bool == FALSE) {                    $dblist_asterisk_bool = TRUE;                    $dblist_full = PMA_safe_db_list(FALSE, $dbh, FALSE, $rs, $userlink, $cfg, $dblist);                    foreach ($dblist_full AS $dbl_key => $dbl_val) {                        if (!in_array($dbl_val, $dblist)) {                            $true_dblist[] = $dbl_val;                        }                    }                    continue;                } elseif ($dblist[$i] == '*') {                    // We don't want more than one asterisk inside our 'only_db'.                    continue;                }                if ($is_show_dbs && ereg('(^|[^\])(_|%)', $dblist[$i])) {                    $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\'';                    $rs          = PMA_DBI_query($local_query, $dbh);                    // "SHOW DATABASES" statement is disabled                    if ($i == 0                        && (substr(PMA_DBI_getError($dbh), 1, 4) == 1045)) {                        $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));                        $is_show_dbs   = FALSE;                    }                    // Debug                    // else if (PMA_DBI_getError($dbh)) {                    //    PMA_mysqlDie(PMA_DBI_getError($dbh), $local_query, FALSE);                    // }                    while ($row = @PMA_DBI_fetch_row($rs)) {                        $true_dblist[] = $row[0];                    } // end while                    if ($rs) {                        PMA_DBI_free_result($rs);                    }                } else {                    $true_dblist[]     = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));                } // end if... else...            } // end for            $dblist       = $true_dblist;            unset($true_dblist);            $only_db_check = TRUE;        } // end if        // 'only_db' is empty for the current user...        else {            $only_db_check = FALSE;        } // end if (!$dblist_cnt)        if (isset($dblist_full) && !count($dblist_full)) {            $dblist = PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist);        }    } // end server connecting    /**     * Missing server hostname     */    else {        echo $strHostEmpty;    }    /**     * Send HTTP header, taking IIS limits into account     *                   ( 600 seems ok)     *     * @param   string   the header to send     *     * @return  boolean  always true     */     function PMA_sendHeaderLocation($uri)     {         if (PMA_IS_IIS && strlen($uri) > 600) {             echo '<html><head><title>- - -</title>' . "\n";             echo '<meta http-equiv="expires" content="0">' . "\n";             echo '<meta http-equiv="Pragma" content="no-cache">' . "\n";             echo '<meta http-equiv="Cache-Control" content="no-cache">' . "\n";             echo '<meta http-equiv="Refresh" content="0;url=' .$uri . '">' . "\n";             echo '<script language="JavaScript">' . "\n";             echo 'setTimeout ("window.location = unescape(\'"' . $uri . '"\')",2000); </script>' . "\n";             echo '</head>' . "\n";             echo '<body> <script language="JavaScript">' . "\n";             echo 'document.write (\'<p><a href="' . $uri . '">' . $GLOBALS['strGo'] . '</a></p>\');' . "\n";             echo '</script></body></html>' . "\n";         } else {             header('Location: ' . $uri);         }     }    /**     * Get the list and number of available databases.     *     * @param   string   the url to go back to in case of error     *     * @return  boolean  always true     *     * @global  array    the list of available databases     * @global  integer  the number of available databases     * @global  array    current configuration     */    function PMA_availableDatabases($error_url = '')    {        global $dblist;        global $num_dbs;        global $cfg;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?