summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsupahgreg <[email protected]>2021-02-28 14:51:08 +0000
committersupahgreg <[email protected]>2021-02-28 14:51:08 +0000
commitbf98ce106ebdf9154621575eaa6016e912657848 (patch)
tree52a88597d3a55d27c4c02c7f586aa0f4c38145bf
Initial commit.
-rw-r--r--LICENSE24
-rw-r--r--README.md13
-rw-r--r--init.php114
3 files changed, 151 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fdddb29
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9ebf0b6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+Preferences Effective Config Tiny Tiny RSS Plugin
+=================================================
+Overview
+---------------------
+This plugin adds an "Effective Config" section to the System section of Preferences.
+
+Installation
+---------------------
+1. Clone the repo to a **prefs_effective_config** in your tt-rss **plugins.local** directory:
+
+ `git clone https://github.com/supahgreg/ttrss-prefs-effective-config.git` prefs_effective_config
+
+2. Enable the plugin @ Preferences / Plugins
diff --git a/init.php b/init.php
new file mode 100644
index 0000000..f0c174a
--- /dev/null
+++ b/init.php
@@ -0,0 +1,114 @@
+<?php
+class Prefs_Effective_Config extends Plugin {
+
+ private $host;
+ private const CONFIG_KEYS_TO_MASK = ['DB_PASS'];
+ private const PARAM_TYPE_TO_NAME = [
+ Config::T_BOOL => 'bool',
+ Config::T_STRING => 'string',
+ Config::T_INT => 'integer',
+ ];
+
+ function about() {
+ return [
+ 0.1, // version
+ 'Shows your effective tt-rss config @ Preferences --> System', // description
+ 'wn', // author
+ false, // is system
+ 'https://github.com/supahgreg/ttrss-prefs-effective-config/', // more info URL
+ ];
+ }
+
+ function api_version() {
+ return 2;
+ }
+
+ function init($host) {
+ $this->host = $host;
+ $host->add_hook($host::HOOK_PREFS_TAB, $this);
+ }
+
+ function hook_prefs_tab($tab) {
+ if ($tab != 'prefSystem' || !self::is_admin()) {
+ return;
+ }
+?>
+ <div dojoType='dijit.layout.AccordionPane' title='<i class="material-icons">subject</i> <?= __('Effective Config') ?>'>
+ <script type='dojo/method' event='onSelected' args='evt'>
+ if (this.domNode.querySelector('.loading'))
+ window.setTimeout(() => {
+ xhr.post('backend.php', {op: 'pluginhandler', plugin: 'prefs_effective_config', method: 'get_effective_config'}, (reply) => {
+ this.attr('content', reply);
+ });
+ }, 200);
+ </script>
+ <span class='loading'><?= __('Loading, please wait...') ?></span>
+ </div>
+<?php
+ }
+
+ function is_admin() {
+ return ($_SESSION['access_level'] ?? 0) >= 10;
+ }
+
+ function get_effective_config() {
+ if (!self::is_admin()) {
+ print format_error('Access forbidden.');
+ return;
+ }
+?>
+ <style type='text/css'>
+ #config-items-list { text-align: left; }
+ #config-items-list th { border-bottom: 1px solid #000; }
+ #config-items-list td:not(:last-child) { border-right: 1px solid #ccc; }
+ </style>
+
+ <table id='config-items-list' style='text-align: left;'>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Effective Value</th>
+ <th>Environment Variable Value</th>
+ <th>Default Value</th>
+ <th>Type Hint</th>
+ </tr>
+ </thead>
+ <tbody>
+<?php
+ $cfg_instance = new Config();
+ $cfg_rc = new ReflectionClass($cfg_instance);
+
+ $cfg_constants = $cfg_rc->getConstants();
+ $envvar_prefix = $cfg_rc->getConstant('_ENVVAR_PREFIX');
+ $defaults = $cfg_rc->getConstant('_DEFAULTS');
+
+ $params = $cfg_rc->getProperty('params');
+ $params->setAccessible(true);
+
+ foreach ($params->getValue($cfg_instance) as $p => $v) {
+ list ($pval, $ptype) = $v;
+ $env_val = getenv($envvar_prefix . $p);
+ list ($defval, $deftype) = $defaults[$cfg_rc->getConstant($p)];
+
+ print "<tr><td>${envvar_prefix}${p}</td>";
+
+ if (in_array($p, self::CONFIG_KEYS_TO_MASK)) {
+ print '<td class="redacted">redacted</td>';
+ print '<td class="redacted">'.($env_val ? 'redacted' : 'not defined').'</td>';
+ }
+ else {
+ print "<td>${pval}</td>";
+ print "<td>${env_val}</td>";
+ }
+
+ print "<td>${defval}</td>";
+ print '<td>'.self::PARAM_TYPE_TO_NAME[$ptype].'</td>';
+ print '</tr>';
+ }
+?>
+ </tbody>
+ </table>
+<?php
+ }
+}
+