forked from jbuchbinder/legalcase
/
lcm_test_dirs.php
136 lines (101 loc) · 3.44 KB
/
lcm_test_dirs.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
<?php
include('inc/inc_version.php');
include_lcm('inc_presentation');
use_language_of_visitor();
function bad_dirs($bad_dirs, $test_dir, $install) {
install_html_start();
if ($install) {
$titre = _T('directories_setup_start');
} else
$titre = _T('directories_setup_problem');
$bad_url = "lcm_test_dirs.php";
if ($test_dir)
$bad_url .= '?test_dir=' . $test_dir;
echo "<h3>". $titre ."</h3>\n";
echo "<div align='right'>". menu_languages('var_lang_lcm') ."</div>\n";
echo "<div class='box_error'>\n";
echo "<p>". _T('directories_bad_rights') . "</p>\n";
echo "<ul>". $bad_dirs ."</ul>\n";
echo "<p>". _T('directories_bad_rights_cause') . lcm_help('install_permissions') . "</p>\n";
echo "</div>\n";
echo "<p>". _T('directories_continue') ."</p>\n";
echo "<form action='$bad_urls' method='get'>\n";
echo "<div align='right'><button class='fondl' name='Validate'>". _T('button_reload_page')."</button></div>";
echo "</form>";
install_html_end();
}
function absent_dirs($bad_dirs, $test_dir) {
install_html_start();
$titre = _T('directories_setup_start');
$bad_url = "lcm_test_dirs.php";
if ($test_dir)
$bad_url .= '?test_dir='. $test_dir;
echo "<h3>". $titre ."</h3>\n";
echo "<div align='right'>". menu_languages('var_lang_lcm') ."</div>\n";
echo "<div class='box_error'>\n";
echo "<p>". _T('directories_missing') . _T('typo_column') ."</p>\n";
echo "<ul>". $bad_dirs ."</ul>\n";
echo "<p>". _T('directories_missing_possible_cause') ."</p>\n";
echo "</div>\n";
// if ($install)
// echo aide ("install0");
echo "<p>". _T('directories_continue') ."</p>\n";
echo "<form action='$bad_urls' method='get'>\n";
echo "<div align='right'><input type='submit' class='fondl' name='Valider' value='". _T('button_reload_page')."'></div>";
echo "</form>";
install_html_end();
}
// Try to write in a directory
function test_write($my_dir) {
$ok = true;
$file_name = "$my_dir/test.txt";
$f = @fopen($file_name, "w");
if (!$f) $ok = false;
else if (!@fclose($f)) $ok = false;
else if (!@unlink($file_name)) $ok = false;
return $ok;
}
//
// Test rights on directories
//
$install = ! include_config_exists('inc_connect');
$dest_url = _request('url', 'index.php');
// Files to test
$test_dirs[] = (isset($_SERVER['LcmLogDir']) ? $_SERVER['LcmLogDir'] : 'log');
$test_dirs[] = (isset($_SERVER['LcmDataDir']) ? $_SERVER['LcmDataDir'] : 'inc/data');
// To be honest, we should always test for "if file can be read"
// but i'm lazy right now
if (! include_config_exists('inc_connect'))
$test_dirs[] = (isset($_SERVER['LcmConfigDir']) ? $_SERVER['LcmConfigDir'] : 'inc/config');
$bad_dirs = array();
$absent_dirs = array();
foreach ($test_dirs as $my_dir) {
if (@file_exists($my_dir)) {
@umask(0);
// If Apache is the owner of the file
if (! test_write($my_dir))
@chmod($my_dir, 0700);
// I doubt this will work, if above failed, but try anyway
if (! test_write($my_dir))
@chmod($my_dir, 0770);
if (! test_write($my_dir))
@chmod($my_dir, 0777);
if (! test_write($my_dir))
array_push($bad_dirs, "<li>". $my_dir ."</li>\n");
} else {
array_push($absent_dirs, "<li>". $my_dir ."</li>\n");
}
}
if (!empty($bad_dirs)) {
$bad_dirs = join(" ", $bad_dirs);
bad_dirs($bad_dirs, $test_dir, $install);
} else if (!empty($absent_dirs)) {
$absent_dirs = join(" ", $absent_dirs);
absent_dirs($absent_dirs, $test_dir);
} else {
if ($install)
lcm_header("Location: install.php?step=1");
else
lcm_header("Location: " . $dest_url);
}
?>