Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   help needed for internet lockout (http://www.programmingforums.org/showthread.php?t=10591)

Delryn Jul 1st, 2006 1:56 PM

help needed for internet lockout
 
Hey folks
I'm new to this forum, so try not to hurt me too much....I might like it and stick around

Anyway..
I'm trying my hand at bash scripting, starting with something that should be relatively simple.. Locking a teenage daughter out of the internet

I've kinda figured out the means of doing it
and the logistics of it
I just need a bit of help with the small things......
like coding it


Heres what I have at this point (I'll get to the actual questions at the end)

Variables:
- Status (another name may be more applicable)
0=out of time / grounded
1=default (X number of minutes per week)
2=school projects / good behavior (Y number of minutes added to X)
3=holidays (Z number of minutes replacing X)

- Schedule
a) restrictedstart (time of day when internet is denied to that user-probably 10pm)
b) restrictedend (when internet is allow again-probably 6am)
c)schoolstart (time of day that school starts - this would only affect mon-fri)
d)schoolend (I think you get the picture)

- TimeLeft
a clock/timer that counts down X

Using these variables pulled from a . file in the users $home
I figure that I can control the weekly duration online. I think that I have figured out most of the conditional factors with regards to the above variables. Not coded, just figured out.

At this point what I need help with is:
determining if there are any internet accessing programs currently running, I presume the info has to coaxed out of ifconfig?

how can I take the current time and tell if it falls within the restricted (7days a week) or the school (5days/week)

if you can point me in the right direction it would be greatly appreciated, if you post code can I ask for detail documentation (I'm a bit slow learning new commands)

Thanks

Delryn Jul 1st, 2006 2:27 PM

Just found this part out

ifconfig eth0 |grep bytes|cut -d":" -f2|cut -d" " -f1
ifconfig eth0 |grep bytes|cut -d":" -f3|cut -d" " -f1

run this through a loop a few times adding the differences...
should provide a reasonable basis for internet activity

Arevos Jul 1st, 2006 3:16 PM

Quote:

Originally Posted by Delryn
At this point what I need help with is:
determining if there are any internet accessing programs currently running, I presume the info has to coaxed out of ifconfig?

The lsof command lists open files on Linux systems. This includes IP connections (as everything in Unix is a file, yada yada). To list all open network connections:
:

lsof -i
To restrict this to external addresses (-n to remove hostnames):
:

lsof -i -n | egrep -v '\->(10\.|192\.168\.|127\.0\.0\.1)'
Well, you get the idea.

If you haven't thought of it already, the Linux firewall (iptables) is a good tool to use if you want to restrict network access in some fashion (either incoming, or outgoing). One could have a cron job that stops network access at X time, and another that enables it at Y.

Quote:

Originally Posted by Delryn
how can I take the current time and tell if it falls within the restricted (7days a week) or the school (5days/week)

Might have to use a smidgen of Perl or Python for this, unless anyone knows any CLI commands that can do this. Why do you need this functionality, though? Isn't it just a case of enabling access at a certain time, and disabling it at another?

Delryn Jul 2nd, 2006 3:03 PM

Quote:

Originally Posted by Arevos
If you haven't thought of it already, the Linux firewall (iptables) is a good tool to use if you want to restrict network access in some fashion (either incoming, or outgoing). One could have a cron job that stops network access at X time, and another that enables it at Y.

Might have to use a smidgen of Perl or Python for this, unless anyone knows any CLI commands that can do this. Why do you need this functionality, though? Isn't it just a case of enabling access at a certain time, and disabling it at another?

Thanks for the reply
I had looked at iptables, and I will be using them to help filter the content on my computer. As for the timing, this is a shared computer. So I can't just arbitrarily have the system shutdown the internet.

So I need to figure away of determining if the current user is allowed to be using the net at that specific time.

Arevos Jul 2nd, 2006 3:22 PM

Quote:

Originally Posted by Delryn
I had looked at iptables, and I will be using them to help filter the content on my computer. As for the timing, this is a shared computer. So I can't just arbitrarily have the system shutdown the internet.

Using iptables, it's possible to write firewall rules that only apply to packets sent from certain users or groups of users. Here's a short article on how to achieve this.

Presumably, you could have a series of cron jobs that enable/disable access on a per group basis. Thus, all users in a particular group would have their net access revoked from, say, 10pm to 6am, whilst those users not in that group would have free access. One could use iptables-save to construct several rulesets, and then use iptables-restore to update the firewall to use these rulesets at certain times.


All times are GMT -5. The time now is 7:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC