forked from Regss/movielib
/
install.php
186 lines (169 loc) · 6.8 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
<?PHP
session_start();
header('Content-type: text/html; charset=utf-8');
include('config.php');
include('function.php');
/* ############
* # LANGUAGE #
*/############
if (isset($_POST['install_lang'])) {
$_SESSION['install_lang'] = $_POST['install_lang'];
}
// check user language from browser
if (!isset($_SESSION['install_lang'])) {
$install_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if (!file_exists('lang/' . $install_lang . '/lang.php')) {
$install_lang = 'en';
}
$_SESSION['install_lang'] = $install_lang;
} else {
$install_lang = $_SESSION['install_lang'];
}
// check dir for language file
$output_install_lang = '';
$option_install_language = scandir('lang/');
foreach ($option_install_language as $val) {
if (file_exists('lang/' . $val . '/lang.php')) {
if (array_key_exists($val, $langs)) {
$lang_title = $langs[$val];
} else {
$lang_title = $val;
}
$output_install_lang.= '<option' . ($val == $install_lang ? ' selected="selected"' : '') . ' value="' . $val . '">' . $lang_title . '</option>';
}
}
include('lang/' . $install_lang . '/lang.php');
$output_panel = '';
switch ($option) {
case 'license':
/* ###########
* # LICENSE #
*/###########
$license_file = 'LICENSE.txt';
if (file_exists($license_file)) {
$fp = fopen($license_file, 'r');
$license = fread($fp, 88192);
} else {
$license = 'No license file.';
}
$title = $lang['ins_license'];
$output_panel = '
<form>
<textarea class="textera" readonly="readonly">' . $license . '</textarea>
</form>
<a class="box" href="install.php?option=database">' . $lang['ins_accept'] . '</a>
';
break;
case 'database':
/* ################
* # SET DATABASE #
*/################
if (file_exists('db.php')) {
$output_panel_info.= $lang['ins_db_exist'] . '<br />';
}
$title = $lang['inst_conn_db'];
$output_panel = '
<form action="install.php?option=success" method="post">
<table>
<tr><td>' . $lang['inst_server'] . ':</td><td><input type="text" name="host" value="localhost"></td></tr>
<tr><td>' . $lang['inst_port'] . ':</td><td><input type="text" name="port" value="3306"></td></tr>
<tr><td>' . $lang['inst_login'] . ':</td><td><input type="text" name="login" value="xbmc"></td></tr>
<tr><td>' . $lang['inst_pass'] . ':</td><td><input type="password" name="pass" value=""></td></tr>
<tr><td>' . $lang['inst_database'] . ':</td><td><input type="text" name="database" value="movielib"></td></tr>
</table>
<input id="ok" type="submit" value="OK" />
</form>';
break;
case 'success':
/* ##################
* # CHECK DATABASE #
*/##################
$conn_install = mysql_connect($_POST['host'] . ':' . $_POST['port'], $_POST['login'], $_POST['pass']);
if (!$conn_install) {
die($lang['ins_could_connect'] . ' - ' . mysql_error());
}
$create_sql = 'CREATE DATABASE IF NOT EXISTS ' . $_POST['database'];
mysql_q($create_sql);
$sel_install = mysql_select_db($_POST['database']);
if (!$sel_install) {
die($lang['ins_could_connect'] . ' - ' . mysql_error());
}
create_table($mysql_tables, $mysql_indexes, $lang, $version, 1);
// create db.php
$to_write = '<?PHP $mysql_ml = array(\'' . $_POST['host'] . '\', \'' . $_POST['port'] . '\', \'' . $_POST['login'] . '\', \'' . $_POST['pass'] . '\', \'' . $_POST['database'] . '\'); ?>';
$fp = @fopen('db.php', 'w');
if (!$fp) {
$title = $lang['ins_error'];
if (file_exists('db.php')) {
$output_panel_error.= $lang['ins_file_db_ex'] . ' ' . substr(decoct(fileperms('db.php')), -3) . '<br>';
} else {
$output_panel_error.= $lang['ins_file_db_not'] . ' ' . substr(decoct(fileperms('.')), -3) . '<br>';
}
$output_panel = '
<div class="center">' . $lang['ins_file_db_cre'] . ':</div>
<form action="install.php?option=success" method="post">
<textarea readonly="readonly">' . $to_write . '</textarea>
</form>';
} else {
fwrite($fp, $to_write);
fclose($fp);
$title = $lang['ins_finished'];
$output_panel = '<a class="box" href="admin.php?option=delete_install">' . $lang['ins_admin'] . '</a>';
}
// delete session var
$_SESSION = array();
break;
default:
/* ##########
* # README #
*/##########
$readme_file = 'lang/' . $_SESSION['install_lang'] . '/readme';
if (!file_exists($readme_file)) {
$readme_file = 'README.txt';
}
$fp = fopen($readme_file, 'r');
$readme = fread($fp, 88192);
$title = $lang['ins_lang_file'];
$output_panel = '
<form action="install.php" method="post">
<select onchange="this.form.submit()" name="install_lang">' . $output_install_lang . '</select>
</form>
<form>
<textarea readonly="readonly">' . $readme . '</textarea>
</form>
<a class="box" href="install.php?option=license">' . $lang['ins_next'] . '</a>
';
break;
}
/* ##############
* # PANEL INFO #
*/##############
if ($output_panel_info !== '') {
$output_panel_info = '<div class="panel_info">' . $output_panel_info . '</div>';
}
if ($output_panel_error !== '') {
$output_panel_error = '<div class="panel_error">' . $output_panel_error . '</div>';
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>MovieLib - <?PHP echo $lang['ins_title'] ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<![endif]-->
<link type="image/x-icon" href="admin/img/icon.ico" rel="icon" media="all" />
<link type="text/css" href="admin/css/style.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery.script.js"></script>
</head>
<body>
<?PHP echo $output_panel_info ?>
<?PHP echo $output_panel_error ?>
<div class="container_install">
<div class="title"><?PHP echo $title ?></div>
<?PHP echo $output_panel ?>
</div>
</body>
</html>