PHP Classes

File: E1loadd

Recommend this page to a friend!
  Classes of Dmitry A. Kirilin   FSM Chat   E1loadd   Download  
File: E1loadd
Role: Example script
Content type: text/plain
Description: Cisco chatter
Class: FSM Chat
Automated dialog robot using finite state machines
Author: By
Last change: Minor bugfixes
Date: 19 years ago
Size: 1,722 bytes
 

Contents

Class file image Download
#!/usr/bin/php
<?

/*
============================================================================
This script will continuously print active voice call table of Cisco gateway
============================================================================
*/

//This function will print table entries
function myHandler($str){
 if(
preg_match("/(ANS)|(ORG)/",$str))echo $str."\n";
}

include_once(
"fsmchatclass.inc.php");

$chatter=new FSMChat();

//-------------------------
//Now let's define FSM

//In ENABLE state, when cisco gives an enable command prompt, request active call table
//FSM State unchanged.
$chatter->FSM('/\#$/','sleep(1);return("show call active voice compact\n");',NULL,"ENABLE");

//Immediately continue output if there is more than 25 lines (only in ENABLE state)
//FSM State unchanged.
$chatter->FSM('/\s--More--/','return(" ");',NULL,"ENABLE");

//All other strings will be passed to my handler (only in ENABLE state)
//FSM State unchanged.
$chatter->FSM('/.*/','myHandler($STRING);',NULL,"ENABLE");

//Here we will log in and enter enable mode
//FSM State changes from LOGIN (initial) through LOGGEDIN to ENABLE during login process
$chatter->FSM('/^Level\s1\:/','return("cisco_user");',"LOGIN");
$chatter->FSM('/^Level\s2\:/','return("cisco_password\n");',"LOGGEDIN","LOGIN");
$chatter->FSM('/\>$/','return("enable\n");',"LOGGEDIN","LOGGEDIN");
$chatter->FSM('/^Level\s2\:/','return("enable_password\n");',"ENABLE","LOGGEDIN");

//Ignore all other data from cisco
$chatter->FSM('/.*/','',NULL);

//----------------
//Let's go!

$conn=fsockopen("cisco1.domain.tld",23);

//Telnet session, packet-oriented algorithm chosen.
echo "STOP:".$chatter->RunPacket($conn,"LOGIN",1)."\n";

fclose($conn);

?>