From 28b2302d7836f5bb64407dedfd323f22e461f490 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 25 Apr 2017 19:56:39 +0200 Subject: [PATCH] Backup --- debian/postinst | 1 + rest/misc/access-version.php | 37 +++++++++++++++---------- rest/misc/mail.php | 52 +++++------------------------------- web/mailer.php | 40 ++++++++++++++++++--------- web/report.php | 3 ++- 5 files changed, 60 insertions(+), 73 deletions(-) diff --git a/debian/postinst b/debian/postinst index 23f7c1b8..13608102 100755 --- a/debian/postinst +++ b/debian/postinst @@ -3,5 +3,6 @@ cd /usr/share/hedera-web && npm install --production a2enconf hedera-web service apache2 reload +service php5-fpm restart service cron restart diff --git a/rest/misc/access-version.php b/rest/misc/access-version.php index 985891ec..2ccfd746 100755 --- a/rest/misc/access-version.php +++ b/rest/misc/access-version.php @@ -8,19 +8,21 @@ use Vn\Lib\UserException; */ class AccessVersion extends Vn\Web\JsonRequest { - function run ($db) - { - if (empty ($_REQUEST['moduleName'])) - throw new UserException (s('Module name not specified')); + const PARAMS = [ + 'appName' + ,'newVersion' + ]; - $module = $_REQUEST['moduleName']; - + function run ($db) + { // Checks for file errors. + + $moduleFile = $_FILES['moduleFile']; - if (empty ($_FILES['moduleFile']['name'])) + if (empty ($moduleFile['name'])) throw new UserException (s('File not choosed')); - if ($_FILES['moduleFile']['error'] != 0) + if ($moduleFile['error'] != 0) { switch ($_FILES['image']['error']) { @@ -53,14 +55,21 @@ class AccessVersion extends Vn\Web\JsonRequest throw new Lib\Exception (s($message)); } - error_log ($module); - error_log ($_FILES['moduleFile']['tmp_name']); - error_log ("/tmp/$module.png"); + // Defining parameters - // Saves the module. + $appName = $_REQUEST['appName']; + $newVersion = $_REQUEST['newVersion']; + + $uploadDir = '/mnt/cluster/vn-access'; + $uploadFile = "$uploadDir/$appName.7z"; + $archiveDir = "$uploadDir/.archive/$appName"; + $archiveFile = "$archiveDir/$newVersion.7z"; + + // Updates the application + + copy ($moduleFile['tmp_name'], $archiveFile); + rename ($moduleFile['tmp_name'], $uploadFile); - rename ($_FILES['moduleFile']['tmp_name'], "/tmp/$module.png"); - //unlink ($_FILES['moduleFile']['tmp_name']); return TRUE; } } diff --git a/rest/misc/mail.php b/rest/misc/mail.php index b76a7409..c6da11d5 100755 --- a/rest/misc/mail.php +++ b/rest/misc/mail.php @@ -9,63 +9,25 @@ class Mail extends Vn\Lib\Method $db->selectDb ('vn2008'); $db->query ('START TRANSACTION'); - $conf = $db->getRow ( - 'SELECT host, port, secure, sender, sender_name, user, password - FROM hedera.mail_config' - ); + $mailer = new Vn\Web\Mailer ($db); $res = $db->query ( 'SELECT * FROM mail WHERE sent = 0 ORDER BY DATE_ODBC DESC LIMIT 20 FOR UPDATE'); $count = 0; - while ($row = $res->fetch_assoc ()) + while ($row = $res->fetch_object ()) { $sent = 1; $status = 'OK'; try { - //if (!preg_match ('/^[\w\._%-]+@[\w\.-]+\.[A-Za-z]{2,4}$/', $row['to'])) - // throw new Exception ('Destination mail has invalid sintax'); + $mail = $mailer->createObject ($row->to, $row->text, $row->subject); + $mail->AddReplyTo ($row->reply_to, $conf->sender_name); - $mail = new PHPMailer (); - $mail->isSMTP (); - $mail->Host = $conf['host']; - - if (!empty ($conf['user'])) + if (!empty ($row->path)) { - $mail->SMTPAuth = TRUE; - $mail->Username = $conf['user']; - $mail->Password = base64_decode ($conf['password']); - } - else - $mail->SMTPAuth = FALSE; - - if ($conf['secure']) - { - $mail->SMTPSecure = 'ssl'; - $mail->Port = 465; - } - - $mail->setFrom ($conf['sender'], $conf['sender_name']); - $mail->AddReplyTo ($row['reply_to'], $conf['sender_name']); - - if (strpos ($row['to'], ',')) - $mailList = explode (',', $row['to']); - else - $mailList = explode (';', $row['to']); - - foreach ($mailList as $mailTo) - $mail->AddAddress ($mailTo); - - $mail->IsHTML (TRUE); - $mail->Subject = $row['subject']; - $mail->Body = ' '. $row['text']; - $mail->CharSet = 'UTF-8'; - - if (!empty ($row['path'])) - { - $attachment = '/mnt/cluster/pdfs/'. $row['path']; + $attachment = '/mnt/cluster/pdfs/'. $row->path; if (file_exists ($attachment)) $mail->AddAttachment ($attachment, ''); @@ -92,5 +54,3 @@ class Mail extends Vn\Lib\Method echo "Total $count mails sent\n"; } } - - diff --git a/web/mailer.php b/web/mailer.php index 0b9db29b..0b6b5f20 100755 --- a/web/mailer.php +++ b/web/mailer.php @@ -8,42 +8,58 @@ use Vn\Lib\UserException; class Mailer { - static function send ($db, $mailTo, $body, $subject) + private $conf; + + function __construct ($db) { - $conf = $db->getRow ( + $this->conf = $db->getObject ( 'SELECT host, port, secure, sender, sender_name, user, password - FROM mail_config' + FROM hedera.mail_config' ); + } + + function createObject ($mailTo, $body, $subject) + { + $conf = $this->conf; $mail = new \PHPMailer (); $mail->isSMTP (); - $mail->Host = $conf['host']; + $mail->Host = $conf->host; - if (!empty ($conf['user'])) + if (!empty ($conf->user)) { $mail->SMTPAuth = TRUE; - $mail->Username = $conf['user']; - $mail->Password = base64_decode ($conf['password']); + $mail->Username = $conf->user; + $mail->Password = base64_decode ($conf->password); } else $mail->SMTPAuth = FALSE; - if ($conf['secure']) + if ($conf->secure) { $mail->SMTPSecure = 'ssl'; $mail->Port = 465; } - $mail->setFrom ($conf['sender'], $conf['sender_name']); - $mail->AddAddress ($mailTo); - + $mail->setFrom ($conf->sender, $conf->sender_name); $mail->IsHTML (TRUE); $mail->Subject = $subject; $mail->Body = $body; $mail->CharSet = 'UTF-8'; + $mailList = explode (',', $mailTo); + + foreach ($mailList as $to) + $mail->AddAddress ($to); + + return $mail; + } + + function send ($mailTo, $body, $subject) + { + $mail = $this->createObject ($mailTo, $body, $subject); + if (!$mail->Send ()) throw new UserException ('Send error: '.$mail->ErrorInfo); } } - diff --git a/web/report.php b/web/report.php index a7f42ba8..5dcc4486 100755 --- a/web/report.php +++ b/web/report.php @@ -38,7 +38,8 @@ class Report function sendMail ($mail) { - Mailer::send ($this->db, $mail, $this->html, $this->title); + $mailer = new Mailer ($this->db); + $mailer->send ($mail, $this->html, $this->title); } }