1 | <?php |
---|
2 | /** |
---|
3 | * @copyright 2005-2007 OpenPNE Project |
---|
4 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
5 | */ |
---|
6 | |
---|
7 | require_once 'OpenPNE/Action.php'; |
---|
8 | |
---|
9 | // __Framework |
---|
10 | $GLOBALS['__Framework']['current_module'] = ''; |
---|
11 | $GLOBALS['__Framework']['current_type'] = ''; |
---|
12 | $GLOBALS['__Framework']['current_action'] = ''; |
---|
13 | $GLOBALS['__Framework']['default_type'] = 'page'; |
---|
14 | $GLOBALS['__Framework']['default_page'] = ''; |
---|
15 | $GLOBALS['__Framework']['is_secure'] = true; |
---|
16 | |
---|
17 | /** |
---|
18 | * 初期実行 index.php から呼ばれる |
---|
19 | */ |
---|
20 | function openpne_execute() |
---|
21 | { |
---|
22 | $module = ''; |
---|
23 | $type = ''; |
---|
24 | $action = ''; |
---|
25 | |
---|
26 | if (!($module = get_request_var('m'))) { |
---|
27 | // モジュール名の自動設定 |
---|
28 | if (!db_admin_user_exists()) { |
---|
29 | $module = 'setup'; |
---|
30 | } elseif (isKtaiUserAgent()) { |
---|
31 | $module = 'ktai'; |
---|
32 | } else { |
---|
33 | $module = 'pc'; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | $types = array('page', 'do'); |
---|
38 | if ($a = get_request_var('a')) { |
---|
39 | $arr = explode('_', $a, 2); |
---|
40 | if (!empty($arr[1]) && in_array($arr[0], $types)) { |
---|
41 | $type = $arr[0]; |
---|
42 | $action = $arr[1]; |
---|
43 | } |
---|
44 | } |
---|
45 | openpne_forward($module, $type, $action); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * J-PHONE 旧機種対応のため GET 優先でリクエスト変数を取得 |
---|
50 | */ |
---|
51 | function get_request_var($key) |
---|
52 | { |
---|
53 | if (isset($_GET[$key])) { |
---|
54 | return $_GET[$key]; |
---|
55 | } elseif (isset($_POST[$key])) { |
---|
56 | return $_POST[$key]; |
---|
57 | } elseif (isset($_REQUEST[$key])) { |
---|
58 | return $_REQUEST[$key]; |
---|
59 | } else { |
---|
60 | return ''; |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * openpne_forward |
---|
66 | * |
---|
67 | * @param string $module a requested module name. |
---|
68 | * @param string $type request type. 'page' or 'do' |
---|
69 | * @param string $action requested page/command name. |
---|
70 | * @param array $errors error message strings. |
---|
71 | */ |
---|
72 | function openpne_forward($module, $type = '', $action = '', $errors = array()) |
---|
73 | { |
---|
74 | /// module /// |
---|
75 | if (!$module = _check_module($module)) { |
---|
76 | openpne_display_error('モジュールが見つかりません', true); |
---|
77 | } |
---|
78 | $GLOBALS['__Framework']['current_module'] = $module; |
---|
79 | |
---|
80 | // disable modules |
---|
81 | if (in_array($module, (array)$GLOBALS['_OPENPNE_DISABLE_MODULES'])) { |
---|
82 | openpne_display_error('モジュールが無効になっています', true); |
---|
83 | } |
---|
84 | // maintenace mode |
---|
85 | if (OPENPNE_UNDER_MAINTENANCE && |
---|
86 | !in_array($module, (array)$GLOBALS['_OPENPNE_MAINTENANCE_MODULES'])) { |
---|
87 | openpne_display_error(); |
---|
88 | } |
---|
89 | |
---|
90 | // init |
---|
91 | if ($init = openpne_ext_search("{$module}/init.inc")) { |
---|
92 | require_once $init; |
---|
93 | } |
---|
94 | |
---|
95 | /// type /// |
---|
96 | if (!$type) { |
---|
97 | $type = $GLOBALS['__Framework']['default_type']; |
---|
98 | } |
---|
99 | if (!_check_type($type)) { |
---|
100 | openpne_display_error('リクエストの種類が正しくありません', true); |
---|
101 | } |
---|
102 | $GLOBALS['__Framework']['current_type'] = $type; |
---|
103 | |
---|
104 | /// action /// |
---|
105 | if (!$action = _check_action($action)) { |
---|
106 | openpne_display_error('アクションの指定が正しくありません', true); |
---|
107 | } |
---|
108 | |
---|
109 | if (!$file = openpne_ext_search("{$module}/{$type}/{$action}.php")) { |
---|
110 | openpne_display_error('アクションファイルが見つかりません', true); |
---|
111 | } |
---|
112 | require_once $file; |
---|
113 | $class_name = "{$module}_{$type}_{$action}"; |
---|
114 | if (!class_exists($class_name)) { |
---|
115 | openpne_display_error('アクションが見つかりません', true); |
---|
116 | } |
---|
117 | $action_obj = new $class_name(); |
---|
118 | $GLOBALS['__Framework']['current_action'] = $action; |
---|
119 | |
---|
120 | // auth |
---|
121 | if ($GLOBALS['__Framework']['is_secure'] = $action_obj->isSecure()) { |
---|
122 | if ($auth = openpne_ext_search("{$module}/auth.inc")) { |
---|
123 | require_once $auth; |
---|
124 | } else { |
---|
125 | require_once 'auth.inc'; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | // ---------- リクエストバリデーション ---------- |
---|
130 | |
---|
131 | require_once 'OpenPNE/Validator.php'; |
---|
132 | require_once 'OpenPNE/Validator/Common.php'; |
---|
133 | $validator = new OpenPNE_Validator_Common(); |
---|
134 | |
---|
135 | $files = array(); |
---|
136 | if ($ini = openpne_ext_search("{$module}/validate/{$type}/{$action}.ini")) { |
---|
137 | $files[] = $ini; |
---|
138 | } |
---|
139 | list($result, $requests) = $validator->common_validate($files); |
---|
140 | $action_obj->requests = $requests; |
---|
141 | if ($result === false) { |
---|
142 | $errors = $validator->getErrors(); |
---|
143 | $action_obj->handleError($errors); |
---|
144 | } |
---|
145 | |
---|
146 | // ---------------------------------------------- |
---|
147 | |
---|
148 | switch ($type) { |
---|
149 | case 'page': |
---|
150 | $smarty = new OpenPNE_Smarty($GLOBALS['SMARTY']); |
---|
151 | $smarty->templates_dir = $module . '/templates'; |
---|
152 | |
---|
153 | $smarty->assign('requests', $requests); |
---|
154 | |
---|
155 | $smarty->assign('msg', $requests['msg']); |
---|
156 | $smarty->assign('msg1', $requests['msg1']); |
---|
157 | $smarty->assign('msg2', $requests['msg2']); |
---|
158 | $smarty->assign('msg3', $requests['msg3']); |
---|
159 | if ($errors) { |
---|
160 | $smarty->assign('errors', $errors); |
---|
161 | } |
---|
162 | |
---|
163 | if (OPENPNE_USE_PARTIAL_SSL) { |
---|
164 | $a = "{$type}_{$action}"; |
---|
165 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
---|
166 | $p = $_POST; |
---|
167 | } else { |
---|
168 | $p = $_GET; |
---|
169 | } |
---|
170 | switch (openpne_ssl_type($module, $a)) { |
---|
171 | case 'SSL_REQUIRED': |
---|
172 | if (!is_ssl()) { |
---|
173 | openpne_redirect($module, $a, $p); |
---|
174 | } |
---|
175 | break; |
---|
176 | case 'SSL_DISABLED': |
---|
177 | if (is_ssl()) { |
---|
178 | openpne_redirect($module, $a, $p); |
---|
179 | } |
---|
180 | break; |
---|
181 | case 'SSL_SELECTABLE': |
---|
182 | if ($https = is_ssl()) { |
---|
183 | $url = openpne_gen_url($module, $a, $p, true, 'nonssl'); |
---|
184 | } else { |
---|
185 | $url = openpne_gen_url($module, $a, $p, true, 'ssl'); |
---|
186 | } |
---|
187 | $smarty->assign('HTTPS', $https); |
---|
188 | $smarty->assign('SSL_SELECT_URL', $url); |
---|
189 | break; |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | $action_obj->view =& $smarty; |
---|
194 | break; |
---|
195 | } |
---|
196 | |
---|
197 | // init function |
---|
198 | $init_func = "init_{$module}_{$type}"; |
---|
199 | if (function_exists($init_func)) { |
---|
200 | if (isset($smarty)) { |
---|
201 | $init_func($smarty); |
---|
202 | } else { |
---|
203 | $init_func(); |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | $result = $action_obj->execute($requests); |
---|
208 | if ($result == 'success') { |
---|
209 | send_nocache_headers(); |
---|
210 | $smarty->ext_display("{$action}.tpl"); |
---|
211 | } |
---|
212 | // ---------------------------------------------- |
---|
213 | |
---|
214 | //logger |
---|
215 | if (LOG_C_ACCESS_LOG) { |
---|
216 | if ($GLOBALS['__Framework']['is_secure'] && $type == 'page') { |
---|
217 | if ($module == 'pc') { |
---|
218 | p_access_log($GLOBALS['AUTH']->uid(), $action); |
---|
219 | } elseif ($module == 'ktai') { |
---|
220 | p_access_log($GLOBALS['KTAI_C_MEMBER_ID'], $action, 1); |
---|
221 | } |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | return true; |
---|
226 | } |
---|
227 | |
---|
228 | function openpne_display_error($errors = array(), $notfound = false) |
---|
229 | { |
---|
230 | $smarty = new OpenPNE_Smarty($GLOBALS['SMARTY']); |
---|
231 | $smarty->setOutputCharset('SJIS'); |
---|
232 | $smarty->assign('notfound', $notfound); |
---|
233 | if (OPENPNE_DEBUGGING) { |
---|
234 | $smarty->assign('errors', (array)$errors); |
---|
235 | } |
---|
236 | $smarty->ext_display('error.tpl'); |
---|
237 | exit; |
---|
238 | } |
---|
239 | |
---|
240 | function openpne_ext_search($path) |
---|
241 | { |
---|
242 | $dft = OPENPNE_MODULES_DIR . '/' . $path; |
---|
243 | $ext = OPENPNE_MODULES_EXT_DIR . '/' . $path; |
---|
244 | $biz = OPENPNE_MODULES_BIZ_DIR . '/' . $path; |
---|
245 | |
---|
246 | if (USE_EXT_DIR && is_readable($ext)) { |
---|
247 | return $ext; |
---|
248 | } elseif (USE_BIZ_DIR && is_readable($biz)) { |
---|
249 | return $biz; |
---|
250 | } elseif (is_readable($dft)) { |
---|
251 | return $dft; |
---|
252 | } |
---|
253 | |
---|
254 | return false; |
---|
255 | } |
---|
256 | |
---|
257 | /** |
---|
258 | * モジュール名を取得 |
---|
259 | * 空の場合はデフォルトモジュールを返す |
---|
260 | * |
---|
261 | * 間違ったモジュール名を指定した |
---|
262 | * デフォルトモジュールが存在しない場合は false |
---|
263 | * |
---|
264 | * @param string $module module name |
---|
265 | */ |
---|
266 | function _check_module($module) |
---|
267 | { |
---|
268 | // 英数字とアンダーバーのみ |
---|
269 | // 「../」等は許さない |
---|
270 | if (preg_match('/\W/', $module)) { |
---|
271 | // モジュール名が不正です |
---|
272 | return false; |
---|
273 | } |
---|
274 | |
---|
275 | if (empty($module)) { |
---|
276 | // モジュールが指定されていません |
---|
277 | return false; |
---|
278 | } |
---|
279 | |
---|
280 | if ($module == ADMIN_MODULE_NAME) { |
---|
281 | $module = 'admin'; |
---|
282 | } elseif ($module == 'admin') { |
---|
283 | return false; |
---|
284 | } |
---|
285 | |
---|
286 | if (!openpne_ext_search($module)) { |
---|
287 | return false; |
---|
288 | } |
---|
289 | |
---|
290 | return $module; |
---|
291 | } |
---|
292 | |
---|
293 | function _check_type($type) |
---|
294 | { |
---|
295 | switch ($type) { |
---|
296 | case 'page': |
---|
297 | case 'do': |
---|
298 | break; |
---|
299 | default: |
---|
300 | // unknown type |
---|
301 | return false; |
---|
302 | } |
---|
303 | |
---|
304 | return $type; |
---|
305 | } |
---|
306 | |
---|
307 | function _check_action($action) |
---|
308 | { |
---|
309 | // 英数字とアンダーバーのみ |
---|
310 | // 「../」等は許さない |
---|
311 | if (preg_match('/\W/', $action)) { |
---|
312 | // アクション名が不正です |
---|
313 | return false; |
---|
314 | } |
---|
315 | |
---|
316 | if (empty($action)) { |
---|
317 | $type = $GLOBALS['__Framework']['current_type']; |
---|
318 | if (empty($GLOBALS['__Framework']['default_' . $type])) { |
---|
319 | // ページが指定されていません |
---|
320 | return false; |
---|
321 | } else { |
---|
322 | $action = $GLOBALS['__Framework']['default_' . $type]; |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | return $action; |
---|
327 | } |
---|
328 | |
---|
329 | function send_nocache_headers() |
---|
330 | { |
---|
331 | if (!headers_sent()) { |
---|
332 | // no-cache |
---|
333 | // 日付が過去 |
---|
334 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
---|
335 | |
---|
336 | // 常に修正されている |
---|
337 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
---|
338 | |
---|
339 | // HTTP/1.1 |
---|
340 | header('Cache-Control: no-store, no-cache, must-revalidate'); |
---|
341 | header('Cache-Control: post-check=0, pre-check=0', false); |
---|
342 | // HTTP/1.0 |
---|
343 | header('Pragma: no-cache'); |
---|
344 | |
---|
345 | return true; |
---|
346 | } else { |
---|
347 | return false; |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | function handle_kengen_error() |
---|
352 | { |
---|
353 | switch ($GLOBALS['__Framework']['current_module']) { |
---|
354 | case 'pc': |
---|
355 | openpne_forward('pc', 'page', 'h_err_forbidden'); |
---|
356 | break; |
---|
357 | case 'ktai': |
---|
358 | ktai_display_error('このページにはアクセスすることができません。'); |
---|
359 | break; |
---|
360 | default: |
---|
361 | openpne_display_error('このページにはアクセスすることができません。'); |
---|
362 | break; |
---|
363 | } |
---|
364 | exit; |
---|
365 | } |
---|
366 | |
---|
367 | ?> |
---|