forked from OCSInventory-NG/OCSInventory-ocsreports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
222 lines (214 loc) · 8.26 KB
/
install.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/*
* Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
* See the Contributors file for more details about them.
*
* This file is part of OCSInventory-NG/OCSInventory-ocsreports.
*
* OCSInventory-NG/OCSInventory-ocsreports 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.
*
* OCSInventory-NG/OCSInventory-ocsreports 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 OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
set_time_limit(0); //Throw an error if Safe_mode is on, which was removed in 5.4
error_reporting(E_ALL & ~E_NOTICE);
require_once('require/fichierConf.class.php');
require_once('require/function_commun.php');
require_once('require/function_table_html.php');
require_once('var.php');
//show header
html_header(true);
echo "<div class='container-fluid'>";
function printEnTeteInstall($ent) {
echo "<h3>$ent</h3>";
}
/**
* execute sql file
* @global type $l
* @param type $fichier
* @param type $link
* @return boolean
*/
function exec_fichier_sql($fichier, $link) {
global $l;
$db_file = $fichier;
$dbf_handle = @fopen($db_file, "r");
echo "<br>";
if (!$dbf_handle) {
msg_error($l->g(2112) . " : " . $fichier);
return true;
} else {
if (filesize($db_file) > 0) {
$sql_query = fread($dbf_handle, filesize($db_file));
fclose($dbf_handle);
$data_sql = explode(";", $sql_query);
foreach ($data_sql as $v) {
if (is_defined($v)) {
echo ".";
ob_flush();
flush();
mysql2_query_secure($v, $link);
}
}
return false;
}
return true;
}
}
//choose default language
if (!isset($_SESSION['OCS']['LANGUAGE']) || !isset($_SESSION['OCS']["LANGUAGE_FILE"])) {
if (isset($_COOKIE['LANG'])) {
$_SESSION['OCS']['LANGUAGE'] = $_COOKIE['LANG'];
}
if (!isset($_COOKIE['LANG'])) {
$_SESSION['OCS']['LANGUAGE'] = DEFAULT_LANGUAGE;
}
$_SESSION['OCS']["LANGUAGE_FILE"] = new language($_SESSION['OCS']['LANGUAGE']);
}
$l = $_SESSION['OCS']["LANGUAGE_FILE"];
//OCS INSTALLATION
printEnTeteInstall($l->g(2030));
echo "<br>";
// Check requirements ( function_commun.php )
check_requirements();
//post the first form
if (isset($_POST["name"])) {
$link = dbconnect($_POST["host"], $_POST["name"], $_POST["pass"], $_POST["database"]);
if (mysqli_connect_errno()) {
$firstAttempt = false;
msg_error($l->g(2001) . " " . $l->g(249) .
" (" . $l->g(2010) . "=" . $_POST["host"] .
" " . $l->g(2011) . "=" . $_POST["name"] .
" " . $l->g(2014) . "=" . $_POST["pass"] .
")<br>" . $link);
} else {
//if database not exist
if ($link == "NO_DATABASE") {
$link = mysqli_connect($_POST["host"], $_POST["name"], $_POST["pass"]);
//have to execute new install file
$db_file = "files/ocsbase_new.sql";
if (!mysqli_query($link, "CREATE DATABASE " . $_POST['database'] . " CHARACTER SET utf8 COLLATE utf8_bin;") || !mysqli_query($link, "USE " . $_POST['database']) || !mysqli_query($link, "GRANT ALL PRIVILEGES ON " . $_POST['database'] . ".* TO ocs IDENTIFIED BY 'ocs'") || !mysqli_query($link, "GRANT ALL PRIVILEGES ON " . $_POST['database'] . ".* TO ocs@localhost IDENTIFIED BY 'ocs'")) {
$error = mysqli_errno($link);
}
$name_connect = "ocs";
$pass_connect = 'ocs';
} else {
//update
$res = mysql2_query_secure("select tvalue from config where name='GUI_VERSION'", $link);
$item = mysqli_fetch_object($res);
if ($item->tvalue < 7006) {
$db_file = "files/ocsbase.sql";
$name_connect = $_POST["name"];
$pass_connect = $_POST["pass"];
} else {
msg_info($l->g(2105));
$ch = @fopen(CONF_MYSQL, "w");
fwrite($ch, "<?php\n");
fwrite($ch, "define(\"DB_NAME\", \"" . $_POST['database'] . "\");\n");
fwrite($ch, "define(\"SERVER_READ\",\"" . $_POST["host"] . "\");\n");
fwrite($ch, "define(\"SERVER_WRITE\",\"" . $_POST["host"] . "\");\n");
fwrite($ch, "define(\"COMPTE_BASE\",\"" . $_POST["name"] . "\");\n");
fwrite($ch, "define(\"PSWD_BASE\",\"" . $_POST["pass"] . "\");\n");
fwrite($ch, "?>");
fclose($ch);
msg_success("<b><a href='index.php'>" . $l->g(2051) . "</a></b>");
unset($_SESSION['OCS']['SQL_BASE_VERS']);
die();
}
}
if (!$error) {
ob_flush();
flush();
msg_info($l->g(2030));
exec_fichier_sql($db_file, $link);
$ch = @fopen(CONF_MYSQL, "w");
fwrite($ch, "<?php\n");
fwrite($ch, "define(\"DB_NAME\", \"" . $_POST['database'] . "\");\n");
fwrite($ch, "define(\"SERVER_READ\",\"" . $_POST["host"] . "\");\n");
fwrite($ch, "define(\"SERVER_WRITE\",\"" . $_POST["host"] . "\");\n");
fwrite($ch, "define(\"COMPTE_BASE\",\"" . $name_connect . "\");\n");
fwrite($ch, "define(\"PSWD_BASE\",\"" . $pass_connect . "\");\n");
fwrite($ch, "?>");
fclose($ch);
if (!mysqli_connect($_POST["host"], $name_connect, $pass_connect)) {
if (mysqli_connect_errno() == 0) {
echo "<br><center><font color=red><b>" . $l->g(2043) .
" " . $l->g(2044) .
"</b><br></font></center>";
die();
} else {
echo "<br><center><font color=red><b>" . $l->g(2043) .
" (" . $l->g(2017) .
" " . $l->g(2010) .
"=" . $_POST["host"] .
" " . $l->g(2011) .
"=ocs " . $l->g(2014) .
"=ocs)"
. "</b><br></font></center>";
}
echo "<br><center><font color=red><b>" . $l->g(2065) . "</b></font></center>";
unlink(CONF_MYSQL);
} else {
msg_success("<b>" . $l->g(2050) . "</b><br><br><b><a href='index.php'>" . $l->g(2051) . "</a></b>");
unset($_SESSION['OCS']['SQL_BASE_VERS']);
}
die();
} else {
msg_error($l->g(2115));
}
}
//die();
}
//use values in mysql config file
if (is_readable(CONF_MYSQL)) {
require(CONF_MYSQL);
if (defined('COMPTE_BASE')) {
$valNme = COMPTE_BASE;
} else {
$valNme = '';
}
if (defined('PSWD_BASE')) {
$valPass = PSWD_BASE;
} else {
$valPass = '';
}
if (defined('SERVER_WRITE')) {
$valServ = SERVER_WRITE;
} else {
$valServ = '';
}
if (defined('DB_NAME')) {
$valdatabase = DB_NAME;
} else {
$valdatabase = '';
}
}
//show first form
$form_name = 'fsub';
$name_field = array("name", "pass", "database", "host");
$tab_name = array($l->g(247) . ": ", $l->g(248) . ": ", $l->g(1233) . ":", $l->g(250) . ":");
$type_field = array(0, 4, 0, 0);
if (isset($_POST["name"], $_POST["pass"], $_POST["database"], $_POST["host"])) {
$value_field = array($_POST["name"], $_POST["pass"], $_POST["database"], $_POST["host"]);
} else {
$value_field = array($valNme, $valPass, $valdatabase, $valServ);
}
$tab_typ_champ = show_field($name_field, $type_field, $value_field);
modif_values($tab_name, $tab_typ_champ, $tab_hidden, array(
'button_name' => 'INSTALL',
'show_button' => 'BUTTON',
'form_name' => $form_name
));
echo "</div>";
die();
?>