Managing IPTables with API pref. php [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this questionIs there an API so I can manage IPTables with PHP, it's for a project to build a router with a browser login, kinda the same as a Fonera?
This may solve your problem. The tricky part is sudo for apache process and tracking, rest is standard php and iptables:
http://www.andybev.com/index.php/Using_iptables_and_PHP_to_create_a_captive_portal
I think easiest way would be to use exec() for firing IPtables commands. Maybe use your PHP to create a script and then execute that in the end. I don't think there is an "API" to control IPtables only the executable in a lot Linux Distributions.
You can install rfw which is the REST API for iptables and runs as a server with root privileges. Clients can use any HTTP API without special rights, so you can use curl from PHP to send commands to rfw.
Sample command:
PUT /drop/input/eth0/11.22.33.44
which corresponds to:
iptables -I INPUT -i eth0 -s 11.22.33.44 -j DROP
Disclaimer: I started that project.
精彩评论