Example #1
0
def getTempPath(subdir=None):
	global _tmpPath, _firstRun, _subdirs, _instance
	assert ( _instance )

	if not _tmpPath:
		# TODO: read from config
		_tmpPath = '/tmp'
		# append apache user id
		_tmpPath += '/%s' % getCurrentUser()
		# append hash generated from instance unique location
		_tmpPath += '/%s' % _instance

	tempPath = _tmpPath

	if _firstRun:
		_firstRun = False
		_initTemp()

	if subdir:
		tempPath = tempPath+'/'+subdir
		if subdir not in _subdirs:
			logger.show('Creating %s...' % tempPath )
			assert( not os.system( 'mkdir -p %s' % tempPath ) )
			_subdirs.append( subdir )

	return tempPath
Example #2
0
def wsgi(environ, start_response):
    path = environ['PATH_INFO']
    simplePath = path.replace("/", "")
    if "HTTP_COOKIE" in environ:
        cookie = SimpleCookie(environ['HTTP_COOKIE'])
        environ['user'] = utils.getCurrentUser(cookie)
    else:
        environ['user'] = None
    if simplePath in handlers:
        return handlers[simplePath](environ, start_response)
    else:
        responseHeaders = utils.handleBadSessionIds(environ)
        responseHeaders.append(('Cache-Control', 'max-age=86400'))
        if path == '/':
            path = '/index.html'
        with open(
                utils.currentPath + '/static' + path,
                mode="rb",
        ) as stream:
            start_response('200 OK', responseHeaders)
            return [stream.read()]
Example #3
0
def wsgi(environ, start_response):
    path = environ['PATH_INFO']
    simplePath = path.replace("/", "")
    if "HTTP_COOKIE" in environ:
        cookie = SimpleCookie(environ['HTTP_COOKIE'])
        environ['user'] = utils.getCurrentUser(cookie)
    else:
        environ['HTTP_COOKIE'] = None
        environ['user'] = None
    if simplePath in handlers:
        return handlers[simplePath](environ, start_response)
    else:
        responseHeaders = utils.handleBadSessionIds(environ)

        permissionCookie = SimpleCookie(environ['HTTP_COOKIE'])
        if 'permissionLevel' in permissionCookie:
            cookiePermissionLevel = permissionCookie['permissionLevel'].value
            if environ['user'] is not None and str(
                    environ['user'].permissionLevel) != cookiePermissionLevel:
                cookie = cookies.SimpleCookie()
                cookie['permissionLevel'] = environ['user'].permissionLevel
                responseHeaders.append(
                    ('set-cookie', cookie.output(header='')))
        if path == '/':
            path = '/index.html'
        filePath = utils.currentPath + '/static' + path
        with open(
                filePath,
                mode="rb",
        ) as stream:
            statbuf = os.stat(filePath)
            if 'HTTP_IF_NONE_MATCH' in environ:
                if environ['HTTP_IF_NONE_MATCH'] == str(statbuf.st_mtime):
                    start_response('304 NOT MODIFIED', responseHeaders)
                    return [''.encode()]
            responseHeaders.append(('ETag', str(statbuf.st_mtime)))
            start_response('200 OK', responseHeaders)
            return [stream.read()]
Example #4
0
import logging
import sys

import env
from openapi import OpenAPI
import utils
from db import AppHistory


if __name__ == '__main__':
    
    machine, ipaddr = utils.getHostInfo()
    e = utils.Namespace()
    setattr(e, "machine", machine)
    setattr(e, "ipaddr", ipaddr)
    setattr(e, "username", utils.getCurrentUser())
    setattr(e, "program", "fanctl")
    
    def deployApp(args):
        OpenAPI("openapi", None, "deployApp",
                args=(args.brand.upper(), args.module.upper(), args.master_rev, args.config_rev),
                env=e).call()
                
    def rollbackApp(args):
        OpenAPI("openapi", None, "rollbackApp",
                args=(args.brand.upper(), args.module.upper()),env=e).call()

    def stopServer(args):
        # stopServer(args.brand, args.res)
        OpenAPI("openapi", None, "stopServer", args=(args.brand, args.res), env=e).call()