diff --git a/controllers/access_widget.php b/controllers/access_widget.php new file mode 100644 index 0000000..b9f5644 --- /dev/null +++ b/controllers/access_widget.php @@ -0,0 +1,107 @@ + + * @copyright 2018 Avantech + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 3 or later + * @link http://www.egloo.ca/clearos/marketplace/apps/syncthing + */ + +/////////////////////////////////////////////////////////////////////////////// +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// B O O T S T R A P +/////////////////////////////////////////////////////////////////////////////// + +$bootstrap = getenv('CLEAROS_BOOTSTRAP') ? getenv('CLEAROS_BOOTSTRAP') : '/usr/clearos/framework/shared'; +require_once $bootstrap . '/bootstrap.php'; + +/////////////////////////////////////////////////////////////////////////////// +// D E P E N D E N C I E S +/////////////////////////////////////////////////////////////////////////////// + +use \clearos\apps\syncthing\Syncthing as SyncthingLibrary; + +/////////////////////////////////////////////////////////////////////////////// +// C L A S S +/////////////////////////////////////////////////////////////////////////////// + +/** + * Syncthing controller. + * + * @category apps + * @package syncthing + * @subpackage controllers + * @author eGloo + * @copyright 2018 Avantech + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 3 or later + * @link http://www.egloo.ca/clearos/marketplace/apps/syncthing + */ + +class Access_Widget extends ClearOS_Controller +{ + /** + * Syncthing users controller + * + * @return view + */ + + function index() + { + // Load dependencies + //------------------ + + $this->lang->load('syncthing'); + $this->load->library('syncthing/Syncthing'); + + try { + $data['status'] = $this->syncthing->get_users_config($this->session->userdata('username'))[$this->session->userdata('username')]; + if ($data['gui_access'] != SyncthingLibrary::VIA_REVERSE_PROXY && !$this->syncthing->passwords_ok()) + $data['gui_no_auth_warning'] = lang('syncthing_gui_no_auth'); + $data['version'] = $this->syncthing->get_version(); + $data['gui_access'] = $this->syncthing->get_gui_access(); + $data['gui_access_options'] = $this->syncthing->get_gui_access_options(); + } catch (Engine_Engine_Exception $e) { + $this->page->view_exception($e); + return; + } + + if ($data['gui_access'] == SyncthingLibrary::VIA_REVERSE_PROXY) { + $url = "https://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/syncthing/"; + $data['gui_access'] = "$url"; + } else if ($data['gui_access'] == SyncthingLibrary::VIA_LOCALHOST) { + $data['gui_access'] = lang('syncthing_console_access_only'); + } else { + $hostname = $_SERVER['SERVER_NAME']; + if ($data['gui_access'] == SyncthingLibrary::VIA_LAN) + $hostname = $this->syncthing->get_lan_ip(); + $url = "https://" . $hostname . ":" . $data['status']['port']; + $data['gui_access'] = "$url"; + } + + // Load views + //----------- + + $this->page->view_form('syncthing/user_profile', $data, lang('syncthing_app_name')); + } +} diff --git a/deploy/info.php b/deploy/info.php index 6609bc7..e7541d5 100644 --- a/deploy/info.php +++ b/deploy/info.php @@ -4,7 +4,7 @@ // General information ///////////////////////////////////////////////////////////////////////////// $app['basename'] = 'syncthing'; -$app['version'] = '1.1.10'; +$app['version'] = '1.1.11'; $app['release'] = '1'; $app['vendor'] = 'WikiSuite'; $app['packager'] = 'WikiSuite'; @@ -45,7 +45,7 @@ ///////////////////////////////////////////////////////////////////////////// $app['user_profile_widgets'] = [ - 'syncthing/user_profile_settings', + 'syncthing/access_widget', ]; ///////////////////////////////////////////////////////////////////////////// diff --git a/libraries/Syncthing.php b/libraries/Syncthing.php index 49e68ce..90b4300 100644 --- a/libraries/Syncthing.php +++ b/libraries/Syncthing.php @@ -154,11 +154,13 @@ function __construct() /** * Get user settings. * + * @param $selected selected username + * * @return void * @throws Engine_Exception */ - public function get_users() + public function get_users($selected = null) { clearos_profile(__METHOD__, __LINE__); $info = array(); @@ -171,6 +173,8 @@ public function get_users() $group_info = $groupobj->get_info(); foreach ($users as $username => $details) { + if ($selected != null && $selected != $username) + continue; $status = lang('base_disabled'); $enabled = FALSE; @@ -464,7 +468,7 @@ function override_settings() * @throws Engine_Exception */ - function get_users_config() + function get_users_config($selected = null) { clearos_profile(__METHOD__, __LINE__); @@ -472,6 +476,8 @@ function get_users_config() $hostname = gethostname(); $users = $this->get_users(); foreach ($users as $user => $meta) { + if ($selected != null && $selected != $user) + continue; $file = new File(self::FOLDER_HOME . "/$user" . self::FILE_USER_CONFIG, TRUE); if (!$file->exists()) continue; @@ -491,7 +497,7 @@ function get_users_config() 'port' => $match[2] ]; } - if ($xml->gui->password != null) + if (empty($xml->gui->password)) $data[$user]['password'] = TRUE; else $data[$user]['password'] = FALSE; diff --git a/packaging/app-syncthing.spec b/packaging/app-syncthing.spec index 2bda5a1..67b11ed 100644 --- a/packaging/app-syncthing.spec +++ b/packaging/app-syncthing.spec @@ -1,7 +1,7 @@ Name: app-syncthing Epoch: 1 -Version: 1.1.10 +Version: 1.1.11 Release: 1%{dist} Summary: Syncthing License: GPLv3 diff --git a/views/user_profile.php b/views/user_profile.php new file mode 100644 index 0000000..c90cc57 --- /dev/null +++ b/views/user_profile.php @@ -0,0 +1,59 @@ + + * @copyright 2018 Avantech + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License version 3 or later + * @link http://www.egloo.ca/clearos/marketplace/apps/syncthing + */ + +/////////////////////////////////////////////////////////////////////////////// +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Load dependencies +/////////////////////////////////////////////////////////////////////////////// + +$this->lang->load('base'); +$this->lang->load('syncthing'); + +/////////////////////////////////////////////////////////////////////////////// +// Form Header +/////////////////////////////////////////////////////////////////////////////// + +echo form_header(lang('syncthing_app_name')); + +/////////////////////////////////////////////////////////////////////////////// +// Fields +/////////////////////////////////////////////////////////////////////////////// + +echo field_view(lang('syncthing_version'), $version); +echo field_view(lang('base_status'), $status['status']); +echo field_view(lang('syncthing_gui_access'), $gui_access); + +/////////////////////////////////////////////////////////////////////////////// +// Form footer +/////////////////////////////////////////////////////////////////////////////// + +echo form_footer(); + +// vi: expandtab shiftwidth=4 softtabstop=4 tabstop=4