__init__.py :  » Blog » Frog » FrogComplete-1.8 » webapps » filemgr » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Blog » Frog 
Frog » FrogComplete 1.8 » webapps » filemgr » __init__.py
# configuration for this webapp

from filemgr.users import FileUser
import filemgr.snakelets
import os

import logging
log=logging.getLogger("Snakelets.logger")

name="File Manager"
docroot="docroot"
sessionTimeoutSecs=30*60     # 30 minutes
sharedSession=False          # set to True, then also set Frog's one to True --> single signon

defaultOutputEncoding="UTF-8"


# The required privilege is "filemgr_access";
# this is set in the special filemgr user object (filemgr/users.py)
authorizationPatterns={ 
    "*": ["filemgr_access"],   
    "login.y": None,
    "cookiecheck.y": None,
    "about": None,
    "*.css": None,
    "*.js": None
}

def documentAllower(path):
    return True  # allow all (even .py files)

authenticationMethod = ("loginpage", "login.y")

snakelets= { 
    "download" : filemgr.snakelets.DownloadFile
}

configItems = {

    # The authorised users.
    # Use the 'mkuser.py' script to help adding new users.
    # (if you use frog and SharedAuth, you can leave this... it will use Frog's userbase)
    "knownusers" : {
        "user": FileUser("user", None, "/home/user", passwordhash="c0dedbad"),  # XXX set this to correct values
    },
    
}


#
#   USER AUTHORIZATION 
#
def authorizeUser(authmethod, url, username, password, request):
    # try to use shared auth (used with Frog webapp)
    try:
        sharedauth=request.getWebApp().server.getPlugin("SharedAuth")
        result=sharedauth.authorizeUser(authmethod, url, username, password, request)
        if result:
            # auth success!
            # but, FileMgr requires FileUser objects instead of regular LoginUser objects,
            # so we have to convert it. The directory is set by the other auth method.
            return FileUser(result.userid, result.name, result.directory, result.password.encode("hex"))
    except KeyError:
        # no shared auth available
        pass
    # no shared auth available, or shared auth failed. 
    if username in configItems["knownusers"]:
        user = configItems["knownusers"][username]
        if user.checkPassword(password):
            return user
    return None


#
#   WEBAPP INIT
#
def init(webapp):
    import snakeserver.server
    version=snakeserver.server.SNAKELETS_VERSION.split()[1]
    if version.lower().endswith("cvs"):
        version=version[:-3]
    if float(version)<1.42:
        msg="FileMgr requires Snakelets version 1.42 or newer"
        print "ERROR:",msg
        raise RuntimeError(msg)
    os.umask(0077) # protect written files, only readably by current user.
    import mimetypes
    mimetypes.types_map[".java"]="text/x-java-source"
    mimetypes.types_map[".log"]="text/x-logfile"
    mimetypes.types_map[".conf"]="text/x-configfile"
    mimetypes.types_map[".sh"]="text/x-shell-script"

    
def close(webapp):
    pass

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.