Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <style>
- html, body, ul, li, ol, form, fieldset, legend {
- margin: 0;
- padding: 0;
- }
- body {
- margin: 20px;
- font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
- }
- p, label {
- font-size: 90%;
- }
- label {
- display: block;
- width: 200px;
- float: left;
- }
- input[type=text], input[type=password] {
- margin-bottom: 10px;
- width: 200px;
- }
- form {
- padding: 10px;
- border: 1px solid #CCC;
- background-color: #FCFCFC;
- width: 410px;
- }
- </style>
- </head>
- <body>
- <?php
- error_reporting(E_ERROR | E_PARSE);
- function wake($mac, $ipaddr) {
- $data = "";
- for ($i = 0; $i < 6; $i++) {
- $data .= chr(255);
- }
- for ($i = 0; $i < 16; $i++) {
- for ($v = 0; $v < 12; $v = $v + 2) {
- $data .= chr(hexdec(substr($mac, $v, 2)));
- }
- }
- $endpoint = fsockopen("udp://".$ipaddr, 9);
- fwrite($endpoint, $data, 102);
- echo "<p>Magic packet sent</p>";
- echo "<p>Wake another?</p>";
- }
- if ($_GET['macaddr'] && $_GET['ipaddr'] && $_GET["passwd"] && $_GET["username"]) {
- //type username and password to wake after creation/update
- //setpassword
- $validmac = filter_input(INPUT_GET, "macaddr", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^([0-9A-F]{2}[:-]){5}[0-9A-F]{2}$/i")) );
- $validmac = preg_replace('/([-:])?/', '', $validmac);
- if ($validmac) {
- $database = mysql_connect("localhost", "harry", "temphehe");
- if ($database) {
- if (mysql_select_db('wolexample', $database)) {
- //escapes
- $username = mysql_real_escape_string($_GET["username"], $database);
- $ipaddr = mysql_real_escape_string($_GET['ipaddr'], $database);
- $password = sha1(mysql_real_escape_string($_GET["passwd"], $database));
- $result = mysql_query("SELECT password FROM users WHERE username = '$username'", $database);
- if ($result) {
- $row = mysql_fetch_assoc($result);
- if ($row) {
- //we have a user! Now check the pass
- if ($row['password'] == sha1($_GET['passwd'])) {
- if ((mysql_query("UPDATE users SET macaddr = '$validmac', ipaddr = '$ipaddr' WHERE username = '$username' AND password = '$password'", $database))) {
- echo "Info updated successfully";
- }
- else {
- echo "Catastrophic failiure updating database";
- }
- }
- else {
- echo "Wrong password";
- }
- }
- else {
- //make a user
- if (mysql_query("INSERT INTO users VALUES ('$username', '$password', '$validmac', '$ipaddr')", $database)) {
- echo "New user added successfully";
- } else {
- echo "Catastrophic failiure adding user to database";
- }
- }
- }
- } else {
- echo "Catastrophic failiure selecting database";
- }
- } else {
- echo "Catastrophic failiure connecting to database";
- }
- } else {
- echo "Bad input!";
- }
- }
- if ($_GET['username'] && $_GET['passwd'] && !$_GET['macaddr'] && !$_GET['ipaddr']) {
- $database = mysql_connect("localhost", "harry", "temphehe");
- if ($database) {
- if (mysql_select_db('wolexample', $database)) {
- //escapes
- $username = mysql_real_escape_string($_GET["username"], $database);
- $result = mysql_query("SELECT macaddr, ipaddr , password FROM users WHERE username = '$username'", $database);
- if ($result) {
- $row = mysql_fetch_assoc($result);
- if ($row) {
- if ($row['password'] == sha1($_GET['passwd'])) {
- wake($row['macaddr'], $row['ipaddr']);
- }
- else {
- echo "Wrong password";
- }
- }
- else {
- echo "Username does not exist, try creating it";
- }
- }
- else {
- echo "Catastrophic failiure querying database";
- }
- }
- else {
- echo "Catastrophic failiure selecting database";
- }
- }
- else {
- echo "Catastrophic failiure connecting to database";
- }
- }
- if ($_GET['macaddr'] && $_GET['ipaddr'] && !($_GET['username']) && !($_GET['passwd'])) {
- $validmac = filter_input(INPUT_GET, "macaddr", FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^([0-9A-F]{2}[:-]){5}[0-9A-F]{2}$/i")) );
- $validmac = preg_replace('/([-:])?/', '', $validmac);
- if ($validmac) {
- wake($validmac, $_GET['ipaddr']);
- }
- else {
- echo "Bad input!";
- }
- }
- ?>
- <h1>Wake on LAN</h1>
- <form name="wol" action="wol.php" method="get">
- <label for="ipaddr">IP address/hostname:</label><input type="text" name="ipaddr"><br>
- <label for "macaddr">MAC address:</label><input type="text" name="macaddr"><br>
- <p>To save or retrieve your IP address and MAC address, enter a username and password. After creating/updating your info, you'll need to enter your new login info and press the button again, as a user is created/updated when all fields are filled.</p>
- <label for="username">Username:</label><input type="text" name="username"><br>
- <label for="passwd">Password:</label><input type="password" name="passwd"><br>
- <input type="submit" value="Wake/Add data to database">
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment