problem with a php script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with a php script
# 1  
Old 02-28-2009
problem with a php script

The script is called php-ping and it is taken from theworldsend.net
I modified it so that instead of ping he will execute another command called scr
witch telnets to a switch and changes the vlan on an interface

the telnet script:
Code:
#! /bin/bash
(
sleep 0.2; 
echo admin;
sleep 0.2;
echo parola;
echo interface ethernet $2;
echo port access vlan 222;
echo quit;
echo save;
echo y;
sleep 5;
) | telnet $1

ex scr $1(ip) $2(interface)
ex: scr 10.10.10.1 0/2
telnets to 10.10.10.1 and chamges the vlan on the interface 0/2

The php script
Code:
<html>
<?php
$max_count = 10; //maximum count for ping command
$unix      =  1; //set this to 1 if you are on a *unix system      
$windows   =  0; //set this to 1 if you are on a windows system
// -------------------------
// nothing more to be done.
// -------------------------
//globals on or off ?
$register_globals = (bool) ini_get('register_gobals');
$system = ini_get('system');
$unix = (bool) $unix;
$win  = (bool)  $windows;
//
If ($register_globals)
{
   $ip = getenv(REMOTE_ADDR);
   $self = $PHP_SELF;
} 
else 
{
   $submit = $_GET['submit'];
   $count  = $_GET['count'];
   $host   = $_GET['host'];
   $ip     = $_SERVER['REMOTE_ADDR'];
   $self   = $_SERVER['PHP_SELF'];
};
// form submitted ?
If ($submit == "Ping!") 
{
   // over count ?
   If ($count > $max_count) 
   {
      echo 'Maximum for count is: '.$max_count;
      echo '<a href="'.$self.'">Back</a>';
   }
   else 
   {
      // replace bad chars
      $host= preg_replace ("/[^A-Za-z0-9.-]/","",$host);
      $count= preg_replace ("/[^0-9]/","",$count);
      echo '<body bgcolor="#FFFFFF" text="#000000"></body>';
      echo("Ping Output:<br>"); 
      echo '<pre>';           
      //check target IP or domain
      if ($unix) 
      {
         system ("ping -c$count -w$count $host");
               }
      else
      {
         system("ping -n $count $host");
      }
      echo '</pre>';
    }
} 
else 
{
    echo '<body bgcolor="#FFFFFF" text="#000000"></body>';
    echo '<p><font size="2">Your IP is: '.$ip.'</font></p>';
    echo '<form methode="post" action="'.$self.'">';
    echo '   Enter IP or Host <input type="text" name="host" value="'.$ip.'"></input>';
    echo '   Enter Count <input type="text" name="count" size="2" value="4"></input>';
    echo '   <input type="submit" name="submit" value="Ping!"></input>';
    echo '</form>';
    echo '<br><b>'.$system.'</b>';
    echo '</body></html>';
}
?>

Instead of ping i changed to scr command
The problem is that i don't know how to modifiy it so that it reads the interface ($2)

Thank you

Last edited by otheus; 03-05-2009 at 01:03 PM.. Reason: added code tags
# 2  
Old 03-05-2009
I think you simply want:

system ("sc $host $device");

Then change all references to "$ip" to "$device".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

php script problem

$result = shell_exec("/sbin/checkscript.sh jdoe"); echo "$result" ; i am running a script through php. the script is /sbin/checkscript jdoe. this script is supposed to output something similar to this: ################################ #### Welcome John Doe... (0 Replies)
Discussion started by: SkySmart
0 Replies

2. UNIX for Advanced & Expert Users

Running multiple php scripts into one php only, cron mail alert problem...

hi, while separated they produce the usual mail alert and i can see the output... if i write into the php script: <?php system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script1.php'); system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script2.php'); system('php -f... (0 Replies)
Discussion started by: 7stars
0 Replies

3. Solaris

problem in php installation..

hi am senthil, am trying to install PHP in my solaris 10 x86 ... i installed oracle,apache,tomcat,mysql .. the only thing am missing is PHP.. i tried to install php using ./configure .. my ./configure command.. ./configure \ --with-apxs=/usr/apache/bin/apxs \... (4 Replies)
Discussion started by: senkerth
4 Replies

4. Solaris

php installation problem..

hi am senthil, i want to install php 5 in my solaris 10 x86server.. i already enabled apache and my mysql 5 is woking fine.. i want to know the procedure to install php.. i googled it and got some info .. i have doubt in the following thing /configure -with-apache2=/opt/httpd-2.0.49... (1 Reply)
Discussion started by: senkerth
1 Replies

5. Shell Programming and Scripting

php date script problem

i want to store the output of date into a variable and be able to echo out that variable in a sentence. but the below isn't working. <?php #$date_time = date('Y-m-d H:i:s'); putenv("TZ=US/Eastern"); date_time = "date('h:i:s')."\n""; echo ("<li>Today's date is: ($date_time)</li>\n"); ... (1 Reply)
Discussion started by: SkySmart
1 Replies

6. UNIX for Dummies Questions & Answers

PHP scripts problem!

Hi, I've configured a server with Debian Etch 4.0. I followed these instructions: Install and Configure Apache2 with PHP5 and SSL Support in Debian Etch -- Debian Admin But when I try to launch a php script with phpinfo() in my browser, It showed me the download manager window.(i.e. wanna to... (9 Replies)
Discussion started by: mjdousti
9 Replies

7. Shell Programming and Scripting

i have a serious problem in php

hello guys, well as i mentioned first i have a serious problem, i need your help. i have a hosting plan with linux, apache and php. i have a script (that have my UID=32256) inside my web site (in the panel folder -see below-) that creates new scripts (in the pages folder) (the new scripts... (0 Replies)
Discussion started by: mehdi
0 Replies

8. Linux

PHP problem

Hi frnds I installed phpmyadmin for OTRS but when ever i tried to open the phpMyAdmin-2.6.2/index.php page i m getting the following error " urldecode the db name if (isset($lightm_db)) { // no longer urlencoded because of html entities in the db name // $db =... (8 Replies)
Discussion started by: naik_mit
8 Replies

9. Shell Programming and Scripting

Problem with PHP and MySQL

Okay, I'm new to this PHP and MySQL stuff, so help would be VERY much appreciated. :) On my iMac runnning Panther, it has MySQL and PHP installed. Yet when I view a PHP file from the iMac or another computer at my house, I get the source code. What's wrong? (11 Replies)
Discussion started by: Danny_10
11 Replies

10. Shell Programming and Scripting

PHP: problem with index.php

iam geting a error with this index script. heres the error Parse error: parse error in c:\phpdev\www\dev\compulearn\in work\index.php on line 39 Whats wrong?? ------------------------ <?php //display header and left bars include ('header.php'); include ('left.php'); //connect... (13 Replies)
Discussion started by: perleo
13 Replies
Login or Register to Ask a Question