Ejemplo n.º 1
0
/** Drop old object and create a new one
* @param string drop old object query
* @param string create new object query
* @param string drop new object query
* @param string create test object query
* @param string drop test object query
* @param string
* @param string
* @param string
* @param string
* @param string
* @param string
* @return null adminer_redirect in success
*/
function drop_create($drop, $create, $drop_created, $test, $drop_test, $location, $message_drop, $message_alter, $message_create, $old_name, $new_name)
{
    if ($_POST["drop"]) {
        query_adminer_redirect($drop, $location, $message_drop);
    } elseif ($old_name == "") {
        query_adminer_redirect($create, $location, $message_create);
    } elseif ($old_name != $new_name) {
        $created = queries($create);
        queries_adminer_redirect($location, $message_alter, $created && queries($drop));
        if ($created) {
            queries($drop_created);
        }
    } else {
        queries_adminer_redirect($location, $message_alter, queries($test) && queries($drop_test) && queries($drop) && queries($create));
    }
}
Ejemplo n.º 2
0
<?php

$TYPE = $_GET["type"];
$row = $_POST;
if ($_POST && !$error) {
    $link = substr(ME, 0, -1);
    if ($_POST["drop"]) {
        query_adminer_redirect("DROP TYPE " . idf_escape($TYPE), $link, lang('Type has been dropped.'));
    } else {
        query_adminer_redirect("CREATE TYPE " . idf_escape(trim($row["name"])) . " {$row['as']}", $link, lang('Type has been created.'));
    }
}
page_header($TYPE != "" ? lang('Alter type') . ": " . h($TYPE) : lang('Create type'), $error);
if (!$row) {
    $row["as"] = "AS ";
}
?>

<form action="" method="post">
<p>
<?php 
if ($TYPE != "") {
    echo "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm() . ">\n";
} else {
    echo "<input name='name' value='" . h($row['name']) . "' autocapitalize='off'>\n";
    textarea("as", $row["as"]);
    echo "<p><input type='submit' value='" . lang('Save') . "'>\n";
}
?>
<input type="hidden" name="token" value="<?php 
echo $token;
Ejemplo n.º 3
0
/** Redirect by remembered queries
* @param string
* @param string
* @param bool
* @return bool
*/
function queries_adminer_redirect($location, $message, $redirect)
{
    list($queries, $time) = queries(null);
    return query_adminer_redirect($queries, $location, $message, $redirect, false, !$redirect, $time);
}
Ejemplo n.º 4
0
                if (count($databases) == 1 || $db != "") {
                    // ignore empty lines but always try to create single database
                    if (!create_database($db, $row["collation"])) {
                        $success = false;
                    }
                    $last = $db;
                }
            }
            queries_adminer_redirect(ME . "db=" . urlencode($last), lang('Database has been created.'), $success);
        }
    } else {
        // alter database
        if (!$row["collation"]) {
            adminer_redirect(substr(ME, 0, -1));
        }
        query_adminer_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE {$row['collation']}" : ""), substr(ME, 0, -1), lang('Database has been altered.'));
    }
}
page_header(DB != "" ? lang('Alter database') : lang('Create database'), $error, array(), h(DB));
$collations = collations();
$name = DB;
if ($_POST) {
    $name = $row["name"];
} elseif (DB != "") {
    $row["collation"] = db_collation(DB, $collations);
} elseif ($jush == "sql") {
    // propose database name with limited privileges
    foreach (get_vals("SHOW GRANTS") as $grant) {
        if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $grant, $match) && $match[1]) {
            $name = stripcslashes(idf_unescape("`{$match['2']}`"));
            break;
Ejemplo n.º 5
0
<?php

$row = $_POST;
if ($_POST && !$error) {
    $link = preg_replace('~ns=[^&]*&~', '', ME) . "ns=";
    if ($_POST["drop"]) {
        query_adminer_redirect("DROP SCHEMA " . idf_escape($_GET["ns"]), $link, lang('Schema has been dropped.'));
    } else {
        $name = trim($row["name"]);
        $link .= urlencode($name);
        if ($_GET["ns"] == "") {
            query_adminer_redirect("CREATE SCHEMA " . idf_escape($name), $link, lang('Schema has been created.'));
        } elseif ($_GET["ns"] != $name) {
            query_adminer_redirect("ALTER SCHEMA " . idf_escape($_GET["ns"]) . " RENAME TO " . idf_escape($name), $link, lang('Schema has been altered.'));
            //! sp_rename in MS SQL
        } else {
            adminer_redirect($link);
        }
    }
}
page_header($_GET["ns"] != "" ? lang('Alter schema') : lang('Create schema'), $error);
if (!$row) {
    $row["name"] = $_GET["ns"];
}
?>

<form action="" method="post">
<p><input name="name" id="name" value="<?php 
echo h($row["name"]);
?>
" autocapitalize="off">
Ejemplo n.º 6
0
                }
                if (preg_match('~ WITH GRANT OPTION~', $row[0])) {
                    //! don't check inside strings and identifiers
                    $grants["{$match['2']}{$val['2']}"]["GRANT OPTION"] = true;
                }
            }
        }
        if (preg_match("~ IDENTIFIED BY PASSWORD '([^']+)~", $row[0], $match)) {
            $old_pass = $match[1];
        }
    }
}
if ($_POST && !$error) {
    $old_user = isset($_GET["host"]) ? q($USER) . "@" . q($_GET["host"]) : "''";
    if ($_POST["drop"]) {
        query_adminer_redirect("DROP USER {$old_user}", ME . "privileges=", lang('User has been dropped.'));
    } else {
        $new_user = q($_POST["user"]) . "@" . q($_POST["host"]);
        // if $_GET["host"] is not set then $new_user is always different
        $pass = $_POST["pass"];
        if ($pass != '' && !$_POST["hashed"]) {
            // compute hash in a separate query so that plain text password is not saved to history
            $pass = $connection->result("SELECT PASSWORD(" . q($pass) . ")");
            $error = !$pass;
        }
        $created = false;
        if (!$error) {
            if ($old_user != $new_user) {
                $created = queries(($connection->server_info < 5 ? "GRANT USAGE ON *.* TO" : "CREATE USER") . " {$new_user} IDENTIFIED BY PASSWORD " . q($pass));
                $error = !$created;
            } elseif ($pass != $old_pass) {
Ejemplo n.º 7
0
<?php

$TABLE = $_GET["trigger"];
$name = $_GET["name"];
$trigger_options = trigger_options();
$row = (array) trigger($name) + array("Trigger" => $TABLE . "_bi");
if ($_POST) {
    if (!$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_options["Event"]) && in_array($_POST["Type"], $trigger_options["Type"])) {
        // don't use drop_create() because there may not be more triggers for the same action
        $on = " ON " . table($TABLE);
        $drop = "DROP TRIGGER " . idf_escape($name) . ($jush == "pgsql" ? $on : "");
        $location = ME . "table=" . urlencode($TABLE);
        if ($_POST["drop"]) {
            query_adminer_redirect($drop, $location, lang('Trigger has been dropped.'));
        } else {
            if ($name != "") {
                queries($drop);
            }
            queries_adminer_redirect($location, $name != "" ? lang('Trigger has been altered.') : lang('Trigger has been created.'), queries(create_trigger($on, $_POST)));
            if ($name != "") {
                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">
Ejemplo n.º 8
0
if ($_POST && !$error) {
    $name = trim($row["name"]);
    $as = " AS\n{$row['select']}";
    $location = ME . "table=" . urlencode($name);
    $message = lang('View has been altered.');
    if ($_GET["materialized"]) {
        $type = "MATERIALIZED VIEW";
    } else {
        $type = "VIEW";
        if ($jush == "pgsql") {
            $status = table_status($name);
            $type = $status ? strtoupper($status["Engine"]) : $type;
        }
    }
    if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type != "MATERIALIZED VIEW") {
        query_adminer_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . adminer_table($name) . $as, $location, $message);
    } else {
        $temp_name = $name . "_adminer_" . uniqid();
        drop_create("DROP {$type} " . adminer_table($TABLE), "CREATE {$type} " . adminer_table($name) . $as, "DROP {$type} " . adminer_table($name), "CREATE {$type} " . adminer_table($temp_name) . $as, "DROP {$type} " . adminer_table($temp_name), $_POST["drop"] ? substr(ME, 0, -1) : $location, lang('View has been dropped.'), $message, lang('View has been created.'), $TABLE, $name);
    }
}
if (!$_POST && $TABLE != "") {
    $row = view($TABLE);
    $row["name"] = $TABLE;
    if (!$error) {
        $error = error();
    }
}
page_header($TABLE != "" ? lang('Alter view') : lang('Create view'), $error, array("table" => $TABLE), h($TABLE));
?>
Ejemplo n.º 9
0
<?php

$EVENT = $_GET["event"];
$intervals = array("YEAR", "QUARTER", "MONTH", "DAY", "HOUR", "MINUTE", "WEEK", "SECOND", "YEAR_MONTH", "DAY_HOUR", "DAY_MINUTE", "DAY_SECOND", "HOUR_MINUTE", "HOUR_SECOND", "MINUTE_SECOND");
$statuses = array("ENABLED" => "ENABLE", "DISABLED" => "DISABLE", "SLAVESIDE_DISABLED" => "DISABLE ON SLAVE");
$row = $_POST;
if ($_POST && !$error) {
    if ($_POST["drop"]) {
        query_adminer_redirect("DROP EVENT " . idf_escape($EVENT), substr(ME, 0, -1), lang('Event has been dropped.'));
    } elseif (in_array($row["INTERVAL_FIELD"], $intervals) && isset($statuses[$row["STATUS"]])) {
        $schedule = "\nON SCHEDULE " . ($row["INTERVAL_VALUE"] ? "EVERY " . q($row["INTERVAL_VALUE"]) . " {$row['INTERVAL_FIELD']}" . ($row["STARTS"] ? " STARTS " . q($row["STARTS"]) : "") . ($row["ENDS"] ? " ENDS " . q($row["ENDS"]) : "") : "AT " . q($row["STARTS"])) . " ON COMPLETION" . ($row["ON_COMPLETION"] ? "" : " NOT") . " PRESERVE";
        queries_adminer_redirect(substr(ME, 0, -1), $EVENT != "" ? lang('Event has been altered.') : lang('Event has been created.'), queries(($EVENT != "" ? "ALTER EVENT " . idf_escape($EVENT) . $schedule . ($EVENT != $row["EVENT_NAME"] ? "\nRENAME TO " . idf_escape($row["EVENT_NAME"]) : "") : "CREATE EVENT " . idf_escape($row["EVENT_NAME"]) . $schedule) . "\n" . $statuses[$row["STATUS"]] . " COMMENT " . q($row["EVENT_COMMENT"]) . rtrim(" DO\n{$row['EVENT_DEFINITION']}", ";") . ";"));
    }
}
page_header($EVENT != "" ? lang('Alter event') . ": " . h($EVENT) : lang('Create event'), $error);
if (!$row && $EVENT != "") {
    $rows = get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = " . q(DB) . " AND EVENT_NAME = " . q($EVENT));
    $row = reset($rows);
}
?>

<form action="" method="post">
<table cellspacing="0">
<tr><th><?php 
echo lang('Name');
?>
<td><input name="EVENT_NAME" value="<?php 
echo h($row["EVENT_NAME"]);
?>
" maxlength="64" autocapitalize="off">
<tr><th title="datetime"><?php 
Ejemplo n.º 10
0
<?php

$SEQUENCE = $_GET["sequence"];
$row = $_POST;
if ($_POST && !$error) {
    $link = substr(ME, 0, -1);
    $name = trim($row["name"]);
    if ($_POST["drop"]) {
        query_adminer_redirect("DROP SEQUENCE " . idf_escape($SEQUENCE), $link, lang('Sequence has been dropped.'));
    } elseif ($SEQUENCE == "") {
        query_adminer_redirect("CREATE SEQUENCE " . idf_escape($name), $link, lang('Sequence has been created.'));
    } elseif ($SEQUENCE != $name) {
        query_adminer_redirect("ALTER SEQUENCE " . idf_escape($SEQUENCE) . " RENAME TO " . idf_escape($name), $link, lang('Sequence has been altered.'));
    } else {
        adminer_redirect($link);
    }
}
page_header($SEQUENCE != "" ? lang('Alter sequence') . ": " . h($SEQUENCE) : lang('Create sequence'), $error);
if (!$row) {
    $row["name"] = $SEQUENCE;
}
?>

<form action="" method="post">
<p><input name="name" value="<?php 
echo h($row["name"]);
?>
" autocapitalize="off">
<input type="submit" value="<?php 
echo lang('Save');
?>
Ejemplo n.º 11
0
    ksort($row["source"]);
    // enforce input order
    $target = array();
    foreach ($row["source"] as $key => $val) {
        $target[$key] = $row["target"][$key];
    }
    $row["target"] = $target;
    if ($jush == "sqlite") {
        queries_adminer_redirect($location, $message, recreate_table($TABLE, $TABLE, array(), array(), array(" {$name}" => $_POST["drop"] ? "" : " " . format_foreign_key($row))));
    } else {
        $alter = "ALTER TABLE " . table($TABLE);
        $drop = "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name);
        if ($_POST["drop"]) {
            query_adminer_redirect($alter . $drop, $location, $message);
        } else {
            query_adminer_redirect($alter . ($name != "" ? "{$drop}," : "") . "\nADD" . format_foreign_key($row), $location, $message);
            $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "<br>{$error}";
            //! no partitioning
        }
    }
}
page_header(lang('Foreign key'), $error, array("table" => $TABLE), h($TABLE));
if ($_POST) {
    ksort($row["source"]);
    if ($_POST["add"]) {
        $row["source"][] = "";
    } elseif ($_POST["change"] || $_POST["change-js"]) {
        $row["target"] = array();
    }
} elseif ($name != "") {
    $foreign_keys = foreign_keys($TABLE);