コード例 #1
0
ファイル: util.py プロジェクト: sonientaegi/CELLAR_LEGACY
def restart(userinfo) :
    if not userinfo.isAdmin() :
        error("Only super user can reatart CELLAR.")
        return False
     
    info("CELLAR is being restarted by " + userinfo.username)
    call(["uwsgi", "--reload", "uwsgi.pid"])
コード例 #2
0
def dir_reset(fullPath = None):
    """
    Delete any or children index files of fullPath.
    @param fullPath replaces with ROOT if it is None.:  
    """    
    
    if fullPath is None :
        fullPath = config.ROOT
        
    if fullPath == config.ROOT :
        info("index.dir.reset.full : start")
    
    dir_del(fullPath)            
    for child in os.listdir(fullPath) :
        try : 
            childPath = fullPath + os.path.sep + child
            if os.path.isfile(childPath) : continue
            
            dir_reset(childPath)
        except Exception as err :  
            error("index.dir.reset : " + err.__str__())
    
    if fullPath == config.ROOT :
        ok("index.dir.reset.full : finished")
        
    return True
コード例 #3
0
    def load(self):
        try:
            info("Load configuration...")
            fp = None
            fp = open(os.path.join(BASE_DIR, "CELLAR/CELLAR.conf"))
            conf = json.load(fp)
            for key in conf:
                value = conf[key]
                if value == "true":
                    value = True
                elif value == "false":
                    value = False

                # globals()[key] = value
                vars(self)[key] = value
                # info("%30s = %s" % (key, value))
                info("{0:30s} = {1}".format(key, value))

                # for line in conf :
                #     match = re.search("(?P<param>[a-zA-Z_]*)\s*=\s*(?P<value>.*)", line)
                #     if not match :  continue
                #     param = match.group("param")
                #     value = match.group("value")
            ok("Load successfully!")
        except Exception as err:
            warn("Configuration file is not exists or broken.")
        finally:
            if fp: fp.close()
コード例 #4
0
ファイル: __init__.py プロジェクト: SonienTaegi/CELLAR
 def load(self) :
     try :
         info("Load configuration...")
         fp = None
         fp = open(os.path.join(BASE_DIR, "CELLAR/CELLAR.conf"))
         conf = json.load(fp)
         for key in conf :
             value = conf[key]
             if value == "true" :
                 value = True
             elif value == "false" :
                 value = False
             
             # globals()[key] = value
             vars(self)[key] = value
             # info("%30s = %s" % (key, value))
             info("{0:30s} = {1}".format(key, value))
         
             
             # for line in conf :
             #     match = re.search("(?P<param>[a-zA-Z_]*)\s*=\s*(?P<value>.*)", line)
             #     if not match :  continue
             #     param = match.group("param")
             #     value = match.group("value")
         ok("Load successfully!")                
     except Exception as err :
         warn("Configuration file is not exists or broken.")
     finally:
         if fp : fp.close()
コード例 #5
0
ファイル: util.py プロジェクト: sonientaegi/CELLAR_LEGACY
def deleteFiles(request, *args, **kwargs): 
    """
    return {
        ...
        exts : [(ext, errno), ...]
    }
     
    0 : 성공
    1 : 대상이 경로입니다
    2 : -
    3 : 허용되지 않은 요청입니다
    4 : 오류가 발생하였습니다
    5 : 권한 없음
    """     
    groupPath   = request.POST.get("groupPath")
    exts        = request.POST.getlist("exts[]")
     
      
    targetPath  = os.path.normpath(os.path.dirname(groupPath)) + "/"
    filegroup   = os.path.basename(groupPath)
    filenames   = []
    for ext in exts :
        filenames.append(filegroup + ext)
     
    fileManager = CELLAR_FileManager(request)
    resultSet   = fileManager.rmfiles(targetPath, filenames)
    result      = []
    code        = 0
    
    info("file.delete : {0}".format(fileManager.getFullPath(groupPath))) 
    for row in resultSet :
        ext = os.path.splitext(row[0])[1]
        result.append((ext, row[1]))
        if row[1] == 0 :
            ok("file.delete : {0}".format(ext))
        else :
            error("dir.delete : E{0} {1}".format(code, ext))
        
        if row[1] is not 0 :
            code = row[1]
     
    message = {
        0 : "성공",
        1 : "대상이 경로입니다",
        2 : "",
        3 : "허용되지 않은 요청입니다",
        4 : "오류가 발생하였습니다",
        5 : "권한 없음"
    }
    response = {
        "code"      : code,
        "message"   : message[code],
        "groupPath" : groupPath,
        "result"    : result  
    }
    return HttpResponse(json.dumps(response))
コード例 #6
0
ファイル: cellar.py プロジェクト: SonienTaegi/CELLAR
def authorityManager(request, *args, **kwargs) :
    """
    auth_type 
        4 : Read
        2 : Write
        1 : Delete
    """    
    cwd = request.POST.get("path")
    auth_type = request.POST.get("auth_type")
    if auth_type :
        auth_type = int(auth_type)
    else :
        auth_type = 4 
     
    response = render(request, "auth_manager.html", {'cwd' : cwd, 'auth_type' : auth_type})
    log.info(response.content)
    return HttpResponse(response)    
コード例 #7
0
ファイル: util.py プロジェクト: sonientaegi/CELLAR_LEGACY
def userLogin(request, *args, **kwargs):
    redirectURL = None
    context = {}
     
    if request.POST.get("user.login") :
        username = request.POST.get('username')
        password = request.POST.get("password")
        
        redirectURL = request.POST.get("redirectURL", "cellar")
        
        if username and password :
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active :
                login(request, user) 
                   
                # django 에서 직접 만든 ID 의 경우 UserInfo 가 누락되어있으므로 생성해준다.
                if not UserInfo.objects.filter(username=username).exists() :
                    if user.is_superuser :
                        usertype = UserInfo.SUPER 
                    else  :
                        usertype = UserInfo.NORMAL
                       
                    userinfo = UserInfo(username=username, usertype=usertype)
                    userinfo.save()
                     
                if request.POST.get("auto_login") : 
                    request.session.set_expiry(86400 * 365 * 10)
                return redirect(reverse(redirectURL))
            else :
                context['message'] = '아이디 또는 암호가 잘못 되었습니다.'
        else :
            context['message'] = '아이디와 암호를 입력하여 주십시오.'
           
        if username :
            context['username'] = username
           
    else :
        info(kwargs)
        redirectURL = kwargs.get("redirect") 
             
    if redirectURL :
        context['redirectURL'] = redirectURL
             
    return HttpResponse(render(request, "user_login.html", {'userLogin' : context}))
コード例 #8
0
def authorityManager(request, *args, **kwargs):
    """
    auth_type 
        4 : Read
        2 : Write
        1 : Delete
    """
    cwd = request.POST.get("path")
    auth_type = request.POST.get("auth_type")
    if auth_type:
        auth_type = int(auth_type)
    else:
        auth_type = 4

    response = render(request, "auth_manager.html", {
        'cwd': cwd,
        'auth_type': auth_type
    })
    log.info(response.content)
    return HttpResponse(response)
コード例 #9
0
ファイル: util.py プロジェクト: sonientaegi/CELLAR_LEGACY
def upload(request, *args, **kwargs):
    response = { 
        "status"    : "success", 
        "message"   : "" 
    }
    
    fileManager = CELLAR_FileManager(request)
    filename    = request.POST.get("name")
    cwd         = request.POST.get("cwd")
    if cwd is None or not fileManager.isWriteable(cwd) :
        response["status"] = "error"
        response["message"] = "해당 경로에 쓰기 권한이 없습니다."
        return HttpResponseServerError(json.dumps(response))
     
    file = request.FILES["file"]
    if not file :
        response["status"] = "error"
        response["message"] = "파일이 정상적으로 업로드 되지 않았습니다."
        return HttpResponseServerError(json.dumps(response))
     
    dstPath = fileManager._root_norm + cwd + filename
    chunk   = int(request.POST.get("chunk"))
    chunks  = int(request.POST.get("chunks"))
     
    if chunk == 0 :
        info("Upload : " + dstPath + " start")
        mode = "wb"
    else :
        mode = "ab"
    
    info("Upload : " + dstPath + " ({0} / {1})".format(chunk + 1, chunks)) 
    with open(dstPath, mode) as destination:
        destination.write(file.file.read())
    file.file.close()
    
    if chunk + 1 == chunks :
        info("Upload : " + dstPath + " finished")
        
    return HttpResponse(json.dumps(response))