private static function pushNotification($userKey, $message, $title = null, $url = null, $urltitle = null) { Notifications::addLog('Pushover[pushNotification' . ']; $userKey=[' . $userKey . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING'); $notification = new Pushover(); $token = Config::get('applicationToken', 'msg_pushover'); if (is_null($token)) { throw new Exception("Pushover - Application token not specified", 500); } if (is_null($userKey)) { throw new Exception("Pushover - User key not specified", 500); } $notification->setToken($token); $notification->setUser($userKey); $notification->setMessage($message); if (!is_null($title)) { $notification->setTitle($title); } $notification->setHtml(1); $notification->setUrl($url); $notification->setUrlTitle($urltitle); if (!$notification->send()) { Notifications::addError("Pushover - Error in sending a notification to '{$userKey}'"); } else { Notifications::addSuccess('Pushover message sent.'); } }
private static function saveMutation($operation, $fullRelationSignature, $stableAtom, $stableConcept, $modifiedAtom, $modifiedConcept, $source) { if (array_key_exists($fullRelationSignature, Config::get('mutationConcepts', 'MutationExtension'))) { Notifications::addLog("Save mutation on '{$fullRelationSignature}' (editUpdate)", 'Mutation'); $mutConcept = Config::get('mutationConcepts', 'MutationExtension')[$fullRelationSignature]; $database = Database::singleton(); $database->setTrackAffectedConjuncts(false); // Don't track affected conjuncts for Mutation concept and relations; // New Mutation $mut = $database->addAtomToConcept(Concept::createNewAtom($mutConcept), $mutConcept); // Add mut info $database->editUpdate('mutRelation', false, $mut, 'Mutation', $fullRelationSignature, 'Relation'); $database->editUpdate('mutDateTime', false, $mut, 'Mutation', date(DATE_ISO8601), 'DateTime'); if ($source == 'User') { $user = Session::getSessionUserId(); } else { $user = $source; } $database->editUpdate('mutBy', false, $mut, 'Mutation', $user, 'User'); $database->editUpdate('mutOp', false, $mut, 'Mutation', $operation, 'Operation'); // $database->editUpdate('mutReason', false, $mut, 'Mutation', 'zomaar', 'MutationReason'); // TODO: get reason from somewhere $database->editUpdate('mutValue', false, $mut, 'Mutation', $modifiedAtom, 'MutationValue'); $database->editUpdate('mutStable', false, $mut, $mutConcept, $stableAtom, $stableConcept); $database->editUpdate('mutPublish', false, $mut, 'Mutation', $mut, 'Mutation'); $database->setTrackAffectedConjuncts(true); // Enable tracking of affected conjuncts again!! } }
function SendSMS($phonenumber, $message) { $config = Config::get('sendSMSConfig', 'execEngine'); $username = $config['username']; $password = $config['password']; $sender = $config['sender']; Notifications::addLog('Username = '******'ExecEngine'); // Set the Messabeird username and password, and create an instance of the MessageBird class $sms = new MessageBird($username, $password); // Set the sender, could be a number (16 numbers) or letters (11 characters) $sms->setSender($sender); // Add the destination mobile number. // This method can be called several times to add have more then one recipient for the same message $sms->addDestination($phonenumber); //e.g. $sms->addDestination('31600000000'); // Set an reference, optional // $sms->setReference('123456789'); // Set a schedule date-time, optional // $sms->setTimestamp('2014-01-01 10:02'); // Replace non GSM-7 characters by appropriate valid GSM-7 characters // $sms->setReplacechars(false); // If you want a dlr notification of the message send to another url then that you have set on the web site, you can use this parameter. Don't forget to set a reference! // $sms->setDlrUrl('http://www.example.com/dlr_url.php'); // If $test is TRUE, then the message is not actually sent or scheduled, and there will be no credits deducted. // $sms->setTest(true); // Send the message to the destination(s) $sms->sendSms($message); Notifications::addLog("ResponseCode: " . $sms->getResponseCode(), 'ExecEngine'); Notifications::addLog("ResponseMessage: " . $sms->getResponseMessage(), 'ExecEngine'); Notifications::addLog("Balance: " . $sms->getCreditBalance(), 'ExecEngine'); }
function CreateCvrMsgTitle($nonce) { if (!$nonce) { throw new Exception("CreateCvrMsgTitle - cannot make TITLE as no nonce is provided", 500); } Notifications::addLog('Created a challenge message for CEPValidation using [' . $nonce, 'MESSAGING'); return 'Validation code: ' . $nonce; }
public function ParseFile() { Notifications::addLog('------------------------- EXCEL IMPORT STARTED -------------------------', 'ExcelImport'); $this->ProcessFileContent(); Notifications::addLog('------------------------- END OF EXCEL IMPORT -------------------------', 'ExcelImport'); // Close transaction => ROLLBACK or COMMIT. $this->db->closeTransaction('File uploaded', false, true, false); return Notifications::getAll(); }
public static function addHook($hookpoint, $hook) { Hooks::$hooks[$hookpoint][] = $hook; if ($hook['class']) { $log = $hook['class'] . '::'; } $log .= $hook['function'] . '('; $log .= implode(', ', $hook['params']) . ')'; Notifications::addLog("Hook {$log} added to {$hookpoint}", 'Hooks'); }
private static function pushNotification($userKey, $message, $title = null, $url = null, $urltitle = null) { Notifications::addLog('Pushalot - $userKey=[' . $userKey . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING'); if (is_null($userKey)) { throw new Exception("Pushalot - User/API key not specified", 500); } $notification = new Pushalot($userKey); //$pushalot->setProxy('http://localhost:12345','user:pass'); $success = $notification->sendMessage(array('Title' => $title, 'Body' => $message, 'IsImportant' => true, 'IsSilent' => false, 'Image' => 'http://wiki.tarski.nl/skins/common/images/AmpersandLogo.png', 'Source' => 'Ampersand prototype')); if (!$success) { Notifications::addError("Pushalot error '{$notification->getError}()' sending notification to '{$userKey}'"); } else { Notifications::addSuccess('Pushalot message sent.'); } }
function TransitiveClosure($r, $C, $rCopy, $rStar) { if (func_num_args() != 4) { throw new Exception("Wrong number of arguments supplied for function TransitiveClosure(): " . func_num_args() . " arguments", 500); } Notifications::addLog("Exeucte TransitiveClosure({$r},{$C},{$rCopy},{$rStar})", 'ExecEngine'); $warshallRunCount = $GLOBALS['ext']['ExecEngine']['functions']['warshall']['runCount']; $execEngineRunCount = ExecEngine::$runCount; if ($GLOBALS['ext']['ExecEngine']['functions']['warshall']['warshallRuleChecked'][$r]) { if ($warshallRunCount == $execEngineRunCount) { Notifications::addLog("Skipping TransitiveClosure({$r},{$C},{$rCopy},{$rStar})", 'ExecEngine'); return; // this is the case if we have executed this function already in this transaction } } $GLOBALS['ext']['ExecEngine']['functions']['warshall']['warshallRuleChecked'][$r] = true; $GLOBALS['ext']['ExecEngine']['functions']['warshall']['runCount'] = ExecEngine::$runCount; // Compute transitive closure following Warshall's algorithm $closure = RetrievePopulation($r, $C); // get adjacency matrix OverwritePopulation($closure, $rCopy, $C); // store it in the 'rCopy' relation // Get all unique atoms from this population $atoms = array_keys($closure); // 'Src' (left) atoms of pairs in $closure foreach ($closure as $tgtAtomsList) { // Loop to add 'Tgt' atoms that not yet exist $tgtAtoms = array_keys($tgtAtomsList); foreach ($tgtAtoms as $tgtAtom) { if (!in_array($tgtAtom, $atoms)) { $atoms[] = $tgtAtom; } } } foreach ($atoms as $k) { foreach ($atoms as $i) { if ($closure[$i][$k]) { foreach ($atoms as $j) { $closure[$i][$j] = $closure[$i][$j] || $closure[$k][$j]; } } } } OverwritePopulation($closure, $rStar, $C); }
function SendEmail($to, $subject, $message) { // adapted from http://phpmailer.worxware.com/?pg=examplebgmail $config = Config::get('sendEmailConfig', 'execEngine'); $from = $config['from']; $username = $config['username']; $password = $config['password']; Notifications::addLog('Username = '******'ExecEngine'); $mail = new PHPMailer(); $mail->IsSMTP(); // Set mailer to use SMTP // $mail->SMTPDebug = 1; $mail->Host = 'smtp.gmail.com'; // Specify main and backup server $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->Port = 587; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $username; // SMTP username (for GMAIL) $mail->Password = $password; // SMTP password $mail->From = $from; $mail->FromName = 'Ampersand Prototype'; $mail->AddAddress($to); // Add a recipient, e.g. $to = '*****@*****.**', 'Rieks Joosten' $mail->Subject = $subject; $mail->Body = $message; $mail->WordWrap = 50; // Set word wrap to 50 characters if (!$mail->Send()) { Notifications::addError('Mailer Error: ' . $mail->ErrorInfo); } else { Notifications::addSuccess('Email message sent.'); } }
public static function getPairView($srcAtom, $srcConcept, $tgtAtom, $tgtConcept, $pairView) { $database = Database::singleton(); Notifications::addLog('Creating violation message', 'RuleEngine'); $pairStrs = array(); $interfaceIds = array(); foreach ($pairView as $segment) { // interface segment if ($segment['segmentType'] == 'Ifc') { $interfaceIds = explode(';', $segment['Interfaces']); // text segment } elseif ($segment['segmentType'] == 'Text') { $pairStrs[] = $segment['Text']; // expressie segment } elseif ($segment['segmentType'] == 'Exp') { // select starting atom depending on whether the segment uses the src of tgt atom. $atom = $segment['srcOrTgt'] == 'Src' ? $srcAtom : $tgtAtom; // quering the expression $atomEsc = $database->escape($atom); $query = "SELECT DISTINCT `tgt` FROM ({$segment['expSQL']}) AS `results` WHERE `src` = '{$atomEsc}'"; // SRC of TGT kunnen door een expressie gevolgd worden $rows = $database->Exe($query); // returning the result if (count($row) > 1) { throw new Exception("Expression of pairview results in more than one tgt atom", 501); } // 501: Not implemented $pairStrs[] = $rows[0]['tgt']; // unknown segment } else { $errorMessage = "Unknown segmentType '" . $segment['segmentType'] . "' in pairview"; throw new Exception($errorMessage, 501); // 501: Not implemented } } return array('violationMessage' => implode($pairStrs), 'interfaceIds' => $interfaceIds); }
public static function checkAddressSyntax($CEPAddress) { Notifications::addLog('Email checkAddressSyntax for [' . $CEPAddress . ']', 'MESSAGING'); if (!filter_var($CEPAddress, FILTER_VALIDATE_EMAIL) === false) { Notifications::addLog('Email address is syntactically correct.', 'MESSAGING'); return $CEPAddress; } $message = 'Email adress [' . $CEPAddress . '] is syntactically incorrect'; Notifications::addError($message); Notifications::addLog($message, 'MESSAGING'); return $message; }
function datimeGT($gtRelation, $DateConcept, $srcAtom, $tgtAtom) { Notifications::addLog("datimeGT({$gtRelation},{$DateConcept},{$srcAtom},{$tgtAtom})", 'ExecEngine'); if (($dt1 = strtotime($srcAtom)) === false) { Notifications::addError("datimeGT: Illegal date {$dt1} specified in srcAtom (3rd arg): {$srcAtom}"); } if (($dt2 = strtotime($tgtAtom)) === false) { Notifications::addError("datimeGT: Illegal date {$dt2} specified in tgtAtom (4th arg): {$tgtAtom}"); } if ($dt1 == $dt2) { return; } if ($dt1 > $dt2) { InsPair($gtRelation, $DateConcept, $srcAtom, $DateConcept, $tgtAtom); } else { InsPair($gtRelation, $DateConcept, $tgtAtom, $DateConcept, $srcAtom); } return; }
private static function pushNotification($SMSAddr, $message, $title = null, $url = null, $urltitle = null) { Notifications::addLog('UNTESTED !!! SMS[pushNotification' . ']; $SMSAddr=[' . $SMSAddr . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING'); /* Config params for SendSMS function of ExecEngine (using MessageBird.com) * Set the sender, could be a number (16 numbers) or letters (11 characters) * */ // Copy the following line to localSettings.php and provide settings // Config::set('sendSMSConfig', 'execEngine', array('username' => '', 'password' => '', 'sender' => '')); $config = Config::get('sendSMSConfig', 'msg_SMS'); $username = $config['username']; $password = $config['password']; $sender = $config['sender']; Notifications::addLog('Username = '******'MESSAGING'); // Set the Messagebird username and password, and create an instance of the MessageBird class $sms = new MessageBird($username, $password); // Set the sender, could be a number (16 numbers) or letters (11 characters) $sms->setSender($sender); // Add the destination mobile number. // This method can be called several times to add have more then one recipient for the same message $sms->addDestination($SMSAddr); //e.g. $sms->addDestination('31600000000'); // Set an reference, optional // $sms->setReference('123456789'); // Set a schedule date-time, optional // $sms->setTimestamp('2014-01-01 10:02'); // Replace non GSM-7 characters by appropriate valid GSM-7 characters // $sms->setReplacechars(false); // If you want a dlr notification of the message send to another url then that you have set on the web site, you can use this parameter. Don't forget to set a reference! // $sms->setDlrUrl('http://www.example.com/dlr_url.php'); // If $test is TRUE, then the message is not actually sent or scheduled, and there will be no credits deducted. Notifications::addLog("SMS testing is set to TRUE (messages are not actually sent)", 'MESSAGING'); $sms->setTest(true); // Send the message to the destination(s) $sms->sendSms($message); if ($sms->getResponseCode() == "01") { Notifications::addSuccess('SMS message sent.'); } else { Notifications::addError('SMS error: ' . $sms->getResponseMessage()); } Notifications::addLog("SMS Response: " . $sms->getResponseMessage(), 'MESSAGING'); Notifications::addLog("SMS Balance: " . $sms->getCreditBalance(), 'MESSAGING'); }
private static function pushNotification($emailAddr, $message, $title = null, $url = null, $urltitle = null) { Notifications::addLog('Email[pushNotification' . ']; $emailAddr=[' . $emailAddr . ']; $message=[' . $message . ']; $title=[' . $title . ']; $url=[' . $url . ']; $urltitle=[' . $urltitle . ']', 'MESSAGING'); // adapted from http://phpmailer.worxware.com/?pg=examplebgmail $config = Config::get('sendEmailConfig', 'msg_email'); $from = $config['from']; $username = $config['username']; $password = $config['password']; Notifications::addLog('Email.php - Username = '******'MESSAGING'); $mail = new PHPMailer(); $mail->IsSMTP(); // Set mailer to use SMTP // $mail->SMTPDebug = 1; $mail->Host = 'smtp.gmail.com'; // Specify main and backup server $mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted $mail->Port = 465; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $username; // SMTP username (for GMAIL) $mail->Password = $password; // SMTP password $mail->From = $from; $mail->FromName = 'Ampersand Prototype'; $mail->AddAddress($emailAddr); // Add a recipient, e.g. $to = '*****@*****.**', 'Rieks Joosten' $mail->Subject = $title; // $message = $message . 'optional URL'; if ($url != '_NULL' && $url != '') { $mail->IsHTML(true); // make sure we send in HTML if ($urltitle != '_NULL' && $urltitle != '') { $message = '<p>' . $message . '</p><p><a href=' . $url . '>' . $urltitle . '</a></p>'; } else { $message = $message . '<a' . $urltitle . '</a>'; } Notifications::addLog('Email message refactored to: [' . $message . ']', 'MESSAGING'); } $mail->Body = $message; $mail->WordWrap = 50; // Set word wrap to 50 characters if (!$mail->Send()) { Notifications::addError('Mailer Error: ' . $mail->ErrorInfo); } else { Notifications::addSuccess('Email message sent.'); } }
function CreateCvrMsgTitle($Nonce) { Notifications::addLog('Created a challenge message for CEPValidation using [' . $Nonce, 'MESSAGING'); return 'Validation code: ' . $Nonce; }
function logEvent($logtext) { $date = date('Y-m-d H:i:s'); Notifications::addLog("{$date} - {$logtext}"); }
private static function setSessionUser() { // Set sessionUser if (!Config::get('loginEnabled')) { Session::$sessionUser = false; } else { $ifc = new InterfaceObject('SessionUser'); $session = new Atom(session_id(), 'SESSION'); $sessionUsers = array_keys((array) $session->getContent($ifc, true)); if (count($sessionUsers) > 1) { throw new Exception('Multiple session users found. This is not allowed.', 500); } if (empty($sessionUsers)) { Session::$sessionUser = false; } else { Session::$sessionUser = current($sessionUsers); Notifications::addLog("Session user set to '{$sessionUser}'", 'SESSION'); } } }
function ClearConcept($concept, $atom) { if (func_num_args() != 2) { throw new Exception("Wrong number of arguments supplied for function ClearConcept(): " . func_num_args() . " arguments", 500); } Notifications::addLog("ClearConcept({$concept}, {$atom})", 'ExecEngine'); try { $database = Database::singleton(); $database->atomClearConcept($concept, $atom); return "Atom '{$atom}' removed as member from concept '{$concept}'"; } catch (Exception $e) { Notifications::addError('ClearConcept: ' . $e->getMessage()); } }
function RerunExecEngine($logText = 'run ExecEngine again after completion') { Notifications::addLog('Rerun: ' . $logText, 'ExecEngine'); ExecEngine::$doRun = true; return true; }
private function addAffectedRelations($fullRelationSignature) { if (!in_array($fullRelationSignature, $this->affectedRelations) && $this->trackAffectedConjuncts) { Notifications::addLog("Mark relation {$fullRelationSignature} as affected relation", 'CONJUNCTS'); $this->affectedRelations[] = $fullRelationSignature; // add $fullRelationSignature to affected relations. Needed for conjunct evaluation. } }
public static function fixViolations($rule, $violations) { if (count($violations)) { Notifications::addLog('ExecEngine fixing violations for rule: ' . $rule['name'], 'ExecEngine'); foreach ($violations as $violation) { $theMessage = ExecEngine::getPairView($violation['src'], $rule['srcConcept'], $violation['tgt'], $rule['tgtConcept'], $rule['pairView']); // This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given str. Strip_tags() is binary safe. // $theCleanMessage = strip_tags($theMessage); // Determine actions/functions to be taken $functionsToBeCalled = explode('{EX}', $theMessage); // Execute actions/functions foreach ($functionsToBeCalled as $functionToBeCalled) { if (empty($functionToBeCalled)) { continue; } // skips to the next iteration if $functionToBeCalled is empty. This is the case when violation text starts with delimiter {EX} // Determine delimiter if (substr($functionToBeCalled, 0, 2) == '_;') { $delimiter = '_;'; $functionToBeCalled = substr($functionToBeCalled, 2); } else { $delimiter = ';'; } $params = explode($delimiter, $functionToBeCalled); // Split off variables $params = array_map('trim', $params); // Trim all params $params = array_map('phpArgumentInterpreter', $params); // Evaluate phpArguments, using phpArgumentInterpreter function $function = array_shift($params); // First parameter is function name $classMethod = (array) explode('::', $function); if (function_exists($function) || method_exists($classMethod[0], $classMethod[1])) { $successMessage = call_user_func_array($function, $params); Notifications::addLog($successMessage, 'ExecEngine'); } else { $errorMessage = "Function '" . $function . "' does not exists. Create function with " . count($params) . " parameters"; throw new Exception($errorMessage, 500); } } } Notifications::addInfo(self::$roleName . ' fixed violations for rule: ' . $rule['name'], 'ExecEngineSuccessMessage', self::$roleName . ' fixed violations'); } }