0
1
Fork 0
This commit is contained in:
Juan Ferrer Toribio 2017-04-25 19:56:39 +02:00
parent 1e43aead46
commit 28b2302d78
5 changed files with 60 additions and 73 deletions

1
debian/postinst vendored
View File

@ -3,5 +3,6 @@
cd /usr/share/hedera-web && npm install --production cd /usr/share/hedera-web && npm install --production
a2enconf hedera-web a2enconf hedera-web
service apache2 reload service apache2 reload
service php5-fpm restart
service cron restart service cron restart

View File

@ -8,19 +8,21 @@ use Vn\Lib\UserException;
*/ */
class AccessVersion extends Vn\Web\JsonRequest class AccessVersion extends Vn\Web\JsonRequest
{ {
function run ($db) const PARAMS = [
{ 'appName'
if (empty ($_REQUEST['moduleName'])) ,'newVersion'
throw new UserException (s('Module name not specified')); ];
$module = $_REQUEST['moduleName']; function run ($db)
{
// Checks for file errors. // Checks for file errors.
$moduleFile = $_FILES['moduleFile'];
if (empty ($_FILES['moduleFile']['name'])) if (empty ($moduleFile['name']))
throw new UserException (s('File not choosed')); throw new UserException (s('File not choosed'));
if ($_FILES['moduleFile']['error'] != 0) if ($moduleFile['error'] != 0)
{ {
switch ($_FILES['image']['error']) switch ($_FILES['image']['error'])
{ {
@ -53,14 +55,21 @@ class AccessVersion extends Vn\Web\JsonRequest
throw new Lib\Exception (s($message)); throw new Lib\Exception (s($message));
} }
error_log ($module); // Defining parameters
error_log ($_FILES['moduleFile']['tmp_name']);
error_log ("/tmp/$module.png");
// 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; return TRUE;
} }
} }

View File

@ -9,63 +9,25 @@ class Mail extends Vn\Lib\Method
$db->selectDb ('vn2008'); $db->selectDb ('vn2008');
$db->query ('START TRANSACTION'); $db->query ('START TRANSACTION');
$conf = $db->getRow ( $mailer = new Vn\Web\Mailer ($db);
'SELECT host, port, secure, sender, sender_name, user, password
FROM hedera.mail_config'
);
$res = $db->query ( $res = $db->query (
'SELECT * FROM mail WHERE sent = 0 ORDER BY DATE_ODBC DESC 'SELECT * FROM mail WHERE sent = 0 ORDER BY DATE_ODBC DESC
LIMIT 20 FOR UPDATE'); LIMIT 20 FOR UPDATE');
$count = 0; $count = 0;
while ($row = $res->fetch_assoc ()) while ($row = $res->fetch_object ())
{ {
$sent = 1; $sent = 1;
$status = 'OK'; $status = 'OK';
try { try {
//if (!preg_match ('/^[\w\._%-]+@[\w\.-]+\.[A-Za-z]{2,4}$/', $row['to'])) $mail = $mailer->createObject ($row->to, $row->text, $row->subject);
// throw new Exception ('Destination mail has invalid sintax'); $mail->AddReplyTo ($row->reply_to, $conf->sender_name);
$mail = new PHPMailer (); if (!empty ($row->path))
$mail->isSMTP ();
$mail->Host = $conf['host'];
if (!empty ($conf['user']))
{ {
$mail->SMTPAuth = TRUE; $attachment = '/mnt/cluster/pdfs/'. $row->path;
$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'];
if (file_exists ($attachment)) if (file_exists ($attachment))
$mail->AddAttachment ($attachment, ''); $mail->AddAttachment ($attachment, '');
@ -92,5 +54,3 @@ class Mail extends Vn\Lib\Method
echo "Total $count mails sent\n"; echo "Total $count mails sent\n";
} }
} }

View File

@ -8,42 +8,58 @@ use Vn\Lib\UserException;
class Mailer 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 '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 = new \PHPMailer ();
$mail->isSMTP (); $mail->isSMTP ();
$mail->Host = $conf['host']; $mail->Host = $conf->host;
if (!empty ($conf['user'])) if (!empty ($conf->user))
{ {
$mail->SMTPAuth = TRUE; $mail->SMTPAuth = TRUE;
$mail->Username = $conf['user']; $mail->Username = $conf->user;
$mail->Password = base64_decode ($conf['password']); $mail->Password = base64_decode ($conf->password);
} }
else else
$mail->SMTPAuth = FALSE; $mail->SMTPAuth = FALSE;
if ($conf['secure']) if ($conf->secure)
{ {
$mail->SMTPSecure = 'ssl'; $mail->SMTPSecure = 'ssl';
$mail->Port = 465; $mail->Port = 465;
} }
$mail->setFrom ($conf['sender'], $conf['sender_name']); $mail->setFrom ($conf->sender, $conf->sender_name);
$mail->AddAddress ($mailTo);
$mail->IsHTML (TRUE); $mail->IsHTML (TRUE);
$mail->Subject = $subject; $mail->Subject = $subject;
$mail->Body = $body; $mail->Body = $body;
$mail->CharSet = 'UTF-8'; $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 ()) if (!$mail->Send ())
throw new UserException ('Send error: '.$mail->ErrorInfo); throw new UserException ('Send error: '.$mail->ErrorInfo);
} }
} }

View File

@ -38,7 +38,8 @@ class Report
function sendMail ($mail) function sendMail ($mail)
{ {
Mailer::send ($this->db, $mail, $this->html, $this->title); $mailer = new Mailer ($this->db);
$mailer->send ($mail, $this->html, $this->title);
} }
} }