Index: roundup/scripts/roundup_server.py =================================================================== RCS file: /cvsroot/roundup/roundup/roundup/scripts/roundup_server.py,v retrieving revision 1.16.2.3 diff -c -r1.16.2.3 roundup_server.py *** roundup/scripts/roundup_server.py 24 Apr 2003 04:28:33 -0000 1.16.2.3 --- roundup/scripts/roundup_server.py 25 Jul 2003 13:04:22 -0000 *************** *** 123,133 **** else: query = '' ! # figure the tracker if rest == '/': return self.index() l_path = rest.split('/') tracker_name = urllib.unquote(l_path[1]) if self.TRACKER_HOMES.has_key(tracker_name): tracker_home = self.TRACKER_HOMES[tracker_name] tracker = roundup.instance.open(tracker_home) --- 123,147 ---- else: query = '' ! # no tracker - spit out the index if rest == '/': return self.index() + + # figure the tracker l_path = rest.split('/') tracker_name = urllib.unquote(l_path[1]) + + # handle missing trailing '/' + if len(l_path) == 2: + self.send_response(301) + # redirect - XXX https?? + protocol = 'http' + url = '%s://%s%s/'%(protocol, self.headers['host'], self.path) + self.send_header('Location', url) + self.end_headers() + self.wfile.write('Moved Permanently') + return + if self.TRACKER_HOMES.has_key(tracker_name): tracker_home = self.TRACKER_HOMES[tracker_name] tracker = roundup.instance.open(tracker_home) *************** *** 174,183 **** if message: message = _('Error: %(error)s\n\n')%{'error': message} print _('''%(message)sUsage: ! roundup-server [-n hostname] [-p port] [-l file] [-d file] [name=tracker home]* -n: sets the host name -p: sets the port to listen on -l: sets a filename to log to (instead of stdout) -d: daemonize, and write the server's PID to the nominated file --- 188,199 ---- if message: message = _('Error: %(error)s\n\n')%{'error': message} print _('''%(message)sUsage: ! roundup-server [-n hostname] [-p port] [-g group name] [-l file] [-d file] [name=tracker home]* -n: sets the host name -p: sets the port to listen on + -g: sets the gid to this group after listening on the port + -u: sets the uid to this user after listening on the port -l: sets a filename to log to (instead of stdout) -d: daemonize, and write the server's PID to the nominated file *************** *** 251,257 **** try: # handle the command-line args try: ! optlist, args = getopt.getopt(sys.argv[1:], 'n:p:u:d:l:h') except getopt.GetoptError, e: usage(str(e)) --- 267,273 ---- try: # handle the command-line args try: ! optlist, args = getopt.getopt(sys.argv[1:], 'n:p:u:g:d:l:h') except getopt.GetoptError, e: usage(str(e)) *************** *** 260,269 **** --- 276,305 ---- if opt == '-n': hostname = arg elif opt == '-p': port = int(arg) elif opt == '-u': user = arg + elif opt == '-g': group = arg elif opt == '-d': pidfile = abspath(arg) elif opt == '-l': logfile = abspath(arg) elif opt == '-h': usage() + # obtain server before changing user id - allows to use port < 1024 if started as root + address = (hostname, port) + httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) + + if hasattr(os, 'getgid'): + # if root, setgid to the running user + if not os.getgid() and user is not None: + try: + import pwd + except ImportError: + raise ValueError, _("Can't change groups - no pwd module") + try: + gid = pwd.getpwnam(user)[3] + except KeyError: + raise ValueError, _("Group %(group)s doesn't exist")%locals() + os.setgid(gid) + elif os.getgid() and user is not None: + print _('WARNING: ignoring "-g" argument, not root') + if hasattr(os, 'getuid'): # if root, setuid to the running user if not os.getuid() and user is not None: *************** *** 283,288 **** --- 319,325 ---- if not os.getuid() and user is None: raise ValueError, _("Can't run as root!") + # handle tracker specs if args: d = {} *************** *** 301,307 **** # we don't want the cgi module interpreting the command-line args ;) sys.argv = sys.argv[:1] - address = (hostname, port) # fork? if pidfile: --- 338,343 ---- *************** *** 312,318 **** # appending, unbuffered sys.stdout = sys.stderr = open(logfile, 'a', 0) - httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) print _('Roundup server started on %(address)s')%locals() try: httpd.serve_forever() --- 348,353 ----