Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

scripting help with errors

  • 16-04-2004 05:47PM
    #1
    Banned (with Prison Access) Posts: 13,016 ✭✭✭✭


    first of all using redhat 9 php and apache

    right have this script and i want to call it from php so that it will let certain ipaddress/macadress access the net via iptables

    can do this staticly but want to do it dynamicly which means when a users logs on the script will be call and the mac address will be inserted into the iptable and will open the net for a user (the users will be wireless clients)

    anyway have 4 scripts that will do the job but a number of errors remain
    i had a premature header error but got rid of it by entering a echo content-type/plain
    echo at the top of each script

    but now im getting the following error from the error log in the apache folder

    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 9: /root/user/apache/logs/users.txt: No such file or directory
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/add: line 9:
    : command not found
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 12:
    : command not found
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 13:
    : command not found
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 14:

    the file users.txt does exist in that folder!!

    and what the hell is up with those password errors!?
    i have no references to passwords or nothing

    ight as well post up the script as well

    [PHP]#!/bin/bash
    #
    echo Content-type: text/plain
    echo
    read ip_address
    IPTABLES=/sbin/iptables

    sudo arp > /root/users/apache/logs/users.txt

    sudo awk '{if ($1 == "'"$ip_address"'") print $3}'
    /root/users/apache/logs/users.txt |
    /root/users/www/cgi-bin/add
    sudo $IPTABLES -t nat -A POSTROUTING -s $ip_address -j MASQUERADE[/PHP]

    the others are more or less the same and i get the password errors from them too and a nice error on a line where there is no text (typical!)
    if i can debug one script ill be able to do the rest no problem at all

    when i run the above script from a treminal i get
    Content-type: text/plain and the i freezes on me


Comments

  • Registered Users, Registered Users 2 Posts: 1,848 ✭✭✭flamegrill


    Originally posted by jank
    first of all using redhat 9 php and apache

    right have this script and i want to call it from php so that it will let certain ipaddress/macadress access the net via iptables

    can do this staticly but want to do it dynamicly which means when a users logs on the script will be call and the mac address will be inserted into the iptable and will open the net for a user (the users will be wireless clients)

    anyway have 4 scripts that will do the job but a number of errors remain
    i had a premature header error but got rid of it by entering a echo content-type/plain
    echo at the top of each script

    but now im getting the following error from the error log in the apache folder

    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 9: /root/user/apache/logs/users.txt: No such file or directory
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/add: line 9:
    : command not found
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] Password:
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 12:
    : command not found
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 13:
    : command not found
    [Fri Apr 16 19:28:57 2004] [error] [client 192.168.1.49] /root/user/www/cgi-bin/change: line 14:

    the file users.txt does exist in that folder!!

    and what the hell is up with those password errors!?
    i have no references to passwords or nothing

    ight as well post up the script as well

    [PHP]#!/bin/bash
    #
    echo Content-type: text/plain
    echo
    read ip_address
    IPTABLES=/sbin/iptables

    sudo arp > /root/users/apache/logs/users.txt

    sudo awk '{if ($1 == "'"$ip_address"'") print $3}'
    /root/users/apache/logs/users.txt |
    /root/users/www/cgi-bin/add
    sudo $IPTABLES -t nat -A POSTROUTING -s $ip_address -j MASQUERADE[/PHP]

    the others are more or less the same and i get the password errors from them too and a nice error on a line where there is no text (typical!)
    if i can debug one script ill be able to do the rest no problem at all

    when i run the above script from a treminal i get
    Content-type: text/plain and the i freezes on me


    The use of sudo will prompt for a password.

    Best thing for this sort of thing is pop the details into a db and cron a script run by root every minute to add it or run the daemon as root.

    Paul


  • Registered Users, Registered Users 2 Posts: 1,848 ✭✭✭flamegrill


    or if a cron job isn't quick enough?

    a shell script doing the following:

    while (true) do
    /path/to/some/file/to/run/every/10/seconds.sh
    sleep 10
    done

    simply set the sleep option to what ever you want.

    Paul


  • Banned (with Prison Access) Posts: 13,016 ✭✭✭✭jank


    wouldnt it be easier to just set the no password option in the sudoers file

    root ALL=(ALL) NOPASSWD: ALL

    would that work!?
    does the scripts have to be owned by root for this to work


  • Closed Accounts Posts: 97 ✭✭rde


    root ALL=(ALL) NOPASSWD: ALL
    I get a nosebleed every time I read someone, somewhere suggesting this; anything that'll allow sudo su - should be avoided like several plagues. By all means use sudo, but set up a User_Alias and a Cmnd_Alias instead. The syntax is a trifle arcane if you're not used to it, but it's nothing a quick man visudo shouldn't sort out.


Advertisement