コード例 #1
0
    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
コード例 #2
0
    def post(self):
        """ User sign in API """
        rv, code = {"result": False}, 400
        try:
            req = request.json
            hasKey = ["token"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return rv, code

            if not req["token"] == Init.getToken():
                return rv, code
            else:
                tcpServer = TCPServer()
                clients = tcpServer.getClients()

                data = []
                for client in clients:
                    data.append(client)

                url = Init.getApiPath() + "/worker/client/sync/clients"
                j = {"data": data}
                res = Utils.requestUrl(method="POST", url=url, json=j)
                rv["result"], code = True, 200
        except Exception as ex:
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
コード例 #3
0
    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
 def post(self):
     """ User sign in API """
     rv, code = {"result": False}, 400
     try:
         # 값 존재 여부 확인
         req = request.json
         rvKey = ['ip', 'data']
         isKey, isVal = Utils.isDicHasKey(req,
                                          rvKey), Utils.isDicKeyValueNull(
                                              req, rvKey)
         if not (isKey and isVal):
             return rv, code
         webUrl = Init.getWebPath()
         apiPath = Init.getApiPath()
         # Client 정보 최신화
         res = Utils.requestUrl(method="POST",
                                url=webUrl + "/worker/client/sync/device")
         url = Init.getApiPath() + "/worker/client/sync/clients/device"
         j = req
         res = Utils.requestUrl(method="POST", url=url, json=j)
         rv["result"], code = True, 200
     except Exception as ex:
         rv["msg"] = str(ex)
         code = 400
     return rv, code  # ,header{"hi": "hello"}
コード例 #5
0
def registerApi(timer):
    while True:
        token = Init.getToken()
        print(Init.getToken())
        url = Init.getApiPath() + "/worker/command/register"
        j = {"token": token}
        resApi = Utils.requestUrl(method="POST", url=url, json=j)
        if resApi.status_code == 200:
            result = {"result": True}
        else:
            result = {"result": False}
        time.sleep(timer)
    return result
コード例 #6
0
 def ipCheck(cls):
     url = Init.getInitPath() + '/worker/client/authKey'
     res = Utils.requestUrl(method="GET", url=url)
     initJson = json.loads(res.text)
     localIp = socket.gethostbyname(socket.gethostname())
     ip = initJson['ip'] + ":" + localIp
     return ip
コード例 #7
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)
コード例 #8
0
 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
コード例 #9
0
 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
コード例 #10
0
 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
コード例 #11
0
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)
コード例 #14
0
async def worker(cate, msg):
    tcpClient = TCPClient()
    if msg == 'init':
        time.sleep(1)
        ip = Utils.ipCheck()
        reMsg = ip
        tcpClient.reMsg(reMsg)
    if msg == 'sync_system_status':
        device = Device()
        result = device.job_sys_status()
        ip = Utils.ipCheck()
        result["ip"] = ip
        url = Init.getCommandPath() + "/save/client/device/info"
        req = Utils.requestUrl(method='POST', url=url, json=result)
コード例 #15
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
コード例 #16
0
    def post(self):
        """ User sign in API """
        rv, code = {"result": False}, 400
        try:
            req = request.json
            hasKey = ["token"]
            isKey = Utils.isDicHasKey(req, hasKey)
            if not isKey:
                return rv, code

            if not req["token"] == Init.getToken():
                return rv, code
            else:
                msg = {'job': 'sync_system_status'}
                tcpServer = TCPServer()
                tcpServer.sendMessageToAll(json.dumps(msg))
                rv["result"], code = True, 200
        except Exception as ex:
            rv["msg"] = str(ex)
            code = 400
        return rv, code  # ,header{"hi": "hello"}
コード例 #17
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"])
コード例 #18
0
# -*- coding: utf-8 -*-
from flask import Blueprint, render_template
from common.init import Init

template_path = Init.tempPath()
bp_index_error = Blueprint("index_error", __name__, template_folder="/templates")

@bp_index_error.route("/404")
def Error404_view():
    return render_template(template_path + '/error/404.html')
コード例 #19
0
#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
import time
import asyncio

from common.socket.tcp.client.tcpClient import TCPClient
from common.thread.threadDev import ThreadDev

from app.device.device import Device
from common.utils import Utils
from common.init import Init

HOST = Init.getHost()
PORT = Init.getPort()


async def worker(cate, msg):
    tcpClient = TCPClient()
    if msg == 'init':
        time.sleep(1)
        ip = Utils.ipCheck()
        reMsg = ip
        tcpClient.reMsg(reMsg)
    if msg == 'sync_system_status':
        device = Device()
        result = device.job_sys_status()
        ip = Utils.ipCheck()
        result["ip"] = ip
        url = Init.getCommandPath() + "/save/client/device/info"
        req = Utils.requestUrl(method='POST', url=url, json=result)