forked from whinis/eve-jacknife
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
164 lines (157 loc) · 5.02 KB
/
update.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
if (isset ($_GET[ 'source']))
{
echo '<a <p> href="',$_SERVER['PHP_SELF'],'"> Back </ a> </ p>';
echo '<p> This is the code php file: </ p>';
$page = highlight_file($_SERVER [ 'SCRIPT_FILENAME'], TRUE);
$page = str_replace(
array ( '<code>', '/ code>', '','</ are >','< font color ="'),
array ( '<pre style="padding:1em;border:2px solid black;overflow:scroll">', '/ pre>', '','</ span >','< span style = "color:' ), $page);
echo $page;
echo '<a <p> href="',$_SERVER['PHP_SELF'],'"> Back </ a> </ p>';
echo '</ body> </ html>';
exit;
}
if(!file_exists("install.lock"))
die('JackKnife not Installed, Please Run the installer');
if(isset($_GET['sql'])){
include("eve.config.php");
session_start ();
if(!isset($_GET['sql'])){
header('Location: Installer.php?db=1');
}
function import_sql($filename) {
$handle = @gzopen($filename, "r"); // can open normal files, too.
$query = "";
$queries = 0;
while ($handle && !feof($handle)) {
$line = gzgets($handle, 1024); // keep string manipulations sane
if ($line != "" && substr($line, 0, 2) != "--") { // line doesnt start with comment
$query .= $line;
if (substr(trim($line), -1, 1) == ";") {
if (!mysql_query($query))
if(defined("DEBUG"))
echo("MYSQL Error: " . mysql_error() ."<Br><br>in query: $query");
else
echo("MYSQL Error: " . mysql_error());
$query = "";
$queries++;
}
}
}
return true;
}
$mysql=mysql_connect($sql,$sql_u,$sql_p);
if (!$mysql) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db);
$i=1;
$fNum=$_GET['sql'];
if(is_numeric($fNum)&& $fNum>=0 && $fNum<=$_SESSION['fileCount']){
$file="./SQL/".$_SESSION['files'][$fNum];
echo import_sql($file);
}elseif($fNum=="rename"){
if(defined("DB_PREFIX")){
$tables = array();
$rows = mysql_query("SHOW TABLES FROM $db");
while ($row = mysql_fetch_array($rows)) {
$tables[] = $row[0];
}
//Append and Rename all tables in a database
foreach($tables as $table){
$sql='RENAME TABLE ' .$table . ' TO '.DB_PREFIX.$table;
mysql_query($sql);
}
}
}
mysql_close($mysql);
}else{
include("eve.config.php");
session_start ();
$files=scandir("./SQL/");
$fileList=array();
$table=array();
$sqlFiles=array();
$mysql=mysql_connect($sql,$sql_u,$sql_p);
if (!$mysql) {
die('Could not connect: ' . mysql_error());
}
$rows = mysql_query("SHOW TABLES FROM $db");
while ($row = mysql_fetch_array($rows)) {
$tables[$row[0]] = $row[0];
}
foreach ($files as $file)
if(pathinfo($file, PATHINFO_EXTENSION)=="sql"||pathinfo($file, PATHINFO_EXTENSION)=="gz")
$fileList[]=$file;
foreach ($fileList as $file){
$fileName=explode("-",strtolower(substr(pathinfo($file,PATHINFO_BASENAME) ,0,strpos($file,'.'))));
if(preg_match ("/update/i", $file)!=false)
array_unshift($sqlFiles,$file);
else
if(preg_match ("/tables_layouts/i", $file)==false)
$sqlFiles[]=$file;
}
$fileCount=count($sqlFiles);
$_SESSION['fileCount']=$fileCount;
$_SESSION['files']=$sqlFiles;
if(!file_exists("./eve.config.php")){
header('Location: Installer.php');
}
echo "<link REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"audit.style.css\">";
?>
<script type="text/javascript">
function loadXMLDoc(i)
{
document.getElementById('install').onclick="";
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
while(i<=<?php echo $fileCount-1; ?>){
document.getElementById(i).innerHTML="Updating";
document.getElementById(i).style.backgroundColor="blue";
xmlhttp.open("GET",'update.php?sql='+i+'&t='+new Date().getTime(),false);
xmlhttp.send();
if(xmlhttp.responseText==true){
document.getElementById(i).style.backgroundColor="green";
document.getElementById(i).innerHTML="Done";
}else{
document.getElementById(i).style.backgroundColor="red";
document.getElementById(i).innerHTML=xmlhttp.responseText;
document.getElementById('install').onclick=function(){loadXMLDoc(0)};
i=null;
return
}
i++;
}
xmlhttp.open("GET",'Installer.php?sql=rename&t='+new Date().getTime(),false);
xmlhttp.send();
document.getElementById('button').style.display='block';
}
</script>
<?php
$i=0;
echo "<input type='button' value='Install' onclick='loadXMLDoc(0)' id='install'/>";
echo "<table>";
While( $i <= $fileCount-1){
echo"
<tr>
<td>
".$sqlFiles[$i]."
</td>
<td id=$i style=\"background-color:grey\">
Not Started
</td>
</tr>
";
$i++;
}
echo "</table>";
echo "<input type='button' value='Go to Main Page' onclick='window.location = \"index.php\"' style='display:none;' id='button'></input>";
}