2017-05-27 18:09:50 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# write out proxy definitions for zim currently loaded
|
|
|
|
|
|
|
|
import os, sys, syslog
|
|
|
|
|
2017-06-09 23:25:56 +00:00
|
|
|
iiab_zim_path = "/library/zims"
|
2017-05-27 18:09:50 +00:00
|
|
|
kiwix_apache_config = "/etc/apache2/sites-available/kiwix.conf"
|
|
|
|
|
|
|
|
def main ():
|
2017-06-09 23:25:56 +00:00
|
|
|
content = iiab_zim_path + "/content/"
|
|
|
|
index = iiab_zim_path + "/index/"
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
# remove existing file
|
|
|
|
try:
|
|
|
|
os.remove(kiwix_apache_config)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
with open(kiwix_apache_config, 'w') as fp:
|
|
|
|
fp.write("RewriteEngine on\n")
|
|
|
|
fp.write("ProxyPreserveHost on\n")
|
2017-06-16 22:51:15 +00:00
|
|
|
fp.write("ProxyPass /kiwix http://127.0.0.1:3000\n")
|
|
|
|
fp.write("ProxyPassReverse /kiwix http://127.0.0.1:3000\n")
|
|
|
|
|
2017-05-27 18:09:50 +00:00
|
|
|
for filename in os.listdir(content):
|
|
|
|
zimpos = filename.find(".zim")
|
|
|
|
if zimpos != -1:
|
|
|
|
filename = filename[:zimpos]
|
2017-06-16 22:51:15 +00:00
|
|
|
fp.write("RewriteRule %s(.*) http://127.0.0.1:3000/%s$1 [P]\n"% (filename,filename))
|
|
|
|
fp.write("ProxyPassReverse %s$1 http://localhost:3000/%s$1\n" % (filename,filename))
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
# Run the main routine
|
|
|
|
main()
|
|
|
|
|
|
|
|
# vim: tabstop=3 shiftwidth=3 expandtab softtabstop=3
|