- 03
- Mar
Nothing is worse than entering repetitive, monotonous commands into a router to accomplish a simple task. By using PHPTelnet we can create a script that will make use of a web form to provision (create pvc or a Private Virtual Circuit) DSL customers in a Cisco router. The script will also write to a log file for security and troubleshooting purposes. This script could be used for many other tasks as well as it is very easy to modify.
NOTE: Depending on your setup, you may need to make modifications to the script.

First, I will focus on the PHP script, and then the web form.
The first part of the script will call in the PHPTelnet.php file. And grab the variables from our web form with the POST method.
-
require_once "PHPTelnet.php";
-
-
$telnet = new PHPTelnet();
-
-
$vpi = $_POST[‘VPI’];
-
$vci = $_POST[‘VCI’];
-
$spd = $_POST[‘SPD’];
This next section deals with logging the requests to a file named ‘log.txt’. Make sure you manually create the file first.
Initiate the connection. Make sure to modify the IP address, username, and password.
-
if ($vpi >= "1") {
-
// if the first argument to Connect is blank,
-
// PHPTelnet will connect to the local host via 127.0.0.1
-
$result = $telnet->Connect(‘X.X.X.X’,‘username’,‘password’);
This is where the acually commands are being executed. You may assume that each line is one command. After it is executed a return is sent. The syntax is $telnet->DoCommand(’COMMAND HERE’,$result);. The next line will echo any output sent by the terminal. Again, this may vary based on how your Cisco router is configured. You could also add other commands here such as copying the running config to start and so on. You need to modify ‘enablepassword’.
NOTE: The blank command that you see in the 6th to the last line is suppose to be a Ctrl-Z command. Download the script at the end of this post for the included characters to process this command.
-
$telnet->DoCommand(‘en’,$result);
-
// NOTE: $result may contain newlines
-
$telnet->DoCommand(‘enablepassword’, $result);
-
$telnet->DoCommand(‘config t’, $result);
-
$telnet->DoCommand(‘interface ATM1/0.’.$vpi.‘0′.$vci.‘ point-to-point’, $result);
-
$telnet->DoCommand(‘pvc ‘.$vpi.‘/’.$vci, $result);
-
$telnet->DoCommand(‘ubr ‘.$spd, $result);
-
$telnet->DoCommand(‘encapsulation aal5autoppp Virtual-Template1′, $result);
-
$telnet->DoCommand(‘’, $result);
-
$telnet->DoCommand(‘disable’, $result);
-
$telnet->DoCommand(‘exit’, $result);
Now, we will simply disconnect and reset the $vpi variable.
This HTML code could reside in a separate file. The options for the drop down are speeds. You should modify these to match your different DSL speed offerings.
-
<form action="addpvc.php" method="post">
-
<p align="left"><font face="Verdana"><font size="2">VPI: </font> <input type="text" size="9" name="VPI" /><br />
-
<font size="2">VCI: </font> <input type="text" size="9" name="VCI" /> <font size="2">SPEED: </font> <select name="SPD">
-
<option>512</option>
-
<option>1544</option>
-
<option>3072</option>
-
</select> <input type="submit" name="B1" value="Submit" /><input type="reset" name="B2" value="Reset" /></font></p>
-
</form>
Hopefully this will make things easier if you are manually entering DSL provisioning into a Cisco router. Also, you might have noticed this can be used for many other repetitive telnet tasks.
Download the PHP Cisco Provisioning Script
Related Posts
Tags: Cisco, DSL, Featured, Networking, PHP, PHPTelnet, Provisioning, PVC, Tutorials, Web development



April 28th, 2008 at 7:45 pm
I tried using this but it wont even connect to my cisco router.
PHPTelnet seems to be the issue.
The cisco router is showing me :
*Feb 29 02:45:48.439: AAA/BIND(00000215): Bind i/f
*Feb 29 02:45:48.439: AAA/AUTHEN/LOGIN (00000215): Pick method list ‘default’
but i think the issue may be with my php.ini not allowing something… any help ?
April 29th, 2008 at 8:49 am
OK, so what you are showing me here:
*Feb 29 02:45:48.439: AAA/BIND(00000215): Bind i/f
*Feb 29 02:45:48.439: AAA/AUTHEN/LOGIN (00000215): Pick method list ‘default’
Is when the script is trying to login? And is this on the local console of the router or in your web browser?
Also what version and OS of apache/php are you using?
April 29th, 2008 at 2:57 pm
The cisco router is on the local lan - i can connect to it with telnet no problems using the login and pass i have in the script.
I have since managed to connect using my linux web server and that seems to work about 80% of the time, not sure why.
I have added in a command and it doesnt seem to work at all though … the basic ones do now like en and passwords , but when i try to FTP the config to my ftp server (as a monthly backup) using the following command :
$telnet->DoCommand(’copy startup ftp://user:pass@myftpaddress/backup/startup/myrouter.conf‘, $result);
echo $result.” “;
I think the command asks for 2 confirmations but when it ehco’s i get the following style :
IBE-MINE-CPE01#copy startup ftp://u
ser:pass@myftpad
It looks like its putting a space in between the command and not completing the full command or confirming the 2 questions after.
This is a great script , exactly what im looking for , but id like it to work for the commands i want to send to the cisco router if at all possible.
Thanks for any help you can give me with this.
April 29th, 2008 at 7:25 pm
Not sure why it would be cutting it off like that. I’ve never actually used FTP to transfer configs, always TFTP.
Does the command work in the local console? Are you sending a carriage return for the confirmations?
http://www.asciitable.com/
April 30th, 2008 at 2:58 pm
Either Tftp or FTP will come out the same , but im only using FTP as a test and in this case its usually faster for my backups.
The command works when i telnet into the cisco box and run it normally, and it has even worked once from the script , though i think i way messing on the router when it did it.
I have also noticed that the time out times in the PhPtelnet make a difference to what happens and im wondering if there are certain settings required for Cisco ?
Im glad this place is here , cant find anywhere else for this kind of info.
April 30th, 2008 at 4:34 pm
Strange. Works fine for me with defaults. Care to share your script so I can see it? Take out the password, IP, etc.
If you can upload it to rapidshare.com, it would be better than posting the code in the comments.
June 6th, 2008 at 1:56 pm
Hey Guys
Trying to connect to a iNdex phone system using this script but it is failing on login.
What things can I try to sort this? user/pass is correct.
Many Thanks
June 6th, 2008 at 4:04 pm
Is there any authentication logs on the phone system? Look there to see what it is being entered.
Does your username or password have any funky characters?
June 7th, 2008 at 12:14 pm
Hi Shane,
Thanks for you comment, I shall have a look now and see if I can sort it, will update you with my findings. I have tested it will netcat and it seems to be sending the correct login info. Its all plain text characters.
Thanks!
June 7th, 2008 at 12:16 pm
Oh, the only other thing is it does:
Username> SEND USER NAME
Passowrd> SEND PASSWORD
Don’t know if the text before you enter the info could be causing a problem?
Many Thanks
June 7th, 2008 at 1:11 pm
ok, as far as I can see there are not auth logs.
Next idea?
Many Thanks
June 10th, 2008 at 7:45 am
Chris, can you upload the script so I can take a look? Send me the link in the contact form. Please remove any IPs and username/passwords.
June 12th, 2008 at 3:39 pm
Ok, should be in your inbox, error I get is: [PHP Telnet] Connect failed: Login failed username/password is 100% correct.
Thanks for the help!
June 29th, 2008 at 9:14 pm
Hey is their any chance you would know how to change it from telnet to ssh?
June 30th, 2008 at 7:11 am
Not straight off hand, but this might get you started:
http://us2.php.net/manual/en/function.ssh2-connect.php
http://us2.php.net/manual/en/function.ssh2-exec.php