-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
152 lines (123 loc) · 5.43 KB
/
index.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
<?php
require_once dirname(dirname(dirname(__FILE__))). '/pcl/ini.php';
SessionManipulator::start_session();
define("INSTALLER_INDEX", true);
define("NL", "\r\n");
/**
* define and initialize default values for form variables
*/
$db_server = '';
$db_user = '';
$db_pass = '';
$db_name = '';
$tables_prefix = 'mo_';
$installation_complete_url = '';
$status_message = '';
/**
* Get the plugins to install from the current directory.
* The current directory is the directory housing the installer directory
*/
$unified_installer_dir = dirname(__FILE__);
$plugins_dir = str_replace( '\\', '/', dirname($unified_installer_dir) );
$directories = DirectoryInspector::get_directory_contents($plugins_dir, 'DIRECTORIES_ONLY', false);
$eligible_plugins = array(); //every plugin in the directory
$plugins_to_install = array(); //plugins selected by the user to install, this is passed in a session variable to finalize.php
foreach( $directories AS $directory)
{
$config_filename = $directory. '-app-config.php';
if( ($directory != 'unified-installer') && !file_exists($plugins_dir. '/'. $directory. '/'. $config_filename) )
{
$eligible_plugins[] = $directory;
}
}
/**
* declare and set variables needed by installer-form.php
*/
$user_manager_directory_exists = $session_manager_directory_exists = false;
$available_plugins_str = "<div><label>Choose Apps to Install</label><br/>". "\r\n";
foreach($eligible_plugins AS $plugin_directory)
{
if($plugin_directory == 'session-manager')
{
$session_manager_directory_exists = true;
}
if($plugin_directory == 'user-manager')
{
$user_manager_directory_exists = true;
}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
/**
* set values of variables needed by installer-form.php
*/
if(isset($_POST['plugins'][$plugin_directory]))
{
$plugins_to_install[] = $plugin_directory;
}
}
else
{
$plugins_to_install[] = $plugin_directory;
}
$state = isset($_POST['plugins'][$plugin_directory]) ? 'checked="checked"' : '';
$available_plugins_str .= $plugin_directory. " <input type=\"checkbox\" name=\"plugins[$plugin_directory]\" $state /><br/>". "\r\n";
}
$available_plugins_str .= "</div>";
if( ($_SERVER['REQUEST_METHOD'] == 'POST') || isset($_SESSION['unified-installer-plugin-installation-values']) ):
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
foreach($_POST AS $key => $value)
{
$$key = ( !is_array($value) && is_string($value) ) ? trim($value) : $value;
}
}
else if(isset($_SESSION['unified-installer-plugin-installation-values']))
{
foreach($_SESSION['unified-installer-plugin-installation-values'] AS $key => $value)
{
$$key = ( !is_array($value) && is_string($value) ) ? trim($value) : $value;
}
}
$mat[0]['error_condition'] = empty($db_server);
$mat[0]['error_message'] = 'Database server field cannot be empty';
$mat[1]['error_condition'] = empty($db_user);
$mat[1]['error_message'] = 'The Database user field cannot be empty';
$mat[2]['error_condition'] = empty($db_name);
$mat[2]['error_message'] = 'The Database name field cannot be empty';
$mat[3]['error_condition'] = empty($plugins_to_install); //!isset($_POST['plugins']);
$mat[3]['error_message'] = 'You must specify at least one plugin to install';
$mat[4]['error_condition'] = empty($installation_complete_url);
$mat[4]['error_message'] = 'Specify the URL to redirect to on successful install';
$db = new MySql();
$connection_id = @$db->connect( $db_server, $db_user, $db_pass, $db_name );
$mat[5]['error_condition'] = ( $connection_id === false ) || ( $connection_id < 0 );
$mat[5]['error_message'] = 'Unable to connect to the database server. <br/> Make sure the database server name, username and password are correct';
$validate = Validator::validate($mat);
if($validate['error'])
{
$status_message = $validate['status_message'];
require_once('installer-form.php');
exit;
}
$content = "<?php". NL. NL.
"require_once('". PCL_DIR. "/ini.php');". NL. NL. NL.
"/**". NL. "* database server name". NL. "*/". NL.
"defined('DB_SERVER') or define('DB_SERVER', '$db_server');". NL. NL. NL.
"/**". NL. "* database user name". NL. "*/". NL.
"defined('DB_USER') or define('DB_USER', '$db_user');" . NL. NL. NL.
"/**". NL. "* database user password". NL. "*/". NL.
"defined('DB_PASS') or define('DB_PASS', '$db_pass');". NL. NL. NL.
"/**". NL. "* database name". NL. "*/". NL.
"defined('DB_NAME') or define('DB_NAME', '$db_name');". NL. NL. NL.
"/**". NL. "* database tables prefix". NL. "*/". NL.
"defined('TABLES_PREFIX') or define('TABLES_PREFIX', '$tables_prefix');". NL. NL. NL.
"/**". NL. "* File system path to installed plugins directory". NL. "*/". NL.
"defined('PLUGINS_DIR') or define('PLUGINS_DIR', '$plugins_dir');". NL. "";
$config_file = new FileWriter('../unified-install.config.php', 'WRITE_ONLY');
$config_file->write($content);
$_SESSION['plugins_to_install'] = Util::stringify($plugins_to_install); //used to pass the eligible plugins array to 'finalize.php'
$_SESSION['installation_complete_url'] = $installation_complete_url; //ditto
$paths = UrlInspector::get_path($plugins_dir. '/'. $eligible_plugins[0]. '/install');
UrlManipulator::redirect($paths['http_path']);
endif; //end if $_SERVER['REQUEST_METHOD'] == 'POST'
require_once('installer-form.php');