하둡을이용한파일분산시스템 보안관리체제구현
목 차 - 1 -
- 2 -
- 3 -
- 4 -
- 5 -
- 6 -
- 7 -
- 8 -
1. 사용자가웹서버에로그인하여다양한서비스 ( 파일업 / 다운로드, 폴더생성 / 삭제 ) 를활용 2. 웹서버와연동된하둡서버에서업 / 다운로드된파일을분산저장. ( 자료송수신은 SSH 활용 ) - 9 -
- 10 -
- 11 -
<? if($_request["exec"]=="join"){ require_once("database.inc"); $conn = get_connection("time_machine"); // 회원중복가입체크 $sql = "select count(*) cnt from member where member_id='".$_request["member_id"]."'"; $rs = mysql_query($sql); if(mysql_errno()==0 && mysql_num_rows($rs)>0){ $row = mysql_fetch_array($rs); if($row["cnt"] > 0){?> <script language="javascript"> alert(" 회원아이디 '<?= $_REQUEST["member_id"]?>' 는벌써사용중인아이디입니다."); history.back(); </script> <? mysql_free_result($rs); $sql = "insert into member values "; $sql.= "('".$_REQUEST["member_id"]."','".$_REQUEST["name"]."','".$_REQUEST["passw d"]."','".$_request["email"]."', now(), null)"; mysql_query($sql); if(mysql_errno() == 0){ require_once("config.inc"); // 하둡계정생성 exec("mkdir hadoop/'".$_request["member_id"]."';sudo useradd '".$_REQUEST["member_id"]."'; /usr/local/hadoop/bin/hadoop fs -mkdir /user/'".$_request["member_id"]."'; sudo /usr/local/hadoop/bin/hadoop fs -chown '".$_REQUEST["member_id"]."':'".$_REQUEST["member_id"]."' /user/'".$_request["member_id"]."'"); - 12 -
session_start(); $_SESSION["isLogin"] = true; $_SESSION["member_id"] = $_REQUEST["member_id"]; $_SESSION["name"] = $_REQUEST["name"];?> <script language="javascript"> alert(" 회원가입이정상적으로처리되었습니다."); location.replace("./"); </script> <? else{ echo("[db Error]<br>".mysql_error()); mysql_close($conn); exit;?> <html> <head> <title> 사용자등록 </title> <style type="text/css"> table, th, td, input { font-size:9pt; </style> <script language="javascript"> function initpage(){ joinform.member_id.focus(); function checkform(form){ if(form.member_id.value.length==0){ alert(" 아이디를입력하세요!"); form.member_id.focus(); return false; if(form.passwd.value.length==0){ alert(" 비밀번호를입력하세요!"); form.passwd.focus(); return false; if(form.passwd2.value.length==0){ alert(" 비밀번호확인을입력하세요!"); - 13 -
form.passwd2.focus(); return false; if(form.passwd.value!= form.passwd2.value){ alert(" 비밀번호화확인비밀번호가일치하지않습니다."); form.passwd2.value=""; form.passwd2.focus(); return false; function dupcheck(){ var nwidth = 350; var nheight = 120; var ntop = (screen.height - nheight) / 2; var nleft = (screen.width - nwidth) / 2; var strurl = "dupcheck.php"; if(joinform.member_id.value.length>0) strurl += "?exec=check&member_id=" + joinform.member_id.value; window.open(strurl, "dupcheck", "height="+nheight+",width="+nwidth+",top="+ntop+",left="+nleft); </script> </head> <body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" onload="initpage();"> <form name="joinform" action="join.php" method="post" onsubmit="return(checkform(this));"> <input type="hidden" name="exec" value="join"> <table border="0" width="750" cellpadding="5" cellspacing="0" align="center"> <td height="10"> <td align=left colspan="2"> <table border="0" cellspacing="0" width="100%" cellpadding="0"> <td> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <td bgcolor="#c3d9ff" style="padding:5 5 5 5;"> </table> - 14 -
</table> <td> <fieldset style="padding:10 10 10 10;"> <legend><img src="images/join.gif" border="0"></legend> <table border="0" width="100%" cellpadding="5" cellspacing="0"> <td height="30"> <td align="center" valign="middle"> <table border="0" width="600" cellpadding="3" cellspacing="1" bgcolor="#cccccc"> <colgroup> <col nowrap align="center" width="150" bgcolor="#eeeeee" style="color:gray;"> <col nowrap bgcolor="#ffffff"> </colgroup> <td> 아이디 * <td> <input type="text" name="member_id" size="12" maxlength="16"> <input type="button" value=" 중복체크 " onclick="dupcheck();"> ( 영문이나알파벳최대 16자리로입력하세요!) <td> 이름 * <td> <input type="text" name="name" size="20" maxlength="50"> <td> 이메일 * <td> <input type="text" name="email" size="60" maxlength="50"> <i <td> 비밀번호 * - 15 -
<td> <input type="password" name="passwd" size="12" maxlength="12"> ( 최대 12자리까지가능합니다.) <td> 비밀번호확인 * <td> <input type="password" name="passwd2" size="12" maxlength="12"> ( 최대 12자리까지가능합니다.) <td colspan="2" bgcolor="#ffffff" align="left" valign="bottom"> </table> <td align="center" height="40"> <input type="submit" value=" 등록 "> <input type="button" value=" 취소 " onclick="location.replace('./');"> </form> </table> </fieldset> <td height="10"> <td align="center"> <table border="0" width="750" cellpadding="0" cellspacing="0"> <td bgcolor="#c3d9ff" style="padding:5 5 5 5;"> </table> - 16 -
<td align="center"> Copyright c 2014 by Time Machine All rights reserved. </table> </body> </html> <? require_once("config.inc"); require_once("database.inc"); session_start(); if($_session["islogin"]){ echo("<script>location.replace(\"./\");</script>"); exit; $configfile = getcwd().getfileseparator()."time_machine.php"; if($_request["exec"]=="login"){ $sql = "select passwd, name from member where member_id='".$_request["member_id"]."'"; $conn = get_connection("time_machine"); $rs = mysql_query($sql); if(mysql_errno() == 0 && mysql_num_rows($rs)>0){ $row = mysql_fetch_array($rs); if($_request["passwd"]==$row["passwd"]){ $userdir = getini($configfile, "disk.root").getfileseparator().$_request["member_id"]; $_SESSION["isLogin"] = true; $_SESSION["userDir"] = $userdir; if(!file_exists($userdir)) mkdir($userdir); $nexturl = "./"; $_SESSION["member_id"] = $_REQUEST["member_id"]; $_SESSION["name"] = $row["name"]; - 17 -
echo("<script>location.replace(\"./\");</script>"); else{ echo("<script>alert(\" 비밀번호가다릅니다.\");history.back();</script>"); else{ echo("<script>alert(\"'".$_request["member_id"]."' 님은사용자정보에없습니다.\");history.back();</script>"); mysql_free_result($rs); mysql_close($conn);?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>time Machine</title> <style type="text/css"> table, th, td, input, a { font-size:9pt; </style> <script language="javascript"> function initpage(){ loginform.member_id.focus(); function checkform(form){ if(form.member_id.value==""){ alert(" 회원아이디를입력하세요!"); form.member_id.focus(); return false; if(form.passwd.value==""){ alert(" 비밀번호를입력하세요!"); form.passwd.focus(); return false; return true; </script> </head> <body bgcolor="#ffffff" onload="initpage();"> <div align="center"> <table cellspacing="0" width="750" cellpadding="0" border="0"> - 18 -
<td align=left colspan="2"> <table border="0" cellspacing="0" width="100%" cellpadding="0"> <td> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <td bgcolor="#c3d9ff" style="padding:5 5 5 5;"> </table> </table> </table> <table width=100% align=center cellpadding=3 cellspacing=2 border=0> <td align=center> <table cellpadding="0" cellspacing="0" border="0" width="750"> <td rowspan="3" width="20" nowrap><spacer type="horizontal" width="20"> <td width="450" valign="top"> <table cellpadding="0" cellspacing="0" border="0" width="450" style="line-height:200%;"> <td><img src=images/time-machine5.png> </table> <td rowspan="3" width="20" nowrap><spacer type="horizontal" width="20"> <td rowspan="3" width="240" valign="top"> <form name=loginform action="login.php" autocomplete=off method=post> <input type=hidden name="exec" value="login"> <div> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <td><img src=images/crnr_top_l.gif width="10" height="10" alt="" border="0"> <td width="100%" bgcolor="#eeeeee" - 19 -
background="images/brdr_t.gif"><spacer type="block" width="100%" height="10"> <td><img src=images/crnr_top_r.gif width="10" height="10" alt="" border="0"> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#eeeeee"> <td bgcolor="#eeeeee"><img src=images/brdr_l.gif width="10" height="10" alt="" border="0"> <td bgcolor="#eeeeee" nowrap><spacer type="block" width="1" height="10"> <td bgcolor="#eeeeee"><img src=images/brdr_r.gif width="10" height="10" alt="" border="0"> <td background=images/brdr_l.gif style="width:10px;" nowrap> <spacer type="block" width="10" height="1"> <td width="100%"><strong>time Machien 로그인 </strong><br><br> <div style="margin-left:0px;" align="right"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"> <th width="38%"> 아이디 :</th> <td> <input type="text" name="member_id" tabindex="1" style="width:120px;"> <tr valign="top"> <th> 비밀번호 :</th> <td> <input type="password" name="passwd" tabindex="3" style="width:120px;"> <td height="10"> <td colspan="2" align="right"><input type="submit" value=" 로그인 " tabindex="7"> - 20 -
<td colspan="2"><br><hr size="1" noshade><br> <td colspan="2"> <b> 회원아이디가없을경우 :</b> <td colspan="2" align="right"> <a href="join.php"> 무료회원가입 </a><br><br><br> </table> </div> <td style="width:10px" background=images/brdr_r.gif nowrap> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <td><img src=images/crnr_bot_l.gif width="10" height="10" border="0"> <td width="100%" bgcolor="#eeeeee" background=images/brdr_b.gif width="100%"> <spacer type="block" width="100%" height="10"> <td><img src=images/crnr_bot_r.gif width="10" height="10" alt="" border="0"> </table> </form> </div> <td> <table cellpadding="0" cellspacing="0" height="1" width="450" border="0"> <td height="5" nowrap><spacer type="block" height="5"> <td nowrap height="1" width="450" bgcolor="#cccccc"><spacer type="block" width="450" height="1"> <td height="5" nowrap><spacer type="block" height="5"> </table> - 21 -
</table> <tr align="right"> <td height="80"> <td align="center"> <table border="0" width="750" cellpadding="0" cellspacing="0"> <td bgcolor="#c3d9ff" style="padding:5 5 5 5;"> </table> <td align="center"> Copyright c 2014 by Time Machine All rights reserved. </table> </body> </html> <html> <head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> <!-- Optional theme --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min. css"> </head> <body> <!-- Latest compiled and minified JavaScript --> < s c r i p t src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></scri - 22 -
pt> <?php session_start(); if(!$_session["islogin"]){ echo("<script>alert(\" 로그인하세요!\");top.location.replace(\"./\");</script>"); exit; // 위의 link와 script 태그는 bootstrap을적용하기위해사용 echo '<table class="table table-striped">'; / / 테이블시작 echo '<thead>'; // 테이블머리 ( 맨윗줄 ) 시작 echo ''; echo '<th>'; echo '#'; echo '</th>'; echo '<th>filename</th>'; echo '<th>date</th>'; echo ''; echo '</thead>'; // 테이블머리끝 echo '<tbody>'; // 테이블몸통시작 $dh = @opendir("./hadoop/$_session[member_id]"); // 디렉토리열기 $i = 0; while(($file = readdir($dh))!= false) { / / 디렉토리에서파일을가져옴 ( 파일을다가져오면 false반환됨 ) if($file == '.' $file == '..') continue; $file_path = "./hadoop/$_session[member_id]".directory_separator.$file; if(is_file($file_path)) { $i++; echo ''; echo '<td>'; echo "$i"; // 몇번째인지출력 echo ''; echo '<td>'; echo "<a href='$file_path'>$file</a>"; / / 파일다운로드링크생성 echo ''; echo '<td>'; - 23 -
echo date("f d Y H:i:s.", filemtime($file_path)); 수정날자출력 echo ''; echo ''; closedir($dh); // 디렉토리닫음 echo '</tbody>'; // 테이블몸통마침 echo '</table>'; // 테이블마침 //echo "$ii";?> </body> </html> // 파일최종 <? session_start(); if(!$_session["islogin"]){ $save_dir = "hadoop/$_session[member_id]/"; if(is_uploaded_file($_files["file"]["tmp_name"])) { $dest = $save_dir.$_files["file"]["name"]; if(!move_uploaded_file($_files["file"]["tmp_name"], $dest)) { die(" 파일을지정한디렉터리에저장하는데실패했습니다."); exec("sudo /usr/local/hadoop/bin/hadoop fs -put /var/www/html/time/'$dest' /user/'$_session[member_id]'/;sudo /usr/local/hadoop/bin/hadoop fs -chown '$_SESSION[member_id]' /user/'$_session[member_id]'/*;"); echo " 업로드완료!";?> - 24 -
<? $chkvalue = $_POST['checkbox']; $file_path = $_GET['file_path']; for ($i = 0; $i < count($chkvalue); $i++) { unlink($file_path. str_replace(" ", " ", $chkvalue[$i])); exec("/usr/local/hadoop/bin/hadoop fs -ls $file_path"); echo " 삭제완료 </br>";?> - 25 -
- 26 -
- 27 -
- 28 -
- 29 -
- 30 -
- 31 -
- 32 -
- 33 -
- 34 -
- 35 -
- 36 -
- 37 -