diff --git a/forms/cms/contact/contact.js b/forms/cms/contact/contact.js index f2f92226..2b631fcd 100644 --- a/forms/cms/contact/contact.js +++ b/forms/cms/contact/contact.js @@ -14,7 +14,7 @@ Vn.Contact = new Class ,refreshCaptcha: function () { - var url = 'rest.php?method=captcha'; + var url = 'rest.php?method=core/captcha'; this.$('captcha-img').src = url +'&stamp='+ new Date ().getTime (); } diff --git a/forms/cms/contact/ui.xml b/forms/cms/contact/ui.xml index 73bc3a5c..3121df5a 100755 --- a/forms/cms/contact/ui.xml +++ b/forms/cms/contact/ui.xml @@ -14,7 +14,7 @@
+ action="json.php?method=misc/contact">
diff --git a/js/hedera/app.js b/js/hedera/app.js index c1f19258..214df51b 100644 --- a/js/hedera/app.js +++ b/js/hedera/app.js @@ -169,7 +169,7 @@ Vn.App = new Class ,'stack': error.stack }; - var request = new Vn.JsonRequest ('log'); + var request = new Vn.JsonRequest ('core/log'); request.send (params); } diff --git a/rest/core/login.php b/rest/core/login.php index 4fb9e44c..c6bf1710 100755 --- a/rest/core/login.php +++ b/rest/core/login.php @@ -7,8 +7,52 @@ class Login extends Vn\Web\JsonRequest function run () { $this->login (); + $this->updateCredentials (); return TRUE; } + + /** + * Updates the user credentials in other user databases like Samba. + **/ + function updateCredentials () + { + $db = $this->getSysConn (); + + $hasAccount = $db->getValue ( + 'SELECT COUNT(*) > 0 + FROM account.user u + JOIN account.account a ON u.id = a.user_id + WHERE u.name = #', + [$_SESSION['user']] + ); + + if (!$hasAccount) + return; + + $sshConf = $db->getRow ('SELECT host, user, password FROM ssh_config'); + + $ssh = ssh2_connect ($sshConf['host']); + $sshOk = $ssh && ssh2_auth_password ($ssh, + $sshConf['user'], base64_decode ($sshConf['password'])); + + if (!$sshOk) + { + error_log ("Can't connect to SSH server {$sshConf['host']}"); + return; + } + + $user = $this->escape ($_SESSION['user']); + $pass = $this->escape ($_SESSION['password']); + ssh2_exec ($ssh, "samba-tool user add \"$user\" \"$pass\""); + } + + /** + * Escapes the double cuotes from an string. + **/ + function escape ($str) + { + return str_replace ('"', '\\"', $str); + } } ?> diff --git a/rest/dms/add.php b/rest/dms/add.php index aaade4fc..37a0d08c 100644 --- a/rest/dms/add.php +++ b/rest/dms/add.php @@ -7,7 +7,7 @@ use Vn\Lib; /** * Adds a document to the Document Management System. **/ -class DmsAdd extends Vn\Web\JsonRequest +class Add extends Vn\Web\JsonRequest { function run () { diff --git a/rest/image/resize.php b/rest/image/resize.php index 826828a2..865b885d 100644 --- a/rest/image/resize.php +++ b/rest/image/resize.php @@ -13,7 +13,7 @@ use Vn\Hedera\Image; * @param integer $maxWidth The maximum width of resized image in pixels * @param boolean $rewrite Wether to rewrite the destination file if it exits **/ -class ImageResize extends ImageMethod +class Resize extends ImageMethod { function run () { diff --git a/rest/image/sync.php b/rest/image/sync.php index 42239985..396e8c3b 100644 --- a/rest/image/sync.php +++ b/rest/image/sync.php @@ -8,7 +8,7 @@ use Vn\Hedera\Image; * Syncronizes the data directory with the database, this may take * some time. **/ -class ImageSync extends ImageRequest +class Sync extends ImageRequest { private $trashSubdir; diff --git a/rest/image/thumb.php b/rest/image/thumb.php index 215a3a08..f5a7fdbe 100644 --- a/rest/image/thumb.php +++ b/rest/image/thumb.php @@ -12,7 +12,7 @@ use Vn\Hedera\Image; * @param integer $width The width of the thumb * @param integer $height The height of the thumb **/ -class ImageThumb extends ImageRequest +class Thumb extends ImageRequest { function run () { diff --git a/rest/image/upload.php b/rest/image/upload.php index e102770b..d08c831a 100755 --- a/rest/image/upload.php +++ b/rest/image/upload.php @@ -8,7 +8,7 @@ use Vn\Hedera\Image; /** * Uploads a file creating its corresponding sizes. **/ -class ImageUpload extends ImageRequest +class Upload extends ImageRequest { static function run () { diff --git a/rest/misc/contact.php b/rest/misc/contact.php index a49b6d47..88e1e03f 100755 --- a/rest/misc/contact.php +++ b/rest/misc/contact.php @@ -17,21 +17,19 @@ class Contact extends Vn\Web\JsonRequest ,'phone' ,'email' ,'message' - ,'captcha' ]; - if (!$this->checkParams ($_REQUEST, $params) - || !isset ($_SESSION['captcha'])) + if (!$this->checkParams ($_REQUEST, $params)) throw new Lib\UserException (s('Missing parameters'), 'missingParams'); // Checks the antispam code - + $lastCaptcha = $_SESSION['captcha']; unset ($_SESSION['captcha']); - if ($_REQUEST['captcha'] !== $lastCaptcha) + if (empty ($_REQUEST['captcha']) || $_REQUEST['captcha'] !== $lastCaptcha) throw new Lib\UserException (s('Wrong captcha'), 'wrongCaptcha'); - + // Sends the mail $db = $this->getSysConn (); diff --git a/rest/tpv/confirm-mail.php b/rest/tpv/confirm-mail.php index df5557ec..c9dcb54c 100644 --- a/rest/tpv/confirm-mail.php +++ b/rest/tpv/confirm-mail.php @@ -6,7 +6,7 @@ require_once (__DIR__.'/tpv.php'); /** * Gets transaction confirmations from the IMAP mailbox. **/ -class TpvConfirmMail extends Vn\Lib\Method +class ConfirmMail extends Vn\Lib\Method { function run () { diff --git a/rest/tpv/confirm-post.php b/rest/tpv/confirm-post.php index 9716c28b..050ff9c6 100644 --- a/rest/tpv/confirm-post.php +++ b/rest/tpv/confirm-post.php @@ -6,7 +6,7 @@ require_once (__DIR__.'/tpv.php'); /** * Gets transaction confirmation from HTTP POST. **/ -class TpvConfirmPost extends Vn\Web\HttpRequest +class ConfirmPost extends Vn\Web\HttpRequest { function run () { diff --git a/rest/tpv/confirm-soap.php b/rest/tpv/confirm-soap.php index 3a757362..e3183f75 100644 --- a/rest/tpv/confirm-soap.php +++ b/rest/tpv/confirm-soap.php @@ -7,7 +7,7 @@ require_once (__DIR__.'/tpv.php'); /** * Gets transaction confirmation from SOAP service. **/ -class TpvConfirmSoap extends Vn\Web\HttpRequest +class ConfirmSoap extends Vn\Web\HttpRequest { function run () { diff --git a/rest/tpv/transaction.php b/rest/tpv/transaction.php index 9e832740..d9b7deac 100755 --- a/rest/tpv/transaction.php +++ b/rest/tpv/transaction.php @@ -8,7 +8,7 @@ use Vn\Lib; /** * Starts a new TPV transaction and returns the params. **/ -class TpvTransaction extends Vn\Web\JsonRequest +class Transaction extends Vn\Web\JsonRequest { function run () {