Html form to submit data to bash script

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 -

<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 -

Legacy Link Deleted

my bash script -

#!/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

You are expecting the form elements user and passwd to be converted to shell variables and exported to your scripts environment before calling it. It doesn't happen that way (unless there is an apache module for that).
You need something like:

if [ "$REQUEST_METHOD" = "POST" ]
then
   tr '&' '\n' > /tmp/mycgi$$
   echo >> /tmp/mycgi$$
fi
if [ "$REQUEST_METHOD" = "GET" ]
then
   printf "%b\n" "${QUERY_STRING//&/\\n}" > /tmp/mycgi$$
fi
while read line
do
   line=${line//+/ }
   kword=${line%=*}
   val=${line#*=}
   # deal with keyword/value pair here
done < /tmp/mycgi$$
rm /tmp/mycgi$$

Andrew

2 Likes

wow that script looks hard

A lot of it is standard Bash programming. You'll get used to it.

Andrew