//require_once('modules/Users/User.php'); //session_start(); //$cUser = new User(); //$cUser->retrieve($_SESSION['authenticated_user_id']); //$extension = $cUser->asterisk_ext_c; // Use first extension in the list when multiple extensions linked to the account. $extensionsArray = explode(',', $current_user->asterisk_ext_c); $extension = $extensionsArray[0]; //printr($current_user); //print $extension . "<BR><BR>"; // Take the user supplied pattern, we find the part with the #'s (which are the ext)... then we get something like // asterisk_dialout_channel == "SIP/###" --> $matches[1] == SIP/, $matches[2] == "###", $matches[3] is "". // asterisk_dialout_channel == "Local/###@sugarsip/n" --> $matches[1] == Local/, $matches[2] == "###", $matches[3] is "@sugarsip/n". preg_match('/([^#]*)(#+)([^#]*)/', $sugar_config['asterisk_dialout_channel'], $matches); $channel = $matches[1] . $extension . $matches[3]; logLine("Creating Call, channel for originate command is: {$channel}\n"); //format Phone Number $number = $_REQUEST['phoneNr']; $prefix = $sugar_config['asterisk_prefix']; $number = str_replace("+1", "", $number); $number = str_replace(array("(", ")", " ", "-", "/", "."), "", $number); $number = $prefix . $number; echo "Originate Params: Number: {$number}, Channel: {$channel}, Context: {$context}, Exten: {$number}...\n"; $socket = fsockopen($server, $port, $errno, $errstr, 20); if (!$socket) { echo "errstr ({$errno}) <br>\n"; } else { // $result = ReadResponse($socket); // echo "AMI Header: " . $result; // log on to Asterisk fputs($socket, "Action: Login\r\n");
function login() { $result = parent::call('login', $this->auth_array); $this->sessionid = $result['id']; if ($this->sessionid == -1) { logLine("! Soap login failed!\n"); print_r($result); } return $result; }
$start = $db->fetch('SELECT MAX(id) FROM sequence') + 1; logLine('Scouting starts at ' . $start . '...', false); $a = microtime(true); $html = $client->fetch(range($start, $start + 9)); $time = microtime(true) - $a; if (!$html) { $error = error_get_last(); logLine(' scout died: ' . $error['message'], true, false); exit(1); } logLine(sprintf(' scout returned with %.2F KiB markup after %.2F s.', strlen($html) / 1024.0, $time), true, false); logLine('Parsing loot and searching sequences...', false); $parser = new xrstf\oeisApi\Sequence\Parser(); $importer = new xrstf\oeisApi\Sequence\Importer($db); $sequences = $parser->parseDocument($html); if ($sequences === false) { logLine(' error: parsing failed!', true, false); exit(1); } if (count($sequences) === 0) { logLine(' no new sequences found in this chunk :(', true, false); exit(1); } logLine(' oh boy, found ' . count($sequences) . ' new sequences.', true, false); $db->query('BEGIN'); foreach ($sequences as $sequence) { $importer->import($sequence); $sequence->dump(); logLine('Added sequence ' . $sequence->getOEIS() . '.'); } $db->query('COMMIT');
array_push($log, $bLogLine); $bLogLine = implode('', $log); $fp = fopen($file, 'w'); } fputs($fp, $bLogLine); fclose($fp); } return; } } } /* Don't execute in Manager */ if ($modx->context->get('key') == 'mgr') { return ''; } $oldSetting = ignore_user_abort(TRUE); // otherwise can screw-up logfile $data['page'] = $_SERVER['REQUEST_URI']; $t = gettimeofday(); $data['time'] = date('d/m/y H:i:s:') . substr($t['usec'], 0, 3); // H:i:s:u $data['ip'] = $_SERVER['REMOTE_ADDR']; $data['userAgent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '<unknown user agent>'; $data['host'] = get_host($data['ip']); $data['referer'] = empty($_SERVER['HTTP_REFERER']) ? '(empty)' : $_SERVER['HTTP_REFERER']; $msg = implode('`', $data); $maxLines = $modx->getOption('log_max_lines', $scriptProperties, 300); $file = MODX_CORE_PATH . 'logs/pagenotfound.log'; logLine($msg . "\n", $maxLines, $file); ignore_user_abort($oldSetting); return '';
/* * Copyright (c) 2015, xrstf | MIT licensed */ require __DIR__ . '/boot.php'; $app = new xrstf\oeisApi\Application(); $db = $app['database']; $parser = new xrstf\oeisApi\Sequence\Parser(); $importer = new xrstf\oeisApi\Sequence\Importer($db); $files = glob(OEIS_ROOT . '/data/incoming/*.bz2'); foreach ($files as $file) { logLine('Importing ' . basename($file) . '...', false); $html = bzdecompress(file_get_contents($file)); $sequences = $parser->parseDocument($html); if ($sequences === false) { logLine(' error: parsing failed!', true, false); continue; } if (count($sequences) === 0) { logLine(' warning: no sequence table found in markup.', true, false); continue; } $db->query('BEGIN'); foreach ($sequences as $sequence) { $importer->import($sequence); $sequence->dump(); } $db->query('COMMIT'); logLine(' done.', true, false); unlink($file); }
// asterisk_dialout_channel == "Local/###@sugarsip/n" --> $matches[1] == Local/, $matches[2] == "###", $matches[3] is "@sugarsip/n". preg_match('/([^#]*)(#+)([^#]*)/', $sugar_config['asterisk_dialout_channel'], $matches); $channel = $matches[1] . $extension . $matches[3]; logLine("Creating Call, channel for originate command is: {$channel}\n"); $socket = fsockopen($server, $port, $errno, $errstr, 20); if (!$socket) { echo "errstr ({$errno}) <br>\n"; } else { // log on to Asterisk fputs($socket, "Action: Login\r\n"); fputs($socket, $Username); fputs($socket, $Secret); fputs($socket, "\r\n"); $result = fgets($socket, 128); echo "Login Response: " . $result; logLine("[CreateCall] Login Result: {$result}\n"); //format Phone Number $number = $_REQUEST['phoneNr']; $prefix = $sugar_config['asterisk_prefix']; $number = str_replace("+", "00", $number); $number = str_replace(array("(", ")", " ", "-", "/", "."), "", $number); $number = $prefix . $number; echo "Originate Params: Number: {$number}, Channel: {$channel}, Context: {$context}, Exten: {$number}...\n"; // dial number fputs($socket, "Action: originate\r\n"); fputs($socket, "Channel: " . $channel . "\r\n"); fputs($socket, "Context: " . $context . "\r\n"); fputs($socket, "Exten: " . $number . "\r\n"); fputs($socket, "Priority: 1\r\n"); fputs($socket, "Callerid:" . $_REQUEST['phoneNr'] . "\r\n"); fputs($socket, "Variable: CALLERID(number)=" . $extension . "\r\n");
logLine(sprintf(' fetched %.2F KiB markup in %.2F s.', strlen($html) / 1024.0, $time), true, false); logLine('Parsing document and searching sequences...', false); $parser = new xrstf\oeisApi\Sequence\Parser(); $importer = new xrstf\oeisApi\Sequence\Importer($db); $sequences = $parser->parseDocument($html); if ($sequences === false) { logLine(' error: parsing failed!', true, false); bail($db); sleep(3); continue; } if (count($sequences) === 0) { logLine(' error: could not find any sequences in the markup!', true, false); bail($db); sleep(3); continue; } logLine(' okay, found ' . count($sequences) . ' sequences.', true, false); $db->query('BEGIN'); foreach ($sequences as $sequence) { logLine('Importing ' . $sequence->getOEIS(), false); $importer->import($sequence); $sequence->dump(); logLine(' done.', true, false); } // mark all sequences that haven't been updated as missing $db->query('UPDATE sequence SET worker = -worker WHERE worker = %i', [$workerID]); $db->query('COMMIT'); logLine('Finished. Sleeping for 10 seconds...'); sleep(10); }