Skip to content

Commit 3579bca

Browse files
committed
README, including instructions for use with Arch+Apache.
1 parent 337883a commit 3579bca

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

README

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Warning
2+
-------
3+
4+
Use at your own risk -- cgi-bin is powerful and thus has many serious
5+
security implications.
6+
7+
8+
Installation
9+
------------
10+
11+
This example was designed for an Ubuntu installation of apache2 (see
12+
discussion of Arch , below); maybe you can just run
13+
14+
sudo make install
15+
sudo apache2ctl restart
16+
17+
and it will work. You should probably check the paths at the top of
18+
Makefile and test.apache to confirm that they correspond to your
19+
system's web root.
20+
21+
Then browse to http://localhost/ajex/test.php to see what has been
22+
installed.
23+
24+
25+
Debugging
26+
---------
27+
28+
You should see a dumb web form at http://localhost/ajex/test.php. If you
29+
don't, then the files are not getting installed into the right place
30+
for your web server.
31+
32+
When the cgi-bin is working, you'll see a line with the date, and it
33+
will update whenever you click a Submit button. If you see the form,
34+
but it doesn't "work", then the cgi-bin part of the web-server isn't
35+
working. Browse to http://localhost/ajex/cgi-bin/test.py. If you see
36+
the text of the python script, that's bad -- this is that security
37+
issue we warned (or will warn) you about. When cgi-bin is working,
38+
your browser should print some JSON data, like:
39+
40+
{"date": "Wed Feb 22 09:30:39 2017", "also": "Button=None",
41+
"message": "telescopes are 95"}
42+
43+
44+
Security
45+
--------
46+
47+
There are many dangers associated with cgi-bin. I think the two
48+
things that you should be really careful about, going forward, are:
49+
50+
- Assume that the code you have in the cgi-bin directory will, at some
51+
point, be readable by the public. This means that you can't store
52+
database passwords (and so on) in the scripts that live in your
53+
cgi-bin directory. Instead, have your cgi-bin executable, when it
54+
is run, call or import or load those secrets from some other part of
55+
the file-system that is not in the web server's DocumentRoot.
56+
57+
- Always "sanitize" input data before "doing" anything with it. The
58+
degree of sanitization required depends on what you're doing with
59+
it. This includes "escaping" strings that you're passing into
60+
database queries, or sanity checking inputs that you will be passing
61+
to other executables.
62+
63+
64+
Arch Linux
65+
----------
66+
67+
The default DocumentRoot for apache on Arch is /srv/http instead of
68+
/var/www. And "virtual hosts" are often sorted in
69+
/etc/httpd/conf/vhosts. So change the Makefile paths to say:
70+
71+
WEB_INSTALL=/srv/http/ajex
72+
CGI_INSTALL=/srv/http/ajex/cgi-bin
73+
CFG_INSTALL=/etc/httpd/conf/vhosts/ajex.conf
74+
75+
Before you make install, edit test.apache (which will become
76+
ajex.conf) so it's talking about the right directories:
77+
78+
sed -i 's/var\/www/srv\/http/g' test.apache
79+
80+
In the apache configuration, cgi scripts aren't enabled by default.
81+
To enable cgi-bin (note this is dangerous, you have been warned,
82+
etc.), edit /etc/httpd/conf/httpd.conf:
83+
84+
#LoadModule cgid_module modules/mod_cgid.so
85+
#LoadModule cgi_module modules/mod_cgi.so
86+
87+
and uncomment them. You can also tell httpd to include your virtual
88+
host. Somewhere near the end add:
89+
90+
Include conf/vhosts/ajex.conf
91+
92+
Because python3 is the default on Arch, you will probably have to
93+
change the top line of test.py to invoke python2, i.e.
94+
95+
#!/usr/bin/env python2
96+

0 commit comments

Comments
 (0)