예제 #1
0
 function databases($flush = true)
 {
     $return = array();
     foreach (get_databases($flush) as $db) {
         if (!in_array(strtolower($db), $this->disabled)) {
             $return[] = $db;
         }
     }
     return $return;
 }
예제 #2
0
function connect_error()
{
    global $connection, $token, $error, $drivers;
    $databases = array();
    if (DB != "") {
        page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true);
    } else {
        if ($_POST["db"] && !$error) {
            queries_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"]));
        }
        page_header(lang('Select database'), $error, false);
        echo "<p><a href='" . h(ME) . "database='>" . lang('Create new database') . "</a>\n";
        foreach (array('privileges' => lang('Privileges'), 'processlist' => lang('Process list'), 'variables' => lang('Variables'), 'status' => lang('Status')) as $key => $val) {
            if (support($key)) {
                echo "<a href='" . h(ME) . "{$key}='>{$val}</a>\n";
            }
        }
        echo "<p>" . lang('%s version: %s through PHP extension %s', $drivers[DRIVER], "<b>{$connection->server_info}</b>", "<b>{$connection->extension}</b>") . "\n";
        echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
        if ($_GET["refresh"]) {
            set_session("dbs", null);
        }
        $databases = get_databases();
        if ($databases) {
            $scheme = support("scheme");
            $collations = collations();
            echo "<form action='' method='post'>\n";
            echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);'>\n";
            echo "<thead><tr><td>&nbsp;<th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n";
            foreach ($databases as $db) {
                $root = h(ME) . "db=" . urlencode($db);
                echo "<tr" . odd() . "><td>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"]));
                echo "<th><a href='{$root}'>" . h($db) . "</a>";
                echo "<td><a href='{$root}" . ($scheme ? "&amp;ns=" : "") . "&amp;database=' title='" . lang('Alter database') . "'>" . nbsp(db_collation($db, $collations)) . "</a>";
                echo "<td align='right'><a href='{$root}&amp;schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>?</a>";
                echo "\n";
            }
            echo "</table>\n";
            echo "<script type='text/javascript'>tableCheck();</script>\n";
            echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)", 1) . ">\n";
            // 1 - eventStop
            echo "<input type='hidden' name='token' value='{$token}'>\n";
            echo "<a href='" . h(ME) . "refresh=1' onclick='eventStop(event);'>" . lang('Refresh') . "</a>\n";
            echo "</form>\n";
        }
    }
    page_footer("db");
    if ($databases) {
        echo "<script type='text/javascript'>ajaxSetHtml('" . js_adminer_escape(ME) . "script=connect');</script>\n";
    }
}
예제 #3
0
 /** Get cached list of databases
  * @param bool
  * @return array
  */
 function databases($flush = true)
 {
     return get_databases($flush);
 }
예제 #4
0
        json_row("Comment-{$id}", nbsp($table_status["Comment"]));
        if (!is_view($table_status)) {
            foreach (array("Engine", "Collation") as $key) {
                json_row("{$key}-{$id}", nbsp($table_status[$key]));
            }
            foreach ($sums + array("Auto_increment" => 0, "Rows" => 0) as $key => $val) {
                if ($table_status[$key] != "") {
                    $val = number_format($table_status[$key], 0, '.', lang(','));
                    json_row("{$key}-{$id}", $key == "Rows" && $table_status["Engine"] == "InnoDB" && $val ? "~ {$val}" : $val);
                    if (isset($sums[$key])) {
                        $sums[$key] += $table_status["Engine"] != "InnoDB" || $key != "Data_free" ? $table_status[$key] : 0;
                    }
                } elseif (array_key_exists($key, $table_status)) {
                    json_row("{$key}-{$id}");
                }
            }
        }
    }
    foreach ($sums as $key => $val) {
        json_row("sum-{$key}", number_format($val, 0, '.', lang(',')));
    }
    json_row("");
} else {
    // connect
    foreach (count_tables(get_databases()) as $db => $val) {
        json_row("tables-" . js_adminer_escape($db), $val);
    }
    json_row("");
}
exit;
// don't print footer
예제 #5
0
        $name = $table_status["Name"];
        $prefix = ereg_replace("_.*", "", $name);
        $checked = $TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "{$prefix}%" : $name);
        //! % may be part of table name
        $print = "<tr><td>" . checkbox("tables[]", $name, $checked, $name, "formUncheck('check-tables');");
        if (is_view($table_status)) {
            $views .= "{$print}\n";
        } else {
            echo "{$print}<td align='right'><label>" . ($table_status["Engine"] == "InnoDB" && $table_status["Rows"] ? "~ " : "") . $table_status["Rows"] . checkbox("data[]", $name, $checked, "", "formUncheck('check-data');") . "</label>\n";
        }
        $prefixes[$prefix]++;
    }
    echo $views;
} else {
    echo "<thead><tr><th style='text-align: left;'><label><input type='checkbox' id='check-databases'" . ($TABLE == "" ? " checked" : "") . " onclick='formCheck(this, /^databases\\[/);'>" . lang('Database') . "</label></thead>\n";
    $databases = get_databases();
    if ($databases) {
        foreach ($databases as $db) {
            if (!information_schema($db)) {
                $prefix = ereg_replace("_.*", "", $db);
                echo "<tr><td>" . checkbox("databases[]", $db, $TABLE == "" || $TABLE == "{$prefix}%", $db, "formUncheck('check-databases');") . "</label>\n";
                $prefixes[$prefix]++;
            }
        }
    } else {
        echo "<tr><td><textarea name='databases' rows='10' cols='20'></textarea>";
    }
}
?>
</table>
</form>
예제 #6
0
             }
         }
         echo support("comment") ? "<td id='Comment-" . h($name) . "'>&nbsp;" : "";
     }
     echo "<tr><td>&nbsp;<th>" . lang('%d in total', count($tables_list));
     echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : "");
     echo "<td>" . nbsp(db_collation(DB, collations()));
     foreach (array("Data_length", "Index_length", "Data_free") as $key) {
         echo "<td align='right' id='sum-{$key}'>&nbsp;";
     }
     echo "</table>\n";
     echo "<script type='text/javascript'>tableCheck();</script>\n";
     if (!information_schema(DB)) {
         echo "<p>" . ($jush == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'> <input type='submit' name='optimize' value='" . lang('Optimize') . "'> <input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> <input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)", 1) . ">\n";
         // 1 - eventStop
         $databases = support("scheme") ? schemas() : get_databases();
         if (count($databases) != 1 && $jush != "sqlite") {
             $db = isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB);
             echo "<p>" . lang('Move to other database') . ": ";
             echo $databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '">';
             echo " <input type='submit' name='move' value='" . lang('Move') . "' onclick='eventStop(event);'>";
             echo support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "' onclick='eventStop(event);'>" : "";
             echo "\n";
         }
         echo "<input type='hidden' name='token' value='{$token}'>\n";
     }
     echo "</form>\n";
 }
 echo '<p><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
 if (support("view")) {
     echo '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n";
예제 #7
0
    /** Prints navigation after Adminer title
     * @param string can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
     * @return null
     */
    function navigation($missing)
    {
        global $VERSION, $connection, $token, $jush, $drivers;
        ?>
<h1>
<?php 
        echo $this->name();
        ?>
 <span class="version"><?php 
        echo $VERSION;
        ?>
</span>
<a href="http://www.adminer.org/#download" id="version"><?php 
        echo version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : "";
        ?>
</a>
</h1>
<?php 
        if ($missing == "auth") {
            $first = true;
            foreach ((array) $_SESSION["pwds"] as $driver => $servers) {
                foreach ($servers as $server => $usernames) {
                    foreach ($usernames as $username => $password) {
                        if (isset($password)) {
                            if ($first) {
                                echo "<p onclick='eventStop(event);'>\n";
                                $first = false;
                            }
                            echo "<a href='" . h(auth_url($driver, $server, $username)) . "'>({$drivers[$driver]}) " . h($username . ($server != "" ? "@{$server}" : "")) . "</a><br>\n";
                        }
                    }
                }
            }
        } else {
            $databases = get_databases();
            ?>
<form action="" method="post">
<p class="logout">
<?php 
            if (DB == "" || !$missing) {
                echo "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "</a>\n";
                if (support("dump")) {
                    echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Dump') . "</a>\n";
                }
            }
            ?>
<input type="submit" name="logout" value="<?php 
            echo lang('Logout');
            ?>
" onclick="eventStop(event);">
<input type="hidden" name="token" value="<?php 
            echo $token;
            ?>
">
</p>
</form>
<form action="">
<p>
<?php 
            hidden_fields_get();
            echo $databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">';
            ?>
<input type="submit" value="<?php 
            echo lang('Use');
            ?>
"<?php 
            echo $databases ? " class='hidden'" : "";
            ?>
 onclick="eventStop(event);">
<?php 
            if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
                if (support("scheme")) {
                    echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
                    if ($_GET["ns"] != "") {
                        set_schema($_GET["ns"]);
                    }
                }
                if ($_GET["ns"] !== "" && !$missing) {
                    echo '<p><a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create new table') . "</a>\n";
                    $tables = tables_list();
                    if (!$tables) {
                        echo "<p class='message'>" . lang('No tables.') . "\n";
                    } else {
                        $this->tablesPrint($tables);
                        $links = array();
                        foreach ($tables as $table => $type) {
                            $links[] = preg_quote($table, '/');
                        }
                        echo "<script type='text/javascript'>\n";
                        echo "var jushLinks = { {$jush}: [ '" . js_adminer_escape(ME) . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
                        foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
                            echo "jushLinks.{$val} = jushLinks.{$jush};\n";
                        }
                        echo "</script>\n";
                    }
                }
            }
            echo isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">' : (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">' : (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">' : ""));
            echo "</p></form>\n";
        }
    }
예제 #8
0
function get_experiments()
{
    if (empty($experiments)) {
        $dbname = $_GET['database'];
        $urlExperiments = get_databases()[$dbname];
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $urlExperiments);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        $finaldata = (array) json_decode($data);
        ksort($finaldata);
        $experiments = $finaldata;
    }
    return $experiments;
}