Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

Commit

Permalink
Manage user creation/deletion better when using reverse proxy #10
Browse files Browse the repository at this point in the history
  • Loading branch information
bchambers committed Aug 20, 2018
1 parent 0b4c80c commit d494fbe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deploy/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// General information
/////////////////////////////////////////////////////////////////////////////
$app['basename'] = 'syncthing';
$app['version'] = '1.1.15';
$app['version'] = '1.2.0';
$app['release'] = '1';
$app['vendor'] = 'WikiSuite';
$app['packager'] = 'WikiSuite';
Expand Down
8 changes: 8 additions & 0 deletions deploy/service-check
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,12 @@ try {
echo clearos_exception_message($e) . "\n";
}

if ($force) {
try {
$syncthing->update();
} catch (Exception $e) {
echo clearos_exception_message($e) . "\n";
}
}

// vim: syntax=php ts=4
23 changes: 22 additions & 1 deletion libraries/Syncthing.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,18 @@ function update()
$iface_manager = new Iface_Manager();
$lan = $iface_manager->get_most_trusted_ips()[0];
$users = $this->get_users_config();
if ($access == self::VIA_REVERSE_PROXY) {
// Delete any users that don't exist anymore
$lines = $proxy->get_contents_as_array();
foreach ($lines as $line) {
if (preg_match("/RewriteCond %{REMOTE_USER} \"(.*)\"/", $line, $match)) {
if (!array_key_exists($match[1], $users)) {
$proxy->delete_lines("/\s*RewriteCond.* \"" . $match[1] . "\"$/i");
$proxy->delete_lines("/\s*RewriteRule.* # " . $match[1] . "$/i");
}
}
}
}
foreach ($users as $user => $meta) {
$file = new File(self::FOLDER_HOME . "/$user" . self::FILE_USER_CONFIG, TRUE);
if (!$file->exists())
Expand All @@ -562,7 +574,16 @@ function update()
}
try {
$proxy->lookup_line("/\s*RewriteCond %{REMOTE_USER} \"$user\"/i");
$proxy->replace_lines("/\s*RewriteRule \"\\/syncthing\\/\\(\\.\\*\\)\" \"http:\\/\\/127\\.0\\.0\\.1:\d+\\/\\$1\" \\[P\\] # $user/i", "\tRewriteRule \"/syncthing/(.*)\" \"http://127.0.0.1:" . $meta['port'] . "/$1\" [P] # $user\n");
if ($meta['enabled']) {
$proxy->replace_lines("/\s*RewriteRule \"\\/syncthing\\/\\(\\.\\*\\)\" \"http:\\/\\/127\\.0\\.0\\.1:\d+\\/\\$1\" \\[P\\] # $user$/i", "\tRewriteRule \"/syncthing/(.*)\" \"http://127.0.0.1:" . $meta['port'] . "/$1\" [P] # $user\n");
} else {
try {
$proxy->delete_lines("/\s*RewriteCond.* \"$user\"$/i");
$proxy->delete_lines("/\s*RewriteRule.* # $user$/i");
} catch (File_No_Match_Exception $e) {
// Don't need to do anything
}
}
} catch (File_No_Match_Exception $e) {
$proxy->add_lines_after("\tRewriteRule \"/syncthing/(.*)\" \"http://127.0.0.1:" . $meta['port'] . "/$1\" [P] # $user\n", "/RewriteEngine on/i");
$proxy->add_lines_after("\tRewriteCond %{REMOTE_USER} \"$user\"\n", "/RewriteEngine on/i");
Expand Down
2 changes: 1 addition & 1 deletion packaging/app-syncthing.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Name: app-syncthing
Epoch: 1
Version: 1.1.15
Version: 1.2.0
Release: 1%{dist}
Summary: Syncthing
License: GPLv3
Expand Down

0 comments on commit d494fbe

Please sign in to comment.