Last active
August 29, 2015 14:06
-
-
Save mizofumi/b3ab8915239563f90359 to your computer and use it in GitHub Desktop.
Wake On Lan するやつ (自分用に作ったからセキュリティ回りはヤバイ)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //wakeonlanするために必要なもの | |
| //http://gsd.di.uminho.pt/jpo/software/wakeonlan/ | |
| //ユーザ名 | |
| define("USERNAME","username"); | |
| //パスワード(初期値はpassword) | |
| //パスワードを変更する場合はこのページのハッシュを使用してください。 | |
| //http://phpspot.net/php/pg%EF%BC%AD%EF%BC%A4%EF%BC%95%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5%E8%A8%88%E7%AE%97%E3%83%84%E3%83%BC%E3%83%AB.html | |
| define("PASSWORD","5f4dcc3b5aa765d61d8327deb882cf99"); | |
| session_start(); | |
| $dataArray = unserialize(file_get_contents("mac.dat")); | |
| //ログアウト要求があるか | |
| if(($_SESSION["logged"]) && $_POST['logout'] == true){ | |
| print('ログアウトしました'); | |
| $_SESSION["logged"] = false; | |
| } | |
| //ログイン要求があるか | |
| if( (isset($_POST['username'])) && (isset($_POST['password']) )){ | |
| if($_POST['username'] == USERNAME && md5($_POST['password']) == PASSWORD){ | |
| $_SESSION['logged'] = true; | |
| header('Location: ./'); | |
| }else{ | |
| print('ユーザ名またはパスワードが違います'); | |
| } | |
| } | |
| //MACアドレス追加要求があるか | |
| if(($_SESSION["logged"]) && (isset($_POST['add_mac_address']) && (isset($_POST['add_mac_address_name'])) )){ | |
| if(filesize("mac.dat") == 0){ | |
| $dataArray = array($_POST['add_mac_address_name'] => $_POST['add_mac_address']); | |
| }else{ | |
| $dataArray += array($_POST['add_mac_address_name'] => $_POST['add_mac_address']); | |
| } | |
| file_put_contents("mac.dat", serialize($dataArray)); | |
| } | |
| //MACアドレス削除要求があるか | |
| if(($_SESSION["logged"]) && (isset($_POST['del']) )){ | |
| unset($dataArray[$_POST['del']]); | |
| file_put_contents("mac.dat", serialize($dataArray)); | |
| print('削除しました'); | |
| } | |
| //マジックパケット送信要求があるか | |
| if(($_SESSION["logged"]) && (isset($_GET['mac']) )){ | |
| exec("./wakeonlan ".$_GET['mac']); | |
| print('送信しました'); | |
| } | |
| //ログインしてない場合 | |
| if(!$_SESSION["logged"]){ | |
| print('<h1>WOL管理ページ(認証)</h1> | |
| <form method="post"> | |
| ユーザ名: <input type="text" name="username"><br /> | |
| パスワード: <input type="password" name="password"><br /> | |
| <input type="submit" value="ログイン">'); | |
| } | |
| //ログイン済 | |
| if($_SESSION["logged"]){ | |
| //ログアウトボタンを表示 | |
| print('<form method="post"><input type="hidden" name="logout" value="true"><input type="submit" value="ログアウト"></form>'); | |
| //if() | |
| print('<h1>WOL管理ページ(メインページ)</h1> | |
| <h2>端末登録</h2> | |
| <form method="post"> | |
| 端末名<input type="text" name="add_mac_address_name"><br /> | |
| MACアドレス<input type="text" name="add_mac_address"><br /> | |
| <input type="submit" value="MACアドレス登録"> | |
| </form> | |
| <h2>登録済み一覧</h2> | |
| '); | |
| foreach ($dataArray as $key => $value){ | |
| print '<form method="post"><input type="hidden" name="del" value="'.$key.'">'.$key.':<a href="./?mac='.$value.'">'.$value.'</a> : <input type="submit" value="削除"></form>'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment