묻고답하기

//////////////////////////////////////////////////////////////////

function Navigate($fsRoot,$relDir) {

        global $gblEditable, $gblIcon ;

        $self     = $GLOBALS["PHP_SELF"] ;
        $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;
        $fsDir    = $fsRoot . $relDir . "/" ; // current directory

        if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;

        // read directory contents
        if ( !($dir = @opendir($fsDir)) )
                Error("Read Access denied",$relDir) ;
        while ($item = readdir($dir)) {
                if ( $item == ".." || $item == "." ) continue ;
                if ( is_dir($fsDir . $item) ) {
                        $dirList[] = $item ;
                }
                else if ( is_file($fsDir . $item) ) {
                        $fileList[] = $item ;                
                }
                else {
                  // unknown file type
                  // $text = "Could not determine file type of " ;
                  // Error("File Error", $text.$relDir."/".$item) ;
                  // exit ;
                }
        }
        closedir($dir) ;
        $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;

        // start navigation page
        $text  = "Use this page to add, delete or " ;
        $text .= "revise files on this web site." ;

        StartHTML("(Navigate)",$text) ;

        echo "<TABLE BORDER=0 CELLPADDING=2
                CELLSPACING=3 WIDTH="100%">" ;

        // updir bar        
        if ($fsDir != $fsRoot) {
                $parent = dirname($relDir) ;
                if ($parent == "") $parent = "/" ;
?>

<TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>
<A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">
<B><?php echo $parent ?></B></A></TD></TR>

<?php
        }

        // output subdirs
        if (sizeof($dirList) > 0) {
                sort($dirList) ;
?>

<TR><TD></TD><TD COLSPAN=4 CLASS=TOP><HR><b><font size="2">폴더 이름</font></b></TD></TR>
<!--<TR><TD></TD><TD COLSPAN=4 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>-->

<?php
                while (list($key,$dir) = each($dirList)) {

                        $tstr = "<A HREF="" . $self . "?D=" ;
                        $tstr .= urlencode($relDir."/".$dir) ;
                        $tstr .= "">" . $dir . "/</A>" ;
?>

<TR><TD><?php echo $gblIcon("fldr") ?></TD>
<TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD>
</TR>

<?php
                }  // iterate over dirs
        }  // end if no dirs
?>

<TR><TD></TD><TD COLSPAN=4><HR><B><font size="2">현재 경로 : <?php echo $webRoot . $relDir ?></font>
</B></TD></TR>
<TR><TD></TD><TD CLASS=TOP><B><font size="2">파일 이름</font></b></TD>
<TD><?php echo $gblIcon("blank") ?></TD>
<TD CLASS=TOP><B><font size="2">마지막 변경일</font></b></TD><TD CLASS=TOP><B><font size="2">파일 크기</font></b></TD></TR>

<?php
        if (sizeof($fileList) > 0) {
          sort($fileList) ;
          while (list($key,$file) = each($fileList)) {        
            $path = $fsDir."/".$file ;
            $mod  = filemtime($path) ;
            $sz   = filesize($path) ;

            if ($sz >= 10240) {
              $sz = (int)(($sz+1023)/1024) . " k" ;
            }
            else {
              $sz .= " " ;
            } // end size

            $a = $b = "" ;

            if ( ($mod + 30*86400) > time() ) {
              $a  = "<SPAN CLASS=RED TITLE="Newer" ;
              $a .= " than 30 days"> * </SPAN>" ;
            }

            $tstr = $webRoot . $relDir . "/" . $file ;
            $tstr  = "<A HREF="" . $tstr . "">" ;
            $tstr .= $file . "</A>" . $a ;

            $ext = strtolower(strrchr($file,".")) ;
            if ( $ext=="" ||
                 strstr(join(" ",$gblEditable),$ext) )
            {  
              $b  = "<A HREF="" . $self . "?A=C&F=" ;
              $b .= urlencode($file) . "&D=" . urlencode($relDir) ;
              $b .= "" TITLE="List contents">" ;
              $b .= $gblIcon("view") . "</A>" ;
            }

?>

<TR><TD>
<A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)
?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">
<?php echo $gblIcon($ext) ?></A></TD>
<TD CLASS=LST><?php echo $tstr ?></TD>
<TD CLASS=LST ALIGN=center><?php echo $b ?></TD>
<TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>
<TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>

<?php
          }  // iterate over files
        }  // end if no files

        if ($emptyDir) {
?>

<FORM METHOD="POST" ACTION="<?php echo $self ?>">
<TR><TD></TD><TD COLSPAN=4 CLASS=BAR>
  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">
  현재 디렉토리에 파일이 없습니다. 폴더를 삭제하실려면 체크하신후 DELETE를 눌러주세요
  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
</TD></TR>
</FORM>

<?php
        } // end if emptyDir
?>

<TR><TD></TD><TD COLSPAN=4><HR></TD></TR>

<FORM METHOD="POST" ACTION="<?php echo $self ?>">
<TR><TD></TD><TD COLSPAN=4 CLASS=BAR>
<INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>
신규 폴더 만들기 - <!-- 문서 저장-OR-
<INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE :-->
<NOBR>이름 <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">
<INPUT TYPE="SUBMIT" VALUE="폴더생성"></NOBR>
<NOBR> ------------------- <A HREF="<?php echo $self
        ?>?A=U&D=<?php echo urlencode($relDir) ?>">파일 올리기</A>
</NOBR>
</TD></TR>
</FORM>
</TABLE>

<?php
        EndHTML() ;
} // end function Navigate

//////////////////////////////////////////////////////////////////

function UploadPage($fsRoot, $relDir) {

        $self = $GLOBALS["PHP_SELF"] ;
        if ($relDir == "") $relDir = "/" ;
?>

<P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>
<FORM ENCTYPE="multipart/form-data" METHOD="POST"
ACTION="<?php echo $self ?>">
파일이 저장될 위치 : <B><?php echo " " . $relDir ?></B>
<P><font color=red>파일의 경로명을 적어주세요</font><BR>
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">
<INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
<INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
<P><INPUT TYPE="SUBMIT" VALUE="올리기"></P>
<!--<P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
you must upgrade to an RFC1867-compliant browser.</P>
<P>Your browser:<BR><?php// echo $GLOBALS["HTTP_USER_AGENT"] ?></P>-->
</FORM>
</TD></TR>
<TR><TD></TD><TD>
<FORM METHOD="POST" ACTION="<?php echo $self ?>">
<INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>
<INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="취소">
</FORM>
</TD></TR></TABLE></P>

<?php        
} // end function UploadPage

//////////////////////////////////////////////////////////////////

function Error($title,$text="") {
        StartHTML("(".$title.")",$text) ;
        echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
        EndHTML() ;
        exit ;
} // end function Error

//////////////////////////////////////////////////////////////////

function Writeable($path) {
        // fix by -mat- filid brandy, brandy@ecrc.de, 07/JUL/99

        clearstatcache ;
        $perms = @fileperms($path) ;
        $owner = @fileowner($path) ;
        exec("id",$id) ;
        eregi( "^uid=([0-9]*)",$id[0], $regs) ;
        $apacheuid = $regs[1] ;
        $perms = 0777 & $perms ;
        if ( $apacheuid != $owner ) {
                return (06 == (06 & $perms)) ?  1 : 0 ;
        }
        else {
                return (0600 == (0600 & $perms)) ? 1 : 0 ;
        }

} // end function Writable

//////////////////////////////////////////////////////////////////

function CreateHash($user, $pw) {

        global $gblHash ;  // hash function to use

        if ($user == "" || $pw == "") {
                $text = "either no password or no username supplied" ;
                Error("Create Hash",$text) ;
        }
        $title = "(Create Hash)" ;
        StartHTML($title) ;
        echo "<P ALIGN=center>" ;
        echo "<BLOCKQUOTE>Copy the value below and paste it " ;
        echo "into the<BR>value for $gblPw in the source of " ;
        echo "this file<BR><BR><B>" . $gblHash($user.$pw) ;
        echo "</B><BR><BR>Hash function: " . $gblHash ;
        echo "</BLOCKQUOTE></P>" ;
        EndHTML() ;
        exit ;

} // end function CreateHash

//////////////////////////////////////////////////////////////////

function NoEntry() {

        $user = $GLOBALS["PHP_AUTH_USER"] ;
        $pw   = $GLOBALS["PHP_AUTH_PW"] ;        
        $self = $GLOBALS["PHP_SELF"] ;

        $title = "(401 Unauthorized)" ;
        $text  = "No trespassing !" ;
        StartHTML($title,$text) ;
?>

<FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">
<INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">

<BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>
Click below to <B>generate a password hash</B><BR>from
the username-password pair you just<BR>entered. Then include the hash in
the source<BR>of this file.<BR><BR>
<INPUT TYPE="SUBMIT" VALUE="CREATE HASH">
</BLOCKQUOTE></FORM>

<?php
        EndHTML() ;
        exit ;
}

//////////////////////////////////////////////////////////////////

// MAIN PROGRAM
// ============
// query parameters: capital letters
// local functions : begin with capital letters
// global constants: begin with gbl

        $gblFilePerms = "644" ;         // default for new files
        $gblDirPerms  = 0755 ;                // default for new dirs

        // phpinfo() ;
        // exit ;

        // forks before authentication: style sheet and hash
        // creation if password not yet set.
        if ($STYLE == "get") { CSS() ; exit ; }
        if ($HASH != "") {
                CreateHash($USER, $PW) ;
                exit ;
        }

        // authentication if $gblAuth == true
        if ( $gblAuth &&
             $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {
                header("WWW-authenticate: basic realm="$SERVER_NAME"") ;
                header("HTTP/1.0 401 Unauthorized") ;
                NoEntry() ;
                exit ;
        }

        // get current directory relative to $gblFsRoot
        $relDir = $DIR ;        // from POST
        if ($relDir == "") {        // not defined in POST ?
                $relDir = urldecode($D) ;  // then use GET
        }        

        if ($relDir == "/") $relDir = "" ;         
        // default : website root = ""

        if (strstr($relDir,"..")) Error("No updirs allowed");

        // full paths contain "fs" or "Fs". Paths realitve to root of
        // website contain "rel" or "Rel". The script won't let you
        // edit anything above directory equal to http://server.com
        // i.e. below $gblFsRoot.

        $relScriptDir = dirname($SCRIPT_NAME) ;          
        // i.e. /siteman

        $fsScriptDir  = dirname($SCRIPT_FILENAME) ;         
        // i.e. /home/httpd/html/siteman

        $gblFsRoot = substr($fsScriptDir,0,
          strlen($fsScriptDir)-strlen($relScriptDir)) ;
        // i.e. /home/httpd/html

        $fsDir = $gblFsRoot . $relDir ; // current directory
        if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
        
        switch ($POSTACTION) {
        case "UPLOAD" :
                if (!Writeable($fsDir)) Error("Write denied",$relDir) ;
                if (strstr($FN_name,"/"))
                        Error("Non-conforming filename") ;
                // TODO : should rather check for escapeshellcmds
                // but maybe RFC 18xx asserts safe filenames ....
                $source = $FN ;
                $target = $fsDir . "/" . $FN_name ;
                exec("cp $source $target") ;
                exec("chmod $gblFilePerms $target") ;
                clearstatcache() ;
                break ;

        case "SAVE" :
                $path = $gblFsRoot . escapeshellcmd($RELPATH) ;
                $writable = Writeable($path) ;
                $legaldir = Writeable(dirname($path)) ;
                $exists   = (file_exists($path)) ? 1 : 0 ;
// check for legal extension here as well
                 if (!($writable || (!$exists && $legaldir)))
                        Error("Write denied",$RELPATH) ;
                $fh = fopen($path, "w") ;
                fwrite($fh,$FILEDATA) ;
                fclose($fh) ;
                clearstatcache() ;
                break ;

        case "CREATE" :
                // we know $fsDir exists
                if (!Writeable($fsDir)) Error("Write denied",$relDir) ;
                $path = $fsDir . "/" . $FN ;  // file or dir to create
                $relPath = $relDir . "/" . $FN ;
                switch ( $T ) {
                case "D" :  // create a directory
                  if ( ! @mkdir($path,$gblDirPerms) )
                    Error("Mkdir failed",$relPath) ; // eg. if it exists
                  clearstatcache() ;
                  break ;
                case "F" :  // create a new file
// this functionality is doubled in DetailView().
// better keep it here altogether
// chmod perms to $gblFilePerms
                  if ( file_exists($path) && !Writable($path) )
                    Error("File not writable", $relPath) ;
                  $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;
                  header("Location: " . $tstr) ;
                  exit ;
                }
                break ;

        case "DELETE" :  
                if ( $CONFIRM != "on" ) break ;

                $tstr  = "Attempt to delete non-existing object or " ;
                $tstr .= "insufficient privileges: " ;

                if ( $FN != "") {  // delete file
                  $path =  $fsDir . "/" . $FN ;
                  if ( ! @unlink($path) ) {
                    Error("File delete failed", $tstr . $path) ;
                    exit ;
                  }                        
                }
                else {  // delete directory
                  if ( ! @rmdir($fsDir) ) {
                    Error("Rmdir failed", $tstr . $fsDir) ;
                  }
                  else {
                    $relDir = dirname($relDir) ;  // move up
                  }
                }
                break ;

        default :
                // user hit "CANCEL" or undefined action
        }

        // common to all POSTs : redirect to directory view ($relDir)
        if ( $POSTACTION != "" ) {
                $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;
                header("Location: " . $tstr) ;  
                exit ;
        }
        
        // check for mode.. navigate, code display, upload, or detail?
        // $A=U : upload to path given in $D
        // $A=E : display detail of file $D/$F and edit
        // $A=C : display code in file $D/$F
        // default : display directory $D
        
        switch ($A) {
        case "U" :
                // upload to $relDir
                if (!Writeable($gblFsRoot . $relDir))
                        Error("Write access denied",$relDir) ;
                $text  = "Use this page to upload a single " ;
                $text .= "file to <B>$SERVER_NAME</B>." ;
                StartHTML("(Upload Page)", $text) ;
                UploadPage($gblFsRoot, $relDir) ;
                EndHTML() ;
                exit ;
        case "E" :
                // detail of $relDir/$F
                DetailPage($gblFsRoot, $relDir, $F) ;
                exit ;
        case "C" :
                // listing of $relDir/$F
                DisplayCode($gblFsRoot, $relDir, $F) ;
                exit ;
        }

        // default: display directory $relDir
        Navigate($gblFsRoot,$relDir) ;        
        exit ;

        Error("Whooah!","By cartesian logic, this never happens") ;
?>
글쓴이 제목 최종 글
XE 공지 글 쓰기,삭제 운영방식 변경 공지 [16] 2019.03.05 by 남기남
지오테크 [re] 나모로 작업해서 올렸는데 제 컴만 뜨고 딴데는 안뜹니다. [2] 2007.08.10
A|X 시간별 페이지 로드 방법 부탁드립니다. [1] 2007.08.10
박수정 관리자 외에 글쓰기가 안되는데... [1] 2007.08.10
도효진 800*600에 최적화 하려면.. [6] 2007.08.10
김유민 노프레임>제로보드+아웃로그인 [2] 2007.08.10
쿠트다스 [팝업] 채크기능으로 두번다시팝업을띄우지않기 [1] 2007.08.10
동시접속자 라는게 뭔가요? [1] 2007.08.10
바다늑대 D-DAY 기능을 사용할 수 있는 것은?? [4] 2007.08.10
심영우 배경음악에 대한 질문 드립니다.. (__) [4] 2007.08.10
이준원 php 질문 아무리 해도 모르겠어요 [2] 2007.08.10
김유민 노프레임>제로보드+아웃로그인 [1] 2007.08.10
존재의 가벼움 이 폰트가 머죠.....? [이미지포함] [2] 2007.08.10
이도이 테이블안에 테이블을 넣으니까.. [3] 2007.08.10
이성애 새창 연후 ''오늘하루동안 창닫기''하는 방법... [3] 2007.08.10
[사계]봄비 [마땅한질답이 없어서] 검색기능 구현요! [1] 2007.08.10
zyose :) 스타일 시트에서요. [3] 2007.08.10
울산사람 홈페이지 파일을 어디다가 옮겨나야 하나요? [4] 2007.08.10
김형재 http://www.mscast.net/board/zboard.php?id=test 여기에 오셔서 잘못된부분 지적좀 해주세요 ㅠ,.ㅠ [3] 2007.08.10
이진영 퍼미션..을 바꾸다 생긴 에러.... [1] 2007.08.10
상디즈 XP에서 배너같은 그림이 안움직여요..ㅡㅡ;; [1] 2007.08.10
김형재 해상도별 스크립트에 적용에대해 nzeo.com메뉴에대한질문 [2] 2007.08.10
박재중 노프레임 질문좀 드릴께요 [3] 2007.08.10
송봉섭 프레임1개로 잡고 표로 나눈상태에서 표에서 링크가 가능합니까? [2] 2007.08.10
이강지 [질문] HTML 소스를 보니... [2] 2007.08.10
영진 저 좀 도와주세요 [2] 2007.08.10
영진 관리자님 이것 좀 가르쳐주세요. [1] 2007.08.10
이지은 휴... 아이프레임.. 질문요...--;; [1] 2007.08.10
오케바리 웹하드랑 비슷한건데요.. 도와주세요... 2/2 [1] 2007.08.10
오케바리 웹하드랑 비슷한 소스인데요.. 도와주세요 1/2  
이지호 리얼플레이어 파일들(*.ra, *.ram, *.rm)을 게시판에 embed 태그 처럼 쓸수 있는 방법은 없나요??? [1] 2007.08.10