def general(request, *args, **kwargs): userinfo = UserInfo.getUserInfo(request) isSubmitted = request.POST.get("isSubmitted") pageYOffset = "0" if userinfo.isAdmin() and isSubmitted: config.TITLE = request.POST.get("title") config.ROOT = request.POST.get("root") config.HOME_USER = request.POST.get("home_user") config.HOME_GUEST = request.POST.get("home_guest") config.USING_GUEST = isChecked(request, "using_guest") config.LOGIN_CAMPAIGN = isChecked(request, "login_campaign") config.INDEX_FILE = request.POST.get("index_file") config.DEFAULT_AUTH_DIR_READABLE = isChecked(request, "default_readable") config.DEFAULT_AUTH_DIR_WRITEABLE = isChecked(request, "default_writeable") config.DEFAULT_AUTH_DIR_DELETABLE = isChecked(request, "default_deletable") config.DEFAULT_AUTH_DIR_INHERIT = isChecked(request, "default_inherit") config.save() pageYOffset = request.POST.get("pageYOffset") restart(userinfo) context = { "config": vars(config), "pageYOffset": pageYOffset, "isAdmin": UserInfo.getUserInfo(request).isAdmin() } return HttpResponse(render(request, "admin_general.html", context))
def general(request, *args, **kwargs): userinfo = UserInfo.getUserInfo(request) isSubmitted = request.POST.get("isSubmitted"); pageYOffset = "0"; if userinfo.isAdmin() and isSubmitted : config.TITLE = request.POST.get("title") config.ROOT = request.POST.get("root") config.HOME_USER = request.POST.get("home_user") config.HOME_GUEST = request.POST.get("home_guest") config.USING_GUEST = isChecked(request,"using_guest") config.LOGIN_CAMPAIGN = isChecked(request,"login_campaign") config.INDEX_FILE = request.POST.get("index_file") config.DEFAULT_AUTH_DIR_READABLE = isChecked(request,"default_readable") config.DEFAULT_AUTH_DIR_WRITEABLE = isChecked(request,"default_writeable") config.DEFAULT_AUTH_DIR_DELETABLE = isChecked(request,"default_deletable") config.DEFAULT_AUTH_DIR_INHERIT = isChecked(request,"default_inherit") config.save() pageYOffset = request.POST.get("pageYOffset") restart(userinfo) context = { "config" : vars(config), "pageYOffset" : pageYOffset, "isAdmin" : UserInfo.getUserInfo(request).isAdmin() } return HttpResponse(render(request, "admin_general.html", context ))
def userGet(request, *args, **kwargs): username = request.POST.get("username") sessionInfo = UserInfo.getUserInfo(request) response = { "code" : "", "message" : "" } if sessionInfo.isAdmin() or request.user.username == username : result = UserInfo.objects.filter(username__exact = username) if not result.exists() : response["code"] = -1 response["message"] = "존재하지 않는 아이디 입니다." else : userinfo = result[0] user = User.objects.get(username = userinfo.username ) response["username"] = userinfo.username response["name"] = user.first_name response["email"] = user.email response["usertype"] = userinfo.usertype response["home"] = userinfo.home response["memo"] = userinfo.memo response["code"] = 0 else : response["code"] = -4 response["message"] = "권한이 없습니다." return HttpResponse(json.dumps(response))
def userDelete(request, *args, **kwargs): response = { "code" : "", "message" : "" } username = request.POST.get("username") user = User.objects.get(username = username) sessionInfo = UserInfo.getUserInfo(request) if not ( sessionInfo.isAdmin() or request.user.username == username ) : response["code"] = -4 response["message"] = "권한이 없습니다." return HttpResponse(json.dumps(response)) if user.is_superuser : response["code"] = -3 response["message"] = "시스템 관리자 계정은 삭제할 수 없습니다." return HttpResponse(json.dumps(response)) try : with transaction.atomic() : User.objects.get(username__exact = username ).delete() UserInfo.objects.get(username__exact = username ).delete() except IntegrityError : response["code"] = -1 response["message"] = "사용자 계정을 삭제하는 도중에 오류가 발생했습니다." return HttpResponse(json.dumps(response)) response["code"] = 0 response["message"] = "사용자 계정이 삭제 되었습니다." return HttpResponse(json.dumps(response))
def getAuthorizedUsers(request, *args, **kwargs): response = { "code" : 0, "message" : "", "users" : [] } userinfo = UserInfo.getUserInfo(request) fullpath = userinfo.getHomePath() + request.POST.get("path") authType = int(request.POST.get("type")) if userinfo.isAdmin() : file_id = index.dir_get(fullpath) if file_id is not None : for user in UserAuthority.objects.filter(file_id=file_id) : if authType & 4 and not user.readable : continue elif authType & 2 and not user.writeable : continue elif authType & 1 and not user.deletable : continue response['users'].append([user.username.username, user.username.getName(), user.username.usertype]) else : response['code'] = 1 response['message'] = "최고 관리자만 가능합니다" return HttpResponse(json.dumps(response))
def _getContext(request): userInfo = UserInfo.getUserInfo(request) return { "config": config, "isAdmin": userInfo.isAdmin(), "isSuper": userInfo.isSuper(), "is_ajax": request.is_ajax() }
def _getContext(request) : userInfo = UserInfo.getUserInfo(request) return { "config" : config, "isAdmin" : userInfo.isAdmin(), "isSuper" : userInfo.isSuper(), "is_ajax" : request.is_ajax() }
def myinfo(request, *args, **kwargs): userinfo = UserInfo.getUserInfo(request) user = User.objects.get(username=userinfo.username) context = { "username": user.username, "name": user.first_name, "email": user.email, "memo": userinfo.memo } return HttpResponse(render(request, "user_myinfo.html", context))
def myinfo(request, *args, **kwargs): userinfo = UserInfo.getUserInfo(request) user = User.objects.get(username = userinfo.username ) context = { "username" : user.username, "name" : user.first_name, "email" : user.email, "memo" : userinfo.memo } return HttpResponse(render(request, "user_myinfo.html", context))
def simple_response(request, *args, **kwargs): template_name = kwargs["path"] if kwargs["type"] : template_name = kwargs["type"] + "/" + template_name userInfo = UserInfo.getUserInfo(request) context = { "isMetic" : userInfo.isMetic(), "isYeoman" : userInfo.isYeoman(), "isAdmin" : userInfo.isAdmin(), "isSuper" : userInfo.isSuper() } return HttpResponse(render(request, template_name, context))
def simple_response(request, *args, **kwargs): template_name = kwargs["path"] if kwargs["type"]: template_name = kwargs["type"] + "/" + template_name userInfo = UserInfo.getUserInfo(request) context = { "isMetic": userInfo.isMetic(), "isYeoman": userInfo.isYeoman(), "isAdmin": userInfo.isAdmin(), "isSuper": userInfo.isSuper() } return HttpResponse(render(request, template_name, context))
def userNew(request, *args, **kwargs): context = {} userinfo = UserInfo.getUserInfo(request) if request.POST.get("signup") : response = userCreate(request.POST, userinfo.isAdmin()) if response["code"] == 0 : context["code"] = 0 context["message"] = "사용자 {0} 이(가) 등록되었습니다.".format(response["username"]) else : response["isAdmin"] = userinfo.isAdmin() return HttpResponse(render(request, "admin_user_new.html", response )) context["isAdmin"] = userinfo.isAdmin() return HttpResponse(render(request, "admin_user_new.html", context))
def setDefaultAuthority(request, *args, **kwargs): path = request.POST.get("path") response = { "code" : 0, "message" : "", "path" : path, "register" : False, "readable" : config.DEFAULT_AUTH_DIR_READABLE, "writeable" : config.DEFAULT_AUTH_DIR_WRITEABLE, "deletable" : config.DEFAULT_AUTH_DIR_DELETABLE, "inherit" : config.DEFAULT_AUTH_DIR_INHERIT } userinfo = UserInfo.getUserInfo(request) fullpath = userinfo.getHomePath() + request.POST.get("path") if not userinfo.isAdmin() : response['code'] = -1 response['message'] = "권한 초기화는 최고 관리자만 가능합니다" else : inherit = request.POST.get("inherit") if inherit is not None : inherit = inherit == "1" readable = request.POST.get("readable") if readable is not None : readable = readable == "1" writeable = request.POST.get("writeable") if writeable is not None : writeable = writeable == "1" deletable = request.POST.get("deletable") if deletable is not None : deletable = deletable == "1" result = Directory.setAuth(fullpath, inherit, readable, writeable, deletable) if result[0] >= 0 : response["code"] = 0 response["message"] = result[1] response['register'] = True response['inherit'] = inherit response['readable'] = readable response['writeable'] = writeable response['deletable'] = deletable return HttpResponse(json.dumps(response))
def userNew(request, *args, **kwargs): context = {} userinfo = UserInfo.getUserInfo(request) if request.POST.get("signup"): response = userCreate(request.POST, userinfo.isAdmin()) if response["code"] == 0: context["code"] = 0 context["message"] = "사용자 {0} 이(가) 등록되었습니다.".format( response["username"]) else: response["isAdmin"] = userinfo.isAdmin() return HttpResponse( render(request, "admin_user_new.html", response)) context["isAdmin"] = userinfo.isAdmin() return HttpResponse(render(request, "admin_user_new.html", context))
def browseFilelist(request, *args, **kwrags): targetDir = request.POST.get('target') result = util.getFileGroup(request, targetDir) userinfo = UserInfo.getUserInfo(request) auth = Directory.getAuth(userinfo, userinfo.getHomePath() + targetDir) context = { 'target' : targetDir, 'directory' : result[0], 'file' : result[1], 'readable' : auth[0], 'writeable' : auth[1], 'deletable' : auth[2] } # info("browse.filelist : " + targetDir) return HttpResponse(json.dumps(context))
def resetAllAuthority(request, *args, **kwargs) : response = { "code" : 0, "message" : "" } if not UserInfo.getUserInfo(request).isAdmin() : response['code'] = -1 response['message'] = "권한 초기화는 최고 관리자만 가능합니다" else : # DB 초기화 FileDescriptor.objects.all().delete() UserAuthority.objects.all().delete() FileDescriptor(file_id=0, file="", reference=None).save() # 이건 더미 index.dir_reset() return HttpResponse(json.dumps(response))
def download(request, *args, **kwargs): """ Download a file @param kwargs: filepath : Relative file path of target file. Root is user home. """ target = kwargs['filepath'] # Authority Check fileManager = CELLAR_FileManager(request) if target is None or not fileManager.isReadable(os.path.dirname(target)) : raise PermissionDenied fullPath = UserInfo.getUserInfo(request).getHomePath() + "/" + target response = StreamingHttpResponse(FileWrapper(open(fullPath, mode='rb')), content_type='application/octet-stream') response['Content-Length'] = os.path.getsize(fullPath) response['Content-Disposition'] = 'attachment' return response
def getDefaultAuthority(request, *args, **kwargs): path = request.POST.get("path") response = { "path" : path, "register" : False, "readable" : config.DEFAULT_AUTH_DIR_READABLE, "writeable" : config.DEFAULT_AUTH_DIR_WRITEABLE, "deletable" : config.DEFAULT_AUTH_DIR_DELETABLE, "inherit" : config.DEFAULT_AUTH_DIR_INHERIT } userinfo = UserInfo.getUserInfo(request) fullpath = userinfo.getHomePath() + path file_id = index.dir_get(fullpath) if file_id is not None : fileDescriptor = FileDescriptor.objects.get(file_id=file_id) response['register'] = True response['readable'] = fileDescriptor.readable response['writeable'] = fileDescriptor.writeable response['deletable'] = fileDescriptor.deletable response['inherit'] = fileDescriptor.inherit return HttpResponse(json.dumps(response))
def browse(request, *args, **kwrags): targetDir = request.POST.get('target') filelist = util.getFileGroup(request, targetDir) directree = util.getDirTree(request, targetDir, 2) userinfo = UserInfo.getUserInfo(request) auth = Directory.getAuth(userinfo, userinfo.getHomePath() + targetDir) context = { 'target' : targetDir, 'filelist' : { 'directory' : filelist[0], 'file' : filelist[1], 'readable' : auth[0], 'writeable' : auth[1], 'deletable' : auth[2] }, 'directree' : { 'node' : directree } } # info("browse.all : " + targetDir) return HttpResponse(json.dumps(context))
def delDefaultAuthority(request, *args, **kwargs): path = request.POST.get("path") response = { "code" : 0, "message" : "", "path" : path, "register" : False, "readable" : config.DEFAULT_AUTH_DIR_READABLE, "writeable" : config.DEFAULT_AUTH_DIR_WRITEABLE, "deletable" : config.DEFAULT_AUTH_DIR_DELETABLE, "inherit" : config.DEFAULT_AUTH_DIR_INHERIT } userinfo = UserInfo.getUserInfo(request) fullpath = userinfo.getHomePath() + request.POST.get("path") if not userinfo.isAdmin() : response['code'] = 1 response['message'] = "최고 관리자만 가능합니다" elif not Directory.delAuth(fullpath) : response["code"] = -1 response["message"] = "디렉토리 식별자 삭제 실패" return HttpResponse(json.dumps(response))
def setAuthorizedUsers(request, *args, **kwargs): response = { "code" : 0, "message" : "", "users" : [] } userinfo = UserInfo.getUserInfo(request) fullpath = userinfo.getHomePath() + request.POST.get("path") ids = request.POST.getlist("ids[]") readable = request.POST.get('readable') readable = (readable == "1", None)[readable == None] writeable = request.POST.get('writeable') writeable = (writeable == "1", None)[writeable == None] deletable = request.POST.get('deletable') deletable = (deletable == "1", None)[deletable == None] if userinfo.isAdmin() : file_id = index.dir_get(fullpath) if file_id is None : file_id = Directory.setAuth(fullpath, config.DEFAULT_AUTH_DIR_INHERIT, config.DEFAULT_AUTH_DIR_READABLE, config.DEFAULT_AUTH_DIR_WRITEABLE, config.DEFAULT_AUTH_DIR_DELETABLE)[0] fileDescriptor = FileDescriptor.objects.get(file_id=file_id) try : with transaction.atomic() : for authUser in UserInfo.objects.filter(username__in=ids) : userAuthority = None try : userAuthority = UserAuthority.objects.get(username=authUser, file_id=fileDescriptor) if (readable is not None and userAuthority.readable == readable) or \ (writeable is not None and userAuthority.writeable == writeable) or \ (deletable is not None and userAuthority.deletable == deletable) : continue except Exception as err : userAuthority = UserAuthority(username=authUser, file_id=fileDescriptor) if readable is not None : userAuthority.readable = readable if writeable is not None : userAuthority.writeable = writeable if deletable is not None : userAuthority.deletable = deletable userAuthority.save() response['users'].append([ authUser.username, authUser.getName(), authUser.usertype, userAuthority.readable, userAuthority.writeable, userAuthority.deletable]) except Exception as err : response['code'] = -2 response['message'] = err.__str__() response['users'].clear() else : response['code'] = 1 response['message'] = "최고 관리자만 가능합니다" return HttpResponse(json.dumps(response))
def userEdit(request, *args, **kwargs): user_group = {'group': [], 'user': []} users = [] if request.POST.get('user.group.update'): username = request.POST.get('username') groupname = request.POST.get('groupname') assign = request.POST.get('assign') == 'True' or request.POST.get( 'assign') == 'true' if assign: user = UserInfo.objects.get(username=username) group = UserInfo.objects.get(username=groupname) userGroup = UserGroups(user=user, group=group) userGroup.save() else: userGroup = UserGroups.objects.get(user=username, group=groupname) userGroup.delete() if request.is_ajax(): return HttpResponse({ "username": username, "groupname": groupname, "assign": assign }) else: users = UserInfo.objects.filter(username=username) else: search_term = request.POST.get("user.group.search.term") if not search_term or not request.POST.get('user.group.search'): search_term = "" users = UserInfo.objects.filter( username__contains=search_term).exclude(usertype=UserInfo.GROUP) general = 0 groupIndex = {} groups = list(UserInfo.objects.filter(usertype=UserInfo.GROUP)) for group in groups: auth_group = User.objects.get(username=group.username) groupIndex[group.username] = general general = general + 1 user_group['group'].append([ general, { 'username': group.username, 'first_name': auth_group.first_name, 'last_name': auth_group.last_name } ]) for userinfo in users: auth_user = User.objects.get(username=userinfo.username) user = { 'username': userinfo.username, 'first_name': auth_user.first_name, 'last_name': auth_user.last_name, 'usertype': userinfo.usertype, 'isAdmin': userinfo.isAdmin(), 'assign': [] } for group in groups: user['assign'].append([group.username, False]) userGroups = UserGroups.objects.filter(user=userinfo.username) for userGroup in userGroups: user['assign'][groupIndex[userGroup.group.username]][1] = True user_group['user'].append(user) context = { 'user_group': user_group, 'config': vars(config), 'isAdmin': UserInfo.getUserInfo(request).isAdmin() } return render(request, "admin_user_edit.html", context)
def userEdit(request, *args, **kwargs): user_group = { 'group' : [], 'user' : []} users = [] if request.POST.get('user.group.update') : username = request.POST.get('username') groupname = request.POST.get('groupname') assign = request.POST.get('assign') == 'True' or request.POST.get('assign') == 'true' if assign : user = UserInfo.objects.get(username=username) group = UserInfo.objects.get(username=groupname) userGroup = UserGroups(user=user, group=group) userGroup.save() else : userGroup = UserGroups.objects.get(user=username, group=groupname) userGroup.delete() if request.is_ajax() : return HttpResponse({"username" : username, "groupname" : groupname, "assign" : assign }) else : users = UserInfo.objects.filter(username=username) else : search_term = request.POST.get("user.group.search.term") if not search_term or not request.POST.get('user.group.search') : search_term = "" users = UserInfo.objects.filter(username__contains=search_term).exclude(usertype=UserInfo.GROUP) general = 0 groupIndex = {} groups = list(UserInfo.objects.filter(usertype=UserInfo.GROUP)) for group in groups : auth_group = User.objects.get(username=group.username) groupIndex[group.username] = general general = general + 1 user_group['group'].append([general, {'username' : group.username, 'first_name' : auth_group.first_name, 'last_name' : auth_group.last_name }]) for userinfo in users : auth_user = User.objects.get(username=userinfo.username) user = {'username' : userinfo.username, 'first_name' : auth_user.first_name, 'last_name' : auth_user.last_name, 'usertype' : userinfo.usertype, 'isAdmin' : userinfo.isAdmin(), 'assign' : [] } for group in groups : user['assign'].append([group.username, False]) userGroups = UserGroups.objects.filter(user=userinfo.username) for userGroup in userGroups : user['assign'][groupIndex[userGroup.group.username]][1] = True user_group['user'].append(user) context = { 'user_group' : user_group, 'config' : vars(config), 'isAdmin' : UserInfo.getUserInfo(request).isAdmin() } return render(request, "admin_user_edit.html", context)
def etc(request, *args, **kwargs): context = { 'config' : vars(config), 'isAdmin' : UserInfo.getUserInfo(request).isAdmin() } return HttpResponse(render(request, "admin_etc.html", context))
def userUpdate(request, *args, **kwargs): response = { "code" : "", "message" : "" } username = request.POST.get("username") usertype = request.POST.get("usertype") home = None name = request.POST.get("name") email = request.POST.get("email") memo = request.POST.get("memo") password_new = request.POST.get("password_new") password_old = request.POST.get("password_old") if request.POST.__contains__("home") : home = request.POST.get("home") if usertype : usertype = int(usertype) # 권한 확인 - 공통 user = User.objects.get(username = username) userinfo = UserInfo.objects.get(username = username) sessionInfo = UserInfo.getUserInfo(request) if not sessionInfo.isAdmin() and sessionInfo.username != username : response["code"] = -4 response["message"] = "권한이 없습니다." return HttpResponse(json.dumps(response)) # 권한 확인 - 관리자 if not sessionInfo.isAdmin() and ( home is not None or usertype ) : response["code"] = -5 response["message"] = "관리자만이 변경 가능한 항목을 포함하고 있습니다." return HttpResponse(json.dumps(response)) # 시스템 관리자는 계정 유형 변경 불가 if user.is_superuser and usertype and usertype != UserInfo.SUPER : response["code"] = -6 response["message"] = "시스템 관리자의 계정 유형을 변경할 수 없습니다." return HttpResponse(json.dumps(response)) # 암호 변경 요청 시 사용자 암호 확인 if password_new : if sessionInfo.isAdmin() and not password_old : pass elif authenticate(username = username, password = password_old) : pass else : response["code"] = -3 response["message"] = "입력한 기존 암호가 잘못되었습니다." return HttpResponse(json.dumps(response)) try : with transaction.atomic() : # 사용자 정보 갱신 if email : user.email = email if name : user.first_name = name if password_new : user.set_password(password_new) user.save() if home is not None : userinfo.home = home if usertype : userinfo.usertype = usertype if memo : userinfo.memo = memo userinfo.save() response['code'] = 0 response['message'] = "사용자 정보가 변경되었습니다." response['username'] = username response['name'] = user.first_name response['email'] = user.email response['home'] = userinfo.home response['memo'] = userinfo.memo response['usertype'] = userinfo.usertype except Exception as err : response['code'] = -2 response['message'] = err.__str__() return HttpResponse(json.dumps(response))
def __init__(self, request): self.userinfo = UserInfo.getUserInfo(request) FileManager.__init__(self, self.userinfo.getHomePath())
def __init__(self, request): self.userinfo = UserInfo.getUserInfo(request) FileManager.__init__(self, self.userinfo.getHomePath())
def etc(request, *args, **kwargs): context = { 'config': vars(config), 'isAdmin': UserInfo.getUserInfo(request).isAdmin() } return HttpResponse(render(request, "admin_etc.html", context))