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

Commit

Permalink
Added user profile webhook
Browse files Browse the repository at this point in the history
[#8]
  • Loading branch information
bchambers committed May 31, 2018
1 parent 671a0ae commit 9aece7b
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 6 deletions.
107 changes: 107 additions & 0 deletions controllers/access_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/**
* Syncthing controller.
*
* @category apps
* @package syncthing
* @subpackage controllers
* @author eGloo <developer@egloo.ca>
* @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 <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// 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 <developer@egloo.ca>
* @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'] = "<a href='$url' target='_blank'>$url</a>";
} 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'] = "<a href='$url' target='_blank'>$url</a>";
}

// Load views
//-----------

$this->page->view_form('syncthing/user_profile', $data, lang('syncthing_app_name'));
}
}
4 changes: 2 additions & 2 deletions 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.10';
$app['version'] = '1.1.11';
$app['release'] = '1';
$app['vendor'] = 'WikiSuite';
$app['packager'] = 'WikiSuite';
Expand Down Expand Up @@ -45,7 +45,7 @@
/////////////////////////////////////////////////////////////////////////////

$app['user_profile_widgets'] = [
'syncthing/user_profile_settings',
'syncthing/access_widget',
];

/////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 9 additions & 3 deletions libraries/Syncthing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -464,14 +468,16 @@ function override_settings()
* @throws Engine_Exception
*/

function get_users_config()
function get_users_config($selected = null)
{
clearos_profile(__METHOD__, __LINE__);

$data = [];
$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;
Expand All @@ -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;
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.10
Version: 1.1.11
Release: 1%{dist}
Summary: Syncthing
License: GPLv3
Expand Down
59 changes: 59 additions & 0 deletions views/user_profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Syncthing user profile configuration.
*
* @category apps
* @package syncthing
* @subpackage views
* @author eGloo <developer@egloo.ca>
* @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 <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// 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

0 comments on commit 9aece7b

Please sign in to comment.