import binascii
import datetime
import http
import json
import threading
import time
if 82 - 82: Iii1i
from flask import Blueprint , render_template , request , g , redirect , url_for , flash
from sqlalchemy import or_ , and_
if 87 - 87: Ii % i1i1i1111I . Oo / OooOoo * I1Ii1I1 - I1I
import vwAppConfigParam
# from blueprints.wgcomm_pri import WGControllerPri2023
from blueprints . wgcomm_console import WGControllerCenter2023 , checkConnectedSingle
from forms . wgcommform import *
from exts import db
from decorators import login_required
from models . iccard import *
from vwAppConfig import WGTools
import vwAppConfig
from vwAppConfigParam import vwAppConfigParam
if 81 - 81: i1 + ooOOO / oOo0O00 * i1iiIII111 * IiIIii11Ii
__all__ = [
 "bp" ,
 "web_help_startup" ,
 "web_help_startup1" ,
 "web_help_faq" ,
 "web_help_faq_analyst2cards" ,
 "web_help_faq_update_superpassword" ,
 "web_help_faq_webapi" ,
 "web_help_faq_webapi_post" ,
 "web_help_faq_webapi_newcloudserver" ,
]
if 84 - 84: ooo000 - Ooo0Ooo + iI1iII1I1I1i . IIiIIiIi11I1
if 98 - 98: I11iiIi11i1I % oOO
if 31 - 31: i1I
bp = Blueprint ( 'wgcomm_help' , __name__ , url_prefix = '/' )
if 9 - 9: IiI11Ii111 / oOo0O00 / IiIIii11Ii - I11iiIi11i1I - iI1iII1I1I1i
if 16 - 16: i1i1i1111I / i1iiIII111
@ bp . route ( '/web_help_startup' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_help_startup ( ) :
 iiii11iiiiI = {
 "objlist" : None ,
 "wgserver1001" : vwAppConfigParam . wgwsserver1001 ,
 }
 return render_template ( "wgcomm/help-startup.html" , ** iiii11iiiiI )
 if 10 - 10: ooOOO / IIiIIiIi11I1 * oOO / i1I / i1I
 if 61 - 61: Ooo0Ooo - I1I
@ bp . route ( '/web_help_startup1' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_help_startup1 ( ) :
 iIIIII1i111i = {
 "jsonrpc" : "2.0" ,
 "method" : "ExternFunctions" ,
 "params" : [
 {
 "FunctionName" : "SearchController"
 }
 ] ,
 "id" : 4001
 }
 IIiiii1IiIiII = vwAppConfig . sendByHttpWithMsg ( iIIIII1i111i )
 if 32 - 32: iI1iII1I1I1i
 i1iiiiIIIiIi = {
 "jsonrpc" : "2.0" ,
 "method" : "ExternFunctions" ,
 "params" : [
 {
 "FunctionName" : "Get1001RunningInformation"
 }
 ] ,
 "id" : 4001
 }
 II = ""
 OO0000 = [ ]
 oOoo0 = Iio0 ( i1iiiiIIIiIi )
 i1i = None
 if oOoo0 :
  if 87 - 87: Oo - i1I
  if 32 - 32: Ii % i1i1i1111I % i1I - I11iiIi11i1I % i1iiIII111
  II = oOoo0 [ '1001StartupTime' ]
  OO0000 = oOoo0 [ 'JoinedControllerSN' ]
  if len ( OO0000 ) == 0 :
   i1i = '<div class="card-body">'
   i1i = i1i + '<div class="form-group"><label class="text-warning">Please close the firewall or open UDP: 61005, TCP: 61005, 61080, 61081, 61085, 1183 ports.</label></div>'
   i1i = i1i + '<div class="form-group"><label class="text-warning">Ensure the controller is connected to the local area network and on the same subnet as the computer.</label></div>'
   i1i = i1i + '</div>'
  else :
   o0OoOOo00OOO = TBController . query
   i11ii1i1I = o0OoOOo00OOO . all ( )
   IiI = [ ]
   for o00O000o0 in i11ii1i1I :
    IiI . append ( o00O000o0 . f_ControllerSN )
   oOoo = [ ]
   I1i1Ii = [ ]
   Ooo0OO = [ ]
   for ii1Ii1I in OO0000 :
    oo0 = ii1Ii1I [ 'SN' ]
    i11iIii = datetime . datetime . strptime ( ii1Ii1I [ "RefreshTime" ] , "%Y-%m-%d %H:%M:%S" )
    if 40 - 40: IiIIii11Ii . i1 / Oo
    if 46 - 46: IiI11Ii111 - OooOoo * I1Ii1I1 / Ooo0Ooo / Iii1i
    I11iIi1i = datetime . datetime . strptime ( ii1Ii1I [ "ServerTime" ] , "%Y-%m-%d %H:%M:%S" )
    if abs ( int ( I11iIi1i . timestamp ( ) ) - int ( i11iIii . timestamp ( ) ) ) > 60 :
     continue
     if 49 - 49: IIiIIiIi11I1
     if 29 - 29: IiIIii11Ii - oOo0O00
    oOoo . append ( oo0 )
    if oo0 in IiI :
     I1i1Ii . append ( oo0 )
    else :
     Ooo0OO . append ( oo0 )
   if len ( oOoo ) == 0 :
    i1i = '<div class="card-body">'
    i1i = i1i + '<div class="form-group"><label class="text-warning">Please close the firewall or open UDP: 61005, TCP: 61005, 61080, 61081, 61085, 1183 ports.</label></div>'
    i1i = i1i + '<div class="form-group"><label class="text-warning">Ensure the controller is connected to the local area network and on the same subnet as the computer.</label></div>'
    i1i = i1i + '</div>'
   else :
    i1i = '<div class="card-body">'
    i1i = i1i + '<div class="form-group"><label>Searched {} controllers: </label></div>' . format (
 len ( oOoo ) )
    if I1i1Ii :
     i1i = i1i + '<div class="form-group"><label>Added Controllers: {}</label></div>' . format (
 vwAppConfig . getStrFromArray ( I1i1Ii ) )
    if Ooo0OO :
     i1i = i1i + '<div class="form-group"><label>New Controllers: {}</label></div>' . format (
 vwAppConfig . getStrFromArray ( Ooo0OO ) )
     if 30 - 30: I1I . ooo000
    i1i = i1i + '<input type="hidden" class="form-group" id="arrconnotadd" value="{}">' . format (
 vwAppConfig . getStrFromArray ( Ooo0OO ) )
    if 43 - 43: ooOOO . I11iiIi11i1I + ooo000
    if 87 - 87: Iii1i + ooOOO . i1I / Ii + Oo
    if 77 - 77: i1iiIII111 + IiI11Ii111 - Oo % ooo000
    if 74 - 74: Ii + Ooo0Ooo
    if 1 - 1: I1I % Ooo0Ooo + i1iiIII111 . i1iiIII111 % Oo
    if 93 - 93: oOo0O00 % Ooo0Ooo * i1iiIII111
    i1i = i1i + '</div>'
 else :
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">1001CloudServer not running, Please restart Vw3000!!!</label></div>'
  i1i = i1i + '</div>'
  if 52 - 52: oOO + I1I / ooo000 - I1Ii1I1 * i1I % oOo0O00
 iiii11iiiiI = {
 "objlist" : None ,
 "starttime1001" : II ,
 "arrcontrollers" : OO0000 ,
 "autoaddcontrollerinfo" : i1i ,
 }
 return i1i
 if 52 - 52: oOo0O00 . I1I + i1I - i1iiIII111 % iI1iII1I1I1i
 if 57 - 57: I1I * IIiIIiIi11I1 % I1Ii1I1 * i1i1i1111I
def Iio0 ( arrinfob = None , cloudserverip = None , timeoutSec = 3 ) :
 Oo0 = None
 try :
  ooooo = {
 "jsonrpc" : "2.0" ,
 "method" : "Primit64ByteCommand" ,
 "id" : "1005"
 }
  ooooo = arrinfob
  oO00o00OO = vwAppConfigParam . server1001_ip
  if cloudserverip :
   oO00o00OO = cloudserverip
  o00o = vwAppConfigParam . server1001_webport
  Ii11I = http . client . HTTPConnection ( host = oO00o00OO , port = o00o , timeout = 3 )
  iIi = bytes ( json . dumps ( ooooo , sort_keys = False , indent = 4 ) , encoding = 'utf8' )
  O000O0Oo0 = { "Content-type" : "application/json" , "Accept" : "application/json" }
  Ii11I . timeout = timeoutSec
  Ii11I . request ( "POST" , oO00o00OO , iIi , O000O0Oo0 )
  Oo0O0O = Ii11I . getresponse ( )
  Ii1IiIII1 = Oo0O0O . read ( )
  Ii11I . close ( )
  try :
   iiI1 = json . loads ( Ii1IiIII1 . decode ( "utf-8" ) )
   Oo0 = iiI1 [ 'result' ]
  except Exception as iII :
   vwAppConfig . wglog ( iII )
   Oo0 = None
   return Oo0
  return Oo0
 except Exception as iII :
  pass
  print ( iII )
 return None
 if 43 - 43: Ooo0Ooo - I1I . ooo000 - Iii1i % i1I
 if 49 - 49: IiIIii11Ii . ooo000 + oOO - oOO
 if 78 - 78: i1 - ooOOO
@ bp . route ( '/web_help_faq' , methods = [ 'GET' , 'POST' ] )
@ login_required
def web_help_faq ( ) :
 o0OoOOo00OOO = db . session . query ( TBDoor . f_DoorID , TBDoor . f_DoorName , TBDoor . f_DoorNO ,
 TBController . f_ControllerSN ) . join ( TBController ,
 TBController . f_ControllerID == TBDoor . f_ControllerID ,
 isouter = False ) . order_by ( TBDoor . f_DoorName )
 OO = o0OoOOo00OOO . all ( )
 o0OoOOo00OOO = TBReaderpassword . query . filter ( TBReaderpassword . f_Notes . in_ ( [ '1' , '2' , '3' , '4' ] ) ) . order_by (
 TBReaderpassword . f_Notes )
 OoOo00oO000oo = o0OoOOo00OOO . all ( )
 oooOOOoOO = [ '' , '' , '' , '' ]
 for OOOoOo in range ( 4 ) :
  OoOo00oO000oo = TBReaderpassword . query . filter ( TBReaderpassword . f_Notes == str ( OOOoOo + 1 ) ) . first ( )
  if OoOo00oO000oo :
   if OoOo00oO000oo . f_Password > 0 :
    oooOOOoOO [ OOOoOo ] = str ( OoOo00oO000oo . f_Password )
    if 96 - 96: IiIIii11Ii . i1i1i1111I / Ii * i1 . I1I
 iiii11iiiiI = {
 "objlist" : None ,
 "wgserver1001" : vwAppConfigParam . wgwsserver1001 ,
 "doornames" : OO ,
 "superpassword" : oooOOOoOO
 }
 return render_template ( "wgcomm/help-faq.html" , ** iiii11iiiiI )
 if 3 - 3: i1 / IIiIIiIi11I1 / Oo * I1I % iI1iII1I1I1i
 if 90 - 90: I1Ii1I1 + IiI11Ii111 % Oo
@ bp . route ( '/web_help_faq_analyst2cards' , methods = [ 'POST' ] )
@ login_required
def web_help_faq_analyst2cards ( ) :
 I1i = vwAppConfig . parseInt ( request . form . get ( "cardnoA" ) )
 O0oo000o = vwAppConfig . parseInt ( request . form . get ( "cardnoB" ) )
 if 14 - 14: IiI11Ii111 + i1I . IiIIii11Ii . Ooo0Ooo % IiIIii11Ii * i1i1i1111I
 if 65 - 65: Iii1i + IIiIIiIi11I1 - Ooo0Ooo . iI1iII1I1I1i + OooOoo * Ooo0Ooo
 if 23 - 23: ooOOO % oOO % iI1iII1I1I1i - i1I - i1iiIII111 + i1
 if 12 - 12: i1 - i1I - IiI11Ii111
 if 86 - 86: Iii1i + i1iiIII111 - IIiIIiIi11I1 / I1I
 if I1i == 0 :
  if 46 - 46: ooOOO + ooOOO % oOO
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">Entered Card A is not a valid card number. Please re-enter!!!</label></div>'
  i1i = i1i + '</div>'
  return i1i
 if O0oo000o == 0 :
  if 2 - 2: i1i1i1111I / Ooo0Ooo / oOO - IIiIIiIi11I1 / IIiIIiIi11I1
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">Entered Card B is not a valid card number. Please re-enter!!!</label></div>'
  i1i = i1i + '</div>'
  return i1i
 if O0oo000o == I1i :
  if 58 - 58: i1i1i1111I
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">Entered Card A and Card B are the same; no analysis needed!!!</label></div>'
  i1i = i1i + '</div>'
  return i1i
  if 38 - 38: i1 - oOo0O00
 if I1i > 0xffffffff :
  if 85 - 85: IIiIIiIi11I1 + I11iiIi11i1I % Ooo0Ooo + oOO * i1iiIII111
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">Entered Card A exceeds 10 digits, not an IC card value. Please re-enter!!!</label></div>'
  i1i = i1i + '</div>'
  return i1i
 if O0oo000o > 0xffffffff :
  if 46 - 46: ooOOO - ooOOO + Oo / I1I * Oo + oOO
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">Entered Card B exceeds 10 digits, not an IC card value. Please re-enter!!!</label></div>'
  i1i = i1i + '</div>'
  return i1i
 i1II1 = oOoOo ( I1i )
 o0oOoo0O0o0Oo = oOoOo ( O0oo000o )
 IIIIiiIIi = [ 'wiegnad34' , 'wiegand26' , '34 D0 D1 reversed' , '26 D0 D1 reversed' , 'Convert to 34 as 26' , '26 → 34 with D0, D1 reversed' ]
 for OOOoOo in range ( len ( i1II1 ) ) :
  for Ii111iii1 in range ( len ( o0oOoo0O0o0Oo ) ) :
   if i1II1 [ OOOoOo ] == o0oOoo0O0o0Oo [ Ii111iii1 ] :
    oo0O0 = 'i={},j={}' . format ( OOOoOo , Ii111iii1 )
    III1II11i = ''
    iiI1iiii1iii = ''
    if OOOoOo == 0 and Ii111iii1 == 1 :
     oo0O0 = "Card A={}: Input as Wiegand-26" . format ( I1i )
     iiI1iiii1iii = "Card B={}: Input as Wiegand-34" . format ( O0oo000o )
     if 53 - 53: IiI11Ii111 * oOo0O00 - i1 . oOo0O00
     III1II11i = "Suggestion: Adjust the reading device for Card B to Wiegand-26 output format."
    if OOOoOo == 1 and Ii111iii1 == 0 :
     if 91 - 91: iI1iII1I1I1i * i1 . ooOOO
     oo0O0 = "Card A={}: Input as Wiegand-34" . format ( I1i )
     iiI1iiii1iii = "Card B={}: Input as Wiegand-26" . format ( O0oo000o )
     III1II11i = "Suggestion: Adjust the reading device for Card B to Wiegand-34 output format."
    if OOOoOo == 0 and Ii111iii1 == 2 :
     if 81 - 81: I1I * Oo - i1 % OooOoo * ooOOO
     if 19 - 19: Ii
     if 22 - 22: i1I % iI1iII1I1I1i + Oo
     oo0O0 = "Card A={}: " . format ( I1i )
     iiI1iiii1iii = "Card B={}: Input [D0 D1 reversed]" . format ( O0oo000o )
     III1II11i = "Suggestion: Swap the D0 and D1 interfaces on the reading device for Card B."
    if OOOoOo == 0 and Ii111iii1 == 3 :
     if 60 - 60: ooo000 + I11iiIi11i1I + IIiIIiIi11I1 % i1i1i1111I - Ii % Ooo0Ooo
     oo0O0 = "Card A={}: Input as Wiegand-26" . format ( I1i )
     iiI1iiii1iii = "Card B={}: Input as Wiegand-34 [D0 D1 reversed]" . format ( O0oo000o )
     III1II11i = "Suggestion: Swap the D0 and D1 interfaces on the reading device for Card B; also adjust the reading device to Wiegand-26 output format."
    if OOOoOo == 3 and Ii111iii1 == 0 :
     if 95 - 95: ooOOO % i1i1i1111I . i1
     if 87 - 87: Iii1i % ooOOO * Ii % IIiIIiIi11I1 / I11iiIi11i1I
     oo0O0 = "Card A={}: Input as Wiegand-34" . format ( I1i )
     iiI1iiii1iii = "Card B={}: Input as Wiegand-26 [D0 D1 reversed]" . format ( O0oo000o )
     III1II11i = "Suggestion: Swap the D0 and D1 interfaces on the reading device for Card B; also adjust the reading device to Wiegand-34 output format."
    if OOOoOo == 4 and Ii111iii1 == 5 :
     if 84 - 84: I1Ii1I1 + Ooo0Ooo % IIiIIiIi11I1 * i1i1i1111I
     if 61 - 61: i1iiIII111 - Oo + I1Ii1I1
     oo0O0 = "Card A={}: Input as Wiegand-26" . format ( I1i )
     iiI1iiii1iii = "Card B={}: Input as Wiegand-26 [D0 D1 reversed]" . format ( O0oo000o )
     III1II11i = "Suggestion: Swap the D0 and D1 interfaces on the reading device for Card B."
    i1i = '<div class="card-body">'
    i1i = i1i + '<div class="form-group"><label class="text-danger">{}</label></div>' . format ( oo0O0 )
    i1i = i1i + '<div class="form-group"><label class="text-danger">{}</label></div>' . format ( iiI1iiii1iii )
    i1i = i1i + '<div class="form-group"><label class="text-danger">{}</label></div>' . format ( III1II11i )
    i1i = i1i + '</div>'
    return i1i
 if 1 :
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">No correlation found between Card: {} and {}. Please try other card numbers!!!</label></div>' . format (
 I1i , O0oo000o )
  i1i = i1i + '</div>'
  if 43 - 43: IIiIIiIi11I1 * ooo000 + Ii % iI1iII1I1I1i
 return i1i
 if 12 - 12: i1iiIII111 + ooo000 . I11iiIi11i1I
 if 1 - 1: iI1iII1I1I1i % Ii - I11iiIi11i1I / IiI11Ii111 + iI1iII1I1I1i - Ii
def oOoOo ( cardno ) :
 IiII1Iii11 = [ ]
 if 31 - 31: oOo0O00 / Iii1i % Ooo0Ooo % i1 . iI1iII1I1I1i . Oo
 if 83 - 83: oOo0O00 - I11iiIi11i1I
 if 91 - 91: IIiIIiIi11I1 - i1 - iI1iII1I1I1i
 if 71 - 71: I1I - IiI11Ii111
 if 66 - 66: i1i1i1111I / Ooo0Ooo + I11iiIi11i1I + Iii1i + oOo0O00 + i1I
 if 75 - 75: OooOoo - oOO - IiIIii11Ii - oOO + ooo000 % iI1iII1I1I1i
 if 42 - 42: i1 * i1I
 if 50 - 50: Ii - i1iiIII111
 if 96 - 96: ooo000 * OooOoo - Ii - OooOoo
 if 65 - 65: Oo + Oo - iI1iII1I1I1i % OooOoo . Ooo0Ooo
 if 84 - 84: IIiIIiIi11I1 . ooOOO
 if 44 - 44: ooo000 * i1i1i1111I * oOO + i1iiIII111 - IIiIIiIi11I1
 if 70 - 70: IiI11Ii111
 if 9 - 9: oOo0O00 * i1
 I11 = [ 0 ] * 4
 vwAppConfig . longToByte ( cardno , I11 , 0 , 4 )
 I1Ii = I11 [ 0 ] + I11 [ 1 ] * 256 + I11 [ 2 ] * 100000
 if 6 - 6: oOo0O00 . IiIIii11Ii + Ooo0Ooo
 if 19 - 19: Ooo0Ooo % i1I
 ii1I = cardno ^ 0xffffffff
 vwAppConfig . longToByte ( ii1I , I11 , 0 , 4 )
 IiiI1III1iI = I11 [ 0 ] + I11 [ 1 ] * 256 + I11 [ 2 ] * 100000
 if 37 - 37: I1Ii1I1 % iI1iII1I1I1i . i1I + Ooo0Ooo + ooOOO * iI1iII1I1I1i
 oOooO0O0 = cardno
 O0 = cardno
 if cardno < 25565535 and ( cardno % 100000 ) < 65535 :
  oOooO0O0 = int ( ( cardno - ( cardno % 100000 ) ) / 100000 * 65536 + ( cardno % 100000 ) )
  O0 = oOooO0O0 ^ 0xffffff
  if 51 - 51: i1I . Ii * IiI11Ii111
 return [ cardno , I1Ii , ii1I , IiiI1III1iI , oOooO0O0 , O0 ]
 if 96 - 96: i1 + IiIIii11Ii % I1I / IiI11Ii111
 if 33 - 33: OooOoo * Oo * Ii * iI1iII1I1I1i + i1I . IiIIii11Ii
 if 94 - 94: oOo0O00 . i1iiIII111
 if 96 - 96: I1I / oOO / I11iiIi11i1I + I11iiIi11i1I
@ bp . route ( '/web_help_faq_update_superpassword' , methods = [ 'POST' ] )
@ login_required
def web_help_faq_update_superpassword ( ) :
 oOO0Oo = vwAppConfig . parseInt ( request . form . get ( "f_SuperPassword1" ) )
 oo00 = vwAppConfig . parseInt ( request . form . get ( "f_SuperPassword2" ) )
 OOo = vwAppConfig . parseInt ( request . form . get ( "f_SuperPassword3" ) )
 oO000O0O0 = vwAppConfig . parseInt ( request . form . get ( "f_SuperPassword4" ) )
 ooOo00O0o0o0 = [ oOO0Oo , oo00 , OOo , oO000O0O0 ]
 for OOOoOo in range ( 4 ) :
  if TBReaderpassword . query . filter ( TBReaderpassword . f_Notes == str ( OOOoOo + 1 ) ) . all ( ) :
   TBReaderpassword . query . filter ( TBReaderpassword . f_Notes == str ( OOOoOo + 1 ) ) . update ( { "f_Password" : ooOo00O0o0o0 [ OOOoOo ] } ,
 synchronize_session = False )
   db . session . commit ( )
  else :
   OOooooOOooo0 = TBReaderpassword ( f_Password = ooOo00O0o0o0 [ OOOoOo ] , f_BAll = 1 , f_ReaderID = 0 , f_Notes = str ( OOOoOo + 1 ) )
   db . session . add ( OOooooOOooo0 )
   db . session . commit ( )
   if 18 - 18: IiIIii11Ii - oOO * i1I - OooOoo
 o0OOo0OoO ( ooOo00O0o0o0 )
 if 1 :
  i1i = '<div class="card-body">'
  i1i = i1i + '<div class="form-group"><label class="text-danger">Door access password update completed!!!</label></div>' . format (
 )
  i1i = i1i + '</div>'
  if 57 - 57: Oo + IiIIii11Ii
 return i1i
 if 70 - 70: Ii + ooOOO - Oo / i1i1i1111I - I1I * IiI11Ii111
 if 3 - 3: i1iiIII111
def iii1i1iiIi1 ( ) :
 iIIIII1i111i = {
 "jsonrpc" : "2.0" ,
 "method" : "ExternFunctions" ,
 "params" : [
 {
 "FunctionName" : "SearchController"
 }
 ] ,
 "id" : 4001
 }
 IIiiii1IiIiII = vwAppConfig . sendByHttpWithMsg ( iIIIII1i111i )
 if not IIiiii1IiIiII :
  return [ ]
 i1iiiiIIIiIi = {
 "jsonrpc" : "2.0" ,
 "method" : "ExternFunctions" ,
 "params" : [
 {
 "FunctionName" : "Get1001RunningInformation"
 }
 ] ,
 "id" : 4001
 }
 oOoo0 = Iio0 ( i1iiiiIIIiIi )
 oOoo = [ ]
 if oOoo0 :
  if 1 - 1: OooOoo / ooOOO % I1Ii1I1
  if 15 - 15: OooOoo . IiIIii11Ii . i1I / Iii1i + ooOOO / Ii
  II = oOoo0 [ '1001StartupTime' ]
  OO0000 = oOoo0 [ 'JoinedControllerSN' ]
  if len ( OO0000 ) == 0 :
   pass
  else :
   for ii1Ii1I in OO0000 :
    oo0 = ii1Ii1I [ 'SN' ]
    i11iIii = datetime . datetime . strptime ( ii1Ii1I [ "RefreshTime" ] , "%Y-%m-%d %H:%M:%S" )
    if 17 - 17: I11iiIi11i1I - i1i1i1111I . iI1iII1I1I1i - I11iiIi11i1I + Oo % iI1iII1I1I1i
    if 65 - 65: Ii % I11iiIi11i1I
    I11iIi1i = datetime . datetime . strptime ( ii1Ii1I [ "ServerTime" ] , "%Y-%m-%d %H:%M:%S" )
    if 39 - 39: Iii1i * IIiIIiIi11I1 . Ooo0Ooo - Oo
    if abs ( int ( I11iIi1i . timestamp ( ) ) - int ( i11iIii . timestamp ( ) ) ) > 60 :
     continue
    oOoo . append ( oo0 )
 OoO = WGControllerCenter2023 ( )
 if 78 - 78: OooOoo . ooOOO
 for ii1Ii1I in oOoo :
  oo0 = ii1Ii1I
  O0OO00Oo0o0 = ii1Ii1I
  OoO . getswipeSN . append ( oo0 )
  if 84 - 84: I1I * iI1iII1I1I1i - Ooo0Ooo / iI1iII1I1I1i + ooo000
  oOO0OOo = threading . Thread ( target = checkConnectedSingle , args = ( oo0 , O0OO00Oo0o0 , OoO ) )
  oOO0OOo . start ( )
 ooo = time . time ( )
 if 56 - 56: IiIIii11Ii
 while time . time ( ) < ooo + 2 :
  if len ( OoO . getswipeSNConnectedOK ) + len ( OoO . getswipeSNFailed ) == len ( OoO . getswipeSN ) :
   break
  time . sleep ( 0.1 )
  if 17 - 17: i1I . oOO % Oo + IiIIii11Ii - Ooo0Ooo
  if 93 - 93: oOo0O00
 O00 = [ ]
 if len ( OoO . getswipeSNConnectedOK ) > 0 :
  for OOOoOo in range ( len ( OoO . getswipeSNConnectedOK ) ) :
   O0OO00Oo0o0 = OoO . getswipeIdConnectedOK [ OOOoOo ]
   oo0 = OoO . getswipeSNConnectedOK [ OOOoOo ]
   O00 . append ( oo0 )
 return O00
 if 28 - 28: IIiIIiIi11I1 * i1
 if 14 - 14: IiIIii11Ii % ooOOO . i1I
@ bp . route ( '/web_help_faq_webapi' , methods = [ 'POST' , 'GET' ] )
@ login_required
def web_help_faq_webapi ( ) :
 I11111i111 = iii1i1iiIi1 ( )
 if len ( I11111i111 ) == 0 :
  I11111i111 = None
 else :
  I11111i111 . sort ( )
 iiii11iiiiI = {
 "objlist" : I11111i111 ,
 "wgserver1001" : vwAppConfigParam . wgwsserver1001 ,
 }
 return render_template ( "wgcomm/help-webapi.html" , ** iiii11iiiiI )
 if 35 - 35: I1Ii1I1
import asyncio
def OOooo00 ( arrinfob = None , cloudserverip = None , timeoutSec = 3 ) :
 Oo0 = None
 try :
  ooooo = arrinfob
  oO00o00OO = vwAppConfigParam . server1001_ip
  if cloudserverip :
   oO00o00OO = cloudserverip
  o00o = vwAppConfigParam . server1001_webport
  Ii11I = http . client . HTTPConnection ( host = oO00o00OO , port = o00o , timeout = 3 )
  iIi = bytes ( json . dumps ( ooooo , sort_keys = False , indent = 4 ) , encoding = 'utf8' )
  O000O0Oo0 = { "Content-type" : "application/json" , "Accept" : "application/json" }
  Ii11I . timeout = timeoutSec
  Ii11I . request ( "POST" , oO00o00OO , iIi , O000O0Oo0 )
  Oo0O0O = Ii11I . getresponse ( )
  Ii1IiIII1 = Oo0O0O . read ( )
  Ii11I . close ( )
  try :
   iiI1 = json . loads ( Ii1IiIII1 . decode ( "utf-8" ) )
   Oo0 = iiI1
  except Exception as iII :
   vwAppConfig . wglog ( iII )
   Oo0 = None
   return Oo0
  return Oo0
 except Exception as iII :
  pass
  print ( iII )
 return None
 if 52 - 52: OooOoo
 if 95 - 95: i1i1i1111I . I11iiIi11i1I * ooo000 / iI1iII1I1I1i - I1Ii1I1 + IiIIii11Ii
@ bp . route ( '/web_help_faq_webapi_post' , methods = [ 'POST' ] )
@ login_required
def web_help_faq_webapi_post ( ) :
 iIIIII1i111i = request . form . get ( "cmdjson" )
 O0oooo0o0oO = request . form . get ( 'cloudserverip' )
 IIiiii1IiIiII = OOooo00 ( iIIIII1i111i , O0oooo0o0oO )
 if IIiiii1IiIiII :
  return json . dumps ( IIiiii1IiIiII , indent = 2 , ensure_ascii = False )
  if 57 - 57: IIiIIiIi11I1 - iI1iII1I1I1i % ooOOO - I11iiIi11i1I / IiIIii11Ii . Ooo0Ooo
 return "Communication test abnormal???"
 if 15 - 15: i1I * I11iiIi11i1I - oOo0O00
 if 6 - 6: IiI11Ii111 - Ii
def iiiIII ( cloudserverip ) :
 i1iiiiIIIiIi = {
 "jsonrpc" : "2.0" ,
 "method" : "ExternFunctions" ,
 "params" : [
 {
 "FunctionName" : "Get1001RunningInformation"
 }
 ] ,
 "id" : 4001
 }
 oOoo0 = Iio0 ( i1iiiiIIIiIi , cloudserverip )
 if not oOoo0 :
  return None
 oOoo = [ ]
 if oOoo0 :
  if 16 - 16: IIiIIiIi11I1
  if 96 - 96: OooOoo / oOO - i1 * I11iiIi11i1I
  II = oOoo0 [ '1001StartupTime' ]
  OO0000 = oOoo0 [ 'JoinedControllerSN' ]
  if len ( OO0000 ) == 0 :
   pass
  else :
   for ii1Ii1I in OO0000 :
    oo0 = ii1Ii1I [ 'SN' ]
    if 72 - 72: i1i1i1111I + Ii - Iii1i - i1i1i1111I - i1I + Ooo0Ooo
    if 74 - 74: Ooo0Ooo * Oo + Iii1i - i1iiIII111
    if 22 - 22: IiIIii11Ii - Ooo0Ooo . i1 . i1I - ooo000
    if 68 - 68: ooo000
    if 40 - 40: i1 + I1Ii1I1 + I11iiIi11i1I . Oo * I11iiIi11i1I % I1I
    if 100 - 100: OooOoo + Oo / OooOoo
    if 33 - 33: IiI11Ii111 / OooOoo
    if 98 - 98: I1Ii1I1 . IIiIIiIi11I1 * i1I - iI1iII1I1I1i % i1I * IiI11Ii111
    oOoo . append ( oo0 )
 OoO = WGControllerCenter2023 ( )
 if 42 - 42: OooOoo + i1i1i1111I - iI1iII1I1I1i - oOo0O00 * i1I + Ii
 for ii1Ii1I in oOoo :
  oo0 = ii1Ii1I
  O0OO00Oo0o0 = ii1Ii1I
  OoO . getswipeSN . append ( oo0 )
  if 46 - 46: oOo0O00 . iI1iII1I1I1i - Ii . oOo0O00 + i1i1i1111I
  oOO0OOo = threading . Thread ( target = checkConnectedSingle , args = ( oo0 , O0OO00Oo0o0 , OoO , cloudserverip ) )
  oOO0OOo . start ( )
 ooo = time . time ( )
 if 83 - 83: IiI11Ii111
 while time . time ( ) < ooo + 2 :
  if len ( OoO . getswipeSNConnectedOK ) + len ( OoO . getswipeSNFailed ) == len ( OoO . getswipeSN ) :
   break
  time . sleep ( 0.1 )
  if 77 - 77: iI1iII1I1I1i - oOO % Ii * i1I - I1I
  if 42 - 42: I11iiIi11i1I - Ii / Oo - i1i1i1111I + I11iiIi11i1I
 O00 = [ ]
 if len ( OoO . getswipeSNConnectedOK ) > 0 :
  for OOOoOo in range ( len ( OoO . getswipeSNConnectedOK ) ) :
   O0OO00Oo0o0 = OoO . getswipeIdConnectedOK [ OOOoOo ]
   oo0 = OoO . getswipeSNConnectedOK [ OOOoOo ]
   O00 . append ( oo0 )
 return O00
 if 83 - 83: i1 . iI1iII1I1I1i
 if 57 - 57: IiI11Ii111 % IiIIii11Ii / oOo0O00 + Ooo0Ooo - i1iiIII111
@ bp . route ( '/web_help_faq_webapi_newcloudserver' , methods = [ 'POST' ] )
@ login_required
def web_help_faq_webapi_newcloudserver ( ) :
 try :
  if 87 - 87: i1iiIII111 . i1iiIII111 . oOO . ooo000 * oOo0O00
  O0oooo0o0oO = request . form . get ( 'cloudserverip' )
  I11111i111 = iiiIII ( O0oooo0o0oO )
  if I11111i111 :
   if len ( I11111i111 ) == 0 :
    I11111i111 = "There are no controller on line"
   else :
    I11111i111 . sort ( )
    I11111i111 = "OnLine Controller;" + ";" . join ( [ str ( x ) for x in I11111i111 ] )
    if 33 - 33: IiI11Ii111 * i1iiIII111 / i1I . OooOoo * oOo0O00 + ooo000
    if 17 - 17: i1i1i1111I * oOO + i1iiIII111 - I11iiIi11i1I / i1i1i1111I
    if 83 - 83: I11iiIi11i1I - Iii1i + oOo0O00 + I1I / IIiIIiIi11I1 + I1I
    if 29 - 29: i1i1i1111I / oOo0O00
    if 13 - 13: I11iiIi11i1I % i1iiIII111 . OooOoo % ooo000 % OooOoo
    if 21 - 21: IiI11Ii111 * I1Ii1I1
   return I11111i111
   if 93 - 93: Ooo0Ooo . i1 + IiI11Ii111 - oOo0O00
 except :
  pass
 return "Server communicate failed???"
 if 97 - 97: i1 - i1 % IIiIIiIi11I1 + IiIIii11Ii / i1I * iI1iII1I1I1i
 if 60 - 60: I11iiIi11i1I - Ooo0Ooo % I1Ii1I1
class ii1II1 :
 def __init__ ( self ) :
  if 14 - 14: Oo % i1i1i1111I + ooOOO / I11iiIi11i1I - Ooo0Ooo / i1i1i1111I
  if 29 - 29: Iii1i + Ii - I11iiIi11i1I - IiIIii11Ii
  if 31 - 31: IiIIii11Ii . Iii1i / Oo + i1iiIII111
  self . uploadedSNOK = [ ]
  self . uploadedSNFailed = [ ]
  self . uploadedSN = [ ]
  self . uploadedSNConnectedOK = [ ]
  if 19 - 19: oOo0O00 . IIiIIiIi11I1
  self . uploadedIdConnectedOK = [ ]
  self . uploadedSNOK_Delete = [ ]
  if 90 - 90: IIiIIiIi11I1 * iI1iII1I1I1i
  self . uploadedSNFailed_Delete = [ ]
  self . uploadedSN_Delete = [ ]
  self . recvsnpri = [ ]
  self . uploadedSNReply = [ ]
  if 79 - 79: i1i1i1111I
  if 3 - 3: OooOoo / IiI11Ii111 % I11iiIi11i1I
  if 55 - 55: oOo0O00
def o0OOo0OoO ( arrpwd ) :
 OoO = ii1II1 ( )
 o0OoOOo00OOO = db . session . query ( TBController . f_ControllerSN ) . filter ( TBController . f_Enabled >= 1 ) . order_by (
 TBController . f_ControllerSN )
 Iii = o0OoOOo00OOO . all ( )
 if 54 - 54: iI1iII1I1I1i % Oo . IiI11Ii111 - Iii1i % I11iiIi11i1I * i1I
 iIi1Ii = "uploadSuperpassword"
 o0o0Oo00000o = 1
 O0O0oOoO = "8C0000FFFFFFFF0{}000000" . format ( 1 )
 for ooOo00O0o0o0 in arrpwd :
  O0O0oOoO += WGTools . getHexString4Byte ( ooOo00O0o0o0 )
 i1IiiI1I1i1 = "8C0000FFFFFFFF0{}000000" . format ( 2 )
 for ooOo00O0o0o0 in arrpwd :
  i1IiiI1I1i1 += WGTools . getHexString4Byte ( ooOo00O0o0o0 )
 Oooo0OoOoooo = "8C0000FFFFFFFF0{}000000" . format ( 3 )
 for ooOo00O0o0o0 in arrpwd :
  Oooo0OoOoooo += WGTools . getHexString4Byte ( ooOo00O0o0o0 )
 OO0OOo0oOO = "8C0000FFFFFFFF0{}000000" . format ( 4 )
 for ooOo00O0o0o0 in arrpwd :
  OO0OOo0oOO += WGTools . getHexString4Byte ( ooOo00O0o0o0 )
  if 100 - 100: i1iiIII111
 oOO0OOO = ( O0O0oOoO . ljust ( 126 , '0' ) , i1IiiI1I1i1 . ljust ( 126 , '0' ) , Oooo0OoOoooo . ljust ( 126 , '0' ) ,
 OO0OOo0oOO . ljust ( 126 , '0' ) )
 if 24 - 24: IIiIIiIi11I1 * I11iiIi11i1I + i1i1i1111I + Ooo0Ooo
 for Ii1IIiiI1II in Iii :
  oo0 = Ii1IIiiI1II . f_ControllerSN
  iIIIII1i111i = {
 "jsonrpc" : "2.0" ,
 "method" : "Primit64ByteCommand" ,
 "params" : [ { 'ControllerSN' : oo0 ,
 'CommandPacket' : WGTools . getarrStringWithsplitDou ( oOO0OOO )
  } ] ,
 "id" : "1005"
 }
  IIiiii1IiIiII = O0OO ( iIIIII1i111i )
  if not vwAppConfig . successIsTrue ( IIiiii1IiIiII ) :
   OoO . uploadedSNFailed . append ( oo0 )
   vwAppConfig . wglog ( "uploadSingleConfigure {} end Failed1" . format ( oo0 ) )
   return
  oOO0OOo = threading . Thread ( target = oO0OO0oo00OO0 , args = ( oo0 , iIIIII1i111i , OoO ) )
  oOO0OOo . start ( )
  if 96 - 96: Iii1i / IiI11Ii111 / iI1iII1I1I1i * OooOoo . i1 . IiIIii11Ii
 Oo0o0OOOOo0 = time . time ( ) + 3
 while time . time ( ) < Oo0o0OOOOo0 :
  if len ( OoO . uploadedSNOK ) + len ( OoO . uploadedSNFailed ) == len ( OoO . uploadedSN ) :
   break
  time . sleep ( 0.1 )
 return { "updateConOK" : OoO . uploadedSNOK , "updateConFailed" : OoO . uploadedSNFailed }
 if 18 - 18: ooo000 + ooOOO + Oo / I1Ii1I1 . IIiIIiIi11I1
 if 67 - 67: Oo % ooOOO + iI1iII1I1I1i * I1I
def oO0OO0oo00OO0 ( sn , cmdjson , wgcondata , cloudserverip = None , waittimeSec = 3 ) :
 vwAppConfig . wglog ( "sendCommandWithMsgByThread {} start" . format ( sn ) )
 if 79 - 79: IIiIIiIi11I1 * Oo / OooOoo
 if 10 - 10: iI1iII1I1I1i / i1iiIII111 . IiIIii11Ii * i1i1i1111I
 if 71 - 71: oOo0O00 + I1Ii1I1 / I11iiIi11i1I + Oo / I1I
 if 18 - 18: Iii1i - IiIIii11Ii
 if 71 - 71: iI1iII1I1I1i + OooOoo % i1i1i1111I % oOo0O00 . ooo000
 if 92 - 92: I11iiIi11i1I - Ooo0Ooo - i1i1i1111I % i1iiIII111 / i1i1i1111I * iI1iII1I1I1i
 if 60 - 60: IiIIii11Ii % oOO / i1I * OooOoo / I11iiIi11i1I - Ii
 if 16 - 16: oOo0O00 / I1Ii1I1 / i1 + I11iiIi11i1I + oOo0O00
 if 11 - 11: oOO / OooOoo + oOo0O00
 if 79 - 79: I11iiIi11i1I . I1Ii1I1 * i1I % I1Ii1I1 / IiI11Ii111
 if 93 - 93: i1I + Iii1i . Ii . i1I * ooOOO
 I1iI11I1IIi = O0OO ( cmdjson , cloudserverip , waittimeSec )
 if vwAppConfig . successIsTrue ( I1iI11I1IIi ) :
  Oo0ooOOOO = I1iI11I1IIi [ "ReturnPacket" ]
  IiI1I1IIiI1 = bytearray ( binascii . unhexlify ( Oo0ooOOOO . replace ( " " , "" ) ) )
  if IiI1I1IIiI1 [ 8 ] == 0x1 :
   wgcondata . uploadedSNOK . append ( sn )
   vwAppConfig . wglog ( "sendCommandByThread {} end OK" . format ( sn ) )
  else :
   wgcondata . uploadedSNFailed . append ( sn )
   vwAppConfig . wglog ( "sendCommandByThread {} end Failed" . format ( sn ) )
   if 72 - 72: i1iiIII111
   if 31 - 31: ooOOO . i1 - Oo / Ii
 else :
  if 38 - 38: Ooo0Ooo % I1Ii1I1 / i1I + i1iiIII111
  wgcondata . uploadedSNFailed . append ( sn )
  vwAppConfig . wglog ( "sendCommandByThread {} end Failed" . format ( sn ) )
  if 25 - 25: I11iiIi11i1I - iI1iII1I1I1i
  if 64 - 64: Iii1i - ooo000 . I11iiIi11i1I
def O0OO ( arrinfo , cloudserverip = None , timeoutSec = 3 ) :
 Oo0 = None
 try :
  oO00o00OO = vwAppConfigParam . server1001_ip
  if cloudserverip :
   oO00o00OO = cloudserverip
  o00o = vwAppConfigParam . server1001_webport
  Ii11I = http . client . HTTPConnection ( host = oO00o00OO , port = o00o , timeout = 3 )
  iIi = bytes ( json . dumps ( arrinfo , sort_keys = False , indent = 4 ) , encoding = 'utf8' )
  O000O0Oo0 = { "Content-type" : "application/json" , "Accept" : "application/json" }
  Ii11I . timeout = timeoutSec
  Ii11I . request ( "POST" , oO00o00OO , iIi , O000O0Oo0 )
  Oo0O0O = Ii11I . getresponse ( )
  Ii1IiIII1 = Oo0O0O . read ( )
  Ii11I . close ( )
  try :
   iiI1 = json . loads ( Ii1IiIII1 . decode ( "utf-8" ) )
   Oo0 = iiI1 [ 'result' ]
  except :
   Oo0 = None
   return Oo0
  return Oo0
 except Exception as iII :
  pass
  print ( iII )
 return None
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
