修改cico dhcp池的php脚本

修改cico dhcp池的php脚本,php,mysql,Php,Mysql,我正在尝试使调制解调器供应系统的过程自动化。 下面的代码是我的尝试,但我没有列出传递变量的表单除外 脚本的DB部分运行良好。然而,telnet部分并没有像我希望的那样进入路由器,任何人都能对此有所了解。如果我断开telnet部分并通过cli运行它,它就会工作 <? include("config.php"); //setting up db connection try{ $dbh = new PDO("mysql:host=$host;dbname=$db", $mun, $mpass

我正在尝试使调制解调器供应系统的过程自动化。 下面的代码是我的尝试,但我没有列出传递变量的表单除外

脚本的DB部分运行良好。然而,telnet部分并没有像我希望的那样进入路由器,任何人都能对此有所了解。如果我断开telnet部分并通过cli运行它,它就会工作

<?

include("config.php");
//setting up db connection
try{
$dbh = new PDO("mysql:host=$host;dbname=$db", $mun, $mpass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );


 $stmt = $dbh->prepare("INSERT INTO cust_info(firstname, lastname, staddr, city, phone,      acct, ipaddr, hwaddr, cliid, bootfile)
        VALUES (:firstname, :lastname, :staddr, :city, :phone, :acct, :ipaddr, :hwaddr, :cliid, :bootfile)");

        $stmt->bindParam(':firstname', $_POST['firstname']);
        $stmt->bindParam(':lastname', $_POST['lastname']);
        $stmt->bindParam(':staddr', $_POST['staddr']);
        $stmt->bindParam(':city', $_POST['city']);
        $stmt->bindParam(':phone', $_POST['phone']);
        $stmt->bindParam(':acct', $_POST['acct']);
        $stmt->bindParam(':ipaddr', $_POST['ipaddr']);
        $stmt->bindParam(':hwaddr', $_POST['hwaddr']);
        $stmt->bindParam(':cliid', $_POST['cliid']);
        $stmt->bindParam(':bootfile', $_POST['bootfile']);

        $stmt->execute();
echo "done";
}
catch(PDOException $e)
{
echo 'failed: ' . $e->getMessage();
}


$bootfile = $_POST['bootfile'];
$cliid = $_POST['cliid'];
$ipaddr = $_POST['ipaddr'];
$hwaddr = $_POST['hwaddr'];

//Process data from form into cmts

$connection = fsockopen($router_ip, $port, $errno, $errstr, $timeout);

if(!$connection)
{
echo "Connection failed\n";
exit();
}
else
{
fputs($connection, "$username\r");
fputs($connection, "$password\r");
// using term length 0 to keep  pause or more prompt from eating input
fputs($connection, "term length 0\r");
fputs($connection, "enable\r");
fputs($connection, "$password\r");
fputs($connection, "clear ip dhcp binding $ipaddr\r");
fputs($connection, "configure terminal\r");
fputs($connection, "ip dhcp pool $cliid\r");
fputs($connection, "host $ipaddr 255.255.255.0\r");
fputs($connection, "client-identifier $cliid\r");
fputs($connection, "bootfile $bootfile\r");
fputs($connection, "exit\r\n");
fputs($connection, "exit\r\n");
fputs($connection, "clear cable modem 172.16.16.248 reset\r\n");
fputs($connection, "show cable modem remote | inc $hwaddr\r");
fputs($connection, "exit\r");
}
{
fgets($connection, 128);
}
stream_set_timeout($connection, 2);
$timeoutCount = 0;
while (!feof($connection))
{
$content = fgets($connection, 128);
echo $content."<br>";

}
$info = stream_get_meta_data($connection);
if ($info['timed_out'])
{
// If timeout of connection info has got a value, the router not returning a output.
$timeoutCount++;
// We want to count, how many times repeating.
}
 if ($timeoutCount >2)
 {
 // If repeating more than 2 times,
 break;
 // the connection terminating..
 }

 ?> 


布拉德给了我获得所需结果所需的提示,再次感谢你的
检查输入()。看到这一点:您非常容易受到SQL注入攻击。学习使用准备好的/参数化的查询来完全避免这个问题。谢谢你,Brad,今天早上我会研究这个问题,因为我是php新手,所以任何人能提供的建议我都会公开接受。主要的是要确保你只使用了你需要的转义函数。没有什么神奇的功能可以让事情变得“安全”。您在那里所做的一切就是在不增加任何安全性的情况下将数据弄乱。对上下文使用适当的函数。然后,学习PDO和准备/参数化查询,这样您就不必担心SQL注入。@brad修改的代码更接近您的想法。您的DB代码看起来不错!现在是连接部分。。。您提到它在自己的脚本中工作。您是否以不同的方式执行该脚本?您是否看到初始DB插入后的“完成”回音?如果脚本到达打开套接字的位置,请尝试使用数据包嗅探器(如Wireshark)查看该连接的情况。