-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
146 lines (134 loc) · 4.39 KB
/
index.php
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require_once 'config.php';
session_start();
$mensaje = '';
$db_server = DB_SERVER;
$db_name = DB_NAME;
$db_username = DB_USERNAME;
$db_password = '';
function probar_coneccion($db_server, $db_username, $db_password, $db_name)
{
$probar=array();
$probar['conexion']=false;
$probar['existe']=false;
$mysqli = new mysqli($db_server, $db_username, $db_password, $db_name);
$mensaje="";
if (!mysqli_connect_error())
{
$probar['conexion']=true;
$sql = "SHOW TABLES";
$result = $mysqli->query($sql);
if($result->num_rows>0)
{
$probar['existe']=true;
}
}
return $probar;
}
function eliminartablas($db_server, $db_username , $db_password, $db_name)
{
$probar=probar_coneccion($db_server, $db_username , $db_password, $db_name);
$retorna=true;
if($probar['conexion']&&$probar['existe'])
{
$mysqli = new mysqli($db_server, $db_username, $db_password, $db_name);
$sql = "SELECT CONCAT('drop table ',table_name,'; ') FROM information_schema.tables WHERE table_schema ='".$db_name."' ";
$result = $mysqli->query($sql);
while ($fila = $result->fetch_row()) {
echo $fila[0]."<br>";
$mysqli->query($fila[0]);
if (mysqli_connect_error())
{
echo "Error al eliminar la linea con nombre: ".$fila[0];
$retorna=false;
}
}
}
return $retorna;
}
if(@$_POST['enviar'])
{
$db_server = $_POST['db_server'];
$db_name = $_POST['db_name'];
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
$probar=probar_coneccion($db_server, $db_username , $db_password, $db_name);
if($probar['conexion'])
{
$_SESSION['db_password']=$db_password;
$_SESSION['db_server']=$db_server;
$_SESSION['db_name']=$db_name;
$_SESSION['db_username']=$db_username;
if($probar['existe'])
{
$mensaje="Existen datos en la base de datos ";
$mensaje.='<button type = "submit" name="eliminar" value="eliminar" class = "btn btn-primary">Eliminar</button><br><br>';
require_once 'formularioconexion.php';
}
else
{
require_once 'bigdump.php';
}
}
else
{
$mensaje="Los datos del formulario no van en la base de datos";
require_once 'formularioconexion.php';
}
}
else if(@$_POST['config']) {
// Database configuration
defined( 'DB_SERVER' ) or die( ':(' );
$probar=probar_coneccion(DB_SERVER, DB_USERNAME,DB_PASSWORD, DB_NAME);
if($probar['conexion'])
{
$_SESSION['db_password']=DB_PASSWORD;
$_SESSION['db_server']=DB_SERVER;
$_SESSION['db_name']=DB_NAME;
$_SESSION['db_username']=DB_USERNAME;
if($probar['existe'])
{
$mensaje="Existen datos en la base de datos debes eliminarlos ";
$mensaje.='<button type = "submit" name="eliminar" value="eliminar" class = "btn btn-primary">Eliminar</button><br><br>';
require_once 'formularioconexion.php';
}
else
{
$db_password = DB_PASSWORD; //el resto se carga en el principio
require_once 'bigdump.php';
}
}
else
{
$mensaje="Los datos del archivo config no van en la base de datos";
require_once 'formularioconexion.php';
}
}
else if(@$_POST['eliminar'])
{
$db_server = $_POST['db_server'];
$db_name = $_POST['db_name'];
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
if(eliminartablas($db_server, $db_username, $db_password, $db_name))
{
$mensaje = "Se han eliminado todas las tablas vuelve a enviar para continuar";
require_once 'formularioconexion.php';
}
else
{
$mensaje = "No se han podido eliminar todoas las tablas prueba a dar a eliminar otra vez ";
$mensaje.='<button type = "submit" name="eliminar" value="eliminar" class = "btn btn-primary">Eliminar</button>';
require_once 'formularioconexion.php';
}
}
else if(@$_GET['start']) {
$db_password=$_SESSION['db_password'];
$db_server=$_SESSION['db_server'];
$db_name=$_SESSION['db_name'];
$db_username=$_SESSION['db_username'];
require_once 'bigdump.php';
}
else {
require_once 'formularioconexion.php';
}