home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/env python2
- """startup script for webcleaner proxy"""
- import sys
- if sys.version[:5] < "2.0":
- raise SystemExit, "This program requires Python 2.0 or later."
- from webfilter import _,startfunc
- import WebCleanerConf
-
- Usage = _("USAGE\twebcleaner command\n"
- "\n"
- "COMMANDS\n"
- "start\n"
- " Start the proxy. If it is already started, do nothing.\n"
- "stop\n"
- " Stop the proxy. If it is already stopped, do nothing.\n"
- "restart\n"
- " Try to stop the proxy, then start it.\n"
- "reload\n"
- " If the proxy is running read the configuration files again.\n"
- " If it is not running, do nothing.\n"
- "status\n"
- " Print info if the proxy is running or not.\n")
-
-
- def printUsage(msg):
- sys.stderr.write(_("Error: %s\n") % msg)
- sys.stderr.write(_("Execute 'webcleaner -h' for help\n"))
- sys.exit(1)
-
-
- def paginate(text, lines=22):
- """print text in pages of lines size"""
- textlines = string.split(text, "\n")
- curline = 1
- for line in textlines:
- print line
- curline = curline + 1
- if curline >= lines and sys.stdin.isatty():
- curline = 1
- print _("press return to continue...")
- sys.stdin.read(1)
-
-
- def printHelp():
- if os.name!='posix':
- paginate(Usage)
- else:
- print Usage
- sys.exit(0)
-
-
-
- if __name__ == "__main__":
- # Read command line arguments
- import getopt,sys,string,os
- try:
- # Note: cut out the name of the script
- options, args = getopt.getopt(sys.argv[1:], "h", ["help","pidfile="])
- except getopt.error:
- type, value = sys.exc_info()[:2]
- printUsage(value)
-
- for opt,arg in options:
- if opt=="-h" or opt=="--help":
- printHelp()
- else:
- printUsage(_("Unknown option %s") % opt)
-
- if len(args) < 1: printUsage(_("No command given."))
- else:
- command=args[0]
- if len(args) > 1:
- sys.stderr.write(_("WebCleaner: warning, only first command is valid"))
- # start the command
- #errorlog = os.path.join(WebCleanerConf.config_dir, "error.log")
- #sys.stderr = open(errorlog, "a")
- from webfilter import daemon
- if command=='start':
- daemon.start(startfunc)
- elif command=='stop':
- daemon.stop()
- elif command=='restart':
- daemon.restart(startfunc)
- elif command=='reload':
- daemon.reload()
- elif command=='status':
- print daemon.status()
- else:
- printUsage(_("Unknown command %s") % command)
-