Forum Moderators: coopster
1. I need a form that the people on my intranet can fill out and submit and it will input the information into a mysql database so I can convert and then inport the database into microsoft outlook contacts for my manager. This is an appartment complex network so we want certain info, such as email, apt #, name, etc. This is so we can communicate with the leasing residents without having to manually collect information from them. I also want to do a few verification checks before it can be submitted.
2. I then need to take a certain feild and add it to the bottom of a config txt file. This field will be a MAC address of their computer that they will enter for me. This is just a maclist file that the text needs to be inputed to for the user to get internet access through the firewall.
3. Finally I would also like to know if I could exectute a linux bash script with that mac address field so the user can have instant access to the internet. Without this, the user will have to wait until I reload my firewall for their mac address in the above config file to become active. It is a netfilter command that I need to run and the only variable for the command is the source mac address that would be coming from the form.
Any help to get my started would be great. I found a site that helps with PHP forms being placed into a database and I found a site that takes form data and inputs it into a text file but exectuting a script or running a bash command with one of the form fields I cannot find!
Thanks,
Dave
You're in luck. You came to the right place :)
Have a look at these two threads in our PHP Forum Library [webmasterworld.com]:
Basics of extracting data from MySQL using PHP [webmasterworld.com]
Basics of extracting data from CSV files [webmasterworld.com]
And to execute commands on the system itself, you have some options [us4.php.net].
Dave
On the note of the first two links, I need to store the data entered into the form into the mysql database, not extract. I want each person to access this site, enter all their info, click submit, and then it will add it to the database of people. So by the time everyone goes and fills this form out, I will have a list of all residents, their contact info, and most importantly, their mac address.
Also at the same time they submit this and it goes into the database, I want it to also place the mac address field into the end of a file on a new line which is a file on the same system as the server.
Finally, I will have to read up at that link you gave me, but I want to run "/sbin/iptables -I eth2_mac -m mac --mac-source <the MAC address field> -j RETURN" which will give the user instant access through the firewall to the internet.
So is there a previous post or any ideas on how to compile all these users to the one database and then input the mac address to the end of that file? Thanks again, i've been looking around this forum and everyone seems so helpful. I appreciate it.
Dave
really those links are just going at the mysql issue from the other side.
If you look at message 5 in the mysql thread steps 1, 2, 3 and 4 are the same with only minor variations.
1. connect
2. select db
3. build your query from your form data - in this step you are building an INSERT query instead of a SELECT query.
You will obviously have a form that will post to your insert script. It may look something like this
$sql = "INSERT INTO tablename VALUES ('" . $_POST['firstname'] . "','" . $_POST['lastname'] . "','" . $_POST['address'] . "','" . $_POST['email'] . "')";
Hard to say, it depends on what fields you have in your table which relies on what information you need to gather from your clients.
4. insert the info into mysql - this step is exactly the same just needs a new title for your situation.
As for the CSV thread, it gives the basics of working with files. fopen (for append), fwrite, fclose. These can be used to append the MAC address to the file where you store them.
You can then fire off your shell script using exec or passthru.
That help a bit?
Do I just write a regular html form and put the action as action="myaction.php". Or does the form also need to be in a .php and if it does, do I need to do anything special on that page? I just don't know much about php so I don't know if anything has to be added to the code. Like if I want to format the page, do I just use standard html for bg color, adding images, links, etc. Does have php installed just allow me to use it within the html? Sorry for the basic questions, i'm just very new to php and actually web coding in general. The company just wants to stay internal on this instead of paying the high prices of a coder.
Also, in the myaction.php I will be putting the steps 1-4 to add the info to the database, do I also put the commands to append the mac addresses to the config file just after the steps 1-4 of the database? And after that, can I just put the command for the exec script on the same page too?
Thanks,
Dave
do I just use the same exact statement
yep, the mysql_query function is used to send any type of query to mysql. The $query variable will hold a resource identifier which for an insert doesn't really matter, you could not even get the resource id if you wanted.
Do I just write a regular html form and put the action as action="myaction.php"
yep.
Does have php installed just allow me to use it within the html?
Part of the beauty of php is it weaves into html. If you want to do a little php then just put <? to turn on the parser in a .php page. When you have done what you need to turn it off with?> and then go back to regular old html.
do I also put the commands to append the mac addresses to the config file just after the steps 1-4 of the database? And after that, can I just put the command for the exec script on the same page too?
sure, no reason not to.
Warning: fopen(/etc/shorewall/user.mac): failed to open stream: Permission denied in /var/www/html/register.php on line 9
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/html/register.php on line 10
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/html/register.php on line 11
Thanks for registering MAC: 12-43-43-45-34
I setup everything just like others have and I set the permissions to 777 for the user.mac file. It will not work. Any ideas why?
I can give sudo permission for iptables which works but doesnt this open a security risk since if apache was conprimised, my firewall could then be modified through iptables?
Last, I have fwrite commands working and what i see in the file looks correct but when I restart my firewall, i get a command error. The text I store is $writemac = "" . "eth1 " . $mac . "\r\n"; The text appears as "eth1 00:11:22:33:44" which is correct but it gives an error. So i manually removed the space between the mac address and eth1 and then add it back again, it it works just fine. So for some reason fwrite is storing a weird blank space. Any way to keep this from happening?
Thanks.
Dave