Exemplo n.º 1
0
 public function __construct()
 {
     // Check background services
     if (isset($_GET['cms_is_running_background']) && $_GET['cms_is_running_background'] == 1) {
         ServiceManager::checkNeeded();
         exit;
     }
     // Try updating CMS
     if (isset($_GET['key']) && $_GET['key'] == Configuration::getInstance()->get('cms')['unique_key'] && count($_GET) === 2) {
         $updater = Updater::getInstance();
         // Update files from repo
         $updater->updateSourceCode(isset($_GET['branch']) ? $_GET['branch'] : NULL);
         // Update composer only if required
         if (isset($_GET['composer'])) {
             $updater->updateComposerVendors();
         }
         // Update database
         $updater->runMigrations();
         // Run PHPUnit tests
         $updater->runTests();
         // Output
         $out = $updater->getResult();
         $text = json_encode($out, JSON_FORCE_OBJECT);
         echo $text;
         if (stripos($text, 'Code Coverage Report') === false) {
             Mailer::getInstance()->setMessage('Did not find "Code Coverage Report" in updater response:<br><br>' . $text)->setRecipient(CMS_SUPPORT_EMAIL)->setSender(Settings::getCommonEmail(), Configuration::getInstance()->get('site')['name'] . ' - AutoUpdater')->setSubject('Error found during update')->send();
         }
         exit;
     }
     // Else - running usual Admin panel
     // Proceed with request
     $this->parseUrl();
     // Save log
     if (Users::getInstance()->isLogged() && Settings::get('save_back_access_log') && !IS_AJAX_REQUEST) {
         $users_log = new UserLog();
         $users_log->save();
     }
     // Init page data
     if (Users::getInstance()->isLogged()) {
         define('LNG', Users::getInstance()->getUserLng());
     }
     $this->sendHeaders();
     $this->prepareHead();
     $this->parseMenu();
     // Post-scripts
     Page::setTail(PageTail::getInstance());
     // Flush application log
     App::flushLog();
     $this->generateContent();
 }
 public static function addNewFeedback(array $data, $need_to_save_in_db = true, $send_to_emails = [], $files = [])
 {
     $send_to_emails = (array) $send_to_emails;
     $cacher = Cacher::getInstance()->getDefaultCacher();
     $cache_key = 'module_feedback_add_new_feedback_last_send_ts' . VISITOR_HASH;
     // Check message is not sent too quick
     $last_sent_ts = $cacher->get($cache_key);
     if (NOW - $last_sent_ts < self::$sending_period_seconds) {
         return false;
     }
     // Autocreate db
     $feedbacks = new FeedbackRepository();
     $feedback = NULL;
     // Save to Db
     if ($need_to_save_in_db) {
         $feedback = new Feedback();
         $feedback->loadDataFromArray($data);
         $feedback->save();
     }
     // Send email to manager
     if ($send_to_emails) {
         $msg = '<table><tr><th>Field</th><th>Value</th></tr>';
         foreach ($data as $k => $v) {
             if ($v) {
                 $msg .= '<tr><td>' . $k . '</td><td>' . htmlspecialchars($v) . '</td></tr>';
             }
         }
         $msg .= '</table>';
         $mailer = Mailer::getInstance()->setSubject('New feedback from ' . CFG_DOMAIN)->setSender(Settings::getCommonEmail())->setMessage($msg);
         foreach ($send_to_emails as $email) {
             $mailer->setRecipient($email);
         }
         foreach ($files as $file) {
             $mailer->addAttachment($file);
         }
         $mailer->send();
     }
     // Save last send ts
     $cacher->set($cache_key, NOW);
     return $feedback;
 }
Exemplo n.º 3
0
 /**
  * Save log into file, and try to send via email to Developers
  */
 public static function flushLog()
 {
     $last_flush_time = Settings::get('cms_tools_application_log_flush');
     if (NOW - $last_flush_time < 453600) {
         return;
         // We do not need stats too often, wait 7 days
     }
     // Send data to original developer site of the existing domain
     self::sendInformation();
     // Now prepare file with aggregated data
     $app_log = new AppLogEntityRepository();
     $app_log->addSimpleSelectFields(['id', 'ts', 'user_id', 'url', 'msg', 'p', 'do']);
     if ($last_flush_time) {
         $app_log->setWhereOld($last_flush_time);
     }
     $app_log->addOrderByField('ts', true);
     $app_log->setGenerateOutputWithIterator(false);
     $users = new AdminUserRepository();
     $users->setGenerateOutputWithIterator(false);
     $users->addSimpleSelectFieldsAsString('CONCAT(`' . $users->getDbTableName() . '`.`name`, " ", `' . $users->getDbTableName() . '`.`surname`) AS `user`');
     $app_log->mergeWithCollection($users, 'user_id');
     $data_log = $app_log->getAsArrayOfObjectData(true);
     $usage = new AdminUsageEntityRepository();
     $data_usage = $usage->getAsArrayOfObjectData(true);
     if ($data_log || $data_usage) {
         $data = ['data' => ['domain' => CFG_DOMAIN, 'ts' => NOW], 'logs' => ['app_log' => $data_log, 'usage' => $data_usage]];
         // Save in file
         if (!file_exists(DIR_CACHE)) {
             FileSystem::mkDir(DIR_CACHE);
         }
         file_put_contents(DIR_CACHE . 'log_data', gzencode(json_encode($data)));
         // Send stats
         Mailer::getInstance()->setSubject('Application and Usage log from ' . Configuration::getInstance()->get('site')['name'] . '(till ' . date(CFG_CMS_DATETIME_FORMAT, NOW) . ')')->setSender(Configuration::getInstance()->get('site')['email'])->setRecipient(CMS_SUPPORT_EMAIL)->setMessage('View attached file')->addAttachment(DIR_CACHE . 'log_data')->send();
         $usage->deleteObjectCollection();
     }
     Settings::getInstance()->set('cms_tools_application_log_flush', NOW);
 }
<?php

defined('INC') or exit;
use TMCms\Admin\Messages;
use TMCms\Cache\Cacher;
use TMCms\Config\Configuration;
use TMCms\Log\App;
use TMCms\Network\Mailer;
Mailer::getInstance()->setSubject('Message from ' . Configuration::getInstance()->get('site')['name'] . ' (' . CFG_DOMAIN . ')')->setSender(Configuration::getInstance()->get('site')['email'], Configuration::getInstance()->get('site')['name'])->setRecipient(CMS_SUPPORT_EMAIL, CMS_NAME)->setMessage($_POST['message'])->send();
Cacher::getInstance()->getDefaultCacher()->set('cms_home_support_email', NOW);
App::add('Message sent to developers');
Messages::sendGreenAlert('Message sent to developers');
back();