#!/usr/bin/python # Self-modifing Page Counter # Copyright (C) 2021 Neil Fraser, California # https://neil.fraser.name/ # This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. http://www.gnu.org/ # This script is designed to be included in an SHTML document. # e.g. # There is no data file to hold the current page count. Instead, # the script completely rewrites itself each time it executes. Note # that these comments will vanish after the first successful execution. # Change this variable to point at this script: filename = '/home/httpd/cgi-bin/counter.py' n = 1 print('Content-type: text/html' + chr(10) + chr(10) + str(n)) # Here be dragons... t = "#!/usr/bin/python%cn = %d;print('Content-type: text/html' + chr(10) + chr(10) + str(n));t = %c%s%c;f = open('" + filename + "', 'w');f.write(t %% (10, n + 1, 34, t, 34));f.close()" f = open(filename, 'w') f.write(t % (10, n + 1, 34, t, 34)) f.close()