forked from FriendUPCloud/friendup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
218 lines (144 loc) · 5.83 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
<?php
/*******************************************************************************
* *
* This file is part of FRIEND UNIFYING PLATFORM. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
$quit = "Goodbye. Installation aborted.\n";
$mysqldatabase = "";
$mysqlport = "";
$mysqlserver = "";
$mysqluser = "";
$mysqlpass = "";
$fcport = "";
$fcssl = false;
// Set up the mysql database name
mysql:
$result = readline( "Please enter a MySQL database name: " );
echo( "You entered \"$result\", is this correct?" );
$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
if( $yn == 'no' || $yn == 'n' )
goto mysql;
$mysqldatabase = $result;
// Setup the mysql hostname or IP
mysqlhost:
$result = readline( "Please enter your mysql database hostname or IP: " );
echo( "You entered \"$result\", is this correct?" );
$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
if( $yn == 'no' || $yn == 'n' )
goto mysqlhost;
$mysqlserver = strtolower( trim( $result ) );
// Setup the mysql port number
mysqlport:
$result = readline( "Please enter your mysql port number (default is 3306): " );
echo( "You entered \"$result\", is this correct?" );
$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
if( $yn == 'no' || $yn == 'n' )
goto mysqlport;
$mysqlport = trim( $result );
// Setup username for mysql
mysqlusername:
$result = readline( "Please enter mysql username: " );
echo( "You entered \"$result\", is this correct?" );
$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
if( $yn == 'no' || $yn == 'n' )
goto mysqlusername;
$mysqluser = trim( $result );
mysqlpassword:
$result = readline( "Please enter mysql password: " );
echo( "You entered \"$result\", is this correct?" );
$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
if( $yn == 'no' || $yn == 'n' )
goto mysqlpassword;
$mysqlpass = trim( $result );
// Setup friend core port
fcport:
echo( "Please enter the port number for the Friend Core server. If\n" );
$result = readline( "you are not root, it must be higher than 1024 (1025+): " );
echo( "You entered \"$result\", is this correct?" );
$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
if( $yn == 'no' || $yn == 'n' )
goto fcport;
$fcport = trim( $result );
// Setup friend core ssl
$yn = readline( "Will you run the server using SSL (HTTPS) (Yes/No/Quit)? " );
if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );
$yn = strtolower( trim( $yn ) );
$fcssl = $yn == 'y' || $yn == 'yes' ? true : false;
// Now start installing
echo( "---\n\nWe are now ready to install...\n" );
$conn = @mysql_connect( $mysqlserver . ':' . $mysqlport, $mysqluser, $mysqlpass )
or die( "Failed to connect to mysql server. Please use another username or password.\n" );
$result = mysql_query( 'CREATE DATABASE `' . $mysqldatabase . '`' );
if( substr( mysql_error(), 0, 5 ) == 'Can\'t' )
{
die( "The database could not be created.\n" );
}
mysql_query( 'USE ' . $mysqldatabase );
if( !( $db = file_get_contents( 'docs/FriendCoreDatabase.sql' ) ) )
die( "Could not locate friend core database template.\n" );
// Remove comments
$db = preg_replace( '/\-\-[^\n]*?\n/i', '', $db );
$db = preg_replace( '/\/\*[^*]*?\*\/[\;]{0,1}/i', '', $db );
// Install db
if( $rows = explode( ";", $db ) )
{
foreach( $rows as $row )
{
$row = trim( $row );
if( !$row ) continue;
if( substr( $row, 0, 3 ) == 'SET' ) continue;
mysql_query( $row );
}
}
// Set config
$conf = file_get_contents( 'docs/ConfigTemplate.ini' );
$setup = array(
'{user}' => $mysqluser,
'{pass}' => $mysqlpass,
'{host}' => $mysqlserver,
'{db}' => $mysqldatabase,
'{dbport}' => $mysqlport,
'{fchost}' => $mysqlserver,
'{fcport}' => $fcport,
'{fcssl}' => $fcssl ? '1' : '0'
);
foreach( $setup as $k=>$v )
$conf = str_replace( $k, $v, $conf );
// Some folders
if( !file_exists( 'build' ) )
mkdir( 'build' );
if( !file_exists( 'build/cfg' ) )
mkdir( 'build/cfg' );
if( !file_exists( 'build/cfg/crt' ) )
mkdir( 'build/cfg/crt' );
// Write config
if( $f = fopen( 'build/cfg/cfg.ini', 'w+' ) )
{
fwrite( $f, $conf );
fclose( $f );
}
mysql_close( $conn );
echo( "Now go and start FriendCore. You are all set.\n" );
echo( "Your username is: friendadmin\n" );
echo( "Your password is: FriendlyBetaAdministrator\n" );
?>