Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ A simple PHP WakeOnLan UI
###### Installation

1. Clone the repo and copy the `html` folder into your webroot
2. Change the lines below in `config.php` to fit your mysql setup *(DO NOT CREATE DB)*
2. Create SQL user:

```bash
$ sudo mysql
mysql> CREATE DATABASE 'php-wol';
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON 'php-wol'.* TO 'username'@'localhost';
mysql> FLUSH PRIVILEGES;

```
4. Change the lines below in `config.php` to fit your mysql setup

```
private $servername = "localhost";
Expand Down
72 changes: 46 additions & 26 deletions html/db.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,79 @@
<?php
class Database extends PDO {
private string $servername = "localhost";
private string $username = "root";
private string $password = "";
private string $database = "php-wol";
private $servername = "localhost";
private $username = "root";
private $password = "";
private $database = "php-wol";

function __construct() {
// Get configuration
if (file_exists('./config.php')) {
[
"servername" => $this->servername,
"username" => $this->username,
"password" => $this->password,
"database" => $this->database,
] = include('./config.php');
}
// Get configuration
if (file_exists('./config.php')) {
$config = include('./config.php');
$this->servername = $config['servername'];
$this->username = $config['username'];
$this->password = $config['password'];
$this->database = $config['database'];
}

// Create connection
try {
parent::__construct("mysql:{$this->servername}", $this->username, $this->password);
} catch (PDOException $e) {
die('Connection failed: ' . $e->getMessage());
}

//check if database exists
$st = $this->prepare("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{$this->database}'");
$st->execute();
if($st->rowCount() <= 0) $this->create();
else $this->query("USE `{$this->database}`");
// eventually create schema
$this->create();
}

/**
* creates a new database
* creates schema if it does not exists
*/
function create() {
$this->query("CREATE DATABASE `{$this->database}`");
//check if database exists
$st = $this->prepare("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{$this->database}'");
$st->execute();
if($st->rowCount() <= 0) {
$this->query("CREATE DATABASE `{$this->database}`");
}
$this->query("USE `{$this->database}`");
$this->query(<<<EOL

$st = $this->prepare("SELECT 1 FROM server");
$st->execute();
if($st->rowCount() <= 0) {
$q = <<<EOL
CREATE TABLE server (
id varchar(45) NOT NULL PRIMARY KEY,
name varchar(30) NOT NULL,
ip varchar(16) NOT NULL,
mac varchar(20) UNIQUE,
broadcast varchar(16)
);
EOL);
$this->query(<<<EOL
EOL;
$this->query($q);
}

$st = $this->prepare("SELECT 1 FROM user");
$st->execute();
if($st->rowCount() <= 0) {
$q = <<<EOL
CREATE TABLE user (
id int AUTO_INCREMENT NOT NULL PRIMARY KEY,
username varchar(30) NOT NULL UNIQUE,
password binary(64) NOT NULL,
salt binary(64) NOT NULL,
level int NOT NULL
);
EOL);
$this->query("INSERT INTO `user` (`id`, `username`, `password`, `salt`, `level`) VALUES (1, 'admin', 0xa28d2e6472c306c6c57138f5f2c6ff25498e5d3ccd9a63a1bc591f4b5fe1dedd4b4044bcf1cc0b61767f6d7ce8198d94eb432d03fa082261ab4741734f07e9b2, 0xb2c17f0341921fe13306e0d6b4c952d90ad12ce176e962f5d7f28254c51e4345accaafc5d1f003fe346ab8a1bf52330317d1007237ca8f78abd9420d4b5524a3, 3)");
EOL;
$this->query($q);
}

// create admin
$st = $this->prepare("SELECT admin FROM user");
$st->execute();
if($st->rowCount() <= 0) {
$this->query("INSERT INTO `user` (`id`, `username`, `password`, `salt`, `level`) VALUES (1, 'admin', 0xa28d2e6472c306c6c57138f5f2c6ff25498e5d3ccd9a63a1bc591f4b5fe1dedd4b4044bcf1cc0b61767f6d7ce8198d94eb432d03fa082261ab4741734f07e9b2, 0xb2c17f0341921fe13306e0d6b4c952d90ad12ce176e962f5d7f28254c51e4345accaafc5d1f003fe346ab8a1bf52330317d1007237ca8f78abd9420d4b5524a3, 3)");
}


}
}
6 changes: 5 additions & 1 deletion html/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Admin Page</title>
<title>Wake-On-Lan</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-title" content="WOL">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon" href="wol.png">
<link rel="stylesheet" href="css/yeti.bootstrap.min.css"/>
<link rel="stylesheet" href="css/custom.css"/>
<script src="js/jquery-3.2.1.min.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions html/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
if ($auth->hasLevel()) {
if ($_POST['newpassword'] != $_POST['newpassword2'])
$toReturn['msg'] = 'passwords didnt match';
else if ($auth->login($auth->getUsername(), $_POST['password']))
else if (!$auth->login($auth->getUsername(), $_POST['password'])) {
$toReturn['msg'] = 'wrong password';
else {
} else {
$auth->updatePassword($_POST['newpassword']);
$toReturn['response'] = true;
}
Expand Down
3 changes: 3 additions & 0 deletions html/wake.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
}
else if(isset($_POST['mac'], $_POST['broadcast'])) {
$broadcast = $_POST['broadcast'];
if(empty($broadcast)) {
$broadcast = '255.255.255.255';
}
$mac_array = explode(':', $_POST['mac']);

$hwaddr = '';
Expand Down
Binary file added html/wol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.