diff --git a/admin_cb.py b/admin_cb.py new file mode 100755 index 0000000..ff8b6c9 --- /dev/null +++ b/admin_cb.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import cgi +import cgitb +cgitb.enable() + +from urllib import unquote +import sys, os + +# Modify this to point to where you usually run planet. +BASE_DIR = '..' + +# Modify this to point to your venus installation dir, relative to planet dir above. +VENUS_INSTALL = "venus" + +# Config file, relative to planet dir above +CONFIG_FILE = "config/live" + +# Admin page URL, relative to this script's URL +ADMIN_URL = "admin.html" + + +# chdir to planet dir - config may be relative from there +os.chdir(os.path.abspath(BASE_DIR)) + +# Add venus to path. +sys.path.append(VENUS_INSTALL) + +# Add shell dir to path - auto detection does not work +sys.path.append(os.path.join(VENUS_INSTALL, "planet", "shell")) + +# import necessary planet items +from planet import config +from planet.spider import filename + + +# Load config +config.load(CONFIG_FILE) + +# parse query parameters +form = cgi.FieldStorage() + + +# Start HTML output at once +print "Content-Type: text/html;charset=utf-8" # HTML is following +print # blank line, end of headers + + +print '' +print '
Unknown command
" + +elif form['command'].value == "blacklist": + + # find list of urls, in the form bl[n]=url + + for key in form.keys(): + + if not key.startswith("bl"): continue + + url = unquote(form[key].value) + + # find corresponding files + cache_file = filename(cache, url) + blacklist_file = filename(blacklist, url) + + # move to blacklist if found + if os.path.exists(cache_file): + + os.rename(cache_file, blacklist_file) + + print "Blacklisted " + url + "
" + + else: + + print "Unknown file: " + cache_file + "
" + + +elif form['command'].value == "run": + + # run spider and refresh + + from planet import spider, splice + try: + spider.spiderPlanet(only_if_new=False) + print "Successfully ran spider
" + except Exception, e: + print e + + doc = splice.splice() + splice.apply(doc.toxml('utf-8')) + +elif form['command'].value == "refresh": + + # only refresh + + from planet import splice + + doc = splice.splice() + splice.apply(doc.toxml('utf-8')) + + print "Successfully refreshed
" + +elif form['command'].value == "expunge": + + # only expunge + from planet import expunge + expunge.expungeCache() + + print "Successfully expunged
" + + + + +print "Return to admin interface
" + + + +print ""