diff --git a/app/main/controller/api/user.php b/app/main/controller/api/user.php index 74e05bc4..9d660320 100644 --- a/app/main/controller/api/user.php +++ b/app/main/controller/api/user.php @@ -35,7 +35,9 @@ class User extends Controller\Controller{ const SESSION_KEY_CHARACTER_REFRESH_TOKEN = 'SESSION.CHARACTER.REFRESH_TOKEN'; // log text - const LOG_LOGGED_IN = 'userId: %s, userName: %s, charId: %s, charName: %s'; + const LOG_LOGGED_IN = 'userId: [%10s], userName: [%30s], charId: [%20s], charName: %s'; + const LOG_DELETE_ACCOUNT = 'userId: [%10s], userName: [%30s], ip: [%45s]'; + /** * valid reasons for captcha images @@ -340,9 +342,8 @@ class User extends Controller\Controller{ if($status){ // save log - $logText = "id: %s, name: %s, ip: %s"; self::getLogger('DELETE_ACCOUNT')->write( - sprintf($logText, $user->id, $user->name, $f3->get('IP')) + sprintf(self::LOG_DELETE_ACCOUNT, $user->id, $user->name, $f3->get('IP')) ); // remove user diff --git a/app/main/controller/controller.php b/app/main/controller/controller.php index 9ba32888..06b5cb9b 100644 --- a/app/main/controller/controller.php +++ b/app/main/controller/controller.php @@ -19,9 +19,8 @@ class Controller { const COOKIE_NAME_STATE = 'cookie'; const COOKIE_PREFIX_CHARACTER = 'char'; - const LOG_UNAUTHORIZED = 'IP: [%-20s] Agent: [%s]'; - - const ERROR_SESSION_SUSPECT = 'Suspect id: [%30s], ip: [%40s], new ip: [%40s], User-Agent: %s '; + const LOG_UNAUTHORIZED = 'ip: [%45s], User-Agent: [%s]'; + const ERROR_SESSION_SUSPECT = 'Suspect id: [%45s], ip: [%45s], new ip: [%45s], User-Agent: %s '; /** * @var \Base */ diff --git a/app/main/controller/mailcontroller.php b/app/main/controller/mailcontroller.php index 50d99c98..d34ef8f8 100644 --- a/app/main/controller/mailcontroller.php +++ b/app/main/controller/mailcontroller.php @@ -41,4 +41,19 @@ class MailController extends \SMTP{ return $status; } + + /** + * send notification mail for new rally point systems + * @param $to + * @param $msg + * @return bool + */ + public function sendRallyPoint($to, $msg){ + $this->set('To', '<' . $to . '>'); + $this->set('From', 'Pathfinder <' . Controller::getEnvironmentData('SMTP_FROM') . '>'); + $this->set('Subject', 'PATHFINDER - New rally point'); + $status = $this->send($msg); + + return $status; + } } \ No newline at end of file diff --git a/app/main/lib/config.php b/app/main/lib/config.php index 49a7840e..3e6e8781 100644 --- a/app/main/lib/config.php +++ b/app/main/lib/config.php @@ -13,6 +13,7 @@ class Config extends \Prefab { const PREFIX_KEY = 'PF'; const ARRAY_DELIMITER = '-'; + const HIVE_KEY_PATHFINDER = 'PATHFINDER'; const HIVE_KEY_ENVIRONMENT = 'ENVIRONMENT'; /** @@ -147,4 +148,20 @@ class Config extends \Prefab { return $data; } + /** + * get email for notifications by hive key + * @param $key + * @return bool|mixed + */ + static function getNotificationMail($key){ + $f3 = \Base::instance(); + $hiveKey = self::HIVE_KEY_PATHFINDER . '.NOTIFICATION.' . $key; + $mail = false; + if( $f3->exists($hiveKey) ){ + $mail = $f3->get($hiveKey); + } + + return $mail; + } + } \ No newline at end of file diff --git a/app/main/model/systemmodel.php b/app/main/model/systemmodel.php index 32dda8b2..d4aae5b8 100644 --- a/app/main/model/systemmodel.php +++ b/app/main/model/systemmodel.php @@ -8,7 +8,9 @@ namespace Model; +use controller\MailController; use DB\SQL\Schema; +use lib\Config; class SystemModel extends BasicModel { @@ -328,7 +330,11 @@ class SystemModel extends BasicModel { if($rally === 0){ $rally = null; }elseif($rally === 1){ - $rally = date('Y-m-d H:i:s'); + // new rally point set + $currentTimestamp = time(); + $rally = date('Y-m-d H:i:s', $currentTimestamp); + // send rally point notification mail + $this->sendRallyPointMail($currentTimestamp); }else{ $rally = date('Y-m-d H:i:s', $rally); } @@ -484,6 +490,28 @@ class SystemModel extends BasicModel { return $wormholeData; } + protected function sendRallyPointMail($timestamp){ + $recipient = Config::getNotificationMail('RALLY_SET'); + + if( + $recipient && + \Audit::instance()->email($recipient) + ){ + $body = []; + $body[] = "Map:\t\t" . $this->mapId->name; + $body[] = "System:\t\t" . $this->name; + $body[] = "Region:\t\t" . $this->region; + $body[] = "Security:\t" . $this->security; + if(is_object($this->createdCharacterId)){ + $body[] = "Character:\t" . $this->createdCharacterId->name; + } + $body[] = "Time:\t\t" . date('g:i a; F j, Y', $timestamp); + $bodyMsg = implode("\r\n", $body); + + (new MailController())->sendRallyPoint('exodus4d@gmail.com', $bodyMsg); + } + } + /** * see parent */ diff --git a/app/pathfinder.ini b/app/pathfinder.ini index 7408cbc9..5f2238d5 100644 --- a/app/pathfinder.ini +++ b/app/pathfinder.ini @@ -27,7 +27,7 @@ MSG_DISABLED = User registration is currently not allowed COOKIE_EXPIRE = 30 ; restrict login to specific corporations/alliances by id (e.g. 1000166,1000080) -CORPORATION = +CORPORATION = ALLIANCE = ; View ============================================================================================ @@ -69,6 +69,12 @@ MAX_SHARED = 2 ; decrease it on performance problems SEARCH_DEPTH = 7000 +; Email notifications ============================================================================= +; Requires SMTP configuration (see environment.ini) +; Set mail address for recipient (e.g. pathfinder.notification@[YOUR_DOMAIN] ) +[PATHFINDER.NOTIFICATION] +RALLY_SET = + ; TIMER =========================================================================================== [PATHFINDER.TIMER] ; login time (minutes)