This repository was archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmysql_exec.php
More file actions
73 lines (69 loc) · 3.04 KB
/
mysql_exec.php
File metadata and controls
73 lines (69 loc) · 3.04 KB
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
<!Doctype Html>
<?php
session_start();
$status = $_SESSION['status'];
if($status == "1"){
if($_SESSION['logged_in']=="1"){
echo "<p style=\"color:red;\"><b>You are already logged in!!!</b></p>";
$_SESSION['logged_in']="0";
}}else if($status != "1"){
header("Location: /404.php");}
?>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" type="text/css" href="newstyle.css">
<meta HTTP-EQUIV="refresh" CONTENT="300;URL=logout.php">
</head>
<body>
<h1 style="text-align: center;">Admin Panel</h1>
<div id="blueLink">
<a href="logout.php">Logout</a> 
<a href="options.php">Home</a><hr>
</div>
<p>You can execute shell commands seperately from MySQL commands</p>
<form action="" name="query" id="query" method="post">
DBNAM: <input type="text" id="mysql_get" name="mysql_get" placeholder="ex: custom" value="<?php echo $_SESSION[udb];?>"></input><br><br>
HOST :    <input type="text" id="host" name="host" placeholder="localhost" value="<?php echo $_SESSION['host'];?>"></input><br><br>
USER :    <input type="text" id="username" name="username" value="<?php echo $_SESSION['mysql_user'];?>"></input><br><br>
PASS :     <input type="password" id="password" name="password" value="<?php echo $_SESSION['mysql_pass'];?>"></input></br><br>
QUERY:   <textarea id="myquery" name="myquery" placeholder="SELECT * FROM test;" value="<?php echo $_SESSION['query'];?>"></textarea><br><br>
<button type="Submit" value="Submit">Submit</button>
</form>
<script>
var input = document.getElementById('mysql_get');
input.focus();
input.select();
</script>
</body>
<?php
$udb=$_POST['mysql_get'];//Database
$user=$_POST['username'];
$pass=$_POST['password'];
$query=$_POST['myquery'];//Commands
$host=$_POST['host'];
//If the variables are not empty, continue
if (isset($udb, $user, $pass, $query, $host)){
//Set all current values as session variables below
$_SESSION['saved_info']="1";$_SESSION['udb']="$udb";$_SESSION['mysql_user']="$user";$_SESSION['mysql_pass']="$pass";$_SESSION['query']="$query";$_SESSION['host']="$host";
echo "<br> MySQL Query results: <br>";
include("data.php");
$databaseName = $_POST[mysql_get];
$query = $_POST[myquery];
$db = mysqli_connect($host,$user,$pass,$udb) or die("<p style=\"color:red;\"><b>Error: </b> connection to MySQL failed. Please re-enter information and try again.</p>");
mysqli_query($db, $query) or die("Unable to access MYSQL DataBase");
$result = mysqli_query($db, $query);
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
$stringArray = json_encode($row);
$stringArray = str_replace(",", "<br>", $stringArray);
$stringArray = str_replace(array('[', ']', '}', '"'), "", $stringArray);
$stringArray = str_replace("{", "<br>", $stringArray);
$stringArray = str_replace(":", ": ", $stringArray);
echo $stringArray;
$mysqli_close($db);
//Set session variable for mysql.php
$_SESSION['run_seperate']="$query";
include 'mysql.php';
}
?>
</html>