Esempio n. 1
0
function connect_error()
{
    global $adminer, $connection, $token, $error, $drivers;
    if (DB != "") {
        header("HTTP/1.1 404 Not Found");
        page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true);
    } else {
        if ($_POST["db"] && !$error) {
            queries_adminer_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"]));
        }
        page_header(lang('Select database'), $error, false);
        echo "<p class='links'>\n";
        foreach (array('database' => lang('Create new database'), '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>" . h($connection->server_info) . "</b>", "<b>{$connection->extension}</b>") . "\n";
        echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
        $databases = $adminer->databases();
        if ($databases) {
            $scheme = support("scheme");
            $collations = collations();
            echo "<form action='' method='post'>\n";
            echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
            echo "<thead><tr>" . (support("database") ? "<td>&nbsp;" : "") . "<th>" . lang('Database') . " - <a href='" . h(ME) . "refresh=1'>" . lang('Refresh') . "</a>" . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "<td>" . lang('Size') . " - <a href='" . h(ME) . "dbsize=1' onclick=\"return !ajaxSetHtml('" . is_adminer_escape(ME) . "script=connect');\">" . lang('Compute') . "</a>" . "</thead>\n";
            $databases = $_GET["dbsize"] ? count_tables($databases) : array_flip($databases);
            foreach ($databases as $db => $tables) {
                $root = h(ME) . "db=" . urlencode($db);
                echo "<tr" . odd() . ">" . (support("database") ? "<td>" . adminer_checkbox("db[]", $db, in_array($db, (array) $_POST["db"])) : "");
                echo "<th><a href='{$root}'>" . h($db) . "</a>";
                $collation = nbsp(db_collation($db, $collations));
                echo "<td>" . (support("database") ? "<a href='{$root}" . ($scheme ? "&amp;ns=" : "") . "&amp;database=' title='" . lang('Alter database') . "'>{$collation}</a>" : $collation);
                echo "<td align='right'><a href='{$root}&amp;schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>" . ($_GET["dbsize"] ? $tables : "?") . "</a>";
                echo "<td align='right' id='size-" . h($db) . "'>" . ($_GET["dbsize"] ? db_size($db) : "?");
                echo "\n";
            }
            echo "</table>\n";
            echo support("database") ? "<fieldset><legend>" . lang('Selected') . " <span id='selected'></span></legend><div>\n" . "<input type='hidden' name='all' value='' onclick=\"selectCount('selected', formChecked(this, /^db/));\">\n" . "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm() . ">\n" . "</div></fieldset>\n" : "";
            echo "<script type='text/javascript'>tableCheck();</script>\n";
            echo "<input type='hidden' name='token' value='{$token}'>\n";
            echo "</form>\n";
        }
    }
    page_footer("db");
}
Esempio n. 2
0
    $tables_list = tables_list();
    foreach ($tables_list as $name => $type) {
        $prefix = preg_replace('~_.*~', '', $name);
        $checked = $TABLE == "" || $TABLE == (substr($TABLE, -1) == "%" ? "{$prefix}%" : $name);
        //! % may be part of table name
        $print = "<tr><td>" . adminer_checkbox("tables[]", $name, $checked, $name, "checkboxClick(event, this); formUncheck('check-tables');", "block");
        if ($type !== null && !preg_match('~table~i', $type)) {
            $views .= "{$print}\n";
        } else {
            echo "{$print}<td align='right'><label class='block'><span id='Rows-" . h($name) . "'></span>" . adminer_checkbox("data[]", $name, $checked, "", "checkboxClick(event, this); formUncheck('check-data');") . "</label>\n";
        }
        $prefixes[$prefix]++;
    }
    echo $views;
    if ($tables_list) {
        echo "<script type='text/javascript'>ajaxSetHtml('" . is_adminer_escape(ME) . "script=db');</script>\n";
    }
} else {
    echo "<thead><tr><th style='text-align: left;'><label class='block'><input type='checkbox' id='check-databases'" . ($TABLE == "" ? " checked" : "") . " onclick='formCheck(this, /^databases\\[/);'>" . lang('Database') . "</label></thead>\n";
    $databases = $adminer->databases();
    if ($databases) {
        foreach ($databases as $db) {
            if (!information_schema($db)) {
                $prefix = preg_replace('~_.*~', '', $db);
                echo "<tr><td>" . adminer_checkbox("databases[]", $db, $TABLE == "" || $TABLE == "{$prefix}%", $db, "formUncheck('check-databases');", "block") . "\n";
                $prefixes[$prefix]++;
            }
        }
    } else {
        echo "<tr><td><textarea name='databases' rows='10' cols='20'></textarea>";
    }
Esempio n. 3
0
<?php

header("Content-Type: text/javascript; charset=utf-8");
if ($_GET["script"] == "db") {
    $sums = array("Data_length" => 0, "Index_length" => 0, "Data_free" => 0);
    foreach (table_status() as $name => $table_status) {
        $id = is_adminer_escape($name);
        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 = format_number($table_status[$key]);
                    json_row("{$key}-{$id}", $key == "Rows" && $val && $table_status["Engine"] == ($sql == "pgsql" ? "table" : "InnoDB") ? "~ {$val}" : $val);
                    if (isset($sums[$key])) {
                        // ignore innodb_file_per_table because it is not active for tables created before it was enabled
                        $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}", format_number($val));
    }
    json_row("");
} elseif ($_GET["script"] == "kill") {
Esempio n. 4
0
/** Run query which can be killed by AJAX call after timing out
* @param string
* @return array of strings
*/
function slow_query($query)
{
    global $adminer, $token;
    $db = $adminer->database();
    $timeout = $adminer->queryTimeout();
    if (support("kill") && is_object($connection2 = connect()) && ($db == "" || $connection2->select_db($db))) {
        $kill = $connection2->result("SELECT CONNECTION_ID()");
        // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
        ?>
<script type="text/javascript">
var timeout = setTimeout(function () {
	ajax('<?php 
        echo is_adminer_escape(ME);
        ?>
script=kill', function () {
	}, 'token=<?php 
        echo $token;
        ?>
&kill=<?php 
        echo $kill;
        ?>
');
}, <?php 
        echo 1000 * $timeout;
        ?>
);
</script>
<?php 
    } else {
        $connection2 = null;
    }
    ob_flush();
    flush();
    $return = @get_key_vals($query, $connection2, $timeout);
    // @ - may be killed
    if ($connection2) {
        echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
        ob_flush();
        flush();
    }
    return array_keys($return);
}
Esempio n. 5
0
    echo "<tr><td>PRIMARY<td>";
    foreach ($primary["columns"] as $key => $column) {
        echo select_input(" disabled", $fields, $column);
        echo "<label><input disabled type='checkbox'>" . lang('descending') . "</label> ";
    }
    echo "<td><td>\n";
}
$j = 1;
foreach ($row["indexes"] as $index) {
    if (!$_POST["drop_col"] || $j != key($_POST["drop_col"])) {
        echo "<tr><td>" . html_select("indexes[{$j}][type]", array(-1 => "") + $index_types, $index["type"], $j == count($row["indexes"]) ? "indexesAddRow(this);" : 1);
        echo "<td>";
        ksort($index["columns"]);
        $i = 1;
        foreach ($index["columns"] as $key => $column) {
            echo "<span>" . select_input(" name='indexes[{$j}][columns][{$i}]' onchange=\"" . ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . is_adminer_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');\"", $fields ? array_combine($fields, $fields) : $fields, $column);
            echo $jush == "sql" || $jush == "mssql" ? "<input type='number' name='indexes[{$j}][lengths][{$i}]' class='size' value='" . h($index["lengths"][$key]) . "'>" : "";
            echo $jush != "sql" ? adminer_checkbox("indexes[{$j}][descs][{$i}]", 1, $index["descs"][$key], lang('descending')) : "";
            echo " </span>";
            $i++;
        }
        echo "<td><input name='indexes[{$j}][name]' value='" . h($index["name"]) . "' autocapitalize='off'>\n";
        echo "<td><input type='image' class='icon' name='drop_col[{$j}]' src='../adminer/static/cross.gif' alt='x' title='" . lang('Remove') . "' onclick=\"return !editingRemoveRow(this, 'indexes\$1[type]');\">\n";
    }
    $j++;
}
?>
</table>
<p>
<input type="submit" value="<?php 
echo lang('Save');
Esempio n. 6
0
                queries(create_trigger($on, $row + array("Type" => reset($trigger_options["Type"]))));
            }
        }
    }
    $row = $_POST;
}
page_header($name != "" ? lang('Alter trigger') . ": " . h($name) : lang('Create trigger'), $error, array("table" => $TABLE));
?>

<form action="" method="post" id="form">
<table cellspacing="0">
<tr><th><?php 
echo lang('Time');
?>
<td><?php 
echo html_select("Timing", $trigger_options["Timing"], $row["Timing"], "triggerChange(/^" . preg_quote($TABLE, "/") . "_[ba][iud]\$/, '" . is_adminer_escape($TABLE) . "', this.form);");
?>
<tr><th><?php 
echo lang('Event');
?>
<td><?php 
echo html_select("Event", $trigger_options["Event"], $row["Event"], "this.form['Timing'].onchange();");
echo in_array("UPDATE OF", $trigger_options["Event"]) ? " <input name='Of' value='" . h($row["Of"]) . "' class='hidden'>" : "";
?>
<tr><th><?php 
echo lang('Type');
?>
<td><?php 
echo html_select("Type", $trigger_options["Type"], $row["Type"]);
?>
</table>
Esempio 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, $jush, $drivers, $connection;
        ?>
<h1>
<?php 
        echo $this->name();
        ?>
 <span class="version"><?php 
        echo $VERSION;
        ?>
</span>
<a href="http://www.adminer.org/#download" target="_blank" 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 $vendor => $servers) {
                foreach ($servers as $server => $usernames) {
                    foreach ($usernames as $username => $password) {
                        if ($password !== null) {
                            if ($first) {
                                echo "<p id='logins' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
                                $first = false;
                            }
                            $dbs = $_SESSION["db"][$vendor][$server][$username];
                            foreach ($dbs ? array_keys($dbs) : array("") as $db) {
                                echo "<a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>({$drivers[$vendor]}) " . h($username . ($server != "" ? "@{$server}" : "") . ($db != "" ? " - {$db}" : "")) . "</a><br>\n";
                            }
                        }
                    }
                }
            }
        } else {
            if ($_GET["ns"] !== "" && !$missing && DB != "") {
                $connection->select_db(DB);
                $tables = table_status('', true);
            }
            if (support("sql")) {
                ?>
<script type="text/javascript" src="../externals/jush/modules/jush.js"></script>
<script type="text/javascript" src="../externals/jush/modules/jush-textarea.js"></script>
<script type="text/javascript" src="../externals/jush/modules/jush-txt.js"></script>
<script type="text/javascript" src="../externals/jush/modules/jush-<?php 
                echo $jush;
                ?>
.js"></script>
<script type="text/javascript">
<?php 
                if ($tables) {
                    $links = array();
                    foreach ($tables as $table => $type) {
                        $links[] = preg_quote($table, '/');
                    }
                    echo "var jushLinks = { {$jush}: [ '" . is_adminer_escape(ME) . (support("table") ? "table=" : "select=") . "\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
                    foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
                        echo "jushLinks.{$val} = jushLinks.{$jush};\n";
                    }
                }
                ?>
bodyLoad('<?php 
                echo is_object($connection) ? substr($connection->server_info, 0, 3) : "";
                ?>
');
</script>
<?php 
            }
            $this->databasesPrint($missing);
            if (DB == "" || !$missing) {
                echo "<p class='links'>" . (support("sql") ? "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"]) && !isset($_GET["import"])) . ">" . lang('SQL command') . "</a>\n<a href='" . h(ME) . "import='" . bold(isset($_GET["import"])) . ">" . lang('Import') . "</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";
                }
            }
            if ($_GET["ns"] !== "" && !$missing && DB != "") {
                echo '<a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create table') . "</a>\n";
                if (!$tables) {
                    echo "<p class='message'>" . lang('No tables.') . "\n";
                } else {
                    $this->tablesPrint($tables);
                }
            }
        }
    }
Esempio n. 8
0
echo $top;
?>
em;" onselectstart="return false;">
<script type="text/javascript">
var tablePos = {<?php 
echo implode(",", $table_pos_js) . "\n";
?>
};
var em = document.getElementById('schema').offsetHeight / <?php 
echo $top;
?>
;
document.onmousemove = schemaMousemove;
document.onmouseup = function (ev) {
	schemaMouseup(ev, '<?php 
echo is_adminer_escape(DB);
?>
');
};
</script>
<?php 
foreach ($schema as $name => $table) {
    echo "<div class='table' style='top: " . $table["pos"][0] . "em; left: " . $table["pos"][1] . "em;' onmousedown='schemaMousedown(this, event);'>";
    echo '<a href="' . h(ME) . 'table=' . urlencode($name) . '"><b>' . h($name) . "</b></a>";
    foreach ($table["fields"] as $field) {
        $val = '<span' . type_class($field["type"]) . ' title="' . h($field["full_type"] . ($field["null"] ? " NULL" : '')) . '">' . h($field["field"]) . '</span>';
        echo "<br>" . ($field["primary"] ? "<i>{$val}</i>" : $val);
    }
    foreach ((array) $table["references"] as $target_name => $refs) {
        foreach ($refs as $left => $ref) {
            $left1 = $left - $table_pos[$name][1];
Esempio n. 9
0
         $name = $field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : $key);
         if ($name != "") {
             $rank++;
             $names[$key] = $name;
             $column = idf_escape($key);
             $href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key);
             $desc = "&desc%5B0%5D=1";
             echo '<th onmouseover="columnMouse(this);" onmouseout="columnMouse(this, \' hidden\');">';
             echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || !$order && $is_group && $group[0] == $column ? $desc : '')) . '">';
             // $order[0] == $key - COUNT(*)
             echo apply_sql_function($val["fun"], $name) . "</a>";
             //! columns looking like functions
             echo "<span class='column hidden'>";
             echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
             if (!$val["fun"]) {
                 echo '<a href="#fieldset-search" onclick="selectSearch(\'' . h(is_adminer_escape($key)) . '\'); return false;" title="' . lang('Search') . '" class="text jsonly"> =</a>';
             }
             echo "</span>";
         }
         $functions[$key] = $val["fun"];
         next($select);
     }
 }
 $lengths = array();
 if ($_GET["modify"]) {
     foreach ($rows as $row) {
         foreach ($row as $key => $val) {
             $lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
         }
     }
 }