0

setip.php :

<?php
$IP_Addr = $_GET['ip'];
$NetMask = $_GET['ip2'];
$NetWork = $_GET['ip3'];
$Broad = $_GET['ip4'];
$DNS = $_GET['dns1'];

$cmd="sh /var/www/cgi-bin/ipset.sh ".escapeshellarg($IP_Addr)."".escapeshellarg($NetMask)."".escapeshellarg($NetWork)."".escapeshellarg($Broad)."".escapeshellarg($DNS);
 exec("$cmd");

example input : ip=10, ip2=20, ip3=30, ip4=40, dns1=10

ipset.sh :

#!/bin/bash -x
echo "IPADDR=$1"       >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETMASK=$2"     >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETWORK=$3"     >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "Broadcast=$4"   >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "DNS=$5"        >>/etc/sysconfig/network-scripts/ifcfg-eth0

result in ifcfg-eth0 :

IPADDR=1020304010
NETMASK=
NETWORK=
BROADCAST=
DNS=

any sugestion how to pass argument correctly ?

4
  • Try echoing out your command - does it look like it should? Does it work when you run it directly? It looks like you need to add spaces between the arguments.... Commented Dec 19, 2013 at 16:30
  • I think you need spaces between each argument. Commented Dec 19, 2013 at 16:31
  • And use shell_exec instead of exec Commented Dec 19, 2013 at 16:35
  • yes it works, forgt about the spaces ^^ Commented Dec 19, 2013 at 16:51

1 Answer 1

1

Solved, add space between argument.

  <?php
    $IP_Addr = $_GET['ip'];
    $NetMask = $_GET['ip2'];
    $NetWork = $_GET['ip3'];
    $Broad = $_GET['ip4'];
    $DNS = $_GET['dns1'];

    $cmd="sh /var/www/cgi-bin/ipset.sh ".escapeshellarg($IP_Addr)." ".escapeshellarg($NetMask)." ".escapeshellarg($NetWork)." ".escapeshellarg($Broad)." ".escapeshellarg($DNS);
     exec("$cmd");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.