Skip to content

Commit

Permalink
Check permission for control commands
Browse files Browse the repository at this point in the history
PalMA now allows commands only from IP addresses which were registered before.
This fixes an old TODO and should terminate the current hacks.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Dec 6, 2019
1 parent 9378ac5 commit 20fcd7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 13 additions & 0 deletions DBConnector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ public function ipAddress()
return $ip;
}

public function checkPermission()
{
$ip = $this->ipAddress();
$ip_list = array();
$rows = $this->query("SELECT address FROM address");
while ($row = $rows->fetchArray(SQLITE3_ASSOC)) {
array_push($ip_list, $row['address']);
}
$rows->finalize();
$allowed = in_array($ip, $ip_list);
return $allowed;
}

public function addUser($username, $address, $device = 'laptop')
{
// Add a new user with his/her address and the device to the database.
Expand Down
8 changes: 3 additions & 5 deletions control.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

// Authors: Alexander Wagner, Stefan Weil

// TODO: Authentisierung. Funktioniert hier nicht mit auth.php,
// daher vielleicht über Datenbankabfrage.

// Test whether the script was called directly (used for unit test). Use some
// heuristics to detect whether we are not running in a web application.
if (isset($unittest)) {
Expand Down Expand Up @@ -345,7 +342,6 @@ function createNewWindowSafe($db, $w)
createNewWindow($db, $window);
}


function createNewWindow($db, $w)
{
// '$w' already contains 'file', 'handler' and 'date'.
Expand Down Expand Up @@ -568,7 +564,9 @@ function processRequests($db)
}
} // processRequests

processRequests($db);
if ($db->checkPermission() || $unittest[__FILE__]) {
processRequests($db);
}

if ($unittest[__FILE__]) {
// Experimental: Get function call from startx.
Expand Down

0 comments on commit 20fcd7b

Please sign in to comment.