Completed
Pull Request — develop (#518)
by Agel_Nash
06:14
created

action_summary.php ➔ f_owc()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 6
nop 3
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
if( ! function_exists('f_owc')){
3
    /**
4
     * @param $path
5
     * @param $data
6
     * @param null|int $mode
7
     */
8
    function f_owc($path, $data, $mode = null){
9
        try {
10
            // make an attempt to create the file
11
            $hnd = fopen($path, 'w');
12
            fwrite($hnd, $data);
13
            fclose($hnd);
14
15
            if(null !== $mode) chmod($path, $mode);
16
        }catch(Exception $e){
17
            // Nothing, this is NOT normal
18
            unset($e);
19
        }
20
    }
21
}
22
23
$installMode = isset($_POST['installmode']) ? (int)$_POST['installmode'] : 0;
24
if( ! isset($_lang)) $_lang = array();
25
26
echo '<div class="stepcontainer">
27
      <ul class="progressbar">
28
          <li class="visited">' . $_lang['choose_language'] . '</li>
29
          <li class="visited">' . $_lang['installation_mode'] . '</li>
30
          <li class="visited">' . $_lang['optional_items'] . '</li>
31
          <li class="active">' . $_lang['preinstall_validation'] . '</li>
32
          <li>' . $_lang['install_results'] . '</li>
33
  </ul>
34
  <div class="clearleft"></div>
35
</div>';
36
37
echo '<h2>' . $_lang['preinstall_validation'] . '</h2>';
38
echo '<h3>' . $_lang['summary_setup_check'] . '</h3>';
39
40
$errors = 0;
41
42
43
// check PHP version
44
define('PHP_MIN_VERSION', '5.4.0');
45
$phpMinVersion = PHP_MIN_VERSION; // Maybe not necessary. For backward compatibility
46
echo '<p>' . $_lang['checking_php_version'];
47
// -1 if left is less, 0 if equal, +1 if left is higher
48
if (version_compare(phpversion(), PHP_MIN_VERSION) < 0) {
49
    $errors++;
50
    $tmp = $_lang['you_running_php'] . phpversion() . str_replace('[+min_version+]', PHP_MIN_VERSION, $_lang["modx_requires_php"]);
51
    echo '<span class="notok">' . $_lang['failed'] . '</span>' . $tmp . '</p>';
52
} else {
53
    echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
54
}
55
56
57
// check if iconv is available
58
echo '<p>' . $_lang['checking_iconv'];
59
$iconv = (int) function_exists('iconv');
60 View Code Duplication
if ($iconv == '0'){
61
    echo '<span class="notok">' . $_lang['failed'].'</span></p><p><strong>'.$_lang['checking_iconv_note'].'</strong></p>';
62
    $errors++;
63
} else {
64
    echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
65
}
66
// check sessions
67
echo '<p>' . $_lang['checking_sessions'];
68 View Code Duplication
if ($_SESSION['test'] != 1) {
69
    echo '<span class="notok">' . $_lang['failed'].  '</span></p>';
70
    $errors++;
71
} else {
72
    echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
73
}
74
75
76
// check directories
77
// cache exists?
78
echo '<p>' . $_lang['checking_if_cache_exist'];
79 View Code Duplication
if (!file_exists("../assets/cache") || !file_exists("../assets/cache/rss")) {
80
    echo '<span class="notok">' . $_lang['failed'] . '</span></p>';
81
    $errors++;
82
} else {
83
    echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
84
}
85
86
87
// cache writable?
88
echo '<p>' . $_lang['checking_if_cache_writable'];
89 View Code Duplication
if (!is_writable("../assets/cache")) {
90
    $errors++;
91
    echo '<span class="notok">' . $_lang['failed'] . '</span></p>';
92
} else {
93
    echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
94
}
95
96
97
// cache files writable?
98
echo '<p>' . $_lang['checking_if_cache_file_writable'];
99
$tmp = "../assets/cache/siteCache.idx.php";
100
if ( ! file_exists($tmp)) {
101
    f_owc($tmp, "<?php //EVO site cache file ?>");
102
}
103 View Code Duplication
if ( ! is_writable($tmp)) {
104
    $errors++;
105
    echo '<span class="notok">' . $_lang['failed'] . '</span></p>';
106
} else {
107
    echo '<span class="ok">'.$_lang['ok'].'</span></p>';
108
}
109
110
111
echo '<p>'.$_lang['checking_if_cache_file2_writable'];
112 View Code Duplication
if ( ! is_writable("../assets/cache/sitePublishing.idx.php")) {
113
    $errors++;
114
    echo '<span class="notok">'.$_lang['failed'].'</span></p>';
115
} else {
116
    echo '<span class="ok">'.$_lang['ok'].'</span></p>';
117
}
118
119
120
// File Browser directories exists?
121
echo '<p>'.$_lang['checking_if_images_exist'];
122 View Code Duplication
switch(true){
123
    case !file_exists("../assets/images"):
124
    case !file_exists("../assets/files"):
125
    case !file_exists("../assets/backup"):
126
    case !file_exists("../assets/.thumbs"):
127
        $errors++;
128
        echo '<span class="notok">'.$_lang['failed'].'</span></p>';
129
        break;
130
    default:
131
        echo '<span class="ok">'.$_lang['ok'].'</span></p>';
132
}
133
134
135
// File Browser directories writable?
136
echo '<p>'.$_lang['checking_if_images_writable'];
137 View Code Duplication
switch(true){
138
    case !is_writable("../assets/images"):
139
    case !is_writable("../assets/files"):
140
    case !is_writable("../assets/backup"):
141
    case !is_writable("../assets/.thumbs"):
142
        $errors++;
143
        echo '<span class="notok">'.$_lang['failed'].'</span></p>';
144
        break;
145
    default:
146
        echo '<span class="ok">'.$_lang['ok'].'</span></p>';
147
}
148
149
150
// export exists?
151
echo '<p>'.$_lang['checking_if_export_exists'];
152 View Code Duplication
if (!file_exists("../assets/export")) {
153
    echo '<span class="notok">'.$_lang['failed'].'</span></p>';
154
    $errors++;
155
} else {
156
    echo '<span class="ok">'.$_lang['ok'].'</span></p>';
157
}
158
159
160
// export writable?
161
echo '<p>'.$_lang['checking_if_export_writable'];
162 View Code Duplication
if (!is_writable("../assets/export")) {
163
    echo '<span class="notok">'.$_lang['failed'].'</span></p>';
164
    $errors++;
165
} else {
166
    echo '<span class="ok">'.$_lang['ok'].'</span></p>';
167
}
168
169
170
// config.inc.php writable?
171
echo '<p>'.$_lang['checking_if_config_exist_and_writable'];
172
$tmp = "../".MGR_DIR."/includes/config.inc.php";
173
if (!is_file($tmp)) {
174
    f_owc($tmp, "<?php //EVO configuration file ?>", 0666);
175
}
176
$isWriteable = is_writable($tmp);
177 View Code Duplication
if (!$isWriteable) {
178
    $errors++;
179
    echo '<span class="notok">'.$_lang['failed'].'</span></p><p><strong>'.$_lang['config_permissions_note'].'</strong></p>';
180
} else {
181
    echo '<span class="ok">'.$_lang['ok'].'</span></p>';
182
}
183
184
185
// connect to the database
186
if ($installMode == 1) {
187
    include "../".MGR_DIR."/includes/config.inc.php";
188
} else {
189
    // get db info from post
190
    $database_server = $_POST['databasehost'];
191
    $database_user = $_SESSION['databaseloginname'];
192
    $database_password = $_SESSION['databaseloginpassword'];
193
    $database_collation = $_POST['database_collation'];
194
    $database_charset = substr($database_collation, 0, strpos($database_collation, '_') - 1);
195
    $database_connection_charset = $_POST['database_connection_charset'];
196
    $database_connection_method = $_POST['database_connection_method'];
197
    $dbase = '`' . $_POST['database_name'] . '`';
198
    $table_prefix = $_POST['tableprefix'];
199
}
200
echo '<p>'.$_lang['creating_database_connection'];
201
if (!$conn = mysqli_connect($database_server, $database_user, $database_password)) {
202
    $errors++;
203
    echo '<span class="notok">'.$_lang['database_connection_failed'].'</span><p />'.$_lang['database_connection_failed_note'].'</p>';
204
} else {
205
    echo '<span class="ok">'.$_lang['ok'].'</span></p>';
206
}
207
208
209
// make sure we can use the database
210
if ($installMode > 0 && !mysqli_query($conn, "USE {$dbase}")) {
211
    $errors++;
212
    echo '<span class="notok">'.$_lang['database_use_failed'].'</span><p />'.$_lang["database_use_failed_note"].'</p>';
213
}
214
215
// check the database collation if not specified in the configuration
216 View Code Duplication
if (!isset ($database_connection_charset) || empty ($database_connection_charset)) {
217
    if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) {
218
        $rs = mysqli_query($conn, "show session variables like 'collation_server'");
219
    }
220
    if ($rs && $collation = mysqli_fetch_row($rs)) {
221
        $database_collation = $collation[1];
222
    }
223
    if (empty ($database_collation)) {
224
        $database_collation = 'utf8_unicode_ci';
225
    }
226
    $database_charset = substr($database_collation, 0, strpos($database_collation, '_') - 1);
227
    $database_connection_charset = $database_charset;
228
}
229
230
// determine the database connection method if not specified in the configuration
231
if (!isset($database_connection_method) || empty($database_connection_method)) {
232
    $database_connection_method = 'SET CHARACTER SET';
233
}
234
235
// check table prefix
236
if ($conn && $installMode == 0) {
237
    echo '<p>' . $_lang['checking_table_prefix'] . $table_prefix . '`: ';
238 View Code Duplication
    if ($rs= mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) {
239
        echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_already_inuse'] . '</p>';
240
        $errors++;
241
        echo "<p>" . $_lang['table_prefix_already_inuse_note'] . '</p>';
242
    } else {
243
        echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
244
    }
245
} elseif ($conn && $installMode == 2) {
246
    echo '<p>' . $_lang['checking_table_prefix'] . $table_prefix . '`: ';
247 View Code Duplication
    if (!$rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) {
248
        echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_not_exist'] . '</p>';
249
        $errors++;
250
        echo '<p>' . $_lang['table_prefix_not_exist_note'] . '</p>';
251
  } else {
252
        echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
253
  }
254
}
255
256
// check mysql version
257
if ($conn) {
258
    echo '<p>' . $_lang['checking_mysql_version'];
259
    if ( version_compare(mysqli_get_server_info($conn), '5.0.51', '=') ) {
260
        echo '<span class="notok">'  . $_lang['warning'] . '</span></b>&nbsp;&nbsp;<strong>' . $_lang['mysql_5051'] . '</strong></p>';
261
        echo '<p><span class="notok">' . $_lang['mysql_5051_warning'] . '</span></p>';
262
    } else {
263
        echo '<span class="ok">' . $_lang['ok'] . '</span>&nbsp;&nbsp;<strong>' . $_lang['mysql_version_is'] . mysqli_get_server_info($conn) . '</strong></p>';
264
    }
265
}
266
267
// check for strict mode
268
if ($conn) {
269
    echo '<p>'. $_lang['checking_mysql_strict_mode'];
270
    $mysqlmode = mysqli_query($conn, "SELECT @@global.sql_mode");
271
    if (mysqli_num_rows($mysqlmode) > 0){
272
        $modes = mysqli_fetch_array($mysqlmode, MYSQLI_NUM);
273
        //$modes = array("STRICT_TRANS_TABLES"); // for testing
274
        // print_r($modes);
275
        foreach ($modes as $mode) {
276
            if (stristr($mode, "STRICT_TRANS_TABLES") !== false || stristr($mode, "STRICT_ALL_TABLES") !== false) {
277
                echo '<span class="notok">' . $_lang['warning'] . '</span></b> <strong>&nbsp;&nbsp;' . $_lang['strict_mode'] . '</strong></p>';
278
                echo '<p><span class="notok">' . $_lang['strict_mode_error'] . '</span></p>';
279
            } else {
280
                echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
281
            }
282
        }
283
    } else {
284
        echo '<span class="ok">' . $_lang['ok'] . '</span></p>';
285
    }
286
}
287
// Version and strict mode check end
288
289
// andrazk 20070416 - add install flag and disable manager login
290
// assets/cache writable?
291
if (is_writable("../assets/cache")) {
292
    if (file_exists('../assets/cache/installProc.inc.php')) {
293
        @chmod('../assets/cache/installProc.inc.php', 0755);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
294
        unlink('../assets/cache/installProc.inc.php');
295
    }
296
297
    f_owc("../assets/cache/installProc.inc.php", '<?php $installStartTime = '.time().'; ?>');
298
}
299
300
if($installMode > 0 && $_POST['installdata'] == "1") {
301
    echo '<p class="notes"><strong>' . $_lang['sample_web_site'] . ':</strong> ' . $_lang['sample_web_site_note'] . '</p>';
302
}
303
304
if ($errors > 0) {
305
    echo '<p>';
306
    echo $_lang['setup_cannot_continue'] . ' ';
307
308
    if($errors > 1){
309
        echo $errors . " " . $_lang['errors'] . $_lang['please_correct_errors'] . $_lang['and_try_again_plural'];
310
    }else{
311
        echo $_lang['error'] . $_lang['please_correct_error'] . $_lang['and_try_again'];
312
    }
313
314
    echo $_lang['visit_forum'];
315
    echo '</p>';
316
}
317
318
echo '<p>&nbsp;</p>';
319
320
$nextAction= $errors > 0 ? 'summary' : 'install';
321
$nextButton= $errors > 0 ? $_lang['retry'] : $_lang['install'];
322
$nextVisibility= $errors > 0 || isset($_POST['chkagree']) ? 'visible' : 'hidden';
323
$agreeToggle= $errors > 0 ? '' : ' onclick="if(document.getElementById(\'chkagree\').checked){document.getElementById(\'nextbutton\').style.visibility=\'visible\';}else{document.getElementById(\'nextbutton\').style.visibility=\'hidden\';}"';
324
?>
325
<form name="install" id="install_form" action="index.php?action=<?php echo $nextAction ?>" method="post">
326
  <div>
327
    <input type="hidden" value="<?php echo $install_language?>" name="language" />
328
    <input type="hidden" value="<?php echo $manager_language?>" name="managerlanguage" />
329
    <input type="hidden" value="<?php echo $installMode ?>" name="installmode" />
330
    <input type="hidden" value="<?php echo trim($_POST['database_name'], '`'); ?>" name="database_name" />
331
    <input type="hidden" value="<?php echo $_POST['tableprefix'] ?>" name="tableprefix" />
332
    <input type="hidden" value="<?php echo $_POST['database_collation'] ?>" name="database_collation" />
333
    <input type="hidden" value="<?php echo $_POST['database_connection_charset'] ?>" name="database_connection_charset" />
334
    <input type="hidden" value="<?php echo $_POST['database_connection_method'] ?>" name="database_connection_method" />
335
    <input type="hidden" value="<?php echo $_POST['databasehost'] ?>" name="databasehost" />
336
    <input type="hidden" value="<?php echo $_POST['cmsadmin'] ?>" name="cmsadmin" />
337
    <input type="hidden" value="<?php echo $_POST['cmsadminemail'] ?>" name="cmsadminemail" />
338
    <input type="hidden" value="<?php echo $_POST['cmspassword'] ?>" name="cmspassword" />
339
    <input type="hidden" value="<?php echo $_POST['cmspasswordconfirm'] ?>" name="cmspasswordconfirm" />
340
341
    <input type="hidden" value="1" name="options_selected" />
342
343
    <input type="hidden" value="<?php echo $_POST['installdata'] ?>" name="installdata" />
344
<?php
345
    $templates = isset ($_POST['template']) ? $_POST['template'] : array ();
346
    foreach ($templates as $i => $template) echo '<input type="hidden" name="template[]" value="'.$template.'" />';
347
348
    $tvs = isset ($_POST['tv']) ? $_POST['tv'] : array ();
349
    foreach ($tvs as $i => $tv) echo '<input type="hidden" name="tv[]" value="'.$tv.'" />';
350
351
    $chunks = isset ($_POST['chunk']) ? $_POST['chunk'] : array ();
352
    foreach ($chunks as $i => $chunk) echo '<input type="hidden" name="chunk[]" value="'.$chunk.'" />';
353
354
    $snippets = isset ($_POST['snippet']) ? $_POST['snippet'] : array ();
355
    foreach ($snippets as $i => $snippet) echo '<input type="hidden" name="snippet[]" value="'.$snippet.'" />';
356
357
    $plugins = isset ($_POST['plugin']) ? $_POST['plugin'] : array ();
358
    foreach ($plugins as $i => $plugin) echo '<input type="hidden" name="plugin[]" value="'.$plugin.'" />';
359
360
    $modules = isset ($_POST['module']) ? $_POST['module'] : array ();
361
    foreach ($modules as $i => $module) echo '<input type="hidden" name="module[]" value="'.$module.'" />';
362
?>
363
</div>
364
365
<h2><?php echo $_lang['agree_to_terms'];?></h2>
366
<p>
367
<input type="checkbox" value="1" id="chkagree" name="chkagree" style="line-height:18px" <?php echo isset($_POST['chkagree']) ? 'checked="checked" ':""; ?><?php echo $agreeToggle;?>/><label for="chkagree" style="display:inline;float:none;line-height:18px;"> <?php echo $_lang['iagree_box']?> </label>
368
</p>
369
    <p class="buttonlinks">
370
        <a href="javascript:document.getElementById('install_form').action='index.php?action=options&language=<?php echo $install_language?>';document.getElementById('install_form').submit();" class="prev" title="<?php echo $_lang['btnback_value']?>"><span><?php echo $_lang['btnback_value']?></span></a>
371
        <a id="nextbutton" href="javascript:document.getElementById('install_form').submit();" title="<?php echo $nextButton ?>" style="visibility:<?php echo $nextVisibility;?>"><span><?php echo $nextButton ?></span></a>
372
    </p>
373
</form>
374