Register
It is currently Wed Dec 13, 2017 12:44 pm

html form to submit data to bash script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon Jul 17, 2017 2:08 pm   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
hi all,

im going to design a web html form so users can input what username and password they want to make the ftp account, once they enter in a username and password they click on the submit button and it submits it to a bash script and then the bash script will run and finish of making the ftp account

the variables of both the html form and bash script are the same ie user passwd

it doesnt work, what am i doing wrong?

here is my html form page -
Code:
<form>
<form action="/scripts/create_user.sh" method="post">
Username:<br>
<input type="text" name="user"><br><br>
Password:<br>
<input type="text" name="passwd"><br><br>
<input type="submit" value="Submit">

</form>

what the form looks like -

https://s12.postimg.org/5rcs8rbb1/ftp_web.png

my bash script -
Code:
#!/bin/bash

dir=/sftp
group=sftpusers

echo "$user:$passwd" >> /ftp_details/accounts.csv

useradd -g $group -d $dir/$user -s /sbin/nologin $user
mkdir -p $dir/$user/data
chown root $dir/$user
chmod 755 $dir/$user
chown $user $dir/$user/data
chmod 755 $dir/$user/data
touch $dir/$user/data/WARNING_everything_in_here_will_get_removed_in_14_days_time.txt

cheers,

rob


Top
 Profile  
 PostPosted: Tue Jul 18, 2017 7:04 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Did you check the link you posted?
There is no form.

Which webserver is running?
Do you use cgi? Whatelse?

How get the vars user and password get set?


Top
 Profile  
 PostPosted: Thu Jul 20, 2017 3:37 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
the link works, this is just a simple html form i have made using the html codes (in first post)

the webserver is a centos 7 machine with apache installed

i use cgi for the bash script to run as i have put it in the /var/www/cgi-bin/createuser.sh

thats the thing i want to know how you go about getting the variables from html form passed to the bash script


Top
 Profile  
 PostPosted: Thu Jul 20, 2017 4:16 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Read about the CGI here: https://en.wikipedia.org/wiki/Common_Gateway_Interface#Using_CGI_scripts

To see, what's going on use in your script a simple
Code:
echo $*


It is bloody dangerous to do this.

Consider this URL:
http://your.webserver.tld/createuser.sh?user="exec rm -rf ."

In real live the above URL will be urlencoded and works for a GET request.
POST request are slightly different.
But i think you get the point.

NEVER EVER EXPOSE CGI WITHOUT PROPER MEASURES TO FIGHT ALL THREATS!!!
USE A WEBFRAMEWORK HAVING ALL THESE THINGS BUILD IN!!!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP