Remove PAGI quickstart example for security check
Showing
3 changed files
with
0 additions
and
394 deletions
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * PAGI basic use example. Please see run.sh in this same directory for an | ||
| 4 | * example of how to actually run this from your dialplan. | ||
| 5 | * | ||
| 6 | * Note: The client accepts an array with options. The available options are | ||
| 7 | * | ||
| 8 | * stdin => Optional. If set, should contain an already open stream from | ||
| 9 | * where the client will read data (useful to make it interact with fastagi | ||
| 10 | * servers or even text files to mock stuff when testing). If not set, stdin | ||
| 11 | * will be used by the client. | ||
| 12 | * | ||
| 13 | * stdout => Optional. Same as stdin but for the output of the client. | ||
| 14 | * | ||
| 15 | * | ||
| 16 | * PHP Version 5 | ||
| 17 | * | ||
| 18 | * @category Pagi | ||
| 19 | * @package examples | ||
| 20 | * @subpackage quickstart | ||
| 21 | * @author Marcelo Gornstein <[email protected]> | ||
| 22 | * @license http://marcelog.github.com/PAGI/ Apache License 2.0 | ||
| 23 | * @version SVN: $Id$ | ||
| 24 | * @link http://marcelog.github.com/PAGI/ | ||
| 25 | * | ||
| 26 | * Copyright 2011 Marcelo Gornstein <[email protected]> | ||
| 27 | * | ||
| 28 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 29 | * you may not use this file except in compliance with the License. | ||
| 30 | * You may obtain a copy of the License at | ||
| 31 | * | ||
| 32 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 33 | * | ||
| 34 | * Unless required by applicable law or agreed to in writing, software | ||
| 35 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 36 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 37 | * See the License for the specific language governing permissions and | ||
| 38 | * limitations under the License. | ||
| 39 | * | ||
| 40 | */ | ||
| 41 | use PAGI\Application\PAGIApplication; | ||
| 42 | use PAGI\Client\ChannelStatus; | ||
| 43 | use PAGI\CallSpool\CallFile; | ||
| 44 | use PAGI\CallSpool\Impl\CallSpoolImpl; | ||
| 45 | declare(ticks=1); | ||
| 46 | /** | ||
| 47 | * PAGI basic use example. Please see run.sh in this same directory for an | ||
| 48 | * example of how to actually run this from your dialplan. | ||
| 49 | * | ||
| 50 | * Note: The client accepts an array with options. The available options are | ||
| 51 | * | ||
| 52 | * stdin => Optional. If set, should contain an already open stream from | ||
| 53 | * where the client will read data (useful to make it interact with fastagi | ||
| 54 | * servers or even text files to mock stuff when testing). If not set, stdin | ||
| 55 | * will be used by the client. | ||
| 56 | * | ||
| 57 | * stdout => Optional. Same as stdin but for the output of the client. | ||
| 58 | * | ||
| 59 | * PHP Version 5 | ||
| 60 | * | ||
| 61 | * @category Pagi | ||
| 62 | * @package examples | ||
| 63 | * @subpackage quickstart | ||
| 64 | * @author Marcelo Gornstein <[email protected]> | ||
| 65 | * @license http://marcelog.github.com/PAGI/ Apache License 2.0 | ||
| 66 | * @link http://marcelog.github.com/PAGI/ | ||
| 67 | */ | ||
| 68 | class MyPAGIApplication extends PAGIApplication | ||
| 69 | { | ||
| 70 | /** | ||
| 71 | * (non-PHPdoc) | ||
| 72 | * @see PAGI\Application.PAGIApplication::init() | ||
| 73 | */ | ||
| 74 | public function init() | ||
| 75 | { | ||
| 76 | $this->log('Init'); | ||
| 77 | $client = $this->getAgi(); | ||
| 78 | $client->answer(); | ||
| 79 | } | ||
| 80 | /** | ||
| 81 | * Logs to asterisk console. | ||
| 82 | * | ||
| 83 | * @param string $msg Message to log. | ||
| 84 | * | ||
| 85 | * @return void | ||
| 86 | */ | ||
| 87 | public function log($msg) | ||
| 88 | { | ||
| 89 | $agi = $this->getAgi(); | ||
| 90 | $this->logger->debug($msg); | ||
| 91 | $agi->consoleLog($msg); | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * (non-PHPdoc) | ||
| 96 | * @see PAGI\Application.PAGIApplication::shutdown() | ||
| 97 | */ | ||
| 98 | public function shutdown() | ||
| 99 | { | ||
| 100 | try | ||
| 101 | { | ||
| 102 | $this->log('Shutdown'); | ||
| 103 | $client = $this->getAgi(); | ||
| 104 | $client->hangup(); | ||
| 105 | } catch(\Exception $e) { | ||
| 106 | |||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | /** | ||
| 111 | * (non-PHPdoc) | ||
| 112 | * @see PAGI\Application.PAGIApplication::run() | ||
| 113 | */ | ||
| 114 | public function run() | ||
| 115 | { | ||
| 116 | $this->log('Run'); | ||
| 117 | $client = $this->getAgi(); | ||
| 118 | $loggerFacade = $client->getAsteriskLogger(); | ||
| 119 | $loggerFacade->notice('hello notice'); | ||
| 120 | $loggerFacade->warn('hello warn'); | ||
| 121 | $loggerFacade->debug('hello debug'); | ||
| 122 | $loggerFacade->error('hello error'); | ||
| 123 | $loggerFacade->dtmf('hello dtmf'); | ||
| 124 | //$this->log($client->faxReceive('/tmp/a.tiff')->__toString()); | ||
| 125 | //$this->log($client->faxSend('/tmp/a.tiff')->__toString()); | ||
| 126 | $variables = $client->getChannelVariables(); | ||
| 127 | |||
| 128 | $this->log('Config dir: ' . $variables->getDirectoryConfig()); | ||
| 129 | $this->log('Config file: ' . $variables->getConfigFile()); | ||
| 130 | $this->log('Module dir: ' . $variables->getDirectoryModules()); | ||
| 131 | $this->log('Spool dir: ' . $variables->getDirectorySpool()); | ||
| 132 | $this->log('Monitor dir: ' . $variables->getDirectoryMonitor()); | ||
| 133 | $this->log('Var dir: ' . $variables->getDirectoryVar()); | ||
| 134 | $this->log('Data dir: ' . $variables->getDirectoryData()); | ||
| 135 | $this->log('Log dir: ' . $variables->getDirectoryLog()); | ||
| 136 | $this->log('Agi dir: ' . $variables->getDirectoryAgi()); | ||
| 137 | $this->log('Key dir: ' . $variables->getDirectoryKey()); | ||
| 138 | $this->log('Run dir: ' . $variables->getDirectoryRun()); | ||
| 139 | $this->log('Request: '. $variables->getRequest()); | ||
| 140 | $this->log('Channel: '. $variables->getChannel()); | ||
| 141 | $this->log('Language: '. $variables->getLanguage()); | ||
| 142 | $this->log('Type: '. $variables->getType()); | ||
| 143 | $this->log('UniqueId: ' . $variables->getUniqueId()); | ||
| 144 | $this->log('Version: ' . $variables->getVersion()); | ||
| 145 | $this->log('CallerId: ' . $variables->getCallerId()); | ||
| 146 | $this->log('CallerId name: ' . $variables->getCallerIdName()); | ||
| 147 | $this->log('CallerId pres: ' . $variables->getCallingPres()); | ||
| 148 | $this->log('CallingAni2: ' . $variables->getCallingAni2()); | ||
| 149 | $this->log('CallingTon: ' . $variables->getCallingTon()); | ||
| 150 | $this->log('CallingTNS: ' . $variables->getCallingTns()); | ||
| 151 | $this->log('DNID: ' . $variables->getDNID()); | ||
| 152 | $this->log('RDNIS: ' . $variables->getRDNIS()); | ||
| 153 | $this->log('Context: ' . $variables->getContext()); | ||
| 154 | $this->log('Extension: ' . $variables->getDNIS()); | ||
| 155 | $this->log('Priority: ' . $variables->getPriority()); | ||
| 156 | $this->log('Enhanced: ' . $variables->getEnhanced()); | ||
| 157 | $this->log('AccountCode: ' . $variables->getAccountCode()); | ||
| 158 | $this->log('ThreadId: ' . $variables->getThreadId()); | ||
| 159 | $this->log('Arguments: ' . intval($variables->getTotalArguments())); | ||
| 160 | for ($i = 0; $i < $variables->getTotalArguments(); $i++) { | ||
| 161 | $this->log(' -- Argument ' . intval($i) . ': ' . $variables->getArgument($i)); | ||
| 162 | } | ||
| 163 | |||
| 164 | $result = $client->sayDigits('12345', '12#'); | ||
| 165 | if (!$result->isTimeout()) { | ||
| 166 | $this->log('Read: ' . $result->getDigits()); | ||
| 167 | } else { | ||
| 168 | $this->log('Timeouted for say digits.'); | ||
| 169 | } | ||
| 170 | |||
| 171 | $result = $client->sayNumber('12345', '12#'); | ||
| 172 | if (!$result->isTimeout()) { | ||
| 173 | $this->log('Read: ' . $result->getDigits()); | ||
| 174 | } else { | ||
| 175 | $this->log('Timeouted for say number.'); | ||
| 176 | } | ||
| 177 | |||
| 178 | $result = $client->getData('welcome', 10000, 4); | ||
| 179 | if (!$result->isTimeout()) { | ||
| 180 | $this->log('Read: ' . $result->getDigits()); | ||
| 181 | } else { | ||
| 182 | $this->log('Timeouted for get data with: ' . $result->getDigits()); | ||
| 183 | } | ||
| 184 | |||
| 185 | $result = $client->getOption('welcome', '0123456789*#', 10000); | ||
| 186 | if (!$result->isTimeout()) { | ||
| 187 | $this->log('Read: ' . $result->getDigits()); | ||
| 188 | } else { | ||
| 189 | $this->log('Timeouted for get option.'); | ||
| 190 | } | ||
| 191 | |||
| 192 | $result = $client->streamFile('welcome', '#'); | ||
| 193 | if (!$result->isTimeout()) { | ||
| 194 | $this->log('Read: ' . $result->getDigits()); | ||
| 195 | } else { | ||
| 196 | $this->log('Timeouted for stream file.'); | ||
| 197 | } | ||
| 198 | |||
| 199 | $this->log('Channel status: ' . ChannelStatus::toString($client->channelStatus())); | ||
| 200 | $this->log('Channel status: ' . ChannelStatus::toString($client->channelStatus($variables->getChannel()))); | ||
| 201 | $this->log('Variable: ' . $client->getVariable('EXTEN')); | ||
| 202 | $this->log('FullVariable: ' . $client->getFullVariable('EXTEN')); | ||
| 203 | $cdr = $client->getCDR(); | ||
| 204 | $this->log('CDRVariable: ' . $cdr->getSource()); | ||
| 205 | $cdr->setAccountCode('foo'); | ||
| 206 | $this->log('CDRVariable: ' . $cdr->getAccountCode()); | ||
| 207 | |||
| 208 | $callerId = $client->getCallerId(); | ||
| 209 | $this->log('CallerID: ' . $callerId); | ||
| 210 | $callerId->setName('pepe'); | ||
| 211 | $this->log('CallerID: ' . $callerId); | ||
| 212 | $client->setCallerId('foo', '123123'); | ||
| 213 | $this->log('CallerID: ' . $callerId); | ||
| 214 | |||
| 215 | $this->log($client->exec('Dial', array('SIP/sip', 30, 'r'))); | ||
| 216 | $this->log($client->dial('SIP/01', array(30, 'r'))); | ||
| 217 | |||
| 218 | $result = $client->sayPhonetic('marcelog', '123#'); | ||
| 219 | if (!$result->isTimeout()) { | ||
| 220 | $this->log('Read: ' . $result->getDigits()); | ||
| 221 | } else { | ||
| 222 | $this->log('Timeouted for say phonetic.'); | ||
| 223 | } | ||
| 224 | |||
| 225 | $result = $client->sayAlpha('marcelog', '123#'); | ||
| 226 | if (!$result->isTimeout()) { | ||
| 227 | $this->log('Read: ' . $result->getDigits()); | ||
| 228 | } else { | ||
| 229 | $this->log('Timeouted for say alpha.'); | ||
| 230 | } | ||
| 231 | |||
| 232 | $result = $client->sayTime(time(), '123#'); | ||
| 233 | if (!$result->isTimeout()) { | ||
| 234 | $this->log('Read: ' . $result->getDigits()); | ||
| 235 | } else { | ||
| 236 | $this->log('Timeouted for say time.'); | ||
| 237 | } | ||
| 238 | |||
| 239 | $result = $client->sayDateTime(time(), 'mdYHMS', '123#'); | ||
| 240 | if (!$result->isTimeout()) { | ||
| 241 | $this->log('Read: ' . $result->getDigits()); | ||
| 242 | } else { | ||
| 243 | $this->log('Timeouted for say datetime.'); | ||
| 244 | } | ||
| 245 | |||
| 246 | $result = $client->sayDate(time(), '123#'); | ||
| 247 | if (!$result->isTimeout()) { | ||
| 248 | $this->log('Read: ' . $result->getDigits()); | ||
| 249 | } else { | ||
| 250 | $this->log('Timeouted for say date.'); | ||
| 251 | } | ||
| 252 | |||
| 253 | $client->setPriority(1000); | ||
| 254 | $client->setExtension(1000); | ||
| 255 | $client->setContext('foo'); | ||
| 256 | $client->setMusic(true); | ||
| 257 | sleep(10); | ||
| 258 | $client->setMusic(false); | ||
| 259 | |||
| 260 | $result = $client->waitDigit(10000); | ||
| 261 | if (!$result->isTimeout()) { | ||
| 262 | $this->log('Read: ' . $result->getDigits()); | ||
| 263 | } else { | ||
| 264 | $this->log('Timeouted for waitdigit.'); | ||
| 265 | } | ||
| 266 | $result = $client->record('/tmp/asd', 'wav', '#'); | ||
| 267 | if ($result->isInterrupted()) { | ||
| 268 | if ($result->isHangup()) { | ||
| 269 | $this->log('hangup when recording.'); | ||
| 270 | } else { | ||
| 271 | $this->log('interrupted with: ' . $result->getDigits()); | ||
| 272 | } | ||
| 273 | $this->log('Recorded: ' . $result->getEndPos()); | ||
| 274 | } | ||
| 275 | //$this->log($client->databaseGet('SIP', 'Registry')); | ||
| 276 | //$client->setAutoHangup(10); | ||
| 277 | //sleep(20); | ||
| 278 | } | ||
| 279 | |||
| 280 | /** | ||
| 281 | * (non-PHPdoc) | ||
| 282 | * @see PAGI\Application.PAGIApplication::errorHandler() | ||
| 283 | */ | ||
| 284 | public function errorHandler($type, $message, $file, $line) | ||
| 285 | { | ||
| 286 | $this->log( | ||
| 287 | 'ErrorHandler: ' | ||
| 288 | . implode(' ', array($type, $message, $file, $line)) | ||
| 289 | ); | ||
| 290 | } | ||
| 291 | |||
| 292 | /** | ||
| 293 | * (non-PHPdoc) | ||
| 294 | * @see PAGI\Application.PAGIApplication::signalHandler() | ||
| 295 | */ | ||
| 296 | public function signalHandler($signal) | ||
| 297 | { | ||
| 298 | $this->log('SignalHandler got signal: ' . $signal); | ||
| 299 | $this->shutdown(); | ||
| 300 | exit(0); | ||
| 301 | } | ||
| 302 | } |
| 1 | #!/bin/bash | ||
| 2 | ################################################################################ | ||
| 3 | # Sample application to run from your dialplan. | ||
| 4 | ################################################################################ | ||
| 5 | # Get our base directory (the one where this script is located) | ||
| 6 | me=$(dirname ${0}) | ||
| 7 | root=${me}/../../.. | ||
| 8 | export root=`cd ${root}; pwd` | ||
| 9 | |||
| 10 | # This is the application that will be run. | ||
| 11 | export PAGIApplication=MyPAGIApplication | ||
| 12 | |||
| 13 | # Make sure this is in the include path. | ||
| 14 | export PAGIBootstrap=MyPAGIApplication.php | ||
| 15 | |||
| 16 | # PHP to run and options | ||
| 17 | php=/usr/php/bin/php | ||
| 18 | phpoptions="-c ${root}/resources/php.ini -d include_path=${root}/docs/examples/quickstart" | ||
| 19 | |||
| 20 | # Standard.. the idea is to have a common launcher. | ||
| 21 | launcher=${root}/src/mg/PAGI/Application/PAGILauncher.php | ||
| 22 | |||
| 23 | # Go! | ||
| 24 | ${php} ${phpoptions} ${launcher} | ||
| 25 |
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Spooling calls exmaples. | ||
| 4 | * | ||
| 5 | * PHP Version 5.3 | ||
| 6 | * | ||
| 7 | * Copyright 2011 Marcelo Gornstein <[email protected]> | ||
| 8 | * | ||
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 10 | * you may not use this file except in compliance with the License. | ||
| 11 | * You may obtain a copy of the License at | ||
| 12 | * | ||
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 14 | * | ||
| 15 | * Unless required by applicable law or agreed to in writing, software | ||
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 18 | * See the License for the specific language governing permissions and | ||
| 19 | * limitations under the License. | ||
| 20 | * | ||
| 21 | */ | ||
| 22 | use PAGI\CallSpool\CallFile; | ||
| 23 | use PAGI\CallSpool\Impl\CallSpoolImpl; | ||
| 24 | use PAGI\DialDescriptor\SIPDialDescriptor; | ||
| 25 | use PAGI\DialDescriptor\DAHDIDialDescriptor; | ||
| 26 | |||
| 27 | $dialDescriptor = new DAHDIDialDescriptor('1949890333', 1); | ||
| 28 | $callFile = new CallFile($dialDescriptor); | ||
| 29 | $callFile->setContext('campaign'); | ||
| 30 | $callFile->setExtension('failed'); | ||
| 31 | $callFile->setVariable('foo', 'bar'); | ||
| 32 | $callFile->setPriority('1'); | ||
| 33 | $callFile->setMaxRetries('0'); | ||
| 34 | $callFile->setWaitTime(10); | ||
| 35 | $callFile->setCallerId('some<123123>'); | ||
| 36 | |||
| 37 | echo "Call file generated (DAHDI dial descriptor):\n"; | ||
| 38 | echo $callFile->serialize(); | ||
| 39 | echo "\n\n"; | ||
| 40 | |||
| 41 | $dialDescriptor = new SIPDialDescriptor('24', 'example.com'); | ||
| 42 | |||
| 43 | $callFile = new CallFile($dialDescriptor); | ||
| 44 | $callFile->setContext('default'); | ||
| 45 | $callFile->setExtension('777'); | ||
| 46 | $callFile->setVariable('foo', 'bar'); | ||
| 47 | $callFile->setPriority('1'); | ||
| 48 | $callFile->setMaxRetries('0'); | ||
| 49 | $callFile->setWaitTime(10); | ||
| 50 | $callFile->setCallerId('some<123123>'); | ||
| 51 | |||
| 52 | echo "Call file generated (SIP dial descriptor):\n"; | ||
| 53 | echo $callFile->serialize(); | ||
| 54 | echo "\n\n\n"; | ||
| 55 | |||
| 56 | echo "Spooling generated SIP call\n"; | ||
| 57 | $spool = CallSpoolImpl::getInstance( | ||
| 58 | array( | ||
| 59 | 'tmpDir' => '/tmp', | ||
| 60 | 'spoolDir' => '/tmp/spoolExample' | ||
| 61 | ) | ||
| 62 | ); | ||
| 63 | |||
| 64 | $spool->spool($callFile); | ||
| 65 | |||
| 66 | echo "Spooling generated SIP call to run in 30 seconds\n"; | ||
| 67 | $spool->spool($callFile, time() + 30); |
-
Please register or sign in to post a comment