]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/prefs.php
add several HOOK_PREFS_TAB_SECTION hook points
[tt-rss.git] / classes / pref / prefs.php
index c6b109877eb8c4095ac0672ad25b3708018541b7..e8926194e6ebf767b8a6ea9761d70cb670e1f0d0 100644 (file)
@@ -230,6 +230,10 @@ class Pref_Prefs extends Handler_Protected {
                        }
                        </script>";
 
+                       if ($otp_enabled) {
+                               print_notice("Changing your current password will disable OTP.");
+                       }
+
                        print "<table width=\"100%\" class=\"prefPrefsList\">";
 
                        print "<tr><td width=\"40%\">".__("Old password")."</td>";
@@ -260,7 +264,45 @@ class Pref_Prefs extends Handler_Protected {
 
                                if ($otp_enabled) {
 
-                                       print "<p>".__("One time passwords are currently enabled. Change your current password and refresh this page to reconfigure.") . "</p>";
+                                       print_notice("One time passwords are currently enabled. Enter your current password below to disable.");
+
+                                       print "<form dojoType=\"dijit.form.Form\">";
+
+                               print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
+                               evt.preventDefault();
+                               if (this.validate()) {
+                                       notify_progress('Disabling OTP', true);
+
+                                       new Ajax.Request('backend.php', {
+                                               parameters: dojo.objectToQuery(this.getValues()),
+                                               onComplete: function(transport) {
+                                                       notify('');
+                                                       if (transport.responseText.indexOf('ERROR: ') == 0) {
+                                                               notify_error(transport.responseText.replace('ERROR: ', ''));
+                                                       } else {
+                                                               window.location.reload();
+                                                       }
+                                       }});
+                                       this.reset();
+                               }
+                               </script>";
+
+                               print "<table width=\"100%\" class=\"prefPrefsList\">";
+
+                               print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
+
+                               print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
+                                       name=\"password\"></td></tr>";
+
+                               print "</table>";
+
+                               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
+                               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpdisable\">";
+
+                               print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
+                                       __("Disable OTP")."</button>";
+
+                               print "</form>";
 
                                } else {
 
@@ -275,7 +317,7 @@ class Pref_Prefs extends Handler_Protected {
                                        print "<form dojoType=\"dijit.form.Form\" id=\"changeOtpForm\">";
 
                                        print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
-                                       print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeotp\">";
+                                       print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"otpenable\">";
 
                                        print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
                                        evt.preventDefault();
@@ -285,18 +327,37 @@ class Pref_Prefs extends Handler_Protected {
                                                new Ajax.Request('backend.php', {
                                                        parameters: dojo.objectToQuery(this.getValues()),
                                                        onComplete: function(transport) {
-                                                               window.location.reload();
+                                                               notify('');
+                                                               if (transport.responseText.indexOf('ERROR: ') == 0) {
+                                                                       notify_error(transport.responseText.replace('ERROR: ', ''));
+                                                               } else {
+                                                                       window.location.reload();
+                                                               }
                                                } });
 
                                        }
                                        </script>";
 
+                                       print "<table width=\"100%\" class=\"prefPrefsList\">";
+
+                                       print "<tr><td width=\"40%\">".__("Enter your password")."</td>";
+
+                                       print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\"
+                                               name=\"password\"></td></tr>";
+
+                                       print "<tr><td colspan=\"2\">";
+
                                        print "<input dojoType=\"dijit.form.CheckBox\" required=\"1\"
                                                type=\"checkbox\" id=\"enable_otp\" name=\"enable_otp\"/> ";
                                        print "<label for=\"enable_otp\">".__("I have scanned the code and would like to enable OTP")."</label>";
 
+                                       print "</td></tr><tr><td colspan=\"2\">";
+
+                                       print "</td></tr>";
+                                       print "</table>";
+
                                        print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
-                                               __("Save OTP setting")."</button>";
+                                               __("Enable OTP")."</button>";
 
                                        print "</form>";
 
@@ -305,6 +366,10 @@ class Pref_Prefs extends Handler_Protected {
                        }
                }
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefPrefsAuth");
+
                print "</div>"; #pane
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">";
@@ -533,6 +598,10 @@ class Pref_Prefs extends Handler_Protected {
 
                print "</table>";
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefPrefsPrefsInside");
+
                print '</div>'; # inside pane
                print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
 
@@ -560,66 +629,149 @@ class Pref_Prefs extends Handler_Protected {
                                <label for='prefs_show_advanced'>" .
                                __("Show additional preferences") . "</label>";
 
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB_SECTION,
+                       "hook_prefs_tab_section", "prefPrefsPrefsOutside");
+
+               print "</form>";
                print '</div>'; # inner pane
                print '</div>'; # border container
-               print "</form>";
 
                print "</div>"; #pane
 
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Plugins')."\">";
 
-               if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE) && CHECK_FOR_NEW_VERSION) {
-                       print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Update Tiny Tiny RSS')."\">";
+               print "<h2>".__("Plugins")."</h2>";
 
-                       if ($_SESSION["pref_last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
-                               $_SESSION["version_data"] = @check_for_update($this->link);
-                               $_SESSION["pref_last_version_check"] = time();
-                       }
+               print_notice("You will need to reload Tiny Tiny RSS for plugin changes to take effect.");
 
-                       if (is_array($_SESSION["version_data"])) {
-                               $version = $_SESSION["version_data"]["version"];
-                               print_notice(T_sprintf("New version of Tiny Tiny RSS is available (%s).", "<b>$version</b>"));
+               print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
 
-                               print "<p><button dojoType=\"dijit.form.Button\" onclick=\"return updateSelf()\">".
-                                       __('Update Tiny Tiny RSS')."</button></p>";
+               print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
+               evt.preventDefault();
+               if (this.validate()) {
+                       notify_progress('Saving data...', true);
 
-                       } else {
-                               print_notice(__("Your Tiny Tiny RSS installation is up to date."));
-                       }
+                       new Ajax.Request('backend.php', {
+                               parameters: dojo.objectToQuery(this.getValues()),
+                               onComplete: function(transport) {
+                                       notify('');
+                                       if (confirm(__('Selected plugins have been enabled. Reload?'))) {
+                                               window.location.reload();
+                                       }
+                       } });
 
-                       print "</div>"; #pane
                }
+               </script>";
 
-               print "</div>"; #container
-       }
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">";
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setplugins\">";
 
-       function updateSelf() {
-               print "<form style='display : block' name='self_update_form' id='self_update_form'>";
+               print "<table width='100%' class='prefPluginsList'>";
 
-               print "<div class='error'>".__("Do not close this dialog until updating is finished. Backup your tt-rss directory before continuing.")."</div>";
+               print "<tr><td colspan='4'><h3>".__("System plugins")."</h3></td></tr>";
 
-               print "<ul class='selfUpdateList' id='self_update_log'>";
-               print "<li>" . __("Ready to update.") . "</li>";
-               print "</ul>";
+               print "<tr class=\"title\">
+                               <td width=\"5%\">&nbsp;</td>
+                               <td width='10%'>".__('Plugin')."</td>
+                               <td width=''>".__('Description')."</td>
+                               <td width='5%'>".__('Version')."</td>
+                               <td width='10%'>".__('Author')."</td></tr>";
 
-               print "<div class='dlgButtons'>";
-               print "<button id=\"self_update_start_btn\" dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('updateSelfDlg').start()\" >".
-                       __("Start update")."</button>";
-               print "<button id=\"self_update_stop_btn\" onclick=\"return dijit.byId('updateSelfDlg').close()\" dojoType=\"dijit.form.Button\">".
-                       __("Close this window")."</button>";
-               print "</div>";
-               print "</form>";
-       }
+               $system_enabled = array_map("trim", explode(",", PLUGINS));
+               $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS")));
 
-       function performUpdate() {
-               $step = (int) $_REQUEST["step"];
-               $params = json_decode($_REQUEST["params"], true);
-               $force = (bool) $_REQUEST["force"];
+               $tmppluginhost = new PluginHost($link);
+               $tmppluginhost->load_all($tmppluginhost::KIND_ALL);
 
-               if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE) && CHECK_FOR_NEW_VERSION) {
-                       include "update_self.php";
+               foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
+                       $about = $plugin->about();
 
-                       print   json_encode(update_self_step($this->link, $step, $params, $force));
+                       if ($about[3] && strpos($name, "example") === FALSE) {
+                               if (in_array($name, $system_enabled)) {
+                                       $checked = "checked='1'";
+                               } else {
+                                       $checked = "";
+                               }
+
+                               print "<tr>";
+
+                               print "<td align='center'><input disabled='1'
+                                               dojoType=\"dijit.form.CheckBox\" $checked
+                                               type=\"checkbox\"></td>";
+
+                               print "<td>$name</td>";
+                               print "<td>" . htmlspecialchars($about[1]) . "</td>";
+                               print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
+                               print "<td>" . htmlspecialchars($about[2]) . "</td>";
+
+                               print "</tr>";
+
+                       }
                }
+
+               print "<tr><td colspan='4'><h3>".__("User plugins")."</h3></td></tr>";
+
+               print "<tr class=\"title\">
+                               <td width=\"5%\">&nbsp;</td>
+                               <td width='10%'>".__('Plugin')."</td>
+                               <td width=''>".__('Description')."</td>
+                               <td width='5%'>".__('Version')."</td>
+                               <td width='10%'>".__('Author')."</td></tr>";
+
+
+               foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
+                       $about = $plugin->about();
+
+                       if (!$about[3] && strpos($name, "example") === FALSE) {
+
+                               if (in_array($name, $system_enabled)) {
+                                       $checked = "checked='1'";
+                                       $disabled = "disabled='1'";
+                                       $rowclass = '';
+                               } else if (in_array($name, $user_enabled)) {
+                                       $checked = "checked='1'";
+                                       $disabled = "";
+                                       $rowclass = "Selected";
+                               } else {
+                                       $checked = "";
+                                       $disabled = "";
+                                       $rowclass = '';
+                               }
+
+                               print "<tr class='$rowclass'>";
+
+                               print "<td align='center'><input id='FPCHK-$name' name='plugins[]' value='$name' onclick='toggleSelectRow2(this);'
+                                       dojoType=\"dijit.form.CheckBox\" $checked $disabled
+                                       type=\"checkbox\"></td>";
+
+                               print "<td><label for='FPCHK-$name'>$name</label></td>";
+                               print "<td><label for='FPCHK-$name'>" . htmlspecialchars($about[1]) . "</label></td>";
+                               print "<td>" . htmlspecialchars(sprintf("%.2f", $about[0])) . "</td>";
+                               print "<td>" . htmlspecialchars($about[2]) . "</td>";
+
+                               print "</tr>";
+
+
+
+                       }
+
+               }
+
+               print "</table>";
+
+               print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
+                       __("Enable selected plugins")."</button></p>";
+
+               print "</form>";
+
+               print "</div>"; #pane
+
+               global $pluginhost;
+               $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB,
+                       "hook_prefs_tab", "prefPrefs");
+
+               print "</div>"; #container
        }
 
        function toggleAdvanced() {
@@ -632,27 +784,65 @@ class Pref_Prefs extends Handler_Protected {
                require_once "lib/otphp/lib/totp.php";
                require_once "lib/phpqrcode/phpqrcode.php";
 
-               $result = db_query($this->link, "SELECT login,salt
+               $result = db_query($this->link, "SELECT login,salt,otp_enabled
                        FROM ttrss_users
                        WHERE id = ".$_SESSION["uid"]);
 
                $base32 = new Base32();
 
                $login = db_fetch_result($result, 0, "login");
-               $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
+               $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled"));
+
+               if (!$otp_enabled) {
+                       $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt")));
+                       $topt = new \OTPHP\TOTP($secret);
+                       print QRcode::png($topt->provisioning_uri($login));
+               }
+       }
+
+       function otpenable() {
+               $password = db_escape_string($_REQUEST["password"]);
 
-               $topt = new \OTPHP\TOTP($secret);
+               $module_class = "auth_" . $_SESSION["auth_module"];
+               $authenticator = new $module_class($this->link);
+               $enable_otp = $_REQUEST["enable_otp"] == "on";
+
+               if ($authenticator->check_password($_SESSION["uid"], $password)) {
+
+                       if ($enable_otp) {
+                               db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
+                                       id = " . $_SESSION["uid"]);
+
+                               print "OK";
+                       }
+               } else {
+                       print "ERROR: ".__("Incorrect password");
+               }
 
-               print QRcode::png($topt->provisioning_uri($login));
        }
 
-       function changeotp() {
-               $enable_otp = $_REQUEST["enable_otp"];
+       function otpdisable() {
+               $password = db_escape_string($_REQUEST["password"]);
+
+               $module_class = "auth_" . $_SESSION["auth_module"];
+               $authenticator = new $module_class($this->link);
+
+               if ($authenticator->check_password($_SESSION["uid"], $password)) {
 
-               if ($enable_otp == "on") {
-                       db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE
+                       db_query($this->link, "UPDATE ttrss_users SET otp_enabled = false WHERE
                                id = " . $_SESSION["uid"]);
+
+                       print "OK";
+               } else {
+                       print "ERROR: ".__("Incorrect password");
                }
+
+       }
+
+       function setplugins() {
+               $plugins = join(",", $_REQUEST["plugins"]);
+
+               set_pref($this->link, "_ENABLED_PLUGINS", $plugins);
        }
 }
 ?>