Source Code เพื่อ การศึกษา
managefilephp.txt
9102
<? $admin_password = ''; $viewer_password = ''; ############################### $version = "5.25520910"; $maxsize = 50000000; // 50 MB $fontcolor = "blue"; // Sample: white, red $bgtable = "#dddddd"; $bgtbh = "#ffff00"; $bgrow1 = "#ffffdd"; $bgrow2 = "white"; $linkcolor = "blue"; $program_name = "ระบบจัดการแฟ้มออนไลน์"; ############################### if (isset($_POST["admin_passwd"]) && strlen($_POST["admin_passwd"]) > 0 && strlen($admin_password) == 0) install_process(); if (strlen($admin_password) == 0) install_form(); if (!isset($_REQUEST['passwd'])) $_REQUEST['passwd'] = ""; $crypt = trim(crypt($_REQUEST['passwd'],$_REQUEST['passwd'].strlen($_REQUEST['passwd']))); ############################### # Source code : http://www.thaiall.com/perlphpasp/source.pl?9102 # Information: # 1. This file may be index.php or managefile.php # 2. using for admin, user, public ?passwd=yourpassword # 3. php 5.2.5 verified # 4. ถ้าแก้ใน php.ini ให้ upload_max_filesize = 50M และ post_max_size = 50M ก็จะส่งได้ 50 MB ?><html><head><title><? echo $program_name." ".$version; ?></title> <meta http-equiv="content-type" content="text/html; charset=windows-874"> <meta http-equiv="cache-control" content="no-cache"> <style type="text/css"> body,td,a{font-family:microsoft sans serif;font-size:10pt;} a:link,a:visited{color:<?=$linkcolor?>;} </style> </head><body topmargin="0" leftmargin="0"> <? if ($crypt != $viewer_password) { ?> <form enctype="multipart/form-data" action="" method="post" target="_top"> <table bgcolor="<?=$bgtable ?>" width="100%"><td valign="top" width="150"> <b>ระบบจัดการแฟ้มออนไลน์</b><br>รหัสผ่าน : <input name=passwd type=password size=10 value="<?=$_REQUEST['passwd'];?>"> <? if ($crypt != $admin_password && $crypt != $viewer_password) echo "<br><input type=submit name=login value=Login><input name=directory type=hidden value=.></form>"; if ($crypt == $admin_password || $crypt == $viewer_password) { if ($crypt == $admin_password) echo "<td valign=top align=center bgcolor=#cccccc>นำแฟ้มเข้าระบบ <input type=file name=upload size=10> <input type=submit name=pro value=Upload></td> <td valign=top align=center>ชื่อแฟ้มที่ต้องการลบ <input name=delfile> <input type=submit name=pro value=Delete></td>"; //<td valign=top align=center bgcolor=#cccccc>โฟรเดอร์ <input name=directory value=. size=10><br><input type=submit name=pro value=List> เช่น . หรือ ../main</td>"; echo "<input name=directory value='.' type=hidden>"; echo "</form>"; ?><td align=right><form enctype="multipart/form-data" action='' method=get target=_top> <input type=hidden name=passwd value=""><input type=submit value=Logout> </td></form> <? } } ?> </table> <br><base target="_blank"><? if(isset($_REQUEST['directory'])) $dir = $_REQUEST['directory']; else $dir ="."; if (isset($_FILES['upload']) && $crypt==$admin_password) { $size = $_FILES['upload']['size']; // == upload process == if ($size > 0 && $size < $maxsize && $_POST['pro']=="Upload") { $name = $_FILES['upload']['name']; $copypath = $_REQUEST['directory']; copy($_FILES['upload']['tmp_name'],"$copypath/$name"); echo "<table align=center width=760 bgcolor=red><td bgcolor=#dddddd>Upload Report<td><font color=white>"; echo "ส่งแฟ้มเข้าระบบเรียบร้อยแล้ว โดยแฟ้ม <font size=4>$name</font> มีขนาด $size ไบท์</table>"; } // == delete process == $cnt = strpos($_POST['delfile'], "/"); if (strlen($cnt)=="0" && file_exists($_POST['delfile']) && $_POST['pro']=="Delete") { $d = $_POST['delfile']; unlink("$dir/$d"); echo "Delete เรียบร้อย<ol>"; } } if ($crypt==$admin_password || $crypt==$viewer_password) { // == file listing process == echo "<table align=center width=760 bgcolor=$bgtable>"; $i = 0; $total = 0; $dir_handle=opendir($dir); $retVal = array(); while ($file = readdir($dir_handle)) { $k = filemtime("$dir/$file").$file; if (isset($_REQUEST['sort']) && $_REQUEST['sort'] == "name") $k = $file; $retVal["$k"] = $file; } closedir($dir_handle); if (isset($_REQUEST['st']) && $_REQUEST['st'] == "asc") ksort($retVal); else krsort($retVal); echo "<tr align=center bgcolor=$bgtbh><td><font color=black>ลำดับ<td><font color=black>ประเภท<td align=center><font color=black>ชื่อแฟ้ม |<a href=?directory=.&sort=name&st=asc&passwd=". $_REQUEST['passwd'] ." target=_self>A</a>|<a href=?directory=.&sort=name&st=desc&passwd=". $_REQUEST['passwd'] ." target=_self>D</a> <td><font color=black>วันที่แฟ้ม |<a href=?&directory=.&sort=date&st=asc&passwd=". $_REQUEST['passwd'] ." target=_self>A</a>|<a href=?&directory=.&sort=date&st=desc&passwd=". $_REQUEST['passwd'] ." target=_self>D</a> <td><font color=black>ขนาดแฟ้ม"; while (list($key, $list) = each($retVal)) { if ($list != "." && $list != ".." && $list != "index.php" && $list != "managefile.php" ) { $i = $i + 1; $filesize = filesize("$dir/$list"); $filetype = filetype("$dir/$list"); $total = $total + $filesize; if ($i % 2 == 0) { echo "<tr bgcolor=$bgrow1>"; } else { echo "<tr bgcolor=$bgrow2>"; } echo "<td align=center width=30>$i<td align=center width=30>$filetype<td><a href='$list' target=_blank>$list</a><td width=80 align=right>"; echo date("Y-m-d h:ia",filemtime("$dir/$list")); echo "<td align=right width=80>"; if ($filetype == "file") echo number_format($filesize,0,',',','); echo ""; } } echo "<tr><td colspan=5 align=right bgcolor=$bgtbh><font size=4>". number_format($total,0,',',','); echo "</table>"; } else { //echo "<center>Upload ไม่สำเร็จ หรือ ส่งเข้าไปแล้ว หรือยังไม่ได้ สั่งงานอะไร</center>"; } // เปลี่ยนรหัสผ่าน โดยคัดลอกค่าที่เข้ารหัสแล้วไปแทนค่าในตัวแปร admin_password ในบรรทัดที่ 3 echo "<center><br>โปรแกรมรุ่น $version <a href=http://www.thaiall.com/perlphpasp/source.pl?9102>.</a> ( รหัสลับสำหรับผู้ดูแลระบบ <font color=red>$crypt</font> )</body></html>"; function install_form() { ?> <form action="" method=post> <table align=center> <tr><td colspan=2 bgcolor=#dddddd align=center><b>ติดตั้งโปรแกรม</b> : ระบบจัดการแฟ้มออนไลน์ <tr><td colspan=2 bgcolor=#ddffdd align=center><b>เพื่อสร้าง</b> 1)รหัสผ่านสำหรับบริหารจัดการ และ 2)รหัสผ่านสำหรับดูรายชื่อแฟ้ม</b> <tr><td colspan=2 bgcolor=#ddffff align=center>เว็บเพจหน้านี้จะปรากฎออกมา <b>เพียงครั้งเดียว</b> เพื่อนำรหัสที่ท่านกรอกนี้ไปติดตั้งระบบ (First Installation) <br><b>ดังนั้น</b> หลังจากกรอกรหัสทั้ง 2 ด้านล่าง แล้วกดปุ่มบันทึก จะไม่พบหน้านี้อีก <tr bgcolor=#ffffdd><td>รหัสผ่านสำหรับ<u>ผู้บริหารจัดการห้องเก็บข้อมูล</u> (ท่านรู้แต่เพียงผู้เดียว) <td bgcolor=white><input name=admin_passwd> มีรหัสนี้เพื่อให้ท่านสามารถ upload file หรือ delete file<br> <tr bgcolor=#ffffdd><td>รหัสผ่านสำหรับ<u>ผู้ดูรายชื่อแฟ้ม</u> อาทิ น.ศ. หรือเพื่อนร่วมงาน <td bgcolor=white><input name=viewer_passwd> ถ้าว่างไว้จะไม่อนุญาตให้ผู้ใช้ทั่วไปมาดูรายชื่อแฟ้ม<br> <tr><td colspan=2 align=center><input type=submit value="บันทึก"> <br>ก่อนกดปุ่มนี้ ท่านควรจดรหัสทั้ง 2 ไว้ <br>เพื่อนำไปบอกให้นักศึกษา หรือเพื่อนร่วมงาน สามารถเข้ามาดูรายชื่อแฟ้มที่ท่านเผยแพร่ </table> </form> <? exit; } function install_process() { $apass = trim(crypt($_POST['admin_passwd'],$_POST['admin_passwd'].strlen($_POST['admin_passwd']))); $vpass = trim(crypt($_POST['viewer_passwd'],$_POST['viewer_passwd'].strlen($_POST['viewer_passwd']))); if (strlen($_POST['viewer_passwd']) == 0) $vpass = ""; if(isset($_SERVER["PATH_TRANSLATED"])) $f = $_SERVER["PATH_TRANSLATED"]; else $f = $_SERVER["DOCUMENT_ROOT"].$_SERVER["REQUEST_URI"]; $old_file = file($f); $count_old = count($old_file); $w = fopen($f,"w"); $l = 1; foreach ($old_file as $v) { if ($l == 2) fputs($w,"\$admin_password = '$apass';\r\n"); if ($l == 3) fputs($w,"\$viewer_password = '$vpass';\r\n"); if ($l != 2 && $l != 3) fputs($w,$v); $l++; } fputs($w,"\n"); fclose($w); echo "<center>"; if (count(file($f)) == $count_old) { echo "แฟ้มนี้ไม่ได้รับอนุญาตให้เขียนทับ ท่านต้องแก้ไขสิทธิ์การเข้าถึงแฟ้มนี้ก่อน"; } else echo "ติดตั้งระบบสำหรับท่าน เรียบร้อยแล้ว<br>กดปุ่มข้างล่างนี้ เพื่อขอเข้าสู่ระบบ ด้วยรหัสผ่านที่ท่านกำหนดขึ้น<form action=''><input type=submit value=เข้าสู่ระบบ></form>"; exit; } ?>
ปรับปรุงโปรแกรม source.pl : 2553-03-20