Changeset 3841

Show
Ignore:
Timestamp:
12/16/08 13:16:38 (4 years ago)
Author:
rcarvalho
Message:
 
Location:
branch/UmitWeb
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branch/UmitWeb/share/umit/config/umitweb.conf

    r3587 r3841  
    9898enable_highlight = True 
    9999 
    100 [paths] 
    101 config_file = config/umit.conf 
    102 umit_icon = share/icons/umit/umit_48.ico 
    103 nmap_command_path = nmap 
    104 locale_dir = share/locale 
    105 misc_dir = misc 
    106 icons_dir = share/icons/umit 
    107 pixmaps_dir = share/pixmaps 
    108 config_dir = /home/rodox/.umit 
    109 docs_dir = docs 
    110  
    111100[port_list_highlight] 
    112101regex = PORT\s+STATE\s+SERVICE(\s+VERSION)?.* 
     
    117106underline = 0 
    118107 
     108[web] 
     109server_port = 8859 
     110server_address = 0.0.0.0 
     111requires_root = true 
  • branch/UmitWeb/umitCore/BasePaths.py

    r3232 r3841  
    4747 
    4848base_paths = dict(config_file = 'umit.conf', 
    49                   webconfig_file = 'umitweb.conf', 
    50                   security_file = 'security.xml', 
    5149                  config_dir = '.umit', 
    5250                  user_dir = os.path.join(HOME, '.umit'), 
     
    7371                  i18n_search_sequence = [os.path.join(CURRENT_DIR, LOCALE_DIR), HOME], 
    7472                  umitdb = "umit.db", 
    75                   umitdb_web = "umitweb.db", 
    7673 
    7774                  services = "nmap-services", 
  • branch/UmitWeb/umitWeb/Database.py

    r1263 r3841  
    2424from types import ListType 
    2525from traceback import print_exc 
     26from umitWeb.WebPaths import WPath as Path 
    2627 
    2728try: 
     
    3233    import pysqlite2 as sqlite 
    3334 
    34 #Temporary - waiting instructions about UmitConf 
    35 __connection__ = dbmodule.connect(os.path.join("web.db")) 
     35try: 
     36    webdb = Path.web_db 
     37except: 
     38    webdb = os.path.join(Path.config_dir, "web.db") 
     39    Path.web_db = webdb 
     40     
     41__connection__ = dbmodule.connect(Path.web_db) 
    3642 
    3743 
  • branch/UmitWeb/umitWeb/Server.py

    r1332 r3841  
    3434from umitWeb.WebLogger import getLogger 
    3535from umitWeb.Security import Context 
     36from umitWeb.WebPaths import WPath as Path 
    3637from threading import Thread 
    3738 
     
    260261     
    261262    def __init__(self): 
    262         HTTPServer.__init__(self, ("0.0.0.0", 8059), UmitRequestHandler) 
     263        HTTPServer.__init__(self, (Path.web_server_address, int(Path.web_server_port)), UmitRequestHandler) 
    263264        UmitWebServer.currentInstance = self 
    264265         
  • branch/UmitWeb/umitWeb/WebPaths.py

    r3810 r3841  
    1717# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
    1818 
    19 from os.path import join, split, exists 
    20 from umitCore.BasePaths import base_paths, HOME 
     19from os.path import join, split, exists, dirname 
     20import re 
     21from umitCore.BasePaths import base_paths, HOME, CONFIG_DIR 
    2122from umitCore.Paths import Paths, Path, copy_config_file 
    2223 
     
    2526 
    2627base_paths.update(dict(webconfig_file='umitweb.conf', 
    27                        security_file='security.xml')) 
     28                       config_file='umitweb.conf', 
     29                       security_file='security.xml', 
     30                       web_db=join('share', 'config', 'web.db'))) 
    2831                        
    2932class WebPaths(Paths): 
    3033    templates_dir = TEMPLATES_DIR 
    3134    media_dir = MEDIA_DIR 
     35    web_section = "web" 
    3236     
    3337    def __init__(self): 
     
    4145            "webconfig_file", 
    4246            "security_file", 
    43             "umitdb_web" 
     47            "web_db" 
     48        ] 
     49         
     50        self.web_settings = [ 
     51            "web_server_port", 
     52            "web_server_address", 
     53            "web_requires_root" 
    4454        ] 
    4555     
     
    5060           not exists(join(self.config_dir, "umitweb.conf")): 
    5161           create_web_files(self.config_file, HOME) 
     62            
     63    def __getattr__(self, name): 
     64        if self.config_file_set: 
     65            try: 
     66                attr = Paths.__getattr__(self, name) 
     67                return attr 
     68            except NameError, e: 
     69                if name in self.web_settings: 
     70                    return self.config_parser.get(self.web_section, re.sub(r"^web_", "", name)) 
     71                else: 
     72                    raise e 
     73        else: 
     74            raise Exception("Must set config file location first") 
    5275 
    5376 
    5477def create_web_files(config_file, user_home): 
    5578    user_dir = join(user_home, base_paths['config_dir']) 
    56     main_dir = split(config_file)[0] 
     79    main_dir = join(dirname(__file__), CONFIG_DIR) 
    5780    copy_config_file("security.xml", main_dir, user_dir) 
    5881    copy_config_file("umitweb.conf", main_dir, user_dir) 
  • branch/UmitWeb/umitweb.py

    r3810 r3841  
    4040 
    4141def main(): 
    42     if sys.platform in ["linux", "darwin"]: 
    43         if os.getuid() != 0: 
    44             raise Exception, "Server MUST run as root." 
     42    if Path.web_requires_root in ["true", "on", "1"]: 
     43        if sys.platform in ["linux", "darwin"]: 
     44            if os.getuid() != 0: 
     45                raise Exception, "Server MUST run as root." 
    4546         
    4647    server = UmitWebServer() 
    4748    try: 
    48         print "UmitWebServer started on 0.0.0.0:8059" 
     49        print "UmitWebServer started on %s:%d" % (Path.web_server_address, int(Path.web_server_port)) 
    4950        server.run() 
    5051    except KeyboardInterrupt: