Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from stappersg/cgibin_example
Add a CGI-bin example Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/python3 | ||
|
||
import cgi | ||
import cgitb | ||
import datetime | ||
|
||
|
||
cgitb.enable(display=0, logdir="/var/log/onboard") | ||
|
||
# Create instance of FieldStorage | ||
form = cgi.FieldStorage() | ||
|
||
# Get data from fields | ||
if form.getvalue('username'): | ||
username = form.getvalue('username') | ||
else: | ||
username = "username" | ||
|
||
if form.getvalue('gecos'): | ||
gecos = form.getvalue('gecos') | ||
else: | ||
gecos = "gecos" | ||
|
||
if form.getvalue('sshkey'): | ||
sshkey = form.getvalue('sshkey') | ||
else: | ||
sshkey = "no_sshkey entered" | ||
|
||
mmss = datetime.datetime.now().strftime("%M%S") | ||
f = open("/var/www/onboard/file/%s.text" % mmss, "w") | ||
f.write("# k:v, k:v, separator, line(s)\n") | ||
f.write("username: %s\n"% username) | ||
f.write("gecos: %s\n"% gecos) | ||
f.write("# SSH public key(s)\n") | ||
f.write("%s\n"% sshkey) | ||
f.close() | ||
|
||
print("Content-type:text/html") | ||
print() # separator | ||
print("<html>") | ||
print("<head>") | ||
print("<title>So far</title>") | ||
print("</head>") | ||
print("<body>") | ||
print("<p>Hello %s</p>" % username) | ||
print('<p>There is now <a href="/onboard/file/%s.text">file/%s.text</a>.</p>' % (mmss,mmss)) | ||
print("<p>It has to be further processed, outside this <i>web form stuff</i></p>") | ||
print('<p><a href="/onboard/">Back to <b>onboard begin</b></a></p>') | ||
print("</body>") | ||
print("</html>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
For Your Information | ||
|
||
This text file helps | ||
* to tell that CGI-bin/onboard_ask.py writes files in this directory | ||
* showing that created files are visible | ||
|
||
(And this file ensures that git is aware of the onboard/file/ directory.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<html> | ||
<head/> | ||
<body> | ||
<h3>Welcome</h3> | ||
<p> | ||
Please provide information for SSH access. | ||
</p> | ||
|
||
<form action = "/cgi-bin/onboard_ask.py" method = "post"> | ||
Your preferred user name: <br/> | ||
(Example: <i>ws</i>)<br/> | ||
<input type = "text" name = "username"/> <br/> | ||
<br/> | ||
Gecos, the fifth field in a <tt>/etc/passwd</tt> record: <br/> | ||
(Example: <i>Winston Smith</i>)<br/> | ||
(Example: <i>Winston Smith,room,phone,home phone,other</i>)<br/> | ||
<input type = "text" name = "gecos"/> <br/> | ||
<br/> | ||
Public part of SSH key you gonna use: <br/> | ||
<textarea name = "sshkey" cols = "72" rows = "6"> | ||
something like | ||
cat ~/.ssh/id_algoritm.pub | ||
</textarea> <br/> | ||
|
||
<input type = "submit" value = "Submit" /> | ||
</form> | ||
<body> | ||
</html> |