Code

Added non-login password dialog which closes #86
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 9 Jul 2007 14:26:27 +0000 (14:26 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 9 Jul 2007 14:26:27 +0000 (14:26 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6783 594d385d-05f5-0310-b6e9-bd551577e9d8

Changelog
FAQ
html/index.php
html/password.php
html/themes/default/password-style.css [new file with mode: 0644]
ihtml/themes/default/password.tpl [new file with mode: 0644]
include/class_password-methods.inc
include/functions.inc

index a9f34cbf474a5d092b0238167bdd85a18395e0f5..2c60d8fe209ff05441c7b46f9853767b4a168a89 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ GOsa2 changelog
   - Fixed several IE6 related Java-Script problems
   - Removed png.js by default. Looks ugly, but performs. Take
     a look at the FAQ on how to re-enable it for IE.
+  - Added non-login password change dialog
 
 * gosa 2.5.11a
   - Added chinese translation
diff --git a/FAQ b/FAQ
index 25eb63fc20d0ddf1d167d423c3701a37eb5a2445..b99bc62c7ed126d60188b3120c5fb254e3ffa26d 100644 (file)
--- a/FAQ
+++ b/FAQ
@@ -393,3 +393,11 @@ A: Use Firefox, Konqueror, Safari, Opera, IE >= 7, etc. IE is broken and
 
    If you have much time, you can provide a seamless integration with MS
    filter css extension.
+
+
+Q: Is there a way to let users change passwords without logging into GOsa?
+
+A: Yes. Browse to "password.php". You can preset a couple of things i.e.:
+
+   http://your.admin.server/password.php?uid=cajus&method=md5&directory=GONICUS+GmbH
+
index f57227ddd4336cc1fa29599348cd102d67a0ba98..33ff26197b14322da089c148ca52dd87063792c3 100644 (file)
@@ -108,9 +108,6 @@ if (!file_exists(CONFIG_DIR."/".CONFIG_FILE)){
   exit();
 }
 
-/* Reset errors */
-$_SESSION['errors']= "";
-
 /* Check for java script */
 if(isset($_POST['javascript']) && $_POST['javascript'] == "true") {
   $_SESSION['js']= TRUE;
index 4520af89535391064d7c68588f31f87ad640b80c..901469f3bc8fbc936c93aa59e7ecfd387b6b8d09 100644 (file)
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
 function displayPWchanger()
 {
   global $smarty;
-  $smarty->display(get_template_path('passwords.tpl'));
+
+  $smarty->display(get_template_path('password.tpl'));
   exit();
 }
 
@@ -41,6 +41,7 @@ if(is_array($_SESSION) && count($_SESSION)){
 }
 
 /* Reset errors */
+$_SESSION['js']                 = true;
 $_SESSION['errors']             = "";
 $_SESSION['errorsAlreadyPosted']= array();
 $_SESSION['LastError']          = "";
@@ -93,6 +94,28 @@ $domain = 'messages';
 bindtextdomain($domain, "$BASE_DIR/locale");
 textdomain($domain);
 
+/* Generate server list */
+$servers= array();
+if (isset($_POST['server'])){
+       $directory= validate($_POST['server']);
+} else {
+       $directory= $config->data['MAIN']['DEFAULT'];
+}
+foreach ($config->data['LOCATIONS'] as $key => $ignored){
+       $servers[$key]= $key;
+}
+if (isset($_GET['directory']) && isset($servers[$_GET['directory']])){
+       $smarty->assign ("show_directory_chooser", false);
+       $directory= validate($_GET['directory']);
+} else {
+       $smarty->assign ("server_options", $servers);
+       $smarty->assign ("server_id", $directory);
+       $smarty->assign ("show_directory_chooser", true);
+}
+
+/* Set config to selected one */
+$config->set_current($directory);
+$_SESSION['config']= $config;
 
 if ($_SERVER["REQUEST_METHOD"] != "POST"){
   @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
@@ -119,32 +142,133 @@ if ($config->data['MAIN']['FORCESSL'] == 'true' && $ssl != ''){
   exit;
 }
 
-/* Got a formular answer, validate and try to log in */
-if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){
+/* Check for selected password method */
+$method= "";
+if (isset($_GET['method'])){
+       $method= validate($_GET['method']);
+       $tmp = new passwordMethod($config);
+       $available = $tmp->get_available_methods_if_not_loaded();
+       if (!isset($available[$method])){
+               echo _("Error: Password method not available!");
+               exit;
+       }
+}
 
-  /* Reset error messages */
-  $message= "";
+
+/* Check for selected user... */
+if (isset($_GET['uid']) && $_GET['uid'] != ""){
+       $uid= validate($_GET['uid']);
+       $smarty->assign('display_username', false);
+} elseif (isset($_POST['uid'])){
+       $uid= validate($_POST['uid']);
+       $smarty->assign('display_username', true);
+} else {
+       $uid= "";
+       $smarty->assign('display_username', true);
+}
+$current_password= "";
+$smarty->assign("changed", false);
+
+/* Got a formular answer, validate and try to log in */
+if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['apply'])){
 
   /* Destroy old sessions, they cause a successfull login to relog again ...*/
   if(isset($_SESSION['_LAST_PAGE_REQUEST'])){
     $_SESSION['_LAST_PAGE_REQUEST'] = time();
   }
 
-  echo "Well - I'm lazy...";
+  $message= array();
+  $current_password= $_POST['current_password'];
+
+  /* Do new and repeated password fields match? */
+  $new_password= $_POST['new_password'];
+  if ($_POST['new_password'] != $_POST['new_password_repeated']){
+         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
+  } else {
+         if ($_POST['new_password'] == ""){
+                 $message[]= _("The password you've entered as 'New password' is empty.");
+         }
+  }
+
+  /* Password policy fulfilled? */
+  if (isset($config->data['MAIN']['PWDIFFER'])){
+         $l= $config->data['MAIN']['PWDIFFER'];
+         if (substr($_POST['current_password'], 0, $l) == substr($_POST['new_password'], 0, $l)){
+                 $message[]= _("The password used as new and current are too similar.");
+         }
+  }
+  if (isset($config->data['MAIN']['PWMINLEN'])){
+         if (strlen($_POST['new_password']) < $config->data['MAIN']['PWMINLEN']){
+                 $message[]= _("The password used as new is to short.");
+         }
+  }
+
+  /* Validate */
+  if (!ereg("^[A-Za-z0-9_.-]+$", $uid)){
+         $message[]= _("Please specify a valid username!");
+  } elseif (mb_strlen($_POST["current_password"], 'UTF-8') == 0){
+         $message[]= _("Please specify your password!");
+  } else {
+
+         /* Do we have the selected user somewhere? */
+         $ui= ldap_login_user ($uid, $current_password);
+         if ($ui == NULL){
+               $message[]= _("");
+         } else {
+               /* Check acl... */
+               $ca= get_permissions ($ui->dn, $ui->subtreeACL);
+               $ca= get_module_permission($ca, "user", $ui->dn);
+               if (chkacl($ca, "password") != ""){
+                       $message[]= _("You have no permissions to change your password.");
+               }
+         }
+  }
+
+  /* Do we need to show error messages? */
+  if (count ($message) != 0){
+         /* Show error message and continue editing */
+         show_errors($message);
+  } else {
+
+         /* Passed quality check, just try to change the password now */
+         $output= "";
+         if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
+                 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".
+                                 $_POST['current_password']." ".$_POST['new_password'], $resarr);
+                 if(count($resarr) > 0) {
+                         $output= join('\n', $resarr);
+                 }
+         }
+         if ($output != ""){
+                 $message[]= _("External password changer reported a problem: ".$output);
+                 show_errors($message);
+         } else {
+                 if ($method != ""){
+                         change_password ($ui->dn, $_POST['new_password'], 0, $method);
+                 } else {
+                         change_password ($ui->dn, $_POST['new_password']);
+                 }
+                 gosa_log ("User/password has been changed");
+                 $smarty->assign("changed", true);
+         }
+  }
+
+
 }
 
+/* Parameter fill up */
+$params= "";
+foreach (array('uid', 'method', 'directory') as $index){
+       $params.= "&amp;$index=".urlencode($$index);
+}
+$params= preg_replace('/^&amp;/', '?', $params);
+$smarty->assign('params', $params);
+
 /* Fill template with required values */
 $smarty->assign ('date', gmdate("D, d M Y H:i:s"));
-$smarty->assign ('username', $username);
+$smarty->assign ('uid', $uid);
 $smarty->assign ('password_img', get_template_path('images/password.png'));
 
-/* Some error to display? */
-if (!isset($message)){
-  $message= "";
-}
-
-$smarty->assign ("message", $message);
-
 /* Displasy SSL mode warning? */
 if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
   $smarty->assign ("ssl", "<b>"._("Warning").":<\/b> "._("Session will not be encrypted.")." <a style=\"color:red;\" href=\"$ssl\"><b>"._("Enter SSL session")."<\/b></a>!");
@@ -174,8 +298,8 @@ $smarty->assign("focus", $focus);
 
 displayPWchanger();
 
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
 
 </body>
 </html>
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
diff --git a/html/themes/default/password-style.css b/html/themes/default/password-style.css
new file mode 100644 (file)
index 0000000..c6c576b
--- /dev/null
@@ -0,0 +1,53 @@
+body {
+        margin-left:0px;
+        margin-right:0px;
+        margin-top:0px;
+        margin-bottom:0px;
+        background-color:white;
+        color:#00008F;
+        font-family:arial,helvetica,sans-serif;
+       font-size:12px;
+}
+
+h1 {
+       margin:0px;
+       background-color:#A9FBA6;
+       border-bottom:1px solid #AAA;
+       padding-top:0.2em;
+       padding-bottom:0.2em;
+}
+
+img.center {
+        text-align:center;
+        vertical-align:middle;
+}
+
+h1.headline {
+       font-size:2em;
+}
+
+div.success {
+       padding:1em;
+}
+
+p.infotext {
+       padding:0.5em;
+}
+
+table {
+       border-spacing:0.5em;
+}
+
+div.change {
+       margin-right:0.5em;
+       text-align:right;
+}
+
+div.ruler {
+       border-top:1px solid #AAA;
+       width:100%;
+       height:1px;
+       margin-top:0.5em;
+       margin-bottom:0.5em;
+}
+
diff --git a/ihtml/themes/default/password.tpl b/ihtml/themes/default/password.tpl
new file mode 100644 (file)
index 0000000..63f8fb4
--- /dev/null
@@ -0,0 +1,123 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+       "http://www.w3.org/TR/html4/transitional.dtd">
+<html>
+
+<head>
+  <title>GOsa - {t}Change your password{/t}</title>
+
+  <meta name="generator" content="my hands">
+  <meta name="description" content="GOsa - Password changer">
+  <meta name="author" lang="de" content="Cajus Pollmeier">
+
+  <meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT">
+  <meta http-equiv="Last-Modified" content="{$date} GMT">
+  <meta http-equiv="Cache-Control" content="no-cache">
+  <meta http-equiv="Pragma" content="no-cache">
+  <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0">
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+
+  <style type="text/css">@import url('themes/default/password-style.css');</style>
+  <link rel="shortcut icon" href="favicon.ico">
+
+  {if isset($ieworkaround)}<script language="javascript"src="include/png.js" type="text/javascript"></script>{/if}
+  <script language="javascript"src="include/focus.js" type="text/javascript"></script>
+  <script language="javascript"src="include/warning.js" type="text/javascript"></script>
+</head>
+
+<body>
+{* GOsa login - smarty template *}
+{$php_errors}
+{$errors}
+
+{if $changed}
+<div class='success'">
+<img class='center' src='images/true.png' alt='{t}Success{/t}' title='{t}Success{/t}'>&nbsp;<b>{t}Your password has been changed successfully.{/t}</b>
+</div>
+{else}
+<form action='password.php{$params}' method='post' name='mainform' onSubmit='js_check(this);return true;'>
+    <h1 class='headline'>
+    <img class='center' src='{$password_img}' alt='{t}Password{/t}' title='{t}Password{/t}'>
+    {t}Password change{/t}
+    </h1>
+
+    <!-- Display SSL warning message on demand -->
+    <p class='gosaLoginWarning'> {$ssl} </p>
+    <input type='hidden' name='javascript' value='false'/>             
+    {$focus}
+
+    <!-- Display error message on demand -->
+    <p class='gosaLoginWarning'> {$message} </p>
+
+
+    <p class="infotext">
+       {t}This dialog provides a simple way to change your password. Enter the current password and the new password (twice) in the fields below and press the 'Change' button.{/t}
+    </p>
+
+    <div class="ruler"></div>
+    <table>
+      {if $show_directory_chooser}
+      <tr>
+       <td>{t}Directory{/t}</td>
+       <td>
+          <select name='server'  title='{t}Directory{/t}'>
+            {html_options options=$server_options selected=$server_id}
+          </select>
+       </td>
+      </tr>
+      {/if}
+      <tr>
+       <td>{t}Username{/t}</td>
+       <td>{if $display_username}
+           <input type='text' name='uid' maxlength='25' value='{$uid}' title='{t}Username{/t}' onFocus="nextfield= 'current_password';">
+           {else}
+           <i>{$uid}</i>
+           {/if}
+       </td>
+      </tr>
+      <tr>
+       <td>{t}Current password{/t}</td>
+       <td><input type='password' name='current_password' maxlength='25' value='' title='{t}Current password{/t}' onFocus="nextfield= 'new_password';"></td>
+      </tr>
+      <tr>
+       <td>{t}New password{/t}</td>
+       <td><input type='password' name='new_password' maxlength='25' value='' title='{t}New password{/t}' onFocus="nextfield= 'new_password_repeated';"></td>
+      </tr>
+      <tr>
+       <td>{t}New password{/t} ({t}again{/t})</td>
+       <td><input type='password' name='new_password_repeated' maxlength='25' value='' title='{t}New password repeated{/t}' onFocus="nextfield= 'apply';"></td>
+      </tr>
+    </table>
+
+    <div class="ruler"></div>
+
+    <div class="change">
+    <input type='submit' name='apply' value='{t}Change{/t}'
+                 title='{t}Click here to change your password{/t}'>
+    </div>
+    <!-- check, if cookies are enabled -->
+    <p class='gosaLoginWarning'>
+     <script language="JavaScript" type="text/javascript">
+        <!--
+            document.cookie = "gosatest=empty;path=/";
+            if (document.cookie.indexOf( "gosatest=") > -1 )
+                document.cookie = "gosatest=empty;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
+            else
+                document.write("{$cookies}");
+        -->
+     </script>
+    </p>
+
+</form>
+
+{/if}
+
+<!-- Place cursor in username field -->
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+  focus_field('directory', 'username', 'current_password');
+  -->
+</script>
+
+<!-- Spacer for some browsers -->
+<div class='gosaLoginSpacer'></div>
+</body>
index 6d8dc0e3abd9b94c47b336c1e243de1f60064bab..4ebc87bb701e94479e436bd18de96dbcdf49e581 100644 (file)
@@ -122,7 +122,6 @@ function change_password ($dn, $password, $mode=0, $hash= "")
       $hash= strtolower($matches[1]);
     }
 
-
     // Crypt with the detected Method
     $test = new  $available[$hash]($config);
     $test->attrs= $attrs;
index ddb9e1465caa15c773d0e9bd1c572256ab62065a..8867c0674c83c66ac1ee415c1c58361748d8799a 100644 (file)
@@ -1185,8 +1185,7 @@ function print_red()
             "position:absolute' id='e_layer'><table style='width:100%' summary='' border=0>".
             "<tr><td style='vertical-align:top;padding:10px'><img alt='' src='".
             get_template_path($img)."'></td>".
-            "<td style='width:100%'><h1>"._("An error occurred while processing your request").
-            "</h1><b>$string</b><br><br>$addmsg</td></tr><tr><td colspan='2' align='center'><br><button ".
+            "<td style='width:100%'><b>$string</b><br><br>$addmsg</td></tr><tr><td colspan='2' align='center'><br><button ".
             (($_SESSION['js']==FALSE)?"type='submit'":"type='button' name='error_accept'").
             " style='width:80px' onClick='".$hide."'>".
             _("OK")."</button></td></tr></table></div>";