-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin_open_mysql.php
139 lines (131 loc) · 4.48 KB
/
admin_open_mysql.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
<?php
/**
* admin_open_mysql.php
*
* Dernière modification : $Date: 2009-06-04 15:30:17 $
* @author Laurent Delineau <laurent.delineau@ac-poitiers.fr>
* @author Sylvain Payeur
* @copyright Copyright 2003-2008 Laurent Delineau
* @copyright Copyright 2008 Sylvain Payeur
* @link http://www.gnu.org/licenses/licenses.html
* @package admin
* @version $Id: admin_open_mysql.php,v 1.6 2009-06-04 15:30:17 grr Exp $
* @filesource
*
* This file is part of GRR.
*
* GRR is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GRR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRR; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* $Log: admin_open_mysql.php,v $
* Revision 1.6 2009-06-04 15:30:17 grr
* *** empty log message ***
*
* Revision 1.5 2009-02-27 22:05:03 grr
* *** empty log message ***
*
* Revision 1.4 2008-11-16 22:00:58 grr
* *** empty log message ***
*
* Revision 1.3 2008-11-06 21:57:34 grr
* *** empty log message ***
*
* Revision 1.2 2008-11-05 15:04:16 grr
* *** empty log message ***
*
*
*/
include "include/admin.inc.php";
$grr_script_name = "admin_open_mysql.php";
if(authGetUserLevel(getUserName(),-1) < 6)
{
$day = date("d");
$month = date("m");
$year = date("Y");
showAccessDenied($day, $month, $year, '',$back);
exit();
}
$sql_file = isset($_FILES["sql_file"]) ? $_FILES["sql_file"] : NULL;
$file_name = isset($_GET["file_name"]) ? $_GET["file_name"] : NULL;
// Restriction dans le cas d'une démo
VerifyModeDemo();
if (!$file_name) {
print_header("","","","",$type="with_session", $page="admin");
}
else {
echo begin_page("","no_session");
}
echo "<div class=\"page_sans_col_gauche\">";
echo "<br />";
#Si aucun fichier n'a été sélectionné
if (!$file_name and !$sql_file['name'])
exit (get_vocab("admin_import_users_csv11")."<br /><a href=\"admin_config.php?page_config=4\">".get_vocab("back")."</a></div></body></html>");
if (!$file_name) {
#Demande de confirmation
echo "<h3>Restauration à partir du ficher : " ;
echo $sql_file['name']."</h3>\n";
$file_name= str_replace("\\","/",dirname($sql_file['tmp_name'])."/".$sql_file['name']);
$ok = @copy($sql_file['tmp_name'],$file_name);
$file = fopen($file_name, "r") or exit("Unable to open file!");
$line = fgets($file);
#Vérifie si c'est bien un fichier Grr
if (!stristr($line,'#**************** BASE DE DONNEES')) {
fclose($file);
echo "<span class=\"avertissement\">Il ne s'agit pas d'un fichier de sauvegarde GRR.</span><br />";
} else {
#Affiche les infos
echo "<table border=\"1\" cellpadding=\"10\"><tr><td>";
echo "Version : ".substr($line,34,strpos(substr($line,34),"*"))."<br />";
for ($i=1; $i<6; $i++) {
$line = substr(fgets($file),2);
echo $line."<br />";
}
fclose($file);
echo "</td></tr></table>";
}
echo "<h1>" . get_vocab("sure") . "</h1>";
echo "<h1><a href=\"admin_open_mysql.php?file_name=$file_name\">" . get_vocab("YES") . "!</a> <a href=\"admin_config.php?page_config=4\">" . get_vocab("NO") . "!</a></h1>";
echo "</div>";
} else {
#Procède à la restauration
$file = fopen($file_name, "r") or exit("Erreur de lecture de fichier!");
$ok="";
$error = "";
while(!feof($file)) {
$line = fgets($file);
while ($line[0]!='#' and !stristr($line,';') and !feof($file))
$line .= fgets($file);
if (grr_sql_query($line)) {
$ok.="1";
} else {
$ok.="0";
$error .="<hr />".my_htmlspecialcharacters($line);
}
}
fclose($file);
unlink($file_name);
echo "<h3>La restauration est terminée !</h3>" ;
echo strlen($ok)." requêtes ont été exécutées " ;
if (strrpos($ok,'0')) {
echo "avec ".substr_count($ok,'0')." erreur(s) :";
echo $error."<hr />";
} else {
echo "sans erreurs.";
}
echo "<br /><a href=\"login.php\">".get_vocab("msg_logout3")."</a></div>";
}
?>
</body>
</html>