forked from OCSInventory-NG/OCSInventory-ocsreports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
executable file
·288 lines (284 loc) · 9.02 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
//====================================================================================
// OCS INVENTORY REPORTS
// Copyleft Pierre LEMMET 2005
// Web: http://www.ocsinventory-ng.org
//
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
//====================================================================================
//Modified on $Date: 2014 $$Author: Erwan Goalou + Passero
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);
function printEnTeteInstall($ent) {
echo "<h3>$ent</h3>";
}
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val{strlen($val)-1});
switch($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
//
// }
/*
* function to execute sql file
*
*/
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 $k=>$v){
if (trim($v) != ""){
echo ".";
ob_flush();
flush();
mysql2_query_secure($v,$link);
}
}
return false;
}
return true;
}
}
//choose default language
if (!isset($_SESSION['OCS']['LANGUAGE']) or !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>";
//messages lbl
$msg_lbl=array();
$msg_lbl['info']=array();
$msg_lbl['warning']=array();
$msg_lbl['error']=array();
//msg=you have to update database
if( isset($fromAuto) && $fromAuto==true){
$msg_lbl['info'][]= $l->g(2031)." ".$valUpd["tvalue"]." ".$l->g(2032)." (" . GUI_VER . "). ".$l->g(2033);
}
//msg=your config file doesn't exist
if( isset($fromdbconfig_out) && $fromdbconfig_out==true)
$msg_lbl['info'][]=$l->g(2034);
//max to upload
$pms = "post_max_size";
$umf = "upload_max_filesize";
$valTpms = ini_get( $pms );
$valTumf = ini_get( $umf );
$valBpms = return_bytes( $valTpms );
$valBumf = return_bytes( $valTumf );
if( $valBumf>$valBpms )
$MaxAvail = trim(mb_strtoupper($valTpms),"M");
else
$MaxAvail = trim(mb_strtoupper($valTumf),"M");
$msg_lbl['info'][]=$l->g(2040) . " " . $MaxAvail . $l->g(1240) . "<br>" . $l->g(2041)."<br><br><font color=red>".$l->g(2102)."</font>";
//msg=no php-session function
if(!function_exists('session_start')) {
$msg_lbl['error'][]=$l->g(2035);
}
//msg= no mysqli_connect function
if(!function_exists('mysqli_connect')) {
$msg_lbl['error'][]=$l->g(2037);
}
if((file_exists(CONF_MYSQL) and !is_writable(CONF_MYSQL)) or (!file_exists(CONF_MYSQL) and !is_writable(ETC_DIR))) {
$msg_lbl['error'][]="<br><center><font color=red><b>" . $l->g(2052) . "</b></font></center>";
}
//msg for phpversion
if(version_compare(phpversion(), '5.3.7', '<')){
$msg_lbl['warning'][]=$l->g(2113)." ".phpversion()." ) ";
}
if(!class_exists('SoapClient')) {
$msg_lbl['warning'][]=$l->g(6006);
}
if(!function_exists('xml_parser_create')) {
$msg_lbl['warning'][]=$l->g(2036);
}
if(!function_exists('imagefontwidth')) {
$msg_lbl['warning'][]=$l->g(2038);
}
if(!function_exists('openssl_open')) {
$msg_lbl['warning'][]=$l->g(2039);
}
if (is_writable($_SERVER["DOCUMENT_ROOT"])){
if (!file_exists($_SERVER["DOCUMENT_ROOT"]."/download")) {
mkdir($_SERVER["DOCUMENT_ROOT"]."/download");
}
if (!file_exists($_SERVER["DOCUMENT_ROOT"]."/logs")) {
mkdir($_SERVER["DOCUMENT_ROOT"]."/logs");
}
if (!file_exists($_SERVER["DOCUMENT_ROOT"]."/scripts")) {
mkdir($_SERVER["DOCUMENT_ROOT"]."/scripts");
}
}else{
$msg_lbl['warning'][]="Document root should be writable : ".$_SERVER["DOCUMENT_ROOT"];
}
//show messages
foreach ($msg_lbl as $k=>$v){
$show=implode("<br>",$v);
if ($show != ''){
call_user_func_array("msg_".$k, array($show));
//stop if error
if ($k == "error")
die();
}
}
//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;")
or !mysqli_query($link,"USE ".$_POST['database'])
or !mysqli_query($link,"GRANT ALL PRIVILEGES ON ".$_POST['database'].".* TO ocs IDENTIFIED BY 'ocs'")
or !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);
tab_modif_values($tab_name,$tab_typ_champ,$tab_hidden,array(
'button_name' => 'INSTALL',
'show_button' => 'BUTTON',
'form_name' => $form_name
));
die();
?>