MySQL errors bypass
This commit is contained in:
parent
cb305ca7d9
commit
c500f53749
|
@ -1,4 +1,4 @@
|
||||||
hedera-web (1.399-deb8) stable; urgency=low
|
hedera-web (1.400-deb8) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ Hedera.Conf = new Class
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Htk.Toast.showError (_('Password doesn\'t meet the requirements'));
|
Htk.Toast.showError (error.message);
|
||||||
this.$('old-password').select ();
|
this.$('old-password').select ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,8 @@
|
||||||
|
|
||||||
class Account
|
class Account
|
||||||
{
|
{
|
||||||
const USER = 1 << 1;
|
static function sync ($db, $user, $password = NULL)
|
||||||
const PASS = 1 << 2;
|
|
||||||
|
|
||||||
static function sync ($db, $user, $password = NULL, $sync = self::USER)
|
|
||||||
{
|
{
|
||||||
$conf = $db->getRow (
|
|
||||||
'SELECT sambaHost, homesHost, sshUser, sshPass FROM account.accountConfig');
|
|
||||||
$sshPass = base64_decode ($conf['sshPass']);
|
|
||||||
|
|
||||||
$hasAccount = $db->getValue (
|
$hasAccount = $db->getValue (
|
||||||
'SELECT COUNT(*) > 0
|
'SELECT COUNT(*) > 0
|
||||||
FROM account.user u
|
FROM account.user u
|
||||||
|
@ -21,41 +14,49 @@ class Account
|
||||||
|
|
||||||
if (!$hasAccount)
|
if (!$hasAccount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
$conf = $db->getRow (
|
||||||
|
'SELECT sambaHost, homesHost, sshUser, sshPass
|
||||||
|
FROM account.accountConfig'
|
||||||
|
);
|
||||||
|
$sshPass = base64_decode ($conf['sshPass']);
|
||||||
|
|
||||||
$sambaSsh = new SshConnection ($conf['sambaHost']
|
$samba = new SshConnection ($conf['sambaHost']
|
||||||
|
,$conf['sshUser']
|
||||||
|
,$sshPass
|
||||||
|
);
|
||||||
|
$homes = new SshConnection ($conf['homesHost']
|
||||||
,$conf['sshUser']
|
,$conf['sshUser']
|
||||||
,$sshPass
|
,$sshPass
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($sync & self::USER)
|
$escUser = SshConnection::escape ($user);
|
||||||
{
|
|
||||||
$userId = $db->getValue ('SELECT id FROM account.user WHERE name = #', [$user]);
|
|
||||||
$accConf = $db->getRow ('SELECT uidBase, domain FROM account.accountConfig');
|
|
||||||
|
|
||||||
$escUser = SshConnection::escape ($user);
|
// Creates the Samba user and initializes it's home directory
|
||||||
$escUid = SshConnection::escape ($accConf['uidBase'] + $userId);
|
|
||||||
$escMail = SshConnection::escape ("$user@{$accConf['domain']}");
|
|
||||||
|
|
||||||
$sambaSsh->exec (
|
$userId = $db->getValue (
|
||||||
"/mnt/cluster/scripts/create-user.sh $escUser $escUid $escMail");
|
'SELECT id FROM account.user WHERE name = #', [$user]);
|
||||||
|
$accConf = $db->getRow (
|
||||||
|
'SELECT uidBase, domain FROM account.accountConfig');
|
||||||
|
|
||||||
$homesSsh = new SshConnection ($conf['homesHost']
|
$escUid = SshConnection::escape ($accConf['uidBase'] + $userId);
|
||||||
,$conf['sshUser']
|
$escMail = SshConnection::escape ("$user@{$accConf['domain']}");
|
||||||
,$sshPass
|
|
||||||
);
|
|
||||||
$homesSsh->exec (
|
|
||||||
"/mnt/storage/scripts/create-user.sh $escUser");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sync & self::PASS && !empty ($password))
|
$samba->exec (
|
||||||
{
|
"/mnt/cluster/scripts/create-user.sh $escUser $escUid $escMail");
|
||||||
$escUser = SshConnection::escape ($user);
|
$homes->exec (
|
||||||
$escPassword = SshConnection::escape ($password);
|
"/mnt/storage/scripts/create-user.sh $escUser");
|
||||||
$sambaSsh->exec (
|
|
||||||
"/mnt/cluster/scripts/set-password.sh $escUser $escPassword");
|
|
||||||
|
|
||||||
new SshConnection ($conf['homesHost'], $user, $password);
|
// Syncronizes the Samba password
|
||||||
}
|
|
||||||
|
if (empty ($password))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$escPassword = SshConnection::escape ($password);
|
||||||
|
$samba->exec (
|
||||||
|
"/mnt/cluster/scripts/set-password.sh $escUser $escPassword");
|
||||||
|
|
||||||
|
new SshConnection ($conf['homesHost'], $user, $password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,4 +98,3 @@ class SshConnection
|
||||||
return '"'. str_replace ('"', '\\"', $str) .'"';
|
return '"'. str_replace ('"', '\\"', $str) .'"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ChangePassword extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
$db->query ('CALL account.userChangePassword (#, #)',
|
$db->query ('CALL account.userChangePassword (#, #)',
|
||||||
[$oldPassword, $newPassword]);
|
[$oldPassword, $newPassword]);
|
||||||
Account::sync ($db, $_SESSION['user'], $newPassword, Account::PASS | Account::USER);
|
Account::sync ($db, $_SESSION['user'], $newPassword);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"InvalidAction": "Acción inválida"
|
||||||
|
,"EmptyQuery": "Consulta vacía"
|
||||||
|
,"Invalid password": "Contraseña inválida"
|
||||||
|
,"Password does not meet requirements":
|
||||||
|
"La nueva contraseña no reune los requisitos de seguridad necesarios"
|
||||||
|
}
|
|
@ -53,35 +53,17 @@ class Query extends Vn\Web\JsonRequest
|
||||||
}
|
}
|
||||||
catch (Vn\Db\Exception $e)
|
catch (Vn\Db\Exception $e)
|
||||||
{
|
{
|
||||||
$row = NULL;
|
if ($e->getCode () == 1644)
|
||||||
$code = $e->getCode ();
|
|
||||||
$message = $e->getMessage ();
|
|
||||||
|
|
||||||
switch ($code)
|
|
||||||
{
|
{
|
||||||
case 1644: // ER_SIGNAL_EXCEPTION
|
$dbMessage = $e->getMessage ();
|
||||||
{
|
$sql = 'SELECT description FROM sql_message WHERE code = #';
|
||||||
$sql = 'SELECT description, #code code '.
|
$message = $db->getValue ($sql, [$dbMessage]);
|
||||||
'FROM sql_message WHERE code = #code';
|
|
||||||
$row = $db->getRow ($sql, ['code' => $message]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 1305: // ER_SP_DOES_NOT_EXIST
|
|
||||||
{
|
|
||||||
if (strpos ($message, 'EXCEPTION') === FALSE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
$sql = 'SELECT description, @err code '.
|
if ($message)
|
||||||
'FROM sql_message WHERE code = @err';
|
throw new Lib\UserException ($message, $dbMessage);
|
||||||
$row = $db->getRow ($sql);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($row)
|
throw $e;
|
||||||
throw new Lib\UserException ($row['description'], $row['code']);
|
|
||||||
else
|
|
||||||
throw $e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SetPassword extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
$db->query ('CALL account.userSetPassword (#, #)',
|
$db->query ('CALL account.userSetPassword (#, #)',
|
||||||
[$setUser, $setPassword]);
|
[$setUser, $setPassword]);
|
||||||
Account::sync ($db, $setUser, $setPassword, Account::PASS);
|
Account::sync ($db, $setUser, $setPassword);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ class SyncUser extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
function run ($db)
|
function run ($db)
|
||||||
{
|
{
|
||||||
Account::sync ($db, $_REQUEST['syncUser'], NULL, Account::USER);
|
Account::sync ($db, $_REQUEST['syncUser'], NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Vn\Web;
|
namespace Vn\Web;
|
||||||
|
|
||||||
|
use Vn\Db;
|
||||||
use Vn\Lib\Locale;
|
use Vn\Lib\Locale;
|
||||||
use Vn\Lib\UserException;
|
use Vn\Lib\UserException;
|
||||||
|
|
||||||
|
@ -144,7 +145,7 @@ abstract class Service
|
||||||
$db->query ('CALL account.userLogin (#, #)',
|
$db->query ('CALL account.userLogin (#, #)',
|
||||||
[$user, $_POST['password']]);
|
[$user, $_POST['password']]);
|
||||||
}
|
}
|
||||||
catch (\Vn\Db\Exception $e)
|
catch (Db\Exception $e)
|
||||||
{
|
{
|
||||||
if ($e->getMessage () == 'INVALID_CREDENTIALS')
|
if ($e->getMessage () == 'INVALID_CREDENTIALS')
|
||||||
throw new BadLoginException ();
|
throw new BadLoginException ();
|
||||||
|
@ -287,9 +288,17 @@ abstract class Service
|
||||||
if ($method::PARAMS !== NULL && !$method->checkParams ($_REQUEST, $method::PARAMS))
|
if ($method::PARAMS !== NULL && !$method->checkParams ($_REQUEST, $method::PARAMS))
|
||||||
throw new UserException (s('Missing parameters'));
|
throw new UserException (s('Missing parameters'));
|
||||||
|
|
||||||
Locale::addPath ("rest/{$_REQUEST['method']}");
|
Locale::addPath ('rest/'. dirname ($_REQUEST['method']));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$res = $method->run ($methodDb);
|
||||||
|
}
|
||||||
|
catch (Db\Exception $e)
|
||||||
|
{
|
||||||
|
if ($e->getCode () == 1644)
|
||||||
|
throw new UserException (s($e->getMessage ()));
|
||||||
|
}
|
||||||
|
|
||||||
$res = $method->run ($methodDb);
|
|
||||||
$db->query ('CALL account.userLogout ()');
|
$db->query ('CALL account.userLogout ()');
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
|
|
Loading…
Reference in New Issue