Current Path : /compat/linux/proc/68247/root/compat/linux/proc/68247/root/compat/linux/proc/3760/root/home/tools/fm/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //compat/linux/proc/68247/root/compat/linux/proc/68247/root/compat/linux/proc/3760/root/home/tools/fm/fmzip.cgi |
#!/usr/bin/perl -w # # fmzip.cgi # #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// use Module #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= use strict; use CGI::FastTemplate; use LWP::UserAgent; use ADN::HTML; use ADN::Utility; #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// Controller #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// ---------------------------------------------------------- #// 変数設定 #// ---------------------------------------------------------- my $query = ADN::Utility::query(); my $mode = 0; my $action = 0; my $zip = ''; my $type = 0; if ($query->{form}->{mode}) { $mode = $query->{form}->{mode}; } if ($query->{form}->{action}) { $action = $query->{form}->{action}; } if ($query->{form}->{zip}) { $zip = $query->{form}->{zip}; } if ($query->{form}->{type}) { $type = $query->{form}->{type}; } if ($zip) { $zip =~ s/\-//g; } #// ---------------------------------------------------------- #// 設定ファイルからハッシュリファレンス生成 #// ---------------------------------------------------------- #// テスト環境か実環境か判定 my $file_conf0 = './fmadmin.conf'; my $conf0 = ADN::Utility::read_conf($file_conf0); my $path_tml = $conf0->{CUST_PATH_TML}; if ($mode == 1) { $path_tml = $conf0->{CUST_PATH_TML0}; } #// 対象設定ファイルから読み込み my $file_conf = $path_tml . $conf0->{CONF_FORM}; my $conf1 = ADN::Utility::read_conf($file_conf); #// 各ハッシュリファレンスを合成 my $conf = ADN::Utility::merge_conf($conf0, $conf1); $conf->{PATH_TML} = $path_tml; #// ---------------------------------------------------------- #// スイッチ #// ---------------------------------------------------------- my $tml = new CGI::FastTemplate($path_tml); #// URI アクセス my $uri = "http://www.drive.ne.jp/zip.cgi?action=$action&zip=$zip"; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => $uri); my $res = $ua->request($req); unless ($res->is_success) { show_error($tml, $conf, $conf->{ALERT_ZIP_CONNECT}); } #// 結果取得 my $tmp = '/tmp/' . 'fmzip.' . $$; open WRITE, "+>$tmp"; print WRITE $res->content; close WRITE; my $result = ADN::Utility::read_conf($tmp); unlink $tmp; #// エラー判定 unless ($result->{MAKE_ERROR} == 0) { my $code = 'ALERT_ZIP_CODE' . $result->{MAKE_ERROR}; show_error($tml, $conf, $conf->{$code}); } if ($result->{MAKE_NUM} == 0) { show_error($tml, $conf, $conf->{ALERT_ZIP_NORESULT}); } #// 正常時結果出力 $result->{MODE_FORM} = $mode; $result->{TYPE_ZIP} = $type; $result->{PATH_TML} = $path_tml; $result->{FILE_SCRIPT} = $ENV{SCRIPT_NAME}; make_tml($tml, $conf, $result); # print "Content-Type: text/plain;\n\n"; # print $res->content; #// HTML 出力 ADN::HTML::write_adn0($tml, $conf); #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #// Model (Logic) #// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= sub make_tml { my ($tml, $conf, $result) = @_; $tml->define(main => "zip.html"); $tml->assign($conf); $tml->assign(%$result); my $list = ''; my $list_js = ''; my $write_zip = ''; my @list = (); for (my $i = 0; $i < $result->{MAKE_NUM}; $i++) { my $target = 'MAKE_RESULT' . $i; my ($zip, $pref, $addr) = split(/ /, $result->{$target}); my $zip0 = substr($zip, 0, 3); my $zip1 = substr($zip, 3, 4); push(@list, "$zip0,$zip1,$pref,$addr"); $list .= ' <li>' . "$zip0-$zip1 => " . '<input type="radio" name="addr" value="' . "$zip0,$zip1,$pref,$addr" . '"'; if ($result->{MAKE_NUM} == 1) { $list .= ' checked="checked"'; } $list .= ' /> ' . $pref . $addr . "</li>\n"; } if ($result->{TYPE_ZIP} == 0) { $write_zip = "'" . $query->{form}->{zip0} . "', " . "'" . $query->{form}->{zip1} . "', " . "'" . $query->{form}->{pref0} . "', " . "'" . $query->{form}->{addr0} . "', " . $result->{TYPE_ZIP}; } else { $write_zip = "'" . $query->{form}->{zip0} . "', " . "'" . '' . "', " . "'" . $query->{form}->{pref0} . "', " . "'" . $query->{form}->{addr0} . "', " . $result->{TYPE_ZIP}; } my $num = 0; foreach (@list) { my ($zip0, $zip1, $pref, $addr) = split(/,/); $list_js .= ' zip0[' . $num . '] = "' . $zip0 . '";' . "\n"; $list_js .= ' zip1[' . $num . '] = "' . $zip1 . '";' . "\n"; $list_js .= ' pref[' . $num . '] = "' . $pref . '";' . "\n"; $list_js .= ' addr[' . $num . '] = "' . $addr . '";' . "\n"; $num += 1; } $list =~ s/\n$//; $tml->assign( MAKE_LIST => $list, MAKE_LIST_JS => $list_js, WRITE_ZIP => $write_zip, ); } sub show_error { my ($tml, $conf, $msg) = @_; $tml->define(main => 'zip_error.html'); $tml->assign($conf); $tml->assign(MAKE_MSG => $msg); ADN::HTML::write_adn($tml, $conf); exit; }