+ Responder ao Tópico



  1. #1

    Padrão Ajuda em um Codigo PHP, Via Comando

    olá. to tentando criar um arquivo php para agir junto com meu firewall.. so que nao sei como criar essa regra.
    são dois arquivos php!

    index.php

    <html>
    <head>
    <title>
    Administração by Rodolfo
    </title>
    </head>
    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
    <tr><td align="center" valign="middle">
    <table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr><td> </td></tr>
    <tr>
    <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color=red><b> Administração by Rodolfo </b></font></td>
    </tr>
    <tr><td bgcolor="#0000f2" height="2"></td></tr>
    <tr><td> </td></tr>
    <tr><td>
    <div align="center">
    <form action=cadastrar.php method=post>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> IP: <input type="text" name="ip" size="15" style="font-family: Courier New; border-style: dotted; border-color: #666666" maxlength="16"> MAC: MAIUSCULO <input type="name" name="mac" size="15" style="font-family: Courier New; border-style: dotted; border-color: #666666" maxlength="16"> <input type="submit" value="Cadastrar" style="border-style: double"><br>
    </font>
    </form>
    </div>
    </td></tr>


    cadastrar.php
    IRA EXECUTAR O SEGUINTE COMANDO

    shell_exec("/usr/bin/sudo /sbin/iptables -t filter -A FORWARD -d 0/0 -s $ip -m mac --mac-source $mac -j ACCEPT");
    shell_exec("/usr/bin/sudo /sbin/iptables -t filter -A FORWARD -d $ip -s 0/0 -j ACCEPT");
    shell_exec("/usr/bin/sudo /sbin/iptables -t nat -A POSTROUTING -s $ip -o eth0 -j MASQUERADE");
    shell_exec("/usr/bin/sudo /sbin/iptables -t nat -A POSTROUTING -s $ip -o eth0 -j MASQUERADE");
    shell_exec("/usr/bin/sudo /sbin/iptables -t filter -A INPUT -s $ip -d 0/0 -m mac --mac-source $mac -j ACCEPT");
    shell_exec("/usr/bin/sudo /sbin/iptables -t filter -A OUTPUT -s $ip -d 0/0 -j ACCEPT");

    minha duvida é como ligar esse cadastra.php para reconhecer o index.html e executar esse comando de acordo com oque eu digitar na index.


    Obrigado!

  2. #2

    Smile

    Voce ja esta passando os parametros por post no arquivo index. oque tem que fazer agora eh recupera-los no arquivo cadastra.
    Faça o seguinte:

    <?php

    //pagina cadastra.php

    $ip = $_POST['ip'];
    $mac = $_POST['mac'];



    ?>

    essa função ($_POST[]) recupera os parametrospassados pelo promulario post da pagina anterior, no caso, index.php. Agora que voce tem as variaveis definidas, é soh executar os comandos.
    para fazer o teste e ver se as variaveis foram mesmo recuperadas mande mostralas na tela:

    <?php

    echo $mac;
    echo $ip;

    ?>


    Espero ter ajudado.

  3. #3

  4. #4

    Padrão

    pode ser feito desta maneira tambem:

    Código :
    #!/usr/bin/php -q
    <?
    if ($_SERVER['argc'] > 1) {
       $mac = $_SERVER['argv']['1'];
       $ip = $_SERVER['argv']['2'];
     
       echo "MAC RECEBIDO: " . $mac . "\n";
       echo "IP RECEBIDO: " . $ip . "\n";
    }
    ?>

    ai vc executa o cadastro php assim:

    # cadastro.php 00:00:00:11:11:11 000.000.000.000