function call($command, $user) { \app\log('calling func'); if (!empty($user)) { $command_type = 'receiver'; } else { $command_type = 'sender'; } $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'commands'; $tpl_path = $path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $command_type; $file = $path . DIRECTORY_SEPARATOR . $command_type . DIRECTORY_SEPARATOR . $command . '.php'; $template = $tpl_path . DIRECTORY_SEPARATOR . $command . '.phtml'; \app\log($file); if (!file_exists($file)) { \app\log('Command ' . $command . ' not implemented for ' . $command_type); exit('Command ' . $command . ' not implemented for ' . $command_type); } include $file; \app\log($file); $function = "\\command\\" . $command; $result = $function(); \app\log($result); if (!empty($result)) { \app\log('sending'); \app\run('email', 'send', array($result, $template)); } else { \app\log('nothing to send'); exit('nothing to send'); } }
function remoteError($errno, $errstr, $errfile, $errline) { $message = ''; if (!(error_reporting() & $errno)) { \app\log('unknown problem'); return; } switch ($errno) { case E_USER_ERROR: $message = "<b>My ERROR</b> [{$errno}] {$errstr}<br />\n"; $message .= " Fatal error on line {$errline} in file {$errfile}"; $message .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; $message .= "Aborting...<br />\n"; \app\log($message); exit(1); break; case E_USER_WARNING: $message = "<b>My WARNING</b> [{$errno}] {$errstr}<br />\n"; \app\log($message); break; case E_USER_NOTICE: $message = "<b>My NOTICE</b> [{$errno}] {$errstr}<br />\n"; \app\log($message); break; default: $message = "Unknown error type: [{$errno}] {$errstr}<br />\n"; \app\log($message); break; } return true; }
function send($result, $template, $subject = 'sibip') { \app\log('sending prep'); $config = \configuration\load(); $mailgun = new \Mailgun\Mailgun($config['key']); $domain = $config['domain']; \app\log('composed'); $mailgun->sendMessage($domain, array('from' => '*****@*****.**', 'to' => \app\run('input', 'post', 'sender'), 'subject' => $subject, 'text' => \email\composeText($result), 'html' => \email\composeHTML($template, $result))); }
function find($data) { \app\log('finding'); $sender = \app\run('input', 'post', 'sender'); $user = R::findOne('user', ' email = ?', [$sender]); if (empty($user)) { \app\log('not found'); return false; } \app\log('found'); return $user; }
function verify_signature() { $config = \app\run('configuration', 'load'); $timestamp = \app\run('input', 'post', 'timestamp'); $token = \app\run('input', 'post', 'token'); $signature = \app\run('input', 'post', 'signature'); if (empty($timestamp) || empty($token) || empty($signature)) { \app\log('incomplete'); exit('incomplete'); } $data = $timestamp . $token; $code = hash_hmac('sha256', $data, $config['key']); if ($code == $signature) { return true; } \app\log('nope'); exit('nope'); }