def syncCommands(self):
        delCommands = []
        commands = {}
        method = "POST"
        apiUrl = Init.apiPath() + "/worker/command/list"
        resCommand = Utils.requestUrl(method=method, url=apiUrl)
        if resCommand.status_code == 200:
            resCommandJson = json.loads(resCommand.text)
            if resCommandJson["result"]:
                commands = resCommandJson['data']
        for command in commands:
            try:
                j = {"token": commands[command]}
                commandChkUrl = "http://" + command + ":" + str(
                    Init.getCommandPort()) + "/command/check/connect"
                resCommandChk = Utils.requestUrl(method=method,
                                                 url=commandChkUrl,
                                                 json=j)
                if resCommandChk.status_code == 200:
                    resCommandChkJson = json.loads(resCommand.text)
                    if not resCommandJson["result"]:
                        delCommands.append(command)
            except Exception as ex:
                delCommands.append(command)

        if len(delCommands) > 0:
            apiCommandDelUrl = Init.apiPath() + "/worker/command/delete"
            j = {"ip": delCommands}
            resApiCommandDel = Utils.requestUrl(method=method,
                                                url=apiCommandDelUrl,
                                                json=j)

        for command in delCommands:
            del commands[command]
        return commands
Exemplo n.º 2
0
def menu_page_client_device_view():
    # 세션 여부 체크
    userInfo = Session().checkSession()
    if not userInfo["result"]:
        return redirect(url_for("index_sign.signin_view"))

    menu = Menu()
    # 메뉴 권한 확인
    isMenuAuth = menu.isAuth("/client/device", userInfo["data"])
    if not isMenuAuth["result"]:
        return redirect(url_for("index_index.index_view"))
    menuHtml = menu.list("/client/device", userInfo["data"])

    apiUrl = Init.apiPath() + "/user/authority"
    resAuthority = Utils.requestUrl(method="GET", url=apiUrl)
    if resAuthority.status_code == 200:
        resAuthorityJson = json.loads(resAuthority.text)
    if resAuthorityJson["result"]:
        authoritys = resAuthorityJson["data"]
    else:
        authoritys = None
    return render_template(template_path +
                           '/main/menu/pages/client/device.html',
                           menuHtml=menuHtml,
                           authoritys=authoritys)
    def syncClinetCount(self):
        result = True
        # 연결된 Command 정보 추출
        commandList = {}
        method = "POST"

        apiUrl = Init.apiPath() + "/worker/command/list"
        resCommand = Utils.requestUrl(method=method, url=apiUrl)
        if resCommand.status_code == 200:
            resCommandJson = json.loads(resCommand.text)
            if resCommandJson["result"]:
                commandList = resCommandJson['data']
        for command in commandList:
            try:
                j = {"token": commandList[command]}
                commandUrl = "http://" + command + ":" + str(
                    Init.getCommandPort()) + "/order/check/clients"
                resCommand = Utils.requestUrl(method=method,
                                              url=commandUrl,
                                              json=j)
            except Exception as ex:
                commandDelUrl = "http://" + command + ":" + str(
                    Init.getCommandPort()) + "/worker/command/del"
                print(ex)
        return result
 def list(self, url:str, userInfo:dict):
     list = None
     method = "POST"
     apiUrl = Init.apiPath() + "/sys/main/menu"
     resMenu = Utils.requestUrl(method=method, url=apiUrl, json=userInfo)
     if resMenu.status_code == 200:
         resMenuJson = json.loads(resMenu.text)
         if resMenuJson["result"]:
             list = resMenuJson['data']
     navHtml = ""
     if list:
         for i in range(len(list)):
             m = list[i]
             if m['depth'] == 1:
                 navHtml = navHtml + """<li class="sidebar-header">
                         %s
                     <li> 
                 """ % (m["name"])
                 for j in range((i+1), len(list)):
                     m2 = list[j]
                     if m["id"] == m2["pid"]:
                         if m2["url"] is not None:
                             if m2["url"] == url:
                                 active = ' active'
                             else:
                                 active = ''
                             navHtml = navHtml + """<li class="sidebar-item%s">
                                 <a class="sidebar-link" href="%s">
                                     <i class="align-middle" data-feather="sliders"></i> <span class="align-middle">%s</span>
                                 </a>
                             </li>
                             """ % (active, m2["url"], m2["name"])
                         else:
                             show = ""
                             nav2Html = ""
                             for k in range((j+1), len(list)):
                                 m3 = list[k]
                                 if m2["id"] == m3["pid"]:
                                     if m3["url"] == url:
                                         active = " active"
                                         show = " show"
                                     else:
                                         active = ""
                                     nav2Html = nav2Html+""" <li class="sidebar-item%s"><a class="sidebar-link" href="%s">%s</a></li>""" % (active, m3["url"], m3["name"])
                             navHtml = navHtml + """<li class="sidebar-item">
                                 <a href="#nav-%s" data-toggle="collapse" class="sidebar-link collapsed">
                                     <i class="align-middle" data-feather="users"></i> <span class="align-middle">%s</span>
                                 </a>
                                 <ul id="nav-%s" class="sidebar-dropdown list-unstyled collapse%s" data-parent="#sidebar">
                             """ % (m2["name"], m2["name"], m2["name"], show)
                             navHtml = navHtml + nav2Html
                             navHtml = navHtml + """
                                 </ul>
                             </li>
                             """
             else:
                 continue
     return navHtml
 def getCommandList(self):
     commands = {}
     method = "POST"
     apiUrl = Init.apiPath() + "/worker/command/list"
     resCommand = Utils.requestUrl(method=method, url=apiUrl)
     if resCommand.status_code == 200:
         resCommandJson = json.loads(resCommand.text)
         commands = resCommandJson['data']
     return commands
 def getClientDeviceList(self):
     clients = {}
     method = "POST"
     apiUrl = Init.apiPath() + "/worker/client/get/clients/device"
     resClient = Utils.requestUrl(method=method, url=apiUrl)
     if resClient.status_code == 200:
         resClientJson = json.loads(resClient.text)
         clients = resClientJson['data']
     return clients
def menu_setting_auth_register_ajax():
    if not Session().checkSession():
        return redirect(url_for('index_sign.signin_view'))
    result = {"result": False, "msg": "아이디 혹은 패스워드를 확인해주세요."}
    j = {"token": "123", "account": request.json}
    method = "POST"
    url = Init.apiPath() + "/user/register"
    resApi = Utils.requestUrl(method=method, url=url, json=j)

    if resApi.status_code == 200:
        result = {"result": True}
    return json.dumps(result)
def signout_ajax():
    result = {"result": False, "msg": "로그아웃에 실패하였습니다."}
    j = {"token": "123", "session": session["sessionKey"]}
    method = "POST"
    url = Init.apiPath() + "/auth/user/signout"
    resSignout = Utils.requestUrl(method=method, url=url, json=j)

    if resSignout.status_code == 200:
        loginJson = json.loads(resSignout.text)
        if loginJson["result"]:
            result["result"] = True
            del result["msg"]
    return json.dumps(result)
def signin_ajax():
    result = {"result": False, "msg": "아이디 혹은 패스워드를 확인해주세요."}
    j = {"token": "123", "account": request.json}
    method = "POST"
    url = Init.apiPath() + "/auth/user/signin"
    resLogin = Utils.requestUrl(method=method, url=url, json=j)

    if resLogin.status_code == 200:
        loginJson = json.loads(resLogin.text)
        if loginJson["result"]:
            session["sessionKey"] = loginJson["data"]["session"]
            result["result"] = True
            del result["msg"]
    return json.dumps(result)
Exemplo n.º 10
0
 def checkSession(self):
     result = {"result": False}
     if "sessionKey" not in session:
         return result
     else:
         method = "POST"
         url = Init.apiPath()+"/auth/user/chk/session"
         j = {
             "session":session["sessionKey"]
         }
         res = Utils.requestUrl(method=method, url=url, json=j)
         if res.status_code == 200:
             result = json.loads(res.text)
         else:
             del session["sessionKey"]
         return result
Exemplo n.º 11
0
# -*- coding: utf-8 -*-
from flask import Blueprint, render_template, url_for, redirect, request
from common.auth.session import Session
from common.auth.menu import Menu
from common.worker.command import Command
from common.utils import Utils
from common.init import Init
import json

template_path = Init.tempPath()
api_path = Init.apiPath()
bp_menu_page_client_device_main = Blueprint("menu_page_client_device_main",
                                            __name__,
                                            template_folder="/templates")
'''
디바이스 화면
Device screen
author: 이재영 (Jae Young Lee)
'''


@bp_menu_page_client_device_main.route("/")
def menu_page_client_device_view():
    # 세션 여부 체크
    userInfo = Session().checkSession()
    if not userInfo["result"]:
        return redirect(url_for("index_sign.signin_view"))

    menu = Menu()
    # 메뉴 권한 확인
    isMenuAuth = menu.isAuth("/client/device", userInfo["data"])