| [57] | 1 | <? | 
|---|
| [98] | 2 | // echo "funs.php 成功載入<BR>"; | 
|---|
|  | 3 | require_once ("./etc/init.php"); | 
|---|
| [57] | 4 |  | 
|---|
| [98] | 5 | class W_user | 
|---|
|  | 6 | { | 
|---|
|  | 7 | var $operator = "";  // 信件類別 identification、new_password) | 
|---|
|  | 8 | var $user = "";    // 使用者帳號 | 
|---|
|  | 9 | var $email = "";     // 使用者註冊 e-mail | 
|---|
|  | 10 | var $new_password = "";  // 新密碼 | 
|---|
|  | 11 | var $activate_code = "";   // 認證碼 | 
|---|
|  | 12 | var $hadoop_user = "";   // hadoop 帳號 | 
|---|
|  | 13 | var $hadoop_password = ""; // hadoop 密碼 | 
|---|
| [104] | 14 | var $reg_date = "";  // 註冊日期 | 
|---|
| [57] | 15 |  | 
|---|
| [104] | 16 | // 取得現在時間 | 
|---|
|  | 17 | function get_current_date() | 
|---|
|  | 18 | { | 
|---|
|  | 19 | return date("Y-m-d, H:i:s"); | 
|---|
|  | 20 | } | 
|---|
|  | 21 |  | 
|---|
| [98] | 22 | // 重新導向 | 
|---|
|  | 23 | function redirect_to($w_url, $message) | 
|---|
|  | 24 | { | 
|---|
|  | 25 | header ("refresh:5 ;url=$w_url"); | 
|---|
|  | 26 | echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">'; | 
|---|
|  | 27 | echo "<BR> 此網頁將於 5 秒後重新導向 <BR>"; | 
|---|
|  | 28 | echo "<BR> ======== System Message ========"; | 
|---|
|  | 29 | echo "<BR>" . $message; | 
|---|
|  | 30 | } | 
|---|
| [57] | 31 |  | 
|---|
| [98] | 32 | // 取得認證信內容 | 
|---|
|  | 33 | function get_activate_mailbody() | 
|---|
|  | 34 | { | 
|---|
|  | 35 | global $w_localhost; // 載入主機位址環境變數 | 
|---|
|  | 36 | $str = ' | 
|---|
|  | 37 | <br> | 
|---|
|  | 38 | <br>您好: | 
|---|
|  | 39 | <br> | 
|---|
|  | 40 | <br>請點選以下認證碼啟動您的 Hadoop 帳號: | 
|---|
|  | 41 | <br> | 
|---|
|  | 42 | <br> | 
|---|
|  | 43 | '; | 
|---|
|  | 44 | $str .= "<br><A href=" . "$w_localhost" . "/check_activate_code.php?user=" . | 
|---|
|  | 45 | $this->user . "&" . "act=" . $this->activate_code . ">啟動 Hadoop 帳號</A>"; | 
|---|
|  | 46 | return $str; | 
|---|
|  | 47 | } | 
|---|
| [57] | 48 |  | 
|---|
| [98] | 49 | // 取得密碼信內容 | 
|---|
|  | 50 | function get_new_password_mailbody() | 
|---|
|  | 51 | { | 
|---|
|  | 52 | global $w_localhost;        // 載入主機位址環境變數 | 
|---|
|  | 53 | $str = ' | 
|---|
|  | 54 | <br> | 
|---|
|  | 55 | <br>您好: | 
|---|
|  | 56 | <br> | 
|---|
|  | 57 | <br>以下為您新的密碼: | 
|---|
|  | 58 | <br> | 
|---|
|  | 59 | <br> | 
|---|
|  | 60 | '; | 
|---|
|  | 61 | $str .= " | 
|---|
|  | 62 | <br>請使用以下設定 | 
|---|
|  | 63 | <br>帳號:$this->user | 
|---|
|  | 64 | <br>密碼:$this->new_password | 
|---|
|  | 65 | <br>登入:$w_localhost | 
|---|
|  | 66 | "; | 
|---|
|  | 67 | return $str; | 
|---|
|  | 68 | } | 
|---|
| [57] | 69 |  | 
|---|
| [98] | 70 | // 取得 hadoop 帳號密碼信內容 | 
|---|
|  | 71 | function get_hadoop_user_password_mailbody() | 
|---|
|  | 72 | { | 
|---|
| [103] | 73 | global $w_localhost;       // 載入主機位址環境變數 | 
|---|
|  | 74 | global $w_ssh_server;      // 載入 ssh 主機位址 | 
|---|
| [98] | 75 | $str = ' | 
|---|
|  | 76 | <br> | 
|---|
|  | 77 | <br>您好: | 
|---|
|  | 78 | <br> | 
|---|
|  | 79 | <br>以下為您所申請的 Hadoop 帳號及密碼: | 
|---|
|  | 80 | <br> | 
|---|
|  | 81 | <br> | 
|---|
|  | 82 | '; | 
|---|
|  | 83 | $str .= " | 
|---|
|  | 84 | <br>位址:$w_localhost | 
|---|
|  | 85 | <br>帳號:$this->hadoop_user | 
|---|
|  | 86 | <br>密碼:$this->hadoop_password | 
|---|
|  | 87 | <br> | 
|---|
|  | 88 | <br>請用<a href=\"http://www.csie.ntu.edu.tw/~piaip/pietty/\">SSH Client</a>登入使用。 | 
|---|
| [103] | 89 | <br>Ex. ssh $w_ssh_server -l $this->hadoop_user | 
|---|
| [98] | 90 | "; | 
|---|
|  | 91 | return $str; | 
|---|
|  | 92 | } | 
|---|
| [57] | 93 |  | 
|---|
| [98] | 94 | // 取得認證碼 | 
|---|
|  | 95 | function get_activate_code() | 
|---|
|  | 96 | { | 
|---|
|  | 97 | return md5($this->user . microtime() ); | 
|---|
|  | 98 | } | 
|---|
| [57] | 99 |  | 
|---|
| [98] | 100 | // 取得新密碼 | 
|---|
|  | 101 | function get_new_password() | 
|---|
|  | 102 | { | 
|---|
|  | 103 | return rand(); | 
|---|
|  | 104 | } | 
|---|
|  | 105 | } | 
|---|
| [57] | 106 |  | 
|---|
| [98] | 107 | class W_mysql | 
|---|
|  | 108 | { | 
|---|
|  | 109 | function connect() | 
|---|
|  | 110 | { | 
|---|
|  | 111 | require ("init.php"); | 
|---|
|  | 112 | // 連結資料庫 | 
|---|
|  | 113 | $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error()); | 
|---|
|  | 114 | mysql_select_db($mysql_database, $link) or die(mysql_error() ); | 
|---|
|  | 115 | mysql_query("SET NAMES 'utf8'"); | 
|---|
|  | 116 | return $link; | 
|---|
|  | 117 | } | 
|---|
|  | 118 |  | 
|---|
|  | 119 | function count_is_active_user($link) | 
|---|
|  | 120 | { | 
|---|
|  | 121 | require ("init.php"); | 
|---|
|  | 122 | $str = sprintf("SELECT COUNT(*) | 
|---|
|  | 123 | FROM `%s` | 
|---|
|  | 124 | WHERE `is_activate` = 1 | 
|---|
|  | 125 | GROUP BY `is_activate` | 
|---|
|  | 126 | ",$mysql_table); | 
|---|
|  | 127 | $result = mysql_query($str , $link) or die(mysql_error() ); | 
|---|
|  | 128 | $row = mysql_fetch_row($result); | 
|---|
|  | 129 | return $row[0]; | 
|---|
|  | 130 | } | 
|---|
|  | 131 | function close($link) | 
|---|
|  | 132 | { | 
|---|
|  | 133 | mysql_close($link); | 
|---|
|  | 134 | } | 
|---|
|  | 135 | } | 
|---|
|  | 136 |  | 
|---|
|  | 137 | function test() | 
|---|
|  | 138 | { | 
|---|
| [63] | 139 | echo "<br>========"; | 
|---|
|  | 140 | echo "<br>this is in W_user->test() <br>"; | 
|---|
| [85] | 141 | $str = "<br><A href=" . "$w_localhost" . "/check_activate_code.php?user=" . | 
|---|
| [63] | 142 | $this->user . "&" . "act=" . $this->activate_code . ">啟動 Hadoop 帳號</A>"; | 
|---|
|  | 143 | //echo $this->user; | 
|---|
|  | 144 | //echo $this->activate_code; | 
|---|
| [98] | 145 | } | 
|---|
| [57] | 146 | ?> | 
|---|