source: branches/version-2_5-dev/html/install/index.php @ 19760

Revision 19760, 34.7 KB checked in by Seasoft, 13 years ago (diff)

#771(magic_quotes_gpc が有効な環境を考慮する)実装

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23// ▼require.php 相当
24// rtrim は PHP バージョン依存対策
25define('HTML_PATH', rtrim(realpath(rtrim(realpath(dirname(__FILE__)), '/\\') . '/../'), '/\\') . '/');
26
27require_once HTML_PATH . 'define.php';
28define('INSTALL_FUNCTION', true);
29require_once HTML_PATH . HTML2DATA_DIR . 'require_base.php';
30// ▲require.php 相当
31
32$INSTALL_DIR = realpath(dirname( __FILE__));
33require_once(DATA_PATH . "module/Request.php");
34
35define("INSTALL_LOG", "./temp/install.log");
36ini_set("max_execution_time", 300);
37
38$objPage = new StdClass;
39$objPage->arrDB_TYPE = array(
40    'pgsql' => 'PostgreSQL',
41    'mysql' => 'MySQL'
42);
43$objPage->arrDB_PORT = array(
44    'pgsql' => '',
45    'mysql' => ''
46);
47
48$objDb = new SC_Helper_DB_Ex();
49
50// テンプレートコンパイルディレクトリの書込み権限チェック
51$temp_dir = $INSTALL_DIR . '/temp';
52
53if(!is_writable($temp_dir)) {
54    SC_Utils_Ex::sfErrorHeader($temp_dir . "にユーザ書込み権限(777, 707等)を付与して下さい。", true);
55    exit;
56}
57
58$objView = new SC_InstallView($INSTALL_DIR . '/templates', $INSTALL_DIR . '/temp');
59
60// パラメータ管理クラス
61$objWebParam = new SC_FormParam();
62$objDBParam = new SC_FormParam();
63// パラメータ情報の初期化
64$objWebParam = lfInitWebParam($objWebParam);
65$objDBParam = lfInitDBParam($objDBParam);
66
67//フォーム配列の取得
68$objWebParam->setParam($_POST);
69$objDBParam->setParam($_POST);
70
71$mode = isset($_POST['mode_overwrite']) ? $_POST['mode_overwrite'] : $_POST['mode'];
72
73switch($mode) {
74// ようこそ
75case 'welcome':
76    //$objPage = lfDispAgreement($objPage);
77    $objPage = lfDispStep0($objPage);
78    //$objPage->tpl_onload .= "fnChangeVisible('agreement_yes', 'next');";
79    break;
80
81/* 現在保留中
82
83// 使用許諾契約書の同意
84case 'agreement':
85    $objPage = lfDispStep0($objPage);
86    break;
87*/
88
89// アクセス権限のチェック
90case 'step0':
91    $objPage = lfDispStep0_1($objPage);
92    break;
93// ファイルのコピー
94case 'step0_1':
95    $objPage = lfDispStep1($objPage);
96    break;
97// WEBサイトの設定
98case 'step1':
99    //入力値のエラーチェック
100    $objPage->arrErr = lfCheckWEBError($objWebParam);
101    if(count($objPage->arrErr) == 0) {
102        $objPage = lfDispStep2($objPage);
103    } else {
104        $objPage = lfDispStep1($objPage);
105    }
106    break;
107// データベースの設定
108case 'step2':
109    //入力値のエラーチェック
110    $objPage->arrErr = lfCheckDBError($objDBParam);
111    if(count($objPage->arrErr) == 0) {
112        // 設定ファイルの生成
113        lfMakeConfigFile();
114        $objPage = lfDispStep3($objPage);
115    } else {
116        $objPage = lfDispStep2($objPage);
117    }
118    break;
119// テーブルの作成
120case 'step3':
121    // 入力データを渡す。
122    $arrRet =  $objDBParam->getHashArray();
123    define("DB_TYPE", $arrRet['db_type']);
124    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
125
126    if(count($objPage->arrErr) == 0) {
127        // スキップする場合には次画面へ遷移
128        $skip = $_POST["db_skip"];
129        if ($skip == "on") {
130            $objPage = lfDispComplete($objPage);
131            //$objPage = lfDispStep4($objPage);
132            break;
133        }
134    }
135
136    // テーブルの作成
137    $objPage->arrErr = lfExecuteSQL("./sql/create_table_".$arrRet['db_type'].".sql", $dsn);
138    if(count($objPage->arrErr) == 0) {
139        $objPage->tpl_message.="○:テーブルの作成に成功しました。<br>";
140    } else {
141        $objPage->tpl_message.="×:テーブルの作成に失敗しました。<br>";
142    }
143
144    // ビューの作成
145    if(count($objPage->arrErr) == 0 and $arrRet['db_type'] == 'pgsql') {
146        // ビューの作成
147        $objPage->arrErr = lfExecuteSQL("./sql/create_view.sql", $dsn);
148        if(count($objPage->arrErr) == 0) {
149            $objPage->tpl_message.="○:ビューの作成に成功しました。<br>";
150        } else {
151            $objPage->tpl_message.="×:ビューの作成に失敗しました。<br>";
152        }
153    }
154
155    // 初期データの作成
156    if(count($objPage->arrErr) == 0) {
157        $objPage->arrErr = lfExecuteSQL("./sql/insert_data.sql", $dsn);
158        if(count($objPage->arrErr) == 0) {
159            $objPage->tpl_message.="○:初期データの作成に成功しました。<br>";
160        } else {
161            $objPage->tpl_message.="×:初期データの作成に失敗しました。<br>";
162        }
163    }
164
165    // カラムコメントの書込み
166    if(count($objPage->arrErr) == 0) {
167        $objPage->arrErr = lfExecuteSQL("./sql/column_comment.sql", $dsn);
168        if(count($objPage->arrErr) == 0) {
169            $objPage->tpl_message.="○:カラムコメントの書込みに成功しました。<br>";
170        } else {
171            $objPage->tpl_message.="×:カラムコメントの書込みに失敗しました。<br>";
172        }
173    }
174
175    // テーブルコメントの書込み
176    if(count($objPage->arrErr) == 0) {
177        $objPage->arrErr = lfExecuteSQL("./sql/table_comment.sql", $dsn);
178        if(count($objPage->arrErr) == 0) {
179            $objPage->tpl_message.="○:テーブルコメントの書込みに成功しました。<br>";
180        } else {
181            $objPage->tpl_message.="×:テーブルコメントの書込みに失敗しました。<br>";
182        }
183    }
184
185    // シーケンスの作成
186    if (count($objPage->arrErr) == 0) {
187        $objPage->arrErr = lfCreateSequence(getSequences(), $dsn);
188        if(count($objPage->arrErr) == 0) {
189            $objPage->tpl_message.="○:シーケンスの作成に成功しました。<br>";
190        } else {
191            $objPage->tpl_message.="×:シーケンスの作成に失敗しました。<br>";
192        }
193    }
194
195    if(count($objPage->arrErr) == 0) {
196        $objPage = lfDispStep3($objPage);
197        $objPage->tpl_mode = 'step4';
198    } else {
199        $objPage = lfDispStep3($objPage);
200    }
201    break;
202case 'step4':
203    $objPage = lfDispStep4($objPage);
204    break;
205
206// テーブル類削除
207case 'drop':
208    // 入力データを渡す。
209    $arrRet =  $objDBParam->getHashArray();
210    if (!defined("DB_TYPE")) {
211        define("DB_TYPE", $arrRet['db_type']);
212    }
213    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
214
215    if ($arrRet['db_type'] == 'pgsql'){
216        // ビューの削除
217        $objPage->arrErr = lfExecuteSQL("./sql/drop_view.sql", $dsn, false);
218        if(count($objPage->arrErr) == 0) {
219            $objPage->tpl_message.="○:ビューの削除に成功しました。<br>";
220        } else {
221            $objPage->tpl_message.="×:ビューの削除に失敗しました。<br>";
222        }
223    }
224
225    // テーブルの削除
226    if(count($objPage->arrErr) == 0) {
227        $objPage->arrErr = lfExecuteSQL("./sql/drop_table.sql", $dsn, false);
228        if(count($objPage->arrErr) == 0) {
229            $objPage->tpl_message.="○:テーブルの削除に成功しました。<br>";
230        } else {
231            $objPage->tpl_message.="×:テーブルの削除に失敗しました。<br>";
232        }
233    }
234
235    // シーケンスの削除
236    if(count($objPage->arrErr) == 0) {
237        $objPage->arrErr = lfDropSequence(getSequences(), $dsn);
238        if(count($objPage->arrErr) == 0) {
239            $objPage->tpl_message.="○:シーケンスの削除に成功しました。<br>";
240        } else {
241            $objPage->tpl_message.="×:シーケンスの削除に失敗しました。<br>";
242        }
243    }
244
245    $objPage = lfDispStep3($objPage);
246    break;
247// 完了画面
248case 'complete':
249    // ショップマスタ情報の書き込み
250    $arrRet =  $objDBParam->getHashArray();
251
252    $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
253    $sqlval['shop_name'] = $objWebParam->getValue('shop_name');
254    $sqlval['email01'] = $objWebParam->getValue('admin_mail');
255    $sqlval['email02'] = $objWebParam->getValue('admin_mail');
256    $sqlval['email03'] = $objWebParam->getValue('admin_mail');
257    $sqlval['email04'] = $objWebParam->getValue('admin_mail');
258    $sqlval['email05'] = $objWebParam->getValue('admin_mail');
259    $sqlval['top_tpl'] = "default1";
260    $sqlval['product_tpl'] = "default1";
261    $sqlval['detail_tpl'] = "default1";
262    $sqlval['mypage_tpl'] = "default1";
263    $objQuery = new SC_Query($dsn);
264    $cnt = $objQuery->count("dtb_baseinfo");
265    if($cnt > 0) {
266        $objQuery->update("dtb_baseinfo", $sqlval);
267    } else {
268        $objQuery->insert("dtb_baseinfo", $sqlval);
269    }
270
271    // 管理者登録
272    $login_id = $objWebParam->getValue('login_id');
273    $login_pass = sha1($objWebParam->getValue('login_pass') . ":" . AUTH_MAGIC);
274
275    $sql = "DELETE FROM dtb_member WHERE login_id = ?";
276    $objQuery->query($sql, array($login_id));
277
278    $sql = "INSERT INTO dtb_member (member_id, name, login_id, password, creator_id, authority, work, del_flg, rank, create_date, update_date)
279            VALUES (?,'管理者',?,?,0,0,1,0,1, now(), now());";
280    $member_id = $objQuery->nextVal("dtb_member_member_id");
281    $objQuery->query($sql, array($member_id, $login_id, $login_pass));
282
283    $GLOBAL_ERR = "";
284    $objPage = lfDispComplete($objPage);
285
286    if(isset($_POST['send_info']) && $_POST['send_info'] === 'true'){
287        // サイト情報を送信
288        $req = new HTTP_Request("http://www.ec-cube.net/mall/use_site.php");
289        $req->setMethod(HTTP_REQUEST_METHOD_POST);
290
291        $arrSendData = array();
292        foreach($_POST as $key => $val){
293            if (ereg("^senddata_*", $key)){
294                $arrSendDataTmp = array(str_replace("senddata_", "", $key) => $val);
295                $arrSendData = array_merge($arrSendData, $arrSendDataTmp);
296            }
297        }
298
299        $req->addPostDataArray($arrSendData);
300
301        if (!PEAR::isError($req->sendRequest())) {
302            $response1 = $req->getResponseBody();
303        } else {
304            $response1 = "";
305        }
306        $req->clearPostData();
307    }
308
309    break;
310case 'return_step0':
311    $objPage = lfDispStep0($objPage);
312    break;
313case 'return_step1':
314    $objPage = lfDispStep1($objPage);
315    break;
316case 'return_step2':
317    $objPage = lfDispStep2($objPage);
318    break;
319case 'return_step3':
320    $objPage = lfDispStep3($objPage);
321    break;
322case 'return_agreement':
323    $objPage = lfDispAgreement($objPage);
324    $objPage->tpl_onload .= "fnChangeVisible('agreement_yes', 'next');";
325    break;
326case 'return_welcome':
327default:
328    $objPage = lfDispWelcome($objPage);
329    break;
330}
331
332//フォーム用のパラメータを返す
333$objPage->arrForm = $objWebParam->getFormParamList();
334$objPage->arrForm = array_merge($objPage->arrForm, $objDBParam->getFormParamList());
335
336// SiteInfoを読み込まない
337$objView->assignobj($objPage);
338$objView->display('install_frame.tpl');
339//-----------------------------------------------------------------------------------------------------------------------------------
340// ようこそ画面の表示
341function lfDispWelcome($objPage) {
342    global $objWebParam;
343    global $objDBParam;
344    // hiddenに入力値を保持
345    $objPage->arrHidden = $objWebParam->getHashArray();
346    // hiddenに入力値を保持
347    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
348    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
349    $objPage->arrHidden['agreement'] = $_POST['agreement'];
350    $objPage->tpl_mainpage = 'welcome.tpl';
351    $objPage->tpl_mode = 'welcome';
352    return $objPage;
353}
354
355// 使用許諾契約書の表示
356function lfDispAgreement($objPage) {
357    global $objWebParam;
358    global $objDBParam;
359    // hiddenに入力値を保持
360    $objPage->arrHidden = $objWebParam->getHashArray();
361    // hiddenに入力値を保持
362    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
363    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
364    $objPage->arrHidden['agreement'] = $_POST['agreement'];
365    $objPage->tpl_mainpage = 'agreement.tpl';
366    $objPage->tpl_mode = 'agreement';
367    return $objPage;
368}
369
370// STEP0画面の表示(チェック)
371function lfDispStep0($objPage) {
372    global $objWebParam;
373    global $objDBParam;
374    // hiddenに入力値を保持
375    $objPage->arrHidden = $objWebParam->getHashArray();
376    // hiddenに入力値を保持
377    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
378    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
379    $objPage->arrHidden['agreement'] = $_POST['agreement'];
380    $objPage->tpl_mainpage = 'step0.tpl';
381
382    // プログラムで書込みされるファイル・ディレクトリ
383    $arrWriteFile = array(
384        DATA_PATH . "install.php",
385        HTML_PATH . "user_data",
386        HTML_PATH . "upload",
387        DATA_PATH . "cache/",
388        DATA_PATH . "class/",
389        DATA_PATH . "Smarty/",
390        DATA_PATH . "logs/",
391        DATA_PATH . "downloads/",
392        DATA_PATH . "upload/",
393    );
394
395    $mess = "";
396    $hasErr = false;
397    foreach($arrWriteFile as $val) {
398        // listdirsの保持データを初期化
399        initdirs();
400        if (is_dir($val)) {
401           $arrDirs = listdirs($val);
402        } else {
403            $arrDirs = array($val);
404        }
405
406        foreach ($arrDirs as $path) {
407            if(file_exists($path)) {
408                $filemode = lfGetFileMode($path);
409                $real_path = realpath($path);
410
411                // ディレクトリの場合
412                if(is_dir($path)) {
413                    if(!is_writable($path)) {
414                        $mess.= ">> ×:$real_path($filemode) <br>ユーザ書込み権限(777, 707等)を付与して下さい。<br>";
415                        $hasErr = true;
416                    } else {
417                        GC_Utils_Ex::gfPrintLog("WRITABLE:".$path, INSTALL_LOG);
418                    }
419                } else {
420                    if(!is_writable($path)) {
421                        $mess.= ">> ×:$real_path($filemode) <br>ユーザ書込み権限(666, 606等)を付与して下さい。<br>";
422                        $hasErr = true;
423                    } else {
424                        GC_Utils_Ex::gfPrintLog("WRITABLE:".$path, INSTALL_LOG);
425                    }
426                }
427            } else {
428                $mess.= ">> ×:$path が見つかりません。<br>";
429                $hasErr = true;
430            }
431        }
432    }
433
434    if (ini_get('safe_mode')) {
435        $mess .= ">> ×:PHPのセーフモードが有効になっています。<br>";
436        $hasErr = true;
437    }
438
439    if (get_magic_quotes_gpc()) {
440        $mess .= ">> ×:PHPの設定ディレクティブ「magic_quotes_gpc」が有効になっています。<br>";
441        $hasErr = true;
442    }
443
444    // 問題点を検出している場合
445    if ($hasErr) {
446        $objPage->tpl_mode = 'return_step0';
447    }
448    // 問題点を検出していない場合
449    else {
450        $objPage->tpl_mode = 'step0';
451        umask(0);
452        $path = HTML_PATH . "upload/temp_template";
453        if(!file_exists($path)) {
454            mkdir($path);
455        }
456        $path = HTML_PATH . "upload/save_image";
457        if(!file_exists($path)) {
458            mkdir($path);
459        }
460        $path = HTML_PATH . "upload/temp_image";
461        if(!file_exists($path)) {
462            mkdir($path);
463        }
464        $path = HTML_PATH . "upload/graph_image";
465        if(!file_exists($path)) {
466            mkdir($path);
467        }
468        $path = HTML_PATH . "upload/mobile_image";
469        if(!file_exists($path)) {
470            mkdir($path);
471        }
472        $path = DATA_PATH . "downloads/module";
473        if(!file_exists($path)) {
474            mkdir($path);
475        }
476        $path = DATA_PATH . "downloads/update";
477        if(!file_exists($path)) {
478            mkdir($path);
479        }
480        $path = DATA_PATH . "upload/csv";
481        if(!file_exists($path)) {
482            mkdir($path);
483        }
484        $mess.= ">> ○:アクセス権限は正常です。<br>";
485    }
486
487    $objPage->mess = $mess;
488    $objPage->hasErr = $hasErr;
489
490    return $objPage;
491}
492
493// STEP0_1画面の表示(ファイルのコピー)
494function lfDispStep0_1($objPage) {
495    global $objWebParam;
496    global $objDBParam;
497
498    // hiddenに入力値を保持
499    $objPage->arrHidden = $objWebParam->getHashArray();
500    // hiddenに入力値を保持
501    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
502    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
503    $objPage->arrHidden['agreement'] = $_POST['agreement'];
504    $objPage->tpl_mainpage = 'step0_1.tpl';
505    $objPage->tpl_mode = 'step0_1';
506    // ファイルコピー
507    $objPage->copy_mess = SC_Utils_Ex::sfCopyDir("./user_data/", HTML_PATH . "user_data/", $objPage->copy_mess);
508    $objPage->copy_mess = SC_Utils_Ex::sfCopyDir("./save_image/", HTML_PATH . "upload/save_image/", $objPage->copy_mess);
509    return $objPage;
510}
511
512function lfGetFileMode($path) {
513    $mode = substr(sprintf('%o', fileperms($path)), -3);
514    return $mode;
515}
516
517// STEP1画面の表示
518function lfDispStep1($objPage) {
519    global $objDBParam;
520    // hiddenに入力値を保持
521    $objPage->arrHidden = $objDBParam->getHashArray();
522    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
523    $objPage->arrHidden['agreement'] = $_POST['agreement'];
524    $objPage->tpl_mainpage = 'step1.tpl';
525    $objPage->tpl_mode = 'step1';
526    return $objPage;
527}
528
529// STEP2画面の表示
530function lfDispStep2($objPage) {
531    global $objWebParam;
532    global $objDBParam;
533    // hiddenに入力値を保持
534    $objPage->arrHidden = $objWebParam->getHashArray();
535    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
536    $objPage->arrHidden['agreement'] = $_POST['agreement'];
537    $objPage->tpl_mainpage = 'step2.tpl';
538    $objPage->tpl_mode = 'step2';
539    return $objPage;
540}
541
542// STEP3画面の表示
543function lfDispStep3($objPage) {
544    global $objWebParam;
545    global $objDBParam;
546    // hiddenに入力値を保持
547    $objPage->arrHidden = $objWebParam->getHashArray();
548    // hiddenに入力値を保持
549    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
550    $objPage->arrHidden['agreement'] = $_POST['agreement'];
551    $objPage->tpl_db_skip = $_POST['db_skip'];
552    $objPage->tpl_mainpage = 'step3.tpl';
553    $objPage->tpl_mode = 'step3';
554    return $objPage;
555}
556
557// STEP4画面の表示
558function lfDispStep4($objPage) {
559    global $objWebParam;
560    global $objDBParam;
561    global $objDb;
562
563    // hiddenに入力値を保持
564    $objPage->arrHidden = $objWebParam->getHashArray();
565    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
566    // hiddenに入力値を保持
567    $objPage->arrHidden['agreement'] = $_POST['agreement'];
568
569    $normal_url = $objWebParam->getValue('normal_url');
570    // 語尾に'/'をつける
571    if (!ereg("/$", $normal_url)) $normal_url = $normal_url . "/";
572
573    $arrDbParam = $objDBParam->getHashArray();
574    if (!defined("DB_TYPE")) {
575        define("DB_TYPE", $arrDbParam['db_type']);
576    }
577    $dsn = $arrDbParam['db_type']."://".$arrDbParam['db_user'].":".$arrDbParam['db_password']."@".$arrDbParam['db_server'].":".$arrDbParam['db_port']."/".$arrDbParam['db_name'];
578
579    $objPage->tpl_site_url = $normal_url;
580    $objPage->tpl_shop_name = $objWebParam->getValue('shop_name');
581    $objPage->tpl_cube_ver = ECCUBE_VERSION;
582    $objPage->tpl_php_ver = phpversion();
583    $objPage->tpl_db_ver = $objDb->sfGetDBVersion($dsn);
584    $objPage->tpl_db_skip = $_POST['db_skip'];
585    $objPage->tpl_mainpage = 'step4.tpl';
586    $objPage->tpl_mode = 'complete';
587    return $objPage;
588}
589
590// 完了画面の表示
591function lfDispComplete($objPage) {
592    global $objWebParam;
593    global $objDBParam;
594    // hiddenに入力値を保持
595    $objPage->arrHidden = $objWebParam->getHashArray();
596    // hiddenに入力値を保持
597    $objPage->arrHidden = array_merge($objPage->arrHidden, $objDBParam->getHashArray());
598    $objPage->arrHidden['db_skip'] = $_POST['db_skip'];
599    $objPage->tpl_mainpage = 'complete.tpl';
600    $objPage->tpl_mode = 'complete';
601
602    $secure_url = $objWebParam->getValue('secure_url');
603    // 語尾に'/'をつける
604    if (!ereg("/$", $secure_url)) {
605        $secure_url = $secure_url . "/";
606    }
607    $objPage->tpl_sslurl = $secure_url;
608    return $objPage;
609}
610
611// WEBパラメータ情報の初期化
612function lfInitWebParam($objWebParam) {
613    global $objDb;
614
615    if(defined('SITE_URL')) {
616        $normal_url = SITE_URL;
617    } else {
618        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
619        $normal_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
620    }
621
622    if(defined('SSL_URL')) {
623        $secure_url = SSL_URL;
624    } else {
625        $dir = ereg_replace("install/.*$", "", $_SERVER['REQUEST_URI']);
626        $secure_url = "http://" . $_SERVER['HTTP_HOST'] . $dir;
627    }
628
629    // 店名、管理者メールアドレスを取得する。(再インストール時)
630    if(defined('DEFAULT_DSN')) {
631        $objQuery = new SC_Query();
632        $tables = $objQuery->listTables();
633
634        if(!PEAR::isError($tables) && in_array("dtb_baseinfo", $tables)) {
635            $arrRet = $objQuery->select("shop_name, email01", "dtb_baseinfo");
636            $shop_name = $arrRet[0]['shop_name'];
637            $admin_mail = $arrRet[0]['email01'];
638        }
639    }
640
641    $objWebParam->addParam("店名", "shop_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $shop_name);
642    $objWebParam->addParam("管理者:メールアドレス", "admin_mail", MTEXT_LEN, "", array("EXIST_CHECK","EMAIL_CHECK","EMAIL_CHAR_CHECK","MAX_LENGTH_CHECK"), $admin_mail);
643    $objWebParam->addParam("管理者:ログインID", "login_id", ID_MAX_LEN, "", array("EXIST_CHECK","SPTAB_CHECK", "ALNUM_CHECK"));
644    $objWebParam->addParam("管理者:パスワード", "login_pass", ID_MAX_LEN, "", array("EXIST_CHECK","SPTAB_CHECK", "ALNUM_CHECK"));
645    $objWebParam->addParam("URL(通常)", "normal_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $normal_url);
646    $objWebParam->addParam("URL(セキュア)", "secure_url", MTEXT_LEN, "", array("EXIST_CHECK","URL_CHECK","MAX_LENGTH_CHECK"), $secure_url);
647    $objWebParam->addParam("ドメイン", "domain", MTEXT_LEN, "", array("MAX_LENGTH_CHECK"));
648
649    return $objWebParam;
650}
651
652// DBパラメータ情報の初期化
653function lfInitDBParam($objDBParam) {
654
655    if(defined('DB_SERVER')) {
656        $db_server = DB_SERVER;
657    } else {
658        $db_server = "127.0.0.1";
659    }
660
661    if(defined('DB_TYPE')) {
662        $db_type = DB_TYPE;
663    } else {
664        $db_type = "";
665    }
666
667    if(defined('DB_PORT')) {
668        $db_port = DB_PORT;
669    } else {
670        $db_port = "";
671    }
672
673    if(defined('DB_NAME')) {
674        $db_name = DB_NAME;
675    } else {
676        $db_name = "eccube_db";
677    }
678
679    if(defined('DB_USER')) {
680        $db_user = DB_USER;
681    } else {
682        $db_user = "eccube_db_user";
683    }
684
685    $objDBParam->addParam("DBの種類", "db_type", INT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_type);
686    $objDBParam->addParam("DBサーバ", "db_server", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_server);
687    $objDBParam->addParam("DBポート", "db_port", INT_LEN, "", array("MAX_LENGTH_CHECK"), $db_port);
688    $objDBParam->addParam("DB名", "db_name", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_name);
689    $objDBParam->addParam("DBユーザ", "db_user", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"), $db_user);
690    $objDBParam->addParam("DBパスワード", "db_password", MTEXT_LEN, "", array("EXIST_CHECK","MAX_LENGTH_CHECK"));
691
692    return $objDBParam;
693}
694
695// 入力内容のチェック
696function lfCheckWebError($objFormParam) {
697    // 入力データを渡す。
698    $arrRet =  $objFormParam->getHashArray();
699    $objErr = new SC_CheckError($arrRet);
700    $objErr->arrErr = $objFormParam->checkError();
701
702    // ディレクトリ名のみ取得する
703    $normal_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['normal_url']);
704    $secure_dir = ereg_replace("^https?://[a-zA-Z0-9_~=&\?\.\-]+", "", $arrRet['secure_url']);
705
706    if($normal_dir != $secure_dir) {
707        $objErr->arrErr['normal_url'] = "URLに異なる階層を指定することはできません。";
708        $objErr->arrErr['secure_url'] = "URLに異なる階層を指定することはできません。";
709    }
710
711    // ログインIDチェック
712    $objErr->doFunc(array("管理者:ログインID",'login_id',ID_MIN_LEN , ID_MAX_LEN) ,array("SPTAB_CHECK" ,"NUM_RANGE_CHECK"));
713
714    // パスワードのチェック
715    $objErr->doFunc( array("管理者:パスワード",'login_pass',ID_MIN_LEN ,ID_MAX_LEN ) ,array("SPTAB_CHECK" ,"NUM_RANGE_CHECK" ));
716
717    return $objErr->arrErr;
718}
719
720// 入力内容のチェック
721function lfCheckDBError($objFormParam) {
722    global $objPage;
723
724    // 入力データを渡す。
725    $arrRet =  $objFormParam->getHashArray();
726
727    $objErr = new SC_CheckError($arrRet);
728    $objErr->arrErr = $objFormParam->checkError();
729
730    if(count($objErr->arrErr) == 0) {
731        // 接続確認
732        $dsn = $arrRet['db_type']."://".$arrRet['db_user'].":".$arrRet['db_password']."@".$arrRet['db_server'].":".$arrRet['db_port']."/".$arrRet['db_name'];
733        // Debugモード指定
734        $options['debug'] = PEAR_DB_DEBUG;
735        $objDB = MDB2::connect($dsn, $options);
736        // 接続成功
737        if(!PEAR::isError($objDB)) {
738            $dbFactory = SC_DB_DBFactory_Ex::getInstance();
739            // データベースバージョン情報の取得
740            $objPage->tpl_db_version = $dbFactory->sfGetDBVersion($dsn);
741        } else {
742            $objErr->arrErr['all'] = ">> " . $objDB->message . "<br>";
743            // エラー文を取得する
744            ereg("\[(.*)\]", $objDB->userinfo, $arrKey);
745            $objErr->arrErr['all'].= $arrKey[0] . "<br>";
746            GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
747        }
748    }
749    return $objErr->arrErr;
750}
751
752// SQL文の実行
753function lfExecuteSQL($filepath, $dsn, $disp_err = true) {
754    $arrErr = array();
755
756    if(!file_exists($filepath)) {
757        $arrErr['all'] = ">> スクリプトファイルが見つかりません";
758    } else {
759        if($fp = fopen($filepath,"r")) {
760            $sql = fread($fp, filesize($filepath));
761            fclose($fp);
762        }
763        // Debugモード指定
764        $options['debug'] = PEAR_DB_DEBUG;
765        $objDB = MDB2::connect($dsn, $options);
766        // 接続エラー
767        if(!PEAR::isError($objDB)) {
768            $sql_split = split(";",$sql);
769            foreach($sql_split as $key => $val){
770                SC_Utils::sfFlush();
771                if (trim($val) != "") {
772                    $ret = $objDB->query($val);
773                    if(PEAR::isError($ret) && $disp_err) {
774                        $arrErr['all'] = ">> " . $ret->message . "<br>";
775                        // エラー文を取得する
776                        ereg("\[(.*)\]", $ret->userinfo, $arrKey);
777                        $arrErr['all'].= $arrKey[0] . "<br>";
778                        $objPage->update_mess.=">> テーブル構成の変更に失敗しました。<br>";
779                        GC_Utils_Ex::gfPrintLog($ret->userinfo, INSTALL_LOG);
780                    } else {
781                        GC_Utils_Ex::gfPrintLog("OK:". $val, INSTALL_LOG);
782                    }
783                }
784            }
785        } else {
786            $arrErr['all'] = ">> " . $objDB->message;
787            GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
788        }
789    }
790    return $arrErr;
791}
792
793/**
794 * シーケンスを削除する.
795 *
796 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列
797 * @param string $dsn データソース名
798 * @return array エラーが発生した場合はエラーメッセージの配列
799 */
800function lfDropSequence($arrSequences, $dsn) {
801    $arrErr = array();
802
803    // Debugモード指定
804    $options['debug'] = PEAR_DB_DEBUG;
805    $objDB = MDB2::connect($dsn, $options);
806    $objManager =& $objDB->loadModule('Manager');
807
808    // 接続エラー
809    if (!PEAR::isError($objDB)) {
810
811        $exists = $objManager->listSequences();
812        foreach ($arrSequences as $seq) {
813            $seq_name = $seq[0] . "_" . $seq[1];
814            if (in_array($seq_name, $exists)) {
815                $result = $objManager->dropSequence($seq_name);
816                if (PEAR::isError($result)) {
817                    $arrErr['all'] = ">> " . $result->message . "<br />";
818                    GC_Utils_Ex::gfPrintLog($result->userinfo, INSTALL_LOG);
819                } else {
820                    GC_Utils_Ex::gfPrintLog("OK:". $seq_name, INSTALL_LOG);
821                }
822            }
823        }
824    } else {
825        $arrErr['all'] = ">> " . $objDB->message;
826        GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
827    }
828    return $arrErr;
829}
830
831/**
832 * シーケンスを生成する.
833 *
834 * @param array $arrSequences シーケンスのテーブル名, カラム名の配列
835 * @param string $dsn データソース名
836 * @return array エラーが発生した場合はエラーメッセージの配列
837 */
838function lfCreateSequence($arrSequences, $dsn) {
839   $arrErr = array();
840
841    // Debugモード指定
842    $options['debug'] = PEAR_DB_DEBUG;
843    $objDB = MDB2::connect($dsn, $options);
844    $objManager =& $objDB->loadModule('Manager');
845
846    // 接続エラー
847    if (!PEAR::isError($objDB)) {
848
849        $exists = $objManager->listSequences();
850        foreach ($arrSequences as $seq) {
851            $res = $objDB->query("SELECT max(" . $seq[1] . ") FROM ". $seq[0]);
852            if (PEAR::isError($res)) {
853                $arrErr['all'] = ">> " . $res->userinfo . "<br />";
854                GC_Utils_Ex::gfPrintLog($res->userinfo, INSTALL_LOG);
855                return $arrErr;
856            }
857            $max = $res->fetchOne();
858
859            $seq_name = $seq[0] . "_" . $seq[1];
860            $result = $objManager->createSequence($seq_name, $max + 1);
861            if (PEAR::isError($result)) {
862                $arrErr['all'] = ">> " . $result->message . "<br />";
863                GC_Utils_Ex::gfPrintLog($result->userinfo, INSTALL_LOG);
864            } else {
865                GC_Utils_Ex::gfPrintLog("OK:". $seq_name, INSTALL_LOG);
866            }
867        }
868    } else {
869        $arrErr['all'] = ">> " . $objDB->message;
870        GC_Utils_Ex::gfPrintLog($objDB->userinfo, INSTALL_LOG);
871    }
872    return $arrErr;
873}
874
875// 設定ファイルの作成
876function lfMakeConfigFile() {
877    global $objWebParam;
878    global $objDBParam;
879   
880    $normal_url = $objWebParam->getValue('normal_url');
881    // 語尾に'/'をつける
882    if (!ereg("/$", $normal_url)) {
883        $normal_url = $normal_url . "/";
884    }
885
886    $secure_url = $objWebParam->getValue('secure_url');
887    // 語尾に'/'をつける
888    if (!ereg("/$", $secure_url)) {
889        $secure_url = $secure_url . "/";
890    }
891
892    // ディレクトリの取得
893    $url_dir = ereg_replace("^https?://[a-zA-Z0-9_:~=&\?\.\-]+", "", $normal_url);
894
895    $filepath = DATA_PATH . "install.php";
896
897    $config_data =
898    "<?php\n".
899    "    define ('ECCUBE_INSTALL', 'ON');\n" .
900    "    define ('SITE_URL', '" . $normal_url . "');\n" .
901    "    define ('SSL_URL', '" . $secure_url . "');\n" .
902    "    define ('URL_DIR', '" . $url_dir . "');\n" .
903    "    define ('DOMAIN_NAME', '" . $objWebParam->getValue('domain') . "');\n" .
904    "    define ('DB_TYPE', '" . $objDBParam->getValue('db_type') . "');\n" .
905    "    define ('DB_USER', '" . $objDBParam->getValue('db_user') . "');\n" .
906    "    define ('DB_PASSWORD', '" . $objDBParam->getValue('db_password') . "');\n" .
907    "    define ('DB_SERVER', '" . $objDBParam->getValue('db_server') . "');\n" .
908    "    define ('DB_NAME', '" . $objDBParam->getValue('db_name') . "');\n" .
909    "    define ('DB_PORT', '" . $objDBParam->getValue('db_port') .  "');\n" .
910    "?>";
911
912    if($fp = fopen($filepath,"w")) {
913        fwrite($fp, $config_data);
914        fclose($fp);
915    }
916}
917
918/**
919 * $dir を再帰的に辿ってパス名を配列で返す.
920 *
921 * @param string 任意のパス名
922 * @return array $dir より下層に存在するパス名の配列
923 * @see http://www.php.net/glob
924 */
925$alldirs = array();
926function listdirs($dir) {
927    global $alldirs;
928    $dirs = glob($dir . '/*');
929    if (is_array($dirs) && count($dirs) > 0) {
930        foreach ($dirs as $d) {
931            $alldirs[] = $d;
932            listdirs($d);
933        }
934    }
935    return $alldirs;
936}
937
938/**
939 * 保持したスタティック変数をクリアする。
940 */
941function initdirs() {
942    global $alldirs;
943    $alldirs = array();
944}
945
946/**
947 * シーケンスを使用するテーブル名とカラム名の配列を返す.
948 *
949 * @return array シーケンスを使用するテーブル名とカラム名の配列
950 */
951function getSequences() {
952    return array(array("dtb_best_products","best_id"),
953                 array("dtb_bloc", "bloc_id"),
954                 array("dtb_category", "category_id"),
955                 array("dtb_class", "class_id"),
956                 array("dtb_classcategory", "classcategory_id"),
957                 array("dtb_csv", "no"),
958                 array("dtb_csv_sql", "sql_id"),
959                 array("dtb_customer", "customer_id"),
960                 array("dtb_deliv", "deliv_id"),
961                 array("dtb_holiday", "holiday_id"),
962                 array("dtb_kiyaku", "kiyaku_id"),
963                 array("dtb_mail_history", "send_id"),
964                 array("dtb_maker", "maker_id"),
965                 array("dtb_member", "member_id"),
966                 array("dtb_mobile_kara_mail", "kara_mail_id"),
967                 array("dtb_module_update_logs", "log_id"),
968                 array("dtb_news", "news_id"),
969                 array("dtb_order", "order_id"),
970                 array("dtb_other_deliv", "other_deliv_id"),
971                 array("dtb_pagelayout", "page_id"),
972                 array("dtb_payment", "payment_id"),
973                 array("dtb_products_class", "product_class_id"),
974                 array("dtb_products", "product_id"),
975                 array("dtb_class_combination", "class_combination_id"),
976                 array("dtb_review", "review_id"),
977                 array("dtb_send_history", "send_id"),
978                 array("dtb_site_control", "control_id"),
979                 array("dtb_table_comment", "id"),
980                 array("dtb_trackback", "trackback_id"));
981}
982?>
Note: See TracBrowser for help on using the repository browser.