diff --git a/app/exec/app_config.php b/app/exec/app_config.php index 7210459daa..4d2a439b7e 100644 --- a/app/exec/app_config.php +++ b/app/exec/app_config.php @@ -1,36 +1,43 @@ - \ No newline at end of file diff --git a/app/exec/app_languages.php b/app/exec/app_languages.php index 99b43b7d34..20009613dd 100644 --- a/app/exec/app_languages.php +++ b/app/exec/app_languages.php @@ -1,5 +1,15 @@ PHP Manual"; -$text['description-php']['es-cl'] = "Utilice el siguiente enlace como referencia para PHP: Manual PHP"; -$text['description-php']['pt-pt'] = "Utilize a ligação seguinte como referência para o PHP: PHP Manual"; -$text['description-php']['fr-fr'] = "Utiliser le lien suivant comme référence pour le PHP: Manuel PHP"; -$text['description-php']['pt-br'] = "Utilize a ligação seguinte como referência para o PHP: PHP Manual "; -$text['description-php']['pl'] = "Aby użyć odniesienia do PHP kliknij na ten link: PHP manual"; -$text['description-php']['sv-se'] = "Använd följande länk som en referens gällande PHP: PHP Manual "; -$text['description-php']['uk'] = "Посилання на довідку PHP: PHP Manual"; -$text['description-php']['de-at'] = "Benutzen Sie folgenden Link als PHP Referenz: PHP Manual"; +$text['description-sql']['en-us'] = "Execute statements against the database."; +$text['description-sql']['es-cl'] = "Ejecutar instrucciones de consulta contra la base de datos."; +$text['description-sql']['pt-pt'] = "Executar instruções de consulta no banco de dados."; +$text['description-sql']['fr-fr'] = "Exécuter les instructions de requête contre la base de données."; +$text['description-sql']['pt-br'] = "Executar instruções de consulta no banco de dados."; +$text['description-sql']['pl'] = "Wykonać polecenie zapytania do bazy danych."; +$text['description-sql']['sv-se'] = "Utför fråge uttalanden mot databasen."; +$text['description-sql']['uk'] = "Виконання операторів запитів до бази даних."; +$text['description-sql']['de-at'] = "Führen Sie Abfrage-Anweisungen für die Datenbank."; -$text['description-execute']['en-us'] = "Provides a conventient way to execute system, PHP, and switch commands."; +$text['description-php']['en-us'] = "Execute PHP commands. See: PHP Manual"; +$text['description-php']['es-cl'] = "Utilice el siguiente enlace como referencia para PHP: Manual PHP"; +$text['description-php']['pt-pt'] = "Utilize a ligação seguinte como referência para o PHP: PHP Manual"; +$text['description-php']['fr-fr'] = "Utiliser le lien suivant comme référence pour le PHP: Manuel PHP"; +$text['description-php']['pt-br'] = "Utilize a ligação seguinte como referência para o PHP: PHP Manual"; +$text['description-php']['pl'] = "Aby użyć odniesienia do PHP kliknij na ten link: PHP Manual"; +$text['description-php']['sv-se'] = "Använd följande länk som en referens gällande PHP: PHP Manual"; +$text['description-php']['uk'] = "Посилання на довідку PHP: PHP Manual"; +$text['description-php']['de-at'] = "Benutzen Sie folgenden Link als PHP Referenz: \ No newline at end of file diff --git a/app/exec/exec.php b/app/exec/exec.php index 437a321e8e..95fff44ebf 100644 --- a/app/exec/exec.php +++ b/app/exec/exec.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): @@ -27,7 +27,7 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; -if (permission_exists('exec_command_line') || permission_exists('exec_php_command') || permission_exists('exec_switch')) { +if (permission_exists('exec_view')) { //access granted } else { @@ -48,12 +48,13 @@ else { $setting_preview = ($_SESSION["editor"]["live_preview"]["boolean"] != '') ? $_SESSION["editor"]["live_preview"]["boolean"] : 'true'; //get the html values and set them as variables - $handler = ($_POST["handler"] != '') ? trim($_POST["handler"]) : 'switch'; + $handler = ($_REQUEST["handler"] != '') ? trim($_REQUEST["handler"]) : ((permission_exists('exec_switch')) ? 'switch' : null); $cmd = trim($_POST["cmd"]); //set editor mode switch ($handler) { case 'php': $mode = 'php'; break; + case 'sql': $mode = 'sql'; break; default: $mode = 'text'; } @@ -61,14 +62,26 @@ else { require_once "resources/header.php"; $document['title'] = $text['title-command']; +//pdo voicemail database connection + if (permission_exists('exec_sql')) { + require_once "sql_query_pdo.php"; + } + //scripts and styles ?> @@ -150,32 +204,82 @@ else { ".$text['label-execute']."\n"; - echo "

"; - echo $text['description-execute']."\n"; - echo "

"; + echo ""; + echo " "; + echo " "; + if (permission_exists('exec_sql')) { + echo " "; + } + echo " "; + echo "
"; + echo " ".$text['label-execute']."\n"; + echo "

"; + echo $text['description-execute']."\n"; + echo "
"; + echo " "; + echo " \n"; + if (permission_exists('exec_sql_backup')) { + echo " 0) ? "?id=".$_REQUEST['id'] : null)."'\" value='".$text['button-backup']."'>\n"; + } + echo " "; + echo "
"; + echo "
"; //html form - echo "
\n"; + echo "\n"; + echo "\n"; //sql db id echo ""; echo "\n"; echo " "; echo " "; - echo " \n"; echo "
"; + echo " "; - echo " "; - echo " "; - echo " "; - if (file_exists($_SERVER["PROJECT_ROOT"]."/app/edit/") && permission_exists('script_editor_view')) { + if (permission_exists('exec_switch') || permission_exists('exec_php') || permission_exists('exec_command') || permission_exists('exec_sql')) { + echo " "; + echo " "; + echo " "; + } + if (permission_exists('script_editor_view') && file_exists($_SERVER["PROJECT_ROOT"]."/app/edit/")) { echo " "; echo " "; } echo "
"; - echo " \n"; - if (permission_exists('exec_switch')) { echo "\n"; } - if (permission_exists('exec_php_command')) { echo "\n"; } - if (permission_exists('exec_command_line')) { echo "\n"; } - echo "
\n"; - echo "
"; - echo " "; - echo "     ".$text['label-reset']."\n"; - echo "


"; - echo "
"; + echo " \n"; + if (permission_exists('exec_switch')) { echo "\n"; } + if (permission_exists('exec_php')) { echo "\n"; } + if (permission_exists('exec_command')) { echo "\n"; } + if (permission_exists('exec_sql')) { echo "\n"; } + echo "
\n"; + echo "
"; + //sql controls + if (permission_exists('exec_sql')) { + echo " "; + echo " ".$text['label-table']."
"; + echo " \n"; + echo "

\n"; + echo " ".$text['label-result_type']."
"; + echo " \n"; + echo "

\n"; + echo "
"; + } + echo " "; + echo "     ".$text['label-reset']."\n"; + echo "


"; + echo "
"; echo " \n"; @@ -183,12 +287,13 @@ else { echo "
"; + echo "
" + echo " " ?> - + @@ -286,7 +391,8 @@ else {
- "; echo "
"; @@ -313,7 +419,9 @@ else { highlightGutterLine: false, useSoftTabs: false }); - editor.getSession().setMode({path:'ace/mode/php', inline:true}); + + editor.getSession().setMode({path:'ace/mode/php', inline:true}); + document.getElementById('editor').style.fontSize=''; focus_editor(); @@ -329,6 +437,8 @@ else { return true; } }); + //remove certain keyboard shortcuts + editor.commands.bindKey("Ctrl-T", null); //new browser tab "; + echo "".$text['label-results']."\n"; + echo "

\n"; + echo "\n"; + echo ""; + } //show the footer require_once "resources/footer.php"; diff --git a/app/sql_query/sql_backup.php b/app/exec/sql_backup.php similarity index 98% rename from app/sql_query/sql_backup.php rename to app/exec/sql_backup.php index d213c8f91d..ee324eae00 100644 --- a/app/sql_query/sql_backup.php +++ b/app/exec/sql_backup.php @@ -26,7 +26,7 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; -if (permission_exists('sql_query_backup')) { +if (permission_exists('exec_sql_backup')) { //access granted } else { diff --git a/app/sql_query/sql_db_conversion.php b/app/exec/sql_db_conversion.php similarity index 100% rename from app/sql_query/sql_db_conversion.php rename to app/exec/sql_db_conversion.php diff --git a/app/sql_query/sql_query_db.php b/app/exec/sql_query_db.php similarity index 73% rename from app/sql_query/sql_query_db.php rename to app/exec/sql_query_db.php index d952e4b79d..cd7cf8bbbd 100644 --- a/app/sql_query/sql_query_db.php +++ b/app/exec/sql_query_db.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): @@ -26,7 +26,7 @@ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; -if (if_group("admin") || if_group("superadmin")) { +if (permission_exists('exec_sql')) { //access granted } else { @@ -51,15 +51,16 @@ require_once "resources/paging.php"; echo "\n"; echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; - echo " \n"; echo " \n"; @@ -72,12 +73,7 @@ require_once "resources/paging.php"; if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] > 0) { - $num_rows = $row['num_rows']; - } - else { - $num_rows = '0'; - } + $num_rows = ($row['num_rows'] > 0) ? $row['num_rows'] : '0'; } //prepare to page the results @@ -102,28 +98,28 @@ require_once "resources/paging.php"; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; - echo "
".$text['header-databases'].""; + echo " ".$text['header-databases'].""; + echo " \n"; if (if_group("superadmin")) { - echo " \n"; + echo " \n"; } echo "
\n"; + echo " \n"; echo " ".$text['description-databases'].".

\n"; echo "
\n"; + echo "
\n"; echo "\n"; echo th_order_by('database_type', $text['label-type'], $order_by, $order); echo th_order_by('database_host', $text['label-host'], $order_by, $order); echo th_order_by('database_name', $text['label-name'], $order_by, $order); echo th_order_by('database_description', $text['label-description'], $order_by, $order); - echo "\n"; + echo "\n"; echo "\n"; if ($result_count > 0) { foreach($result as $row) { - echo "\n"; + $tr_link = "href='exec.php?id=".$row['database_uuid']."'"; + echo "\n"; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; - echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } + $c = ($c == 0) ? 1 : 0; } //end foreach unset($sql, $result, $row_count); } //end if results diff --git a/app/sql_query/sql_query_pdo.php b/app/exec/sql_query_pdo.php similarity index 100% rename from app/sql_query/sql_query_pdo.php rename to app/exec/sql_query_pdo.php diff --git a/app/exec/sql_query_result.php b/app/exec/sql_query_result.php new file mode 100644 index 0000000000..a8eb39f3b1 --- /dev/null +++ b/app/exec/sql_query_result.php @@ -0,0 +1,267 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (permission_exists('exec_sql')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//pdo database connection + if (strlen($_REQUEST['id']) > 0) { + require_once "sql_query_pdo.php"; + } + +if (count($_POST)>0) { + $sql_type = trim($_POST["sql_type"]); + $sql_cmd = trim($_POST["cmd"]); + $table_name = trim($_POST["table_name"]); + + $header = "\n"; + $header .= "\n"; + $header .= ""; + $header .= "\n"; + $header .= "\n"; + + $footer = "\n"; + $footer .= "\n"; + + + if ($sql_type == '') { + + echo $header; + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + + //determine queries to run and show + if ($sql_cmd != '') { $sql_array = array_filter(explode(";", $sql_cmd)); } + if ($table_name != '') { $sql_array[] = "select * from ".$table_name; } + $show_query = (sizeof($sql_array) > 1) ? true : false; + + reset($sql_array); + foreach($sql_array as $sql_index => $sql) { + $sql = trim($sql); + + if (sizeof($sql_array) > 1 || $show_query) { + if ($sql_index > 0) { echo "


"; } + echo "".$sql.";
"; + } + + $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try { + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + echo "".$text['label-records'].": ".count($result).""; + echo "

\n"; + } + catch(PDOException $e) { + echo "".$text['label-error'].""; + echo "

\n"; + echo $e->getMessage(); + echo "

\n"; + exit; + } + + echo "
\n"; - echo " 
".$row['database_type']." ".$row['database_host']." ".$row['database_name']." ".$row['database_name']." ".$row['database_description']." \n"; - echo " $v_link_label_edit\n"; + echo " "; + echo " ".$v_link_label_edit."\n"; echo "
\n"; + $x = 0; + foreach ($result[0] as $key => $value) { + echo ""; + $column_array[$x++] = $key; + } + + $x = 1; + foreach ($result as &$row) { + if ($x++ > 1000) { break; } + echo "\n"; + foreach ($column_array as $column_index => $column) { + echo ""; + } + echo "\n"; + $c = ($c == 0) ? 1 : 0; + } + echo "
".$key."
".$row[$column]." 
\n"; + echo "
\n"; + + unset($result, $column_array); + } + echo $footer; + } + + if ($sql_type == "inserts") { + echo $header; + + $sql = trim($sql); + + //get the table data + $sql = (strlen($sql_cmd) == 0) ? "select * from ".$table_name : $sql_cmd; + + if (strlen($sql) > 0) { + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + } + else { + echo "".$text['label-error']."\n"; + echo "

\n"; + echo "
".print_r($db->errorInfo(), true)."
\n"; + echo "

\n"; + exit; + } + + $x = 0; + foreach ($result[0] as $key => $value) { + $column_array[$x++] = $key; + } + + $column_array_count = count($column_array); + + foreach ($result as &$row) { + echo "insert into ".$table_name." ("; + $x = 1; + foreach ($column_array as $column) { + if ($column != "menuid" && $column != "menuparentid") { + echo $column.(($x < $column_array_count) ? "," : null); + } + $x++; + } + echo ") "; + echo "values ( "; + $x = 1; + foreach ($column_array as $column) { + if ($column != "menuid" && $column != "menuparentid") { + echo (!is_null($row[$column])) ? "\"".check_str($row[$column])."\"".(($x < $column_array_count) ? ',' : null) : 'null'; + } + $x++; + } + echo ");
\n"; + } + } + echo $footer; + } + + if ($sql_type == "csv") { + + //set the headers + header('Content-type: application/octet-binary'); + header('Content-Disposition: attachment; filename='.$table_name.'.csv'); + + //get the table data + $sql = trim($sql); + $sql = "select * from ".$table_name; + if (strlen($sql) > 0) { + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + } + else { + echo "".$text['label-error']."\n"; + echo "

\n"; + echo "
".print_r($db->errorInfo(), true)."
\n"; + echo "

\n"; + exit; + } + + $x = 0; + foreach ($result[0] as $key => $value) { + $column_array[$x++] = $key; + } + //column names + echo '"'.implode('","', $column_array).'"'."\r\n"; + //column values + foreach ($result as &$row) { + $x = 1; + foreach ($column_array as $column) { + echo '"'.check_str($row[$column]).'"'.(($x++ < count($column_array)) ? ',' : null); + } + echo "\n"; + } + } + } +} + +?> diff --git a/app/sql_query/app_config.php b/app/sql_query/app_config.php deleted file mode 100644 index 082570598a..0000000000 --- a/app/sql_query/app_config.php +++ /dev/null @@ -1,31 +0,0 @@ - \ No newline at end of file diff --git a/app/sql_query/app_languages.php b/app/sql_query/app_languages.php deleted file mode 100644 index 8b8499a13c..0000000000 --- a/app/sql_query/app_languages.php +++ /dev/null @@ -1,173 +0,0 @@ - \ No newline at end of file diff --git a/app/sql_query/app_menu.php b/app/sql_query/app_menu.php deleted file mode 100644 index da51170b1b..0000000000 --- a/app/sql_query/app_menu.php +++ /dev/null @@ -1,18 +0,0 @@ - \ No newline at end of file diff --git a/app/sql_query/root.php b/app/sql_query/root.php deleted file mode 100644 index 55f9565d6a..0000000000 --- a/app/sql_query/root.php +++ /dev/null @@ -1,87 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2012 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -// make sure the PATH_SEPARATOR is defined - if (!defined("PATH_SEPARATOR")) { - if (strpos($_ENV["OS"], "Win") !== false) { - define("PATH_SEPARATOR", ";"); - } else { - define("PATH_SEPARATOR", ":"); - } - } - - // make sure the document_root is set - $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]); - if(PHP_SAPI == 'cli'){ - chdir(pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME)); - $script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]); - $dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME)); - if (file_exists('/project_root.php')) { - $path = '/'; - } else { - $i = 1; - $path = ''; - while ($i < count($dirs)) { - $path .= '/' . $dirs[$i]; - if (file_exists($path. '/project_root.php')) { - break; - } - $i++; - } - } - $_SERVER["DOCUMENT_ROOT"] = $path; - }else{ - $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); - } - $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); -// try to detect if a project path is being used - if (!defined('PROJECT_PATH')) { - if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) { - define('PROJECT_PATH', '/fusionpbx'); - } elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) { - define('PROJECT_PATH', ''); - } else { - $dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME))); - $i = 1; - $path = $_SERVER["DOCUMENT_ROOT"]; - while ($i < count($dirs)) { - $path .= '/' . $dirs[$i]; - if (file_exists($path. '/project_root.php')) { - break; - } - $i++; - } - if(!file_exists($path. '/project_root.php')){ - die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance"); - } - $project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path); - define('PROJECT_PATH', $project_path); - } - $_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH); - set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]); - } - -?> \ No newline at end of file diff --git a/app/sql_query/sql_query.php b/app/sql_query/sql_query.php deleted file mode 100644 index e2a268093f..0000000000 --- a/app/sql_query/sql_query.php +++ /dev/null @@ -1,164 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2013 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -if (permission_exists('sql_query_execute')) { - //access granted -} -else { - echo "access denied"; - exit; -} - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//show the header - require_once "resources/header.php"; - $document['title'] = $text['title-sql_query']; - -//pdo voicemail database connection - require_once "sql_query_pdo.php"; - -//show the content - //edit area - echo " \n"; - echo " "; - - echo ""; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "
".$text['header-sql_query']."\n"; - echo " \n"; - echo " \n"; - if (strlen($_REQUEST['id']) > 0) { - echo " \n"; - } - else { - echo " \n"; - } - echo "

\n"; - echo "