1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
<?php
/**
* SQL shell.
*
* Copyright 1999-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL-2). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl LGPL-2
* @package Horde
*/
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('horde', array(
'permission' => array('horde:administration:sqlshell')
));
$db = $injector->getInstance('Horde_Db_Adapter');
$q_cache = $session->get('horde', 'sql_query_cache', Horde_Session::TYPE_ARRAY);
$title = _("SQL Shell");
$vars = $injector->getInstance('Horde_Variables');
if ($vars->get('list-tables') || ($command = trim($vars->sql))) {
$session->checkToken($vars->token);
}
if ($vars->get('list-tables')) {
$description = 'LIST TABLES';
$result = $db->tables();
sort($result);
$command = null;
} elseif ($command = trim($vars->sql)) {
// Keep a cache of prior queries for convenience.
if (($key = array_search($command, $q_cache)) !== false) {
unset($q_cache[$key]);
}
$q_cache[] = $command;
$q_cache = array_slice($q_cache, -20);
$session->set('horde', 'sql_query_cache', $q_cache);
// Parse out the query results.
try {
$result = $db->select(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
} catch (Horde_Db_Exception $e) {
$notification->push($e);
}
}
$view = new Horde_View(array(
'templatePath' => HORDE_TEMPLATES . '/admin'
));
$view->session = $session;
$view->addHelper('Horde_Core_View_Helper_Help');
$view->addHelper('Text');
$view->action = Horde::url('admin/sqlshell.php');
$view->command = $command;
$view->q_cache = $q_cache;
$view->title = $title;
if (isset($result)) {
$keys = null;
$rows = array();
$view->results = true;
try {
if (is_object($result) && $result->columnCount()) {
while ($row = $result->fetch(Horde_Db::FETCH_ASSOC)) {
if (is_null($keys)) {
$keys = array();
foreach ($row as $key => $val) {
$keys[] = Horde_String::convertCharset($key, $conf['sql']['charset'], 'UTF-8');
}
}
$tmp = array();
foreach ($row as $val) {
$tmp[] = Horde_String::convertCharset($val, $conf['sql']['charset'], 'UTF-8');
}
$rows[] = $tmp;
}
} elseif (is_array($result)) {
foreach ($result as $val) {
if (is_null($keys)) {
$keys[] = isset($description) ? $description : '';
}
$rows[] = array(
Horde_String::convertCharset($val, $conf['sql']['charset'], 'UTF-8')
);
}
}
} catch (Horde_Db_Exception $e) {
$notification->push($e);
}
if (is_null($keys)) {
$view->success = true;
} else {
$view->keys = $keys;
$view->rows = $rows;
}
}
$page_output->addScriptFile('stripe.js', 'horde');
$page_output->header(array(
'title' => $title
));
require HORDE_TEMPLATES . '/admin/menu.inc';
echo $view->render('sqlshell');
$page_output->footer();
|