GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — p2-php/editfile.php at master · unpush/p2-php Expand file tree/ Copy patheditfile.phpMore file actions 171 lines (139 loc) · 4.7 KB / Copy patheditfile.phpFile metadata and controls171 lines (139 loc) · 4.7 KB 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 <?php /* ファイルをブラウザで編集する */ require_once './conf/conf.inc.php'; $_login->authorize(); // ユーザ認証 // 変数 ================================== $filename = isset($_REQUEST['file']) ? $_REQUEST['file'] : null; $modori_url = isset($_REQUEST['modori_url']) ? $_REQUEST['modori_url'] : null; $encode = isset($_REQUEST['encode']) ? $_REQUEST['encode'] : null; $rows = isset($_REQUEST['rows']) ? intval($_REQUEST['rows']) : ($_conf['ktai'] ? 5 : 36); $cols = isset($_REQUEST['cols']) ? intval($_REQUEST['cols']) : ($_conf['ktai'] ? 0 : 128); $csrfid = P2Util::getCsrfId(__FILE__ . $filename); //========================================================= // 前処理 //========================================================= // 不正ポストチェック if (isset($_POST['filecont'])) { if (!isset($_POST['csrfid']) || $_POST['csrfid'] != $csrfid) { p2die('不正なポストです'); } else { $filecont = $_POST['filecont']; } } // 書き込めるファイルを限定する $writable_files = array( 'p2_aborn_res.txt' => 'あぼーんレス', ); if (!array_key_exists($filename, $writable_files)) { $files_st = implode(', ', array_keys($writable_files)); p2die(basename($_SERVER['SCRIPT_NAME']) . " 先生の書き込めるファイルは、{$files_st}だけ!"); } $path = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . $filename; //========================================================= // メイン //========================================================= if (isset($filecont)) { if (setFile($path, $filecont, $encode)) { P2Util::pushInfoHtml('saved, OK.'); } } editFile($path, $encode, $writable_files[$filename]); exit; //========================================================= // 関数 //========================================================= // {{{ setFile() /** * ファイルに内容をセットする関数 */ function setFile($path, $cont, $encode) { if ($path == '') { p2die('path が指定されていません'); } if ($encode == "EUC-JP") { $cont = mb_convert_encoding($cont, 'CP932', 'CP51932'); } // 書き込む $fp = @fopen($path, 'wb') or p2die("cannot write. ({$path})"); @flock($fp, LOCK_EX); fputs($fp, $cont); @flock($fp, LOCK_UN); fclose($fp); return true; } // }}} // {{{ editFile() /** * ファイル内容を読み込んで編集する関数 */ function editFile($path, $encode, $title) { global $_conf, $modori_url, $rows, $cols, $csrfid; if ($path == '') { p2die('path が指定されていません'); } $filename = basename($path); $ptitle = 'Edit: ' . htmlspecialchars($title, ENT_QUOTES, 'Shift_JIS') . ' (' . $filename . ')'; //ファイル内容読み込み FileCtl::make_datafile($path) or p2die("cannot make file. ({$path})"); $cont = file_get_contents($path); if ($encode == "EUC-JP") { $cont = mb_convert_encoding($cont, 'CP932', 'CP51932'); } $cont_area = htmlspecialchars($cont, ENT_QUOTES); if ($modori_url) { $modori_url_ht = "<p><a href=\"{$modori_url}\">Back</a></p>\n"; } else { $modori_url_ht = ''; } $rows_at = ($rows > 0) ? sprintf(' rows="%d"', $rows) : ''; $cols_at = ($cols > 0) ? sprintf(' cols="%d"', $cols) : ''; // プリント echo $_conf['doctype']; echo <<<EOHEADER <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> {$_conf['extra_headers_ht']} <title>{$ptitle}</title> </head> <body onload="top.document.title=self.document.title;"> EOHEADER; $info_msg_ht = P2Util::getInfoHtml(); echo $modori_url_ht; echo $ptitle; echo <<<EOFORM <form action="{$_SERVER['SCRIPT_NAME']}" method="post" accept-charset="{$_conf['accept_charset']}"> <input type="hidden" name="file" value="{$filename}"> <input type="hidden" name="modori_url" value="{$modori_url}"> <input type="hidden" name="encode" value="{$encode}"> <input type="hidden" name="rows" value="{$rows}"> <input type="hidden" name="cols" value="{$cols}"> <input type="hidden" name="csrfid" value="{$csrfid}"> <input type="submit" name="submit" value="Save"> {$info_msg_ht}<br> <textarea style="font-size:9pt;" id="filecont" name="filecont" wrap="off"{$rows_at}{$cols_at}>{$cont_area}</textarea> {$_conf['detect_hint_input_ht']}{$_conf['k_input_ht']} </form> EOFORM; echo '</body></html>'; return true; } // }}} /* * Local Variables: * mode: php * coding: cp932 * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ // vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |