New: add jquery method for random generation

This commit is contained in:
Regis Houssin 2011-07-09 08:05:08 +00:00
parent db15ab6c4d
commit f7929e9ee0
3 changed files with 84 additions and 11 deletions

View File

@ -0,0 +1,59 @@
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/core/ajaxsecurity.php
* \brief File for return security data
* \version $Id: ajaxsecurity.php,v 1.1 2011/07/09 08:05:08 hregis Exp $
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
require('../main.inc.php');
require_once(DOL_DOCUMENT_ROOT."/lib/security.lib.php");
/*
* View
*/
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead();
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
// Registering the location of boxes
if(isset($_GET['action']) && ! empty($_GET['action']))
{
if ($_GET['action'] == 'getrandompassword' && $user->admin)
{
$generic = $_GET['generic'];
echo getRandomPassword($generic);
}
}
?>

View File

@ -21,7 +21,7 @@
/** /**
* \file htdocs/lib/security.lib.php * \file htdocs/lib/security.lib.php
* \brief Set of function used for dolibarr security * \brief Set of function used for dolibarr security
* \version $Id: security.lib.php,v 1.123 2011/07/04 09:01:38 eldy Exp $ * \version $Id: security.lib.php,v 1.124 2011/07/09 08:05:08 hregis Exp $
*/ */
@ -540,14 +540,16 @@ function dol_efc_config()
/** /**
* Return a generated password using default module * Return a generated password using default module
* @param generic Create generic password
* @return string New value for password * @return string New value for password
*/ */
function getRandomPassword() function getRandomPassword($generic=false)
{ {
global $db,$conf,$langs,$user; global $db,$conf,$langs,$user;
$generated_password=''; $generated_password='';
if ($conf->global->USER_PASSWORD_GENERATED) if ($generic) $generated_password=dol_hash(mt_rand());
else if ($conf->global->USER_PASSWORD_GENERATED)
{ {
$nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED); $nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED);
$nomfichier=$nomclass.".class.php"; $nomfichier=$nomclass.".class.php";
@ -557,6 +559,7 @@ function getRandomPassword()
$generated_password=$genhandler->getNewGeneratedPassword(); $generated_password=$genhandler->getNewGeneratedPassword();
unset($genhandler); unset($genhandler);
} }
return $generated_password; return $generated_password;
} }

View File

@ -21,7 +21,7 @@
/** \file htdocs/paypal/admin/paypal.php /** \file htdocs/paypal/admin/paypal.php
* \ingroup paypal * \ingroup paypal
* \brief Page to setup paypal module * \brief Page to setup paypal module
* \version $Id: paypal.php,v 1.21 2011/07/08 18:08:27 hregis Exp $ * \version $Id: paypal.php,v 1.22 2011/07/09 08:05:08 hregis Exp $
*/ */
require("../../main.inc.php"); require("../../main.inc.php");
@ -89,11 +89,21 @@ print $langs->trans("PaypalDesc")."<br>\n";
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)
{ {
print "\n".'<script type="text/javascript" language="javascript">'; print "\n".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () { print '$(document).ready(function () {
jQuery("#apidoc").hide(); $("#apidoc").hide();
jQuery("#apidoca").click(function() { $("#apidoca").click(function() {
jQuery("#apidoca").hide(); $("#apidoca").hide();
jQuery("#apidoc").show(); $("#apidoc").show();
});
$("#generate_token").click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajaxsecurity.php", {
action: \'getrandompassword\',
generic: true
},
function(token) {
$("#PAYPAL_SECURITY_TOKEN").val(token);
});
}); });
});'; });';
print '</script>'; print '</script>';
@ -177,7 +187,8 @@ print '</td></tr>';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'; print '<tr '.$bc[$var].'><td>';
print $langs->trans("SecurityToken").'</td><td>'; print $langs->trans("SecurityToken").'</td><td>';
print '<input size="16" type="text" name="PAYPAL_SECURITY_TOKEN" value="'.$conf->global->PAYPAL_SECURITY_TOKEN.'">'; print '<input size="48" type="text" id="PAYPAL_SECURITY_TOKEN" name="PAYPAL_SECURITY_TOKEN" value="'.$conf->global->PAYPAL_SECURITY_TOKEN.'">';
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
print '</td></tr>'; print '</td></tr>';
$var=!$var; $var=!$var;
@ -262,5 +273,5 @@ print info_admin($langs->trans("YouCanAddTagOnUrl"));
$db->close(); $db->close();
llxFooter('$Date: 2011/07/08 18:08:27 $ - $Revision: 1.21 $'); llxFooter('$Date: 2011/07/09 08:05:08 $ - $Revision: 1.22 $');
?> ?>