CentOSThis forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
#not declared or $USER gets current user logged name
#see code block below;
#so this can never work $user it has no value within the var
# $passwd cannot work it has not been declared nor a value
#
# after that everything else fails.
Your bash script has to parse the form variables from the QUERY_STRING environment variable.
In addition your bash script needs to be in the /var/www/cgi-bin directory.
Is selinux active? If so you need to permit script execution.
By default useradd requires root privileges. You could setup sudo and add the apache user to the sudoers file to run useradd although it is a bit of a security risk.
You should add some checks to verify the new user does not already exist as well as verify that username and password only contain valid characters.
This is old but does show an example of a bash cgi-bin script.
I have echo and a read commands for both the user and passwd commands
echo "Enter UserName:"
read user
echo "Enter Password:"
read passwd
Code:
read -p "hey you what's your name. hummmm? " user
read -sp "so $user - you know I am going to need a password to get any further
care to provide me with one, hummm? " passwd
As I said to someone who wanted to do something similar, this is very dangerous, especially when exposed to everyone on the Internet. Of course such a thing is possible, but you need to think carefully about the wisdom of doing it.
Web html forms run as apache user not root and as stated can not run useradd by default. Again by allowing apache to run useradd your exposing your system to possible exploits. You need to filter the user name and limit length to 32.
this is my actual script, the script above i edited as i just wanted the script to add the ftp account and not do the echo/read and if statements as i wanted the html to do that bit
#!/bin/bash
dir=/mnt/sftp
group=sftp_users
echo "Enter UserName:"
read user
if id $user ; then
echo "$user already exists as you can see above, please re-run the script"
exit
else
echo "$user not in system, ok to continue"
fi
You need to write a new script to parse the form post inputs and not use read statements. Although you can write the script in just about any language the most common to use for web development is typically php, ruby, perl or python for linux.
thanks michael, mmm may need to learn another programming language other than bash, i thought i could do all this via html intergrating with my bash script
i have read the post you linked, wheres the command to pass the variable from the html to the bash script?
Last edited by robertkwild; 07-18-2017 at 06:51 AM.
We seem to be going around in circles. Read the link. Do some research on cgi , dynamic html programming. Also reread the posts and consider the security implications.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.