/
OriginalFiles.php
186 lines (161 loc) · 4.33 KB
/
OriginalFiles.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
/**
* Handles the creation of files and folders if not found.
*
* Wedge (http://wedge.org)
* Copyright © 2010 René-Gilles Deberdt, wedge.org
* Portions are © 2011 Simple Machines.
* License: http://wedge.org/license/
*/
if (!defined('WEDGE'))
die('Hacking attempt...');
function create_settings_file()
{
$file = '<' . '?php
/**
* Contains the master settings for Wedge, including database credentials.
* DO NOT CHANGE ANYTHING, UNLESS YOU KNOW WHAT YOU\'RE DOING!
*
* Wedge (http://wedge.org)
* Copyright © 2010 René-Gilles Deberdt, wedge.org
* License: http://wedge.org/license/
*/
# 1 = Maintenance Mode (admin-only)
# 2 = Install Mode
# 3 = Closed Mode. EVEN to admins! Change to 0 here to reopen.
$maintenance = 2;
$mtitle = \'Maintenance Mode\';
$mmessage = \'This website is currently under maintenance. Please bear with us, we\\\'ll restore access as soon as we can!\';
# Forum details
$mbname = \'My Community\';
$boardurl = \'http://127.0.0.1/wedge\'; # URL to your forum\'s root folder
$webmaster_email = \'noreply@myserver.com\';
$cookiename = \'WedgeCookie01\';
$cache_type = \'file\';
$we_shot = ' . WEDGE . ';
# MySQL server
$db_server = \'localhost\';
$db_name = \'wedge\';
$db_user = \'root\';
$db_passwd = \'\';
$ssi_db_user = \'\';
$ssi_db_passwd = \'\';
$db_prefix = \'wedge_\';
$db_persist = 0;
$db_error_send = 1;
$db_show_debug = false;
$db_last_error = 0;
';
foreach (array('/Settings_bak.php', '/Settings.php') as $target)
if (!file_exists(ROOT_DIR . $target))
file_put_contents(ROOT_DIR . $target, $file . "\n?" . '>');
}
function create_generic_folders()
{
$folders = array(
'attachments' => true,
'gz' => array(
'app',
'keys',
'css',
'js',
'lang',
),
'media' => array(
'album_icons',
'albums',
'avatars',
'ftp',
'icons',
'tmp',
),
'plugins' => true,
);
foreach ($folders as $key => $folder)
{
if (!file_exists(ROOT_DIR . '/' . $key))
create_generic_folder(ROOT_DIR, $key);
if (is_array($folder))
foreach ($folder as $sub_folder)
if (!file_exists(ROOT_DIR . '/' . $key . '/' . $sub_folder))
create_generic_folder(ROOT_DIR, $key . '/' . $sub_folder);
}
}
function create_generic_folder($root_dir, $folder)
{
// We're gonna let PHP output warnings or errors on mkdir and copy, because it's serious stuff.
$path = str_replace('/', DIRECTORY_SEPARATOR, $root_dir . '/' . $folder);
mkdir($path);
// We need to put and index.php file in all folders.
file_put_contents($path . '/index.php', '<' . '?php
// Redirect to the upper level.
header(\'Location: ../\');');
// Copy assets/icons/media to media/icons. After that, you can freely delete the originals.
if ($folder == 'media/icons' && file_exists($root_dir . '/assets/icons/media'))
foreach (glob($root_dir . '/assets/icons/media/*.png') as $png_file)
copy($png_file, $root_dir . '/media/icons/' . basename($png_file));
// We need to be able to access images and various other files from plugins/, but not the archives of plugins themselves.
if ($folder == 'plugins')
$file = '
<FilesMatch "\.(zip|gz|bz2|tar|xml)$">
Order Deny,Allow
Deny from all
</FilesMatch>';
elseif ($folder == 'gz')
$file = '
<Files *.php>
Deny from all
</Files>
<Files *.lock>
Deny from all
</Files>
<Files index.php>
Allow from all
</Files>';
elseif ($folder == 'gz/lang' || $folder == 'gz/keys')
$file = '
<Files *.php>
Deny from all
</Files>
<Files index.php>
Allow from all
</Files>';
elseif ($folder == 'gz/css' || $folder == 'gz/js')
$file = '
<Files *.php>
Deny from all
</Files>
<Files index.php>
Allow from all
</Files>
<IfModule mod_mime.c>
AddEncoding x-gzip .gz
AddEncoding x-gzip .cgz
AddEncoding x-gzip .jgz
<FilesMatch "\.(js\.gz|jgz)$">
ForceType text/javascript
</FilesMatch>
<FilesMatch "\.(css\.gz|cgz)$">
ForceType text/css
</FilesMatch>
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control "max-age=2592000"
Header set Expires "Thu, 21 March 2025 03:42:00 GMT"
Header set Vary "Accept-Encoding"
</IfModule>
FileETag none';
// That's a peculiar one, security-oriented. Not justified, if you ask me.
elseif ($folder == 'attachments')
$file = '
<Files *>
Order Deny,Allow
Deny from all
Allow from localhost
</Files>
<IfModule mod_mime.c>
RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml
</IfModule>';
if (isset($file))
file_put_contents($path . '/.htaccess', $file);
}