فهرست منبع

Remove SQL Query and rename to app/command

markjcrane 5 سال پیش
والد
کامیت
ea7e9a68d9
7فایلهای تغییر یافته به همراه21 افزوده شده و 1472 حذف شده
  1. 5 10
      app_config.php
  2. 16 86
      command.php
  3. 0 157
      sql_backup.php
  4. 0 501
      sql_db_conversion.php
  5. 0 131
      sql_query_db.php
  6. 0 242
      sql_query_pdo.php
  7. 0 345
      sql_query_result.php

+ 5 - 10
app_config.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
 	//application details
 	//application details
-		$apps[$x]['name'] = "Exec";
+		$apps[$x]['name'] = "Command";
 		$apps[$x]['uuid'] = "1dd98ca6-95f1-e728-7e8f-137fe18dc23c";
 		$apps[$x]['uuid'] = "1dd98ca6-95f1-e728-7e8f-137fe18dc23c";
 		$apps[$x]['category'] = "System";
 		$apps[$x]['category'] = "System";
 		$apps[$x]['subcategory'] = "";
 		$apps[$x]['subcategory'] = "";
@@ -30,23 +30,18 @@
 
 
 	//permission details
 	//permission details
 		$y=0;
 		$y=0;
-		$apps[$x]['permissions'][$y]['name'] = "exec_view";
+		$apps[$x]['permissions'][$y]['name'] = "command_view";
 		$apps[$x]['permissions'][$y]['menu']['uuid'] = "06493580-9131-ce57-23cd-d42d69dd8526";
 		$apps[$x]['permissions'][$y]['menu']['uuid'] = "06493580-9131-ce57-23cd-d42d69dd8526";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$y++;
 		$y++;
-		$apps[$x]['permissions'][$y]['name'] = "exec_command";
+		$apps[$x]['permissions'][$y]['name'] = "command_shell";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$y++;
 		$y++;
-		$apps[$x]['permissions'][$y]['name'] = "exec_php";
+		$apps[$x]['permissions'][$y]['name'] = "command_php";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$y++;
 		$y++;
-		$apps[$x]['permissions'][$y]['name'] = "exec_switch";
+		$apps[$x]['permissions'][$y]['name'] = "command_switch";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$y++;
 		$y++;
-		$apps[$x]['permissions'][$y]['name'] = "exec_sql";
-		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
-		$y++;
-		//$apps[$x]['permissions'][$y]['name'] = "exec_sql_backup";
-		//$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 
 
 ?>
 ?>

+ 16 - 86
exec.php → command.php

@@ -31,7 +31,7 @@
 	require_once "resources/check_auth.php";
 	require_once "resources/check_auth.php";
 
 
 //permissions
 //permissions
-	if (permission_exists('exec_view')) {
+	if (permission_exists('command_view')) {
 		//access granted
 		//access granted
 	}
 	}
 	else {
 	else {
@@ -74,11 +74,6 @@
 	require_once "resources/header.php";
 	require_once "resources/header.php";
 	$document['title'] = $text['title-command'];
 	$document['title'] = $text['title-command'];
 
 
-//pdo database connection
-	if (permission_exists('exec_sql')) {
-		require_once "sql_query_pdo.php";
-	}
-
 //scripts and styles
 //scripts and styles
 	?>
 	?>
 	<script language="JavaScript" type="text/javascript">
 	<script language="JavaScript" type="text/javascript">
@@ -139,7 +134,7 @@
 						$('#response').show();
 						$('#response').show();
 						break;
 						break;
 				<?php } ?>
 				<?php } ?>
-				<?php if (permission_exists('exec_php')) { ?>
+				<?php if (permission_exists('command_php')) { ?>
 					case 'php':
 					case 'php':
 						document.getElementById('description').innerHTML = "<?php echo $text['description-php'];?>";
 						document.getElementById('description').innerHTML = "<?php echo $text['description-php'];?>";
 						editor.getSession().setMode({path:'ace/mode/php', inline:true}); //highlight without opening tag
 						editor.getSession().setMode({path:'ace/mode/php', inline:true}); //highlight without opening tag
@@ -154,30 +149,14 @@
 						$('#response').show();
 						$('#response').show();
 						break;
 						break;
 				<?php } ?>
 				<?php } ?>
-				<?php if (permission_exists('exec_command')) { ?>
+				<?php if (permission_exists('command_shell')) { ?>
 					case 'shell':
 					case 'shell':
 						document.getElementById('description').innerHTML = "<?php echo $text['description-shell'];?>";
 						document.getElementById('description').innerHTML = "<?php echo $text['description-shell'];?>";
 						editor.getSession().setMode('ace/mode/text');
 						editor.getSession().setMode('ace/mode/text');
 						$('#mode option[value=text]').prop('selected',true);
 						$('#mode option[value=text]').prop('selected',true);
-						<?php if (permission_exists('exec_sql')) { ?>
-							$('.sql_controls').hide();
-							document.getElementById('sql_type').selectedIndex = 0;
-							document.getElementById('table_name').selectedIndex = 0;
-							$('#iframe').prop('src','');
-							$('#sql_response').hide();
-						<?php } ?>
 						$('#response').show();
 						$('#response').show();
 						break;
 						break;
 				<?php } ?>
 				<?php } ?>
-				<?php if (permission_exists('exec_sql')) { ?>
-					case 'sql':
-						document.getElementById('description').innerHTML = "<?php echo $text['description-sql'];?>";
-						editor.getSession().setMode('ace/mode/sql');
-						$('#mode option[value=sql]').prop('selected',true);
-						$('.sql_controls').show();
-						$('#response').hide();
-						break;
-				<?php } ?>
 				default:
 				default:
 					break;
 					break;
 			}
 			}
@@ -188,10 +167,6 @@
 			editor.getSession().setValue('');
 			editor.getSession().setValue('');
 			$('#command').val('');
 			$('#command').val('');
 			$('#response').hide();
 			$('#response').hide();
-			<?php if (permission_exists('exec_sql')) { ?>
-				$('#iframe').prop('src','');
-				$('#sql_response').hide();
-			<?php } ?>
 			focus_editor();
 			focus_editor();
 		}
 		}
 	</script>
 	</script>
@@ -230,7 +205,7 @@
 	echo "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
 	echo "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
 	echo "	<tr>";
 	echo "	<tr>";
 	echo "		<td valign='top' align='left' width='50%'>";
 	echo "		<td valign='top' align='left' width='50%'>";
-	echo "			<b>".$text['label-execute']."</b>\n";
+	echo "			<b>".$text['label-command']."</b>\n";
 	echo "		</td>";
 	echo "		</td>";
 	echo "		<td valign='top' align='right' nowrap='nowrap'>";
 	echo "		<td valign='top' align='right' nowrap='nowrap'>";
 
 
@@ -238,60 +213,25 @@
 	echo "				<img src=\"data:image/png;base64, ".$image_base64."\" /><input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='code' id='code' value=''>\n";
 	echo "				<img src=\"data:image/png;base64, ".$image_base64."\" /><input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='code' id='code' value=''>\n";
 	echo "				&nbsp; &nbsp; &nbsp;\n";
 	echo "				&nbsp; &nbsp; &nbsp;\n";
 
 
-	if (permission_exists('exec_switch') || permission_exists('exec_php') || permission_exists('exec_command') || permission_exists('exec_sql')) {
+	if (permission_exists('command_switch') || permission_exists('command_php') || 
+permission_exists('command_shell')) {
 		echo "				<select name='handler' id='handler' class='formfld' style='width:100px;' onchange=\"handler=this.value;set_handler(this.value);\">\n";
 		echo "				<select name='handler' id='handler' class='formfld' style='width:100px;' onchange=\"handler=this.value;set_handler(this.value);\">\n";
-		if (permission_exists('exec_switch')) { echo "<option value='switch' ".(($handler == 'switch') ? "selected='selected'" : null).">".$text['label-switch']."</option>\n"; }
-		if (permission_exists('exec_php')) { echo "<option value='php' ".(($handler == 'php') ? "selected='selected'" : null).">".$text['label-php']."</option>\n"; }
-		if (permission_exists('exec_command')) { echo "<option value='shell' ".(($handler == 'shell') ? "selected='selected'" : null).">".$text['label-shell']."</option>\n"; }
-		if (permission_exists('exec_sql')) { echo "<option value='sql' ".(($handler == 'sql') ? "selected='selected'" : null).">".$text['label-sql']."</option>\n"; }
+		if (permission_exists('command_switch')) { echo "<option value='switch' ".(($handler == 
+'switch') ? "selected='selected'" : null).">".$text['label-switch']."</option>\n"; }
+		if (permission_exists('command_php')) { echo "<option value='php' ".(($handler == 'php') ? 
+"selected='selected'" : null).">".$text['label-php']."</option>\n"; }
+		if (permission_exists('command_shell')) { echo "<option value='shell' ".(($handler == 'shell') ? 
+"selected='selected'" : null).">".$text['label-shell']."</option>\n"; }
 		echo "				</select>\n";
 		echo "				</select>\n";
 	}
 	}
 
 
-	//sql controls
-	if (permission_exists('exec_sql')) {
-		echo "				<span class='sql_controls' ".(($handler != 'sql') ? "style='display: none;'" : null).">";
-		//echo "					".$text['label-table']."<br />";
-		echo "					<select name='table_name' id='table_name' class='formfld'>\n";
-		echo "						<option value=''></option>\n";
-		switch ($db_type) {
-			case 'sqlite': $sql = "select name from sqlite_master where type='table' order by name;"; break;
-			case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and table_type='BASE TABLE' order by table_name"; break;
-			case 'mysql': $sql = "show tables"; break;
-		}
-		$database = new database;
-		$result = $database->select($sql, null, 'all');
-		if (is_array($result) && @sizeof($result) != 0) {
-			foreach ($result as &$row) {
-				$row = array_values($row);
-				echo "					<option value='".escape($row[0])."'>".escape($row[0])."</option>\n";
-			}
-		}
-		unset($sql, $result, $row);
-		echo "					</select>\n";
-		//echo "					<br /><br />\n";
-		//echo "					".$text['label-result_type']."<br />";
-		echo "					<select name='sql_type' id='sql_type' class='formfld'>\n";
-		echo "						<option value=''>".$text['option-result_type_view']."</option>\n";
-		echo "						<option value='csv'>".$text['option-result_type_csv']."</option>\n";
-		echo "						<option value='inserts'>".$text['option-result_type_insert']."</option>\n";
-		echo "					</select>\n";
-		echo "				</span>";
-	}
 	echo "					<input type='button' class='btn' style='margin-top: 0px;' title=\"".$text['button-execute']." [Ctrl+Enter]\" value=\"    ".$text['button-execute']."    \" onclick=\"$('form#frm').submit();\">";
 	echo "					<input type='button' class='btn' style='margin-top: 0px;' title=\"".$text['button-execute']." [Ctrl+Enter]\" value=\"    ".$text['button-execute']."    \" onclick=\"$('form#frm').submit();\">";
 	echo "					<input type='button' class='btn' style='margin-top: 0px;' title=\"\" value=\"    ".$text['button-reset']."    \" onclick=\"reset_editor();\">";
 	echo "					<input type='button' class='btn' style='margin-top: 0px;' title=\"\" value=\"    ".$text['button-reset']."    \" onclick=\"reset_editor();\">";
 
 
-	//if (permission_exists('exec_sql')) {
-	//	echo "			<span class='sql_controls' ".(($handler != 'sql') ? "style='display: none;'" : null).">";
-	//	//echo "				<input type='button' class='btn' alt='".$text['button-select_database']."' onclick=\"document.location.href='sql_query_db.php'\" value='".$text['button-select_database']."'>\n";
-	//	if (permission_exists('exec_sql_backup')) {
-	//		echo "			<input type='button' class='btn' alt='".$text['button-backup']."' onclick=\"document.location.href='sql_backup.php".((strlen($_REQUEST['id']) > 0) ? "?id=".$_REQUEST['id'] : null)."'\" value='".$text['button-backup']."'>\n";
-	//	}
-	//	echo "			</span>";
-	//}
 	echo "		</td>";
 	echo "		</td>";
 	echo "	</tr>";
 	echo "	</tr>";
 	echo "	<tr><td colspan='2'>\n";
 	echo "	<tr><td colspan='2'>\n";
-	echo 			$text['description-execute']."\n";
+	echo 			$text['description-command']."\n";
 	echo "	</tr>\n";
 	echo "	</tr>\n";
 	echo "</table>";
 	echo "</table>";
 	echo "<br>";
 	echo "<br>";
@@ -337,7 +277,6 @@
 					$modes['lua'] = 'Lua';
 					$modes['lua'] = 'Lua';
 					$modes['text'] = 'Text';
 					$modes['text'] = 'Text';
 					$modes['xml'] = 'XML';
 					$modes['xml'] = 'XML';
-					$modes['sql'] = 'SQL';
 					foreach ($modes as $value => $label) {
 					foreach ($modes as $value => $label) {
 						$selected = $value == $mode ? 'selected' : null;
 						$selected = $value == $mode ? 'selected' : null;
 						echo "<option value='".$value."' ".$selected.">".escape($label)."</option>\n";
 						echo "<option value='".$value."' ".$selected.">".escape($label)."</option>\n";
@@ -462,12 +401,12 @@
 			$result = '';
 			$result = '';
 			switch ($handler) {
 			switch ($handler) {
 				case 'shell':
 				case 'shell':
-					if (permission_exists('exec_command') && $command_authorized) {
+					if (permission_exists('command_shell') && $command_authorized) {
 						$result = shell_exec($command . " 2>&1");
 						$result = shell_exec($command . " 2>&1");
 					}
 					}
 					break;
 					break;
 				case 'php':
 				case 'php':
-					if (permission_exists('exec_php') && $command_authorized) {
+					if (permission_exists('command_php') && $command_authorized) {
 						ob_start();
 						ob_start();
 						eval($command);
 						eval($command);
 						$result = ob_get_contents();
 						$result = ob_get_contents();
@@ -475,7 +414,7 @@
 					}
 					}
 					break;
 					break;
 				case 'switch':
 				case 'switch':
-					if (permission_exists('exec_switch') && $command_authorized) {
+					if (permission_exists('command_switch') && $command_authorized) {
 						$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
 						$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
 						if ($fp) { 
 						if ($fp) { 
 							$result = event_socket_request($fp, 'api '.$command);
 							$result = event_socket_request($fp, 'api '.$command);
@@ -493,15 +432,6 @@
 		}
 		}
 	}
 	}
 
 
-//sql result
-	if (permission_exists('exec_sql')) {
-		echo "<span id='sql_response' style='display: none;'>";
-		echo "<b>".$text['label-results']."</b>\n";
-		echo "<br /><br />\n";
-		echo "<iframe name='iframe' id='iframe' style='width: calc(100% - 3px); height: 500px; background-color: #fff; border: 1px solid #c0c0c0;'></iframe>\n";
-		echo "</span>";
-	}
-
 //show the footer
 //show the footer
 	require_once "resources/footer.php";
 	require_once "resources/footer.php";
 
 

+ 0 - 157
sql_backup.php

@@ -1,157 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2014
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-
-//disabled
-	echo "access denied";
-	exit;
-
-//includes
-	include "root.php";
-	require_once "resources/require.php";
-	require_once "resources/check_auth.php";
-
-//check permisions
-	if (permission_exists('exec_sql_backup')) {
-		//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";
-	}
-
-//get the $apps array from the installed apps from the core and mod directories
-	$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
-	$x = 0;
-	foreach ($config_list as &$config_path) {
-		include($config_path);
-		$x++;
-	}
-
-//define a function that checks if the field exists
-	function field_exists($apps, $table_name, $field_name) {
-		$result = false;
-		foreach ($apps as &$row) {
-			$tables = $row["db"];
-			foreach ($tables as &$table) {
-				if ($table['table'] == $table_name) {
-					foreach ($table["fields"] as &$field) {
-						if ($field['deprecated'] != "true") {
-							if (is_array($field["name"])) {
-								if ($field["name"]["text"] == $field_name) {
-									$result = true;
-									break;
-								}
-							}
-							else {
-								if ($field["name"] == $field_name) {
-									$result = true;
-									break;
-								}
-							}
-						}
-					}
-				}
-			}
-		}
-		return $result;
-	}
-
-//set the headers
-	header('Content-type: application/octet-binary');
-	header('Content-Disposition: attachment; filename=database_backup.sql');
-
-//get the list of tables
-	if ($db_type == "sqlite") {
-		$sql = "select name from sqlite_master ";
-		$sql .= "where type='table' ";
-		$sql .= "order by name;";
-	}
-	if ($db_type == "pgsql") {
-		$sql = "select table_name as name ";
-		$sql .= "from information_schema.tables ";
-		$sql .= "where table_schema='public' ";
-		$sql .= "and table_type='BASE TABLE' ";
-		$sql .= "order by table_name ";
-	}
-	if ($db_type == "mysql") {
-		$sql = "show tables";
-	}
-	$database = new database;
-	$result_1 = $database->select($sql, null, 'all');
-	unset($sql);
-
-	if (is_array($result_1) && @sizeof($result_1) != 0) {
-		foreach ($result_1 as &$row_1) {
-			$row_1 = array_values($row_1);
-			$table_name = $row_1[0];
-
-			//get the table data
-				$sql = "select * from ".$table_name;
-				$database = new database;
-				$result_2 = $database->select($sql, null, 'all');
-				unset($sql);
-
-				foreach ($result_2[0] as $key => $value) {
-					if ($row_1[$column] != "db") {
-						if (field_exists($apps, $table_name, $key)) {
-							$column_array[] = $key;
-						}
-					}
-				}
-
-				$column_array_count = count($column_array);
-
-				foreach ($result_2 as &$row_2) {
-					foreach ($column_array as $column) {
-						$columns[] = $column;
-						$values[] = $row_2[$column] != '' ? "'".check_str($row_2[$column])."'" : 'null';
-					}
-					$sql = "insert into ".$table_name." (";
-					$sql .= implode(', ', $columns);
-					$sql .= ") values ( ";
-					$sql .= implode(', ', $values);
-					$sql .= ");";
-					echo $sql."\n";
-
-					unset($columns, $values);
-				}
-				unset($result_2, $row_2);
-
-			unset($column_array);
-		}
-	}
-	unset($result_1, $row_1);
-
-?>

+ 0 - 501
sql_db_conversion.php

@@ -1,501 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2012
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-
-//includes
-	include "root.php";
-	require_once "resources/require.php";
-	require_once "resources/check_auth.php";
-
-//check permissions
-	if (if_group("superadmin")) {
-		//access granted
-	}
-	else {
-		echo "access denied";
-		exit;
-	}
-
-//add multi-lingual support
-	$language = new text;
-	$text = $language->get();
-
-//show errors
-	ini_set('display_errors', '1');
-	//error_reporting (E_ALL); // Report everything
-	error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings
-
-//define the db file exists function
-	function db_field_exists ($tmp_array, $column) {
-		$result = false;
-		foreach ($tmp_array as &$row) {
-			if ($row[0] == $column) {
-				$result = true;
-			}
-			return $result;
-		}
-	}
-	//db_field_exists ($result_dest, $column)
-
-//destination info
-	//set the domain_uuid
-		$dest_domain_uuid = '1';
-
-	//set the database type
-		$db_dest_type = 'mysql'; //sqlite, mysql, pgsql, others with a manually created PDO connection
-
-	//sqlite: the dbfilename and db_file_path are automatically assigned however the values can be overidden by setting the values here.
-		//$dbfilename = 'fusionpbx.db'; //host name/ip address + '.db' is the default database filename
-		//$db_file_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure'; //the path is determined by a php variable
-
-	//mysql: database connection information
-		$db_host = '127.0.0.1'; //set the host only if the database is not local
-		$db_port = '3306';
-		$db_name = 'fusionpbx';
-		$db_username = 'fusionpbx';
-		$db_password = '';
-		$db_create_username = 'root';
-		$db_create_password = '';
-
-	//pgsql: database connection information
-		//$db_host = ''; //set the host only if the database is not local
-		//$db_port = '';
-		//$db_name = '';
-		//$db_username = '';
-		//$db_password = '';
-		//$db_create_username = '';
-		//$db_create_password = '';
-
-	//load data into the database
-
-		//create the sqlite database
-			if ($db_dest_type == "sqlite") {
-				//sqlite database will be created when the config.php is loaded and only if the database file does not exist
-				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
-				$file_contents = file_get_contents($filename);
-				unset($filename);
-				try {
-					$db_dest = new PDO('sqlite:'.$db_filepath.'/'.$db_filename); //sqlite 3
-					//$db_dest = new PDO('sqlite::memory:'); //sqlite 3
-					$db_dest->beginTransaction();
-				}
-				catch (PDOException $error) {
-					print $text['label-error'].": " . $error->getMessage() . "<br/>";
-					die();
-				}
-
-				//replace \r\n with \n then explode on \n
-					$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-				//loop line by line through all the lines of sql code
-					$stringarray = explode("\n", $file_contents);
-					$x = 0;
-					foreach($stringarray as $sql) {
-						try {
-							if(stristr($sql, 'CREATE TABLE') === FALSE) {
-								//not found do not execute
-							}
-							else {
-								//execute create table sql strings
-								$db_dest->query($sql);
-							}
-						}
-						catch (PDOException $error) {
-							echo $text['label-error'].": " . $error->getMessage() . " sql: $sql<br/>";
-						}
-						$x++;
-					}
-					unset ($file_contents, $sql);
-					$db_dest->commit();
-			}
-
-		//create the postgres database
-			if ($db_dest_type == "pgsql") {
-				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
-				$file_contents = file_get_contents($filename);
-
-				//if $db_create_username provided, attempt to create new PG role and database
-					if (strlen($db_create_username) > 0) {
-						//create the database connection
-							try {
-								if (strlen($db_port) == 0) { $db_port = "5432"; }
-								if (strlen($db_host) > 0) {
-									$db_dest = new PDO("pgsql:host={$db_host} port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1");
-								} else {
-									$db_dest = new PDO("pgsql:host=localhost port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1");
-								}
-							} catch (PDOException $error) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-								die();
-							}
-						//create the database, user, grant perms
-							$db_dest->exec("CREATE DATABASE {$db_name}");
-							$db_dest->exec("CREATE USER {$db_username} WITH PASSWORD '{$db_password}'");
-							$db_dest->exec("GRANT ALL ON {$db_name} TO {$db_username}");
-						//close database connection_aborted
-							$db_dest = null;
-					}
-
-				//open database connection with $db_name
-					try {
-						if (strlen($db_port) == 0) { $db_port = "5432"; }
-						if (strlen($db_host) > 0) {
-							$db_dest = new PDO("pgsql:host={$db_host} port={$db_port} dbname={$db_name} user={$db_username} password={$db_password}");
-						} else {
-							$db_dest = new PDO("pgsql:host=localhost port={$db_port} user={$db_username} password={$db_password} dbname={$db_name}");
-						}
-					}
-					catch (PDOException $error) {
-						print $text['label-error'].": " . $error->getMessage() . "<br/>";
-						die();
-					}
-
-				//replace \r\n with \n then explode on \n
-					$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-				//loop line by line through all the lines of sql code
-					$stringarray = explode("\n", $file_contents);
-					$x = 0;
-					foreach($stringarray as $sql) {
-						if (strlen($sql) > 3) {
-							try {
-								if(stristr($sql, 'CREATE TABLE') === FALSE) {
-									//not found do not execute
-								}
-								else {
-									//execute create table sql strings
-									$db_dest->query($sql);
-								}
-							}
-							catch (PDOException $error) {
-								echo $text['label-error'].": " . $error->getMessage() . " sql: $sql<br/>";
-								die();
-							}
-						}
-						$x++;
-					}
-					unset ($file_contents, $sql);
-			}
-
-		//create the mysql database
-		if ($db_dest_type == "mysql") {
-			$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/mysql.sql';
-			$file_contents = file_get_contents($filename);
-
-			//database connection
-				try {
-					if (strlen($db_host) == 0 && strlen($db_port) == 0) {
-						//if both host and port are empty use the unix socket
-						if (strlen($db_create_username) == 0) {
-							$db_dest = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8;", $db_username, $db_password);
-						}
-						else {
-							$db_dest = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8;", $db_create_username, $db_create_password);						}
-					}
-					else {
-						if (strlen($db_port) == 0) {
-							//leave out port if it is empty
-							if (strlen($db_create_username) == 0) {
-								$db_dest = new PDO("mysql:host=$db_host;charset=utf8;", $db_username, $db_password);
-							}
-							else {
-								$db_dest = new PDO("mysql:host=$db_host;charset=utf8;", $db_create_username, $db_create_password);
-							}
-						}
-						else {
-							if (strlen($db_create_username) == 0) {
-								$db_dest = new PDO("mysql:host=$db_host;port=$db_port;charset=utf8;", $db_username, $db_password);
-							}
-							else {
-								$db_dest = new PDO("mysql:host=$db_host;port=$db_port;charset=utf8;", $db_create_username, $db_create_password);
-							}
-						}
-					}
-					$db_dest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-					$db_dest->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
-				}
-				catch (PDOException $error) {
-					if ($v_debug) {
-						print $text['label-error'].": " . $error->getMessage() . "<br/>";
-					}
-				}
-
-			//create the table, user and set the permissions only if the db_create_username was provided
-				if (strlen($db_create_username) > 0) {
-					//select the mysql database
-						try {
-							$db_dest->query("USE mysql;");
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-							}
-						}
-					//create user and set the permissions
-						try {
-							$tmp_sql = "CREATE USER '".$db_username."'@'%' IDENTIFIED BY '".$db_password."'; ";
-							$db_dest->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-							}
-						}
-					//set account to unlimitted use
-						try {
-							$tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'localhost' ";
-							$tmp_sql .= "IDENTIFIED BY '".$db_password."' ";
-							$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
-							$db_dest->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-							}
-						}
-					//create the database and set the create user with permissions
-						try {
-							$tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$db_name."; ";
-							$db_dest->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-							}
-						}
-					//set user permissions
-						try {
-							$db_dest->query("GRANT ALL PRIVILEGES ON ".$db_name.".* TO '".$db_username."'@'%'; ");
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-							}
-						}
-					//make the changes active
-						try {
-							$tmp_sql = "FLUSH PRIVILEGES; ";
-							$db_dest->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print $text['label-error'].": " . $error->getMessage() . "<br/>";
-							}
-						}
-				} //if (strlen($db_create_username) > 0)
-			//select the database
-				try {
-					$db_dest->query("USE ".$db_name.";");
-				}
-				catch (PDOException $error) {
-					if ($v_debug) {
-						print $text['label-error'].": " . $error->getMessage() . "<br/>";
-					}
-				}
-
-			//add the defaults data into the database
-				//replace \r\n with \n then explode on \n
-					$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-				//loop line by line through all the lines of sql code
-					$stringarray = explode("\n", $file_contents);
-					$x = 0;
-					foreach($stringarray as $sql) {
-						if (strlen($sql) > 3) {
-							try {
-								if(stristr($sql, 'CREATE TABLE') === FALSE) {
-									//not found do not execute
-								}
-								else {
-									//execute create table sql strings
-									$db_dest->query($sql);
-								}
-							}
-							catch (PDOException $error) {
-								//echo "error on line $x: " . $error->getMessage() . " sql: $sql<br/>";
-								//die();
-							}
-						}
-						$x++;
-					}
-					unset ($file_contents, $sql);
-		}
-
-//get the list of tables
-	if ($db_dest_type == "sqlite") {
-		$sql = "SELECT name FROM sqlite_master ";
-		$sql .= "WHERE type='table' ";
-		$sql .= "order by name;";
-	}
-	if ($db_dest_type == "pgsql") {
-		$sql = "select table_name as name ";
-		$sql .= "from information_schema.tables ";
-		$sql .= "where table_schema='public' ";
-		$sql .= "and table_type='BASE TABLE' ";
-		$sql .= "order by table_name ";
-	}
-	if ($db_dest_type == "mysql") {
-		$sql = "show tables";
-	}
-	//get the default schema structure
-		$prep_statement = $db_dest->prepare(check_sql($sql));
-		$prep_statement->execute();
-		$result_dest = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-	//clean the content from the table
-		foreach ($result_dest as &$row) {
-			$table_name = $row[0];
-			$sql = 'delete from '.$table_name;
-			//$db_dest->query($sql);
-		}
-
-	//add data into each table
-		foreach ($result_dest as &$row) {
-			//get the table name
-				$table_name = $row[0];
-
-			//$table_name = 'v_extensions';
-			//$db_dest_type = "sqlite";
-
-			//get the table source data
-				$destination_column_array='';
-				unset($destination_column_array);
-				if ($db_dest_type == "sqlite") {
-					$tmp_sql = "PRAGMA table_info($table_name);";
-				}
-				if ($db_dest_type == "pgsql") {
-
-				}
-				if ($db_dest_type == "mysql") {
-					$tmp_sql = "show columns from $table_name;";
-				}
-				if (strlen($tmp_sql) > 0) {
-					$prep_statement_2 = $db_dest->prepare(check_sql($tmp_sql));
-					//$prep_statement_2 = $db->prepare(check_sql($tmp_sql));
-					if ($prep_statement_2) {
-						$prep_statement_2->execute();
-						$result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC);
-					}
-					else {
-						echo "<b>".$text['label-error'].":</b>\n";
-						echo "<pre>\n";
-						print_r($db_dest->errorInfo());
-						echo "</pre>\n";
-					}
-					$x = 0;
-					foreach ($result2 as $row2) {
-						if ($db_dest_type == "sqlite") {
-							$destination_column_array[$x] = $row2['name'];
-						}
-						if ($db_dest_type == "mysql") {
-							$destination_column_array[$x] = $row2['Field'];
-						}
-						if ($db_dest_type == "pgsql") {
-
-						}
-						$x++;
-					}
-					/*
-						$x = 0;
-						foreach ($result2[0] as $key => $value) {
-							if ($db_dest_type == "sqlite" && $key == "name") {
-								$destination_column_array[$x] = $key;
-							}
-							$x++;
-						}
-					*/
-					$destination_column_array_count = count($destination_column_array);
-				}
-				unset($prep_statement_2, $result2);
-				//echo "<pre>\n";
-				//print_r($destination_column_array);
-				//echo "</pre>\n";
-
-			//get the table source data
-				$tmp_sql = "select * from $table_name";
-				if (strlen($tmp_sql) > 0) {
-					$prep_statement_2 = $db->prepare(check_sql($tmp_sql));
-					if ($prep_statement_2) {
-						$prep_statement_2->execute();
-						$result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC);
-					}
-					else {
-						echo "<b>".$text['label-error'].":</b>\n";
-						echo "<pre>\n";
-						print_r($db->errorInfo());
-						echo "</pre>\n";
-					}
-
-					$x = 0;
-					foreach ($result2[0] as $key => $value) {
-						$column_array[$x] = $key;
-						$x++;
-					}
-
-					foreach ($result2 as &$row) {
-						//build the sql query string
-							if (substr($table_name, 0, 2) == 'v_') {
-								$sql = "INSERT INTO $table_name (";
-								$x = 1;
-								foreach ($destination_column_array as $column) {
-									if ($x < $destination_column_array_count) {
-										$sql .= "".$column.", ";
-									}
-									else {
-										$sql .= "".$column."";
-									}
-									$x++;
-								}
-								$sql .= ") ";
-								$sql .= "VALUES( ";
-								$x = 1;
-								foreach ($destination_column_array as $column) {
-									if ($x < $destination_column_array_count) {
-										//if ($column == "domain_uuid") {
-										//	$sql .= "'".$dest_domain_uuid."',";
-										//}
-										//else {
-											$sql .= "'".check_str($row[$column])."', ";
-										//}
-									}
-									else {
-										//if ($column == "domain_uuid") {
-										//	$sql .= "'".$dest_domain_uuid."'";
-										//}
-										//else {
-											$sql .= "'".check_str($row[$column])."'";
-										//}
-									}
-									$x++;
-								}
-								$sql .= ");\n";
-							}
-						//add the sql into the destination database
-							echo $sql."<br />\n";
-							$db_dest->query($sql);
-					}
-				}
-		}
-
-?>

+ 0 - 131
sql_query_db.php

@@ -1,131 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2019
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-
-//includes
-	require_once "root.php";
-	require_once "resources/require.php";
-	require_once "resources/check_auth.php";
-
-//check permissions
-	if (permission_exists('exec_sql')) {
-		//access granted
-	}
-	else {
-		echo "access denied";
-		exit;
-	}
-
-//add multi-lingual support
-	$language = new text;
-	$text = $language->get();
-
-//add the header and title
-	require_once "resources/header.php";
-	$document['title'] = $text['title-databases'];
-
-//include paging
-	require_once "resources/paging.php";
-
-//get variables used to control the order
-	$order_by = $_GET["order_by"];
-	$order = $_GET["order"];
-
-//show the content
-
-	echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
-	echo "	<tr>\n";
-	echo "		<td width='50%' align='left' nowrap='nowrap'><b>".$text['header-databases']."</b></td>\n";
-	echo "		<td width='50%' align='right'>";
-	echo "		<input type='button' class='btn' alt='".$text['button-back']."' onclick=\"document.location.href='exec.php';\" value='".$text['button-back']."'>\n";
-	if (if_group("superadmin")) {
-		echo "	<input type='button' class='btn' alt='".$text['button-manage']."' onclick=\"document.location.href='/core/databases/databases.php';\" value='".$text['button-manage']."'>\n";
-	}
-	echo "		</td>\n";
-	echo "	</tr>\n";
-	echo "	<tr>\n";
-	echo "		<td align='left' colspan='2'>\n";
-	echo "			".$text['description-databases'].".<br /><br />\n";
-	echo "		</td>\n";
-	echo "	</tr>\n";
-	echo "</table>\n";
-
-	//prepare to page the results
-		$sql = "select count(*) from v_databases ";
-		$database = new database;
-		$num_rows = $database->select($sql, null, 'column');
-
-	//prepare to page the results
-		$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
-		$param = "";
-		$page = $_GET['page'];
-		if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
-		list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
-		$offset = $rows_per_page * $page;
-
-	//get the  list
-		$sql = str_replace('count(*)', '*', $sql);
-		$sql .= order_by($order_by, $order);
-		$sql .= limit_offset($rows_per_page, $offset);
-		$database = new database;
-		$result = $database->select($sql, null, 'all');
-		unset($sql);
-
-	$c = 0;
-	$row_style["0"] = "row_style0";
-	$row_style["1"] = "row_style1";
-
-	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
-	echo "<tr>\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 "<td class='list_control_icons' style='width: 25px;'>&nbsp;</td>\n";
-	echo "<tr>\n";
-
-	if (is_array($result) && @sizeof($result) != 0) {
-		foreach($result as $row) {
-			$tr_link = "href='exec.php?id=".escape($row['database_uuid'])."'";
-			echo "<tr ".$tr_link.">\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>".escape($row['database_type'])."&nbsp;</td>\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>".escape($row['database_host'])."&nbsp;</td>\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'><a href='exec.php?id=".escape($row['database_uuid'])."'>".escape($row['database_name'])."</a>&nbsp;</td>\n";
-			echo "	<td valign='top' class='row_stylebg'>".escape($row['database_description'])."&nbsp;</td>\n";
-			echo "	<td class='list_control_icons' style='width: 25px;'>";
-			echo "		<a href='exec.php?id=".escape($row['database_uuid'])."' alt='".$text['button-edit']."'>".$v_link_label_edit."</a>\n";
-			echo "	</td>\n";
-			echo "</tr>\n";
-			$c = ($c == 0) ? 1 : 0;
-		}
-	}
-	unset($result, $row);
-
-	echo "</table>";
-	echo "<br><br>";
-
-//include the footer
-	require_once "resources/footer.php";
-?>

+ 0 - 242
sql_query_pdo.php

@@ -1,242 +0,0 @@
-<?php
-/*
- FusionPBX
- Version: MPL 1.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is FusionPBX
-
- The Initial Developer of the Original Code is
- Mark J Crane <[email protected]>
- Portions created by the Initial Developer are Copyright (C) 2008-2012
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Mark J Crane <[email protected]>
- */
-
-//includes
-	require_once "root.php";
-	require_once "resources/require.php";
-	require_once "resources/check_auth.php";
-
-//check permissions
-	if (permission_exists('exec_sql')) {
-		//access granted
-	}
-	else {
-		echo "access denied";
-		exit;
-	}
-
- //set the default values
-	if (isset($db_file_path) > 0) {
-		$db_path = $db_file_path;
-		$db_name = $dbfilename;
-	}
-
-//get the db connection information
-	if (is_uuid($_REQUEST['id'])) {
-		$sql = "select * from v_databases ";
-		$sql .= "where database_uuid = :database_uuid ";
-		$parameters['database_uuid'] = $_REQUEST['id'];
-		$database = new database;
-		$row = $database->select($sql, $parameters, 'row');
-		if (is_array($row) && @sizeof($row) != 0) {
-			$db_type = $row["database_type"];
-			$db_host = $row["database_host"];
-			$db_port = $row["database_port"];
-			$db_name = $row["database_name"];
-			$db_username = $row["database_username"];
-			$db_password = $row["database_password"];
-			$db_path = $row["database_path"];
-		}
-		unset($sql, $parameters, $row);
-	}
-
-//unset the database connection
-	unset($db);
-
-if (!function_exists('get_db_field_names')) {
-	function get_db_field_names($db, $table, $db_name='fusionpbx') {
-		$query = sprintf('SELECT * FROM %s LIMIT 1', $table);
-		foreach ($db->query($query, PDO::FETCH_ASSOC) as $row) {
-			return array_keys($row);
-		}
-
-		// if we're still here, we need to try something else
-		$fields 	= array();
-		$driver = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
-		if ($driver == 'sqlite') {
-			$query 		= sprintf("Pragma table_info(%s);", $table);
-			$stmt 		= $db->prepare($query);
-			$result 	= $stmt->execute();
-			$rows 		= $stmt->fetchAll(PDO::FETCH_NAMED);
-			//printf('<pre>%s</pre>', print_r($rows, true));
-			$row_count 	= count($rows);
-			//printf('<pre>%s</pre>', print_r($rows, true));
-			for ($i = 0; $i < $row_count; $i++) {
-				array_push($fields, $rows[$i]['name']);
-			}
-			return $fields;
-		} else {
-			$query 		= sprintf("SELECT * FROM information_schema.columns
-			WHERE table_schema='%s' AND table_name='%s';"
-			, $db_name, $table
-			);
-			$stmt 		= $db->prepare($query);
-			$result 	= $stmt->execute();
-			$rows 		= $stmt->fetchAll(PDO::FETCH_NAMED);
-			$row_count 	= count($rows);
-			//printf('<pre>%s</pre>', print_r($rows, true));
-			for ($i = 0; $i < $row_count; $i++) {
-				array_push($fields, $rows[$i]['COLUMN_NAME']);
-			}
-			return $fields;
-		}
-	}
-}
-
-if ($db_type == "sqlite") {
-	if (!function_exists('phpmd5')) {
-		function phpmd5($string) {
-			return md5($string);
-		}
-	}
-
-	if (!function_exists('php_unix_timestamp')) {
-		function php_unix_timestamp($string) {
-			return strtotime($string);
-		}
-	}
-
-	if (!function_exists('phpnow')) {
-		function phpnow() {
-			return date("Y-m-d H:i:s");
-		}
-	}
-
-	if (!function_exists('php_left')) {
-		function php_left($string, $num) {
-			return substr($string, 0, $num);
-		}
-	}
-
-	if (!function_exists('php_right')) {
-		function php_right($string, $num) {
-			return substr($string, (strlen($string)-$num), strlen($string));
-		}
-	}
-
-	if (!function_exists('php_sqlite_data_type')) {
-		function php_sqlite_data_type($string, $field) {
-
-			//get the string between the start and end characters
-			$start = '(';
-			$end = ')';
-			$ini = stripos($string,$start);
-			if ($ini == 0) return "";
-			$ini += strlen($start);
-			$len = stripos($string,$end,$ini) - $ini;
-			$string = substr($string,$ini,$len);
-
-			$str_data_type = '';
-			$string_array = explode(',', $string);
-			foreach($string_array as $lnvalue) {
-				$fieldlistarray = explode (" ", $value);
-				unset($fieldarray, $string, $field);
-			}
-
-			return $str_data_type;
-		}
-	} //end function
-
-	//database connection
-	try {
-		//$db = new PDO('sqlite2:example.db'); //sqlite 2
-		//$db = new PDO('sqlite::memory:'); //sqlite 3
-		$db = new PDO('sqlite:'.realpath($db_path).'/'.$db_name); //sqlite 3
-
-		//add additional functions to SQLite so that they are accessible inside SQL
-		//bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
-		$db->sqliteCreateFunction('md5', 'phpmd5', 1);
-		$db->sqliteCreateFunction('unix_timestamp', 'php_unix_timestamp', 1);
-		$db->sqliteCreateFunction('now', 'phpnow', 0);
-		$db->sqliteCreateFunction('sqlitedatatype', 'php_sqlite_data_type', 2);
-		$db->sqliteCreateFunction('strleft', 'php_left', 2);
-		$db->sqliteCreateFunction('strright', 'php_right', 2);
-	}
-	catch (PDOException $error) {
-		print "error: " . $error->getMessage() . "<br/>";
-		die();
-	}
-} //end if db_type sqlite
-
-if ($db_type == "mysql") {
-	//database connection
-	try {
-		//mysql pdo connection
-			if (strlen($db_host) == 0 && strlen($db_port) == 0) {
-				//if both host and port are empty use the unix socket
-				$db = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;dbname=$db_name", $db_username, $db_password);
-			}
-			else {
-				if (strlen($db_port) == 0) {
-					//leave out port if it is empty
-					$db = new PDO("mysql:host=$db_host;dbname=$db_name;", $db_username, $db_password, array(
-					PDO::ATTR_ERRMODE,
-					PDO::ERRMODE_EXCEPTION
-					));
-				}
-				else {
-					$db = new PDO("mysql:host=$db_host;port=$db_port;dbname=$db_name;", $db_username, $db_password, array(
-					PDO::ATTR_ERRMODE,
-					PDO::ERRMODE_EXCEPTION
-					));
-				}
-			}
-	}
-	catch (PDOException $error) {
-		print "error: " . $error->getMessage() . "<br/>";
-		die();
-	}
-} //end if db_type mysql
-
-if ($db_type == "pgsql") {
-	//database connection
-	try {
-		if (strlen($db_host) > 0) {
-			if (strlen($db_port) == 0) { $db_port = "5432"; }
-			$db = new PDO("pgsql:host=$db_host port=$db_port dbname=$db_name user=$db_username password=$db_password");
-		}
-		else {
-			$db = new PDO("pgsql:dbname=$db_name user=$db_username password=$db_password");
-		}
-	}
-	catch (PDOException $error) {
-		print "error: " . $error->getMessage() . "<br/>";
-		die();
-	}
-} //end if db_type pgsql
-
-if ($db_type == "odbc") {
-	//database connection
-		try {
-			unset($db);
-			$db = new PDO("odbc:$db_name", "$db_username", "$db_password");
-		}
-		catch (PDOException $e) {
-		   echo 'Connection failed: ' . $e->getMessage();
-		}
-} //end if db_type odbc
-
-?>

+ 0 - 345
sql_query_result.php

@@ -1,345 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2019
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-
-//includes
-	include "root.php";
-	require_once "resources/require.php";
-	require_once "resources/check_auth.php";
-
-//check permissions
-	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";
-	}
-
-//check the captcha
-	$code = trim($_REQUEST["code"]);
-	$command_authorized = false;
-	if (strtolower($_SESSION['captcha']) == strtolower($code)) {
-		$command_authorized = true;
-	}
-	if (!$command_authorized) {
-		//catpcha invalid
-		exit;
-	}
-
-//get allowed table names
-	switch ($db_type) {
-		case 'sqlite': $sql = "select name from sqlite_master where type='table' order by name;"; break;
-		case 'pgsql': $sql = "select table_name as name from information_schema.tables where table_schema='public' and table_type='BASE TABLE' order by table_name"; break;
-		case 'mysql': $sql = "show tables"; break;
-	}
-	$database = new database;
-	$rows = $database->select($sql, null, 'all');
-	if (is_array($rows) && @sizeof($rows) != 0) {
-		foreach ($rows as $row) {
-			$tables[] = $row['name'];
-		}
-	}
-	unset($sql, $rows, $row);
-
-//show the content
-	if (is_array($_POST)) {
-		$sql_type = trim($_POST["sql_type"]);
-		$sql_cmd = trim($_POST["command"]);
-		$table_name = trim($_POST["table_name"]);
-	
-		$header = "<html>\n";
-		$header .= "<head>\n";
-		$header .= "<style type='text/css'>\n";
-		$header .= "\n";
-		$header .= "body {\n";
-		$header .= "	font-family: arial;\n";
-		$header .= "	font-size: 12px;\n";
-		$header .= "	color: #444;\n";
-		$header .= "}\n";
-		$header .= "\n";
-		$header .= "th {\n";
-		$header .= "	border-top: 1px solid #444;\n";
-		$header .= "	border-bottom: 1px solid #444;\n";
-		$header .= "	color: #fff;\n";
-		$header .= "	font-size: 12px;\n";
-		$header .= "	font-family: arial;\n";
-		$header .= "	font-weight: bold;\n";
-		$header .= "	background-color: #777;\n";
-		$header .= "	padding: 4px 7px;\n";
-		$header .= "	text-align: left;\n";
-		$header .= "}\n";
-		$header .= "\n";
-		$header .= ".row_style0 {\n";
-		$header .= "	background-color: #eee;\n";
-		$header .= "	border-bottom: 1px solid #999;\n";
-		$header .= "	border-left: 1px solid #fff;\n";
-		$header .= "	font-size: 12px;\n";
-		$header .= "	color: #444;\n";
-		$header .= "	text-align: left;\n";
-		$header .= "	padding: 4px 7px;\n";
-		$header .= "	text-align: left;\n";
-		$header .= "	vertical-align: top;\n";
-		$header .= "}\n";
-		$header .= "\n";
-		$header .= ".row_style0 a:link{ color:#444; }\n";
-		$header .= ".row_style0 a:visited{ color:#444; }\n";
-		$header .= ".row_style0 a:hover{ color:#444; }\n";
-		$header .= ".row_style0 a:active{ color:#444; }\n";
-		$header .= "\n";
-		$header .= ".row_style1 {\n";
-		$header .= "	border-bottom: 1px solid #999;\n";
-		$header .= "	border-left: 1px solid #eee;\n";
-		$header .= "	background-color: #fff;\n";
-		$header .= "	font-size: 12px;\n";
-		$header .= "	color: #444;\n";
-		$header .= "	text-align: left;\n";
-		$header .= "	padding: 4px 7px;\n";
-		$header .= "	text-align: left;\n";
-		$header .= "	vertical-align: top;\n";
-		$header .= "}\n";
-		$header .= "</style>";
-		$header .= "</head>\n";
-		$header .= "<body style='margin: 0; padding: 8;'>\n";
-
-		$footer = "<body>\n";
-		$footer .= "<html>\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 != '' && in_array($table_name, $tables)) { $sql_array[] = "select * from ".$table_name; }
-			$show_query = (sizeof($sql_array) > 1) ? true : false;
-
-			if (is_array($sql_array)) foreach($sql_array as $sql_index => $sql) {
-				$sql = trim($sql);
-
-				if (sizeof($sql_array) > 1 || $show_query) {
-					if ($sql_index > 0) { echo "<br /><br /><br />"; }
-					echo "<span style='display: block; font-family: monospace; padding: 8px; color: green; background-color: #eefff0;'>".escape($sql).";</span><br />";
-				}
-
-				$database = new database;
-				$result = $database->execute($sql, null, 'all');
-				$message = $database->message;
-
-				if ($message['message'] == 'OK' && $message['code'] == 200) {
-					echo "<b>".$text['label-records'].": ".count($result)."</b>";
-					echo "<br /><br />\n";
-				}
-				else {
-					echo "<b>".$text['label-error']."</b>";
-					echo "<br /><br />\n";
-					echo $message['message'].' ['.$message['code']."]<br />\n";
-					if (is_array($message['error']) && @sizeof($message['error']) != 0) {
-						foreach ($message['error'] as $error) {
-							echo "<pre>".$error."</pre><br /><br />\n";
-						}
-					}
-				}
-
-				echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
-				$x = 0;
-				if (is_array($result[0])) {
-					echo "<thead>\n";
-					echo "	<tr>\n";
-					foreach ($result[0] as $key => $value) {
-						echo "<th>".escape($key)."</th>\n";
-						$column_array[$x++] = $key;
-					}
-					echo "	</tr>\n";
-					echo "</thead>\n";
-				}
-				$x = 1;
-				if (is_array($result)) {
-					echo "<tbody>\n";
-					foreach ($result as &$row) {
-						if ($x++ > 1000) { break; }
-						echo "<tr>\n";
-						if (is_array($column_array)) {
-							foreach ($column_array as $column_index => $column) {
-								echo "<td class='".$row_style[$c]."' ".(($column_index == 0) ? "style='border-left: none;'" : null).">".escape($row[$column])."&nbsp;</td>\n";
-							}
-						}
-						echo "</tr>\n";
-						$c = ($c == 0) ? 1 : 0;
-					}
-					echo "</tbody>\n";
-				}
-				echo "</table>\n";
-				echo "<br>\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 && in_array($table_name, $tables)) ? "select * from ".$table_name : $sql_cmd;
-
-				if (strlen($sql) > 0) {
-					$database = new database;
-					$result = $database->execute($sql);
-					$message = $database->message;
-
-					if ($message['message'] != 'OK' || $message['code'] != 200) {
-						echo "<b>".$text['label-error']."</b>";
-						echo "<br /><br />\n";
-						echo $message['message'].' ['.$message['code']."]<br />\n";
-						if (is_array($message['error']) && @sizeof($message['error']) != 0) {
-							foreach ($message['error'] as $error) {
-								echo "<pre>".$error."</pre><br /><br />\n";
-							}
-						}
-						exit;
-					}
-
-					$x = 0;
-					if (is_array($result[0])) {
-						foreach ($result[0] as $key => $value) {
-							$column_array[$x++] = $key;
-						}
-					}
-
-					$column_array_count = count($column_array);
-					if (is_array($result)) {
-						foreach ($result as $index => &$row) {
-
-							echo "<div style='font-family: monospace; border-bottom: 1px solid #ccc; padding-bottom: 8px; ".($index != 0 ? 'padding-top: 8px;' : null)."'>\n";
-							echo "insert into ".$table_name." (";
-							if (is_array($column_array)) {
-								foreach ($column_array as $column) {
-									if ($column != "menuid" && $column != "menuparentid") {
-										$columns[] = $column;
-									}
-								}
-							}
-							if (is_array($columns) && sizeof($columns) > 0) {
-								echo implode(', ', $columns);
-							}
-							echo ") values (";
-							if (is_array($column_array)) {
-								foreach ($column_array as $column) {
-									if ($column != "menuid" && $column != "menuparentid") {
-										$values[] = $row[$column] != '' ? "'".escape($row[$column])."'" : 'null';
-									}
-								}
-							}
-							if (is_array($values) && sizeof($values) > 0) {
-								echo implode(', ', $values);
-							}
-							echo ");\n";
-							echo "</div>\n";
-							unset($columns, $values);
-						}
-					}
-
-				}
-			echo $footer;
-		}
-
-		if ($sql_type == "csv") {
-
-			//set the headers
-				header('Content-type: application/octet-binary');
-				if (strlen($sql_cmd) > 0) {
-					header('Content-Disposition: attachment; filename=data.csv');
-				}
-				else if (in_array($table_name, $tables)) {
-					header('Content-Disposition: attachment; filename='.$table_name.'.csv');
-				}
-
-			//get the table data
-				if (strlen($sql_cmd) > 0) {
-					$sql = $sql_cmd;
-				}
-				else if (in_array($table_name, $tables)) {
-					$sql = "select * from ".$table_name;
-				}
-				if (strlen($sql) > 0) {
-					$database = new database;
-					$result = $database->execute($sql);
-					$message = $database->message;
-
-					if ($message['message'] != 'OK' || $message['code'] != 200) {
-						echo "<b>".$text['label-error']."</b>";
-						echo "<br /><br />\n";
-						echo $message['message'].' ['.$message['code']."]<br />\n";
-						if (is_array($message['error']) && @sizeof($message['error']) != 0) {
-							foreach ($message['error'] as $error) {
-								echo "<pre>".$error."</pre><br /><br />\n";
-							}
-						}
-						exit;
-					}
-
-					//build the column array
-					$x = 0;
-					if (is_array($result[0])) {
-						foreach ($result[0] as $key => $value) {
-							$column_array[$x] = $key;
-							$x++;
-						}
-					}
-
-					//column names
-					echo '"'.implode('","', $column_array).'"'."\r\n";
-
-					//column values
-					if (is_array($result)) {
-						foreach ($result as &$row) {
-							$x = 1;
-							foreach ($column_array as $column) {
-								echo '"'.$row[$column].'"'.($x++ < count($column_array) ? ',' : null);
-							}
-							echo "\n";
-						}
-					}
-				}
-		}
-	}
-
-?>