123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- #INCLUDE "TOTVS.CH"
- #INCLUDE "APWEBEX.CH"
- #DEFINE SESSHTTP "GlbSessions"
- /*
- +----------------------------------------------------------------------------+
- ! FICHA TECNICA DO PROGRAMA !
- +----------------------------------------------------------------------------+
- ! DADOS DO PROGRAMA !
- +------------------+---------------------------------------------------------+
- !Tipo ! Portal SMS !
- +------------------+---------------------------------------------------------+
- !Modulo ! Portal SMS - Insite !
- +------------------+---------------------------------------------------------+
- !Nome ! InSite !
- +------------------+---------------------------------------------------------+
- !Descricao ! Abre comunicacao com o servidor Protheus e as tabelas !
- ! ! que serao utilizadas !
- +------------------+---------------------------------------------------------+
- !Autor ! Anderson Jose Zelenski !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 19/09/2013 !
- +----------------------------------------------------------------------------+
- +------------------+---------------------------------------------------------+
- !Descricao ! Tratamento para verificar se a sessao do usuario esta ok!
- +------------------+---------------------------------------------------------+
- !Autor ! Pedro A. de Souza !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 08/02/2021 !
- +----------------------------------------------------------------------------+
- */
- User Function InSite(lCheckSess)
- Local cHtml := ""
- Local cSrvEmpresa := ""
- Local cSrvFilial := ""
- Local cWebModulo := "FAT"
- Local lConectar := .T.
- local oObjLog := LogSMS():new()
- local oObjSess := LogSMS():new()
- Local nI := 0
- Local aInfo
- Local aDadSess
- Local lOk
- local nQtd := 0
- local nSecs
- default lCheckSess := .t.
- Public cEmpAnt
- Public cFilAnt
- cHtml:= '<META HTTP-EQUIV="Refresh" CONTENT="0 ; URL=u_PortalLogin.apw">'
- // Salvar o log da requisicao
- oObjLog:setFileName("\temp\"+Procname(1)+"_"+dtos(date())+".txt")
- oObjLog:saveMsg("("+ltrim(str(procline(1)))+") *** Portal ")
- if !empty(HTTPHEADIN->REMOTE_ADDR)
- oObjLog:saveMsg('HTTPHEADIN REMOTE_ADDR -> '+HTTPHEADIN->REMOTE_ADDR)
- endif
- if !empty(HTTPHEADIN->REMOTE_PORT)
- oObjLog:saveMsg('HTTPHEADIN REMOTE_PORT -> '+cValToChar(HTTPHEADIN->REMOTE_PORT))
- endif
- if !empty(HTTPCOOKIES->SESSIONID)
- oObjLog:saveMsg('HTTPCOOKIES SESSIONID -> '+HTTPCOOKIES->SESSIONID)
- endif
- if !empty(HttpSession->SESSIONID)
- oObjLog:saveMsg('SESSION SESSIONID -> '+HttpSession->SESSIONID)
- endif
- aInfo := HttpGet->aGets
- if valtype(aInfo) = "A"
- For nI := 1 to len(aInfo)
- oObjLog:saveMsg('GET '+str(nI,3)+' = '+aInfo[nI]+' -> '+&("HTTPGET->"+aInfo[nI]))
- Next
- endif
- aInfo := HttpPost->aPost
- if valtype(aInfo) = "A"
- For nI := 1 to len(aInfo)
- oObjLog:saveMsg('POST '+str(nI,3)+' = '+aInfo[nI]+' -> '+&("HTTPPOST->"+aInfo[nI]))
- Next
- endif
- if !empty(HttpSession->Tipo)
- oObjLog:saveMsg('SESSION = Tipo -> '+HttpSession->Tipo)
- endif
- If !empty(HttpSession->Superv)
- oObjLog:saveMsg('SESSION = Superv -> '+HttpSession->Superv)
- endif
- if !empty(HttpSession->CodVend)
- oObjLog:saveMsg('SESSION = CodVend -> '+HttpSession->CodVend)
- endif
- // Verificar filial logada
- if empty(HttpSession->Empresa)
- cSrvEmpresa := "01"
- else
- cSrvEmpresa := HttpSession->Empresa
- EndIf
- if empty(HttpSession->Filial)
- cSrvFilial := "01"
- else
- cSrvFilial := HttpSession->Filial
- endIf
- //if (cEmpAnt == cSrvEmpresa) .and. (cFilAnt == cSrvFilial) .and. SELECT("SX2") > 0 // valida se a empresa logada é a mesma passada
- if (cEmpAnt == cSrvEmpresa) .and. SELECT("SX2") > 0 // valida se a empresa logada é a mesma passada
- lConectar := .F.
- endIf
- //01.02.2022 - muda a filial corrente sem fazer o reset do ambiente. Leo+Pedro
- if !lConectar .and. cFilAnt <> cSrvFilial
- Conout("INSITE.apl - Trocando somente filial de "+cFilAnt+" para "+cSrvFilial+"...")
- cFilAnt:= cSrvFilial
- cNumEmp:= cEmpAnt+cFilAnt
- FWSM0Util():setSM0PositionBycFilAnt()
- Endif
- if lConectar
- nSecs:= Seconds()
- RpcClearEnv()
- //Tabelas a serem abertas
- // aSrvTabelas:={"SC1","SCR","SC7","SCE","SA1","SA2","SA6","SAK","SAL","SC8","SE1","SEA","SY1","CTT","CT1","SE4","SZX","SZZ","SZW","ZC1","AFR","ZZZ","CTN","CTS","CT3","ZV0","ZV1","ZV2","ZV3","ZM2","ZM0"}
- aSrvTabelas:={"SA1"}
- //RPCSetType(3) //Nao come licença
- /*While !LockbyName("INSITE",.F.,.F.)
- nQtd++
- Sleep(500)
- Conout("INSITE.apl - Aguardando lockbyname. Tentativa "+cValtochar(nQtd)+"...")
- if nQtd > 30
- Conout("INSITE.apl - Excedeu tentativas de lock - não abriu empresa.")
- //Final("não abriu empresa.")
- return (cHtml)
- Endif
- Enddo
- */
- if !RPCSETENV(cSrvEmpresa, cSrvFilial, , , cWebModulo, , aSrvTabelas)
- conout("Falha ao conectar na empresa/filial "+cSrvEmpresa+"/"+cSrvFilial+" - "+DtoC(dDatabase)+" "+time())
- return (cHtml)
- else
- HttpSession->Empresa:= cSrvEmpresa
- HttpSession->Filial:= cSrvFilial
- cEmpAnt:= HttpSession->Empresa
- cFilAnt:= HttpSession->Filial
- conout("Logado na empresa/filial "+cSrvEmpresa+"/"+cSrvFilial+" - "+DtoC(dDatabase)+" "+time())
- endif
- UnLockByName("INSITE",.F.,.F.)
- nSecs:= Seconds() - nSecs
- Conout("[INSITE] - Tempo de abertura: "+cValtochar(nSecs)+"s")
- endIf
- oObjLog:saveMsg('SISTEMA = CNUMEMP -> '+CNUMEMP)
- oObjLog:saveMsg('SISTEMA = cFilAnt -> '+cFilAnt)
- // Verificar se o vendedor da sessao esta correto
- if lCheckSess
- // if empty(HttpSession->SESSIONID)
- // return cHtml
- // endif
- // if empty(HttpSession->CodVend)
- // return cHtml
- // endif
- // oObjSess:setFileName(getArqSess())
- // aInfo := oObjSess:readLog()
- // lOk := .f.
- // for nI := 1 to len(aInfo)
- // aDadSess := StrTokArr(aInfo[nI], ";")
- // if len(aDadSess) > 2
- // if aDadSess[2] == HttpSession->SESSIONID .and. aDadSess[3] == HttpSession->CodVend
- // lOk := .t.
- // exit
- // endif
- // endif
- // next
- // if !lOk
- // return cHtml
- // Endif
- if !checkSess()
- oObjLog:saveMsg('Deu Erro Vai Limpar -> HttpSession->CodVend')
- HttpSession->CodVend := nil
- // return cHtml
- endif
- endif
- return
- /*
- +----------------------------------------------------------------------------+
- ! FICHA TECNICA DO PROGRAMA !
- +----------------------------------------------------------------------------+
- ! DADOS DO PROGRAMA !
- +------------------+---------------------------------------------------------+
- !Tipo ! Portal SMS !
- +------------------+---------------------------------------------------------+
- !Modulo ! Portal SMS - Insite !
- +------------------+---------------------------------------------------------+
- !Nome ! getArqSess !
- +------------------+---------------------------------------------------------+
- !Descricao ! Retorna o nome do arquivo de controle de session do dia !
- +------------------+---------------------------------------------------------+
- !Autor ! Pedro A. de Souza !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 08/02/2021 !
- +----------------------------------------------------------------------------+
- */
- static function getArqSess()
- return "\temp\session_"+dtos(date())+".txt"
- /*
- +----------------------------------------------------------------------------+
- ! FICHA TECNICA DO PROGRAMA !
- +----------------------------------------------------------------------------+
- ! DADOS DO PROGRAMA !
- +------------------+---------------------------------------------------------+
- !Tipo ! Portal SMS !
- +------------------+---------------------------------------------------------+
- !Modulo ! Portal SMS - Insite !
- +------------------+---------------------------------------------------------+
- !Nome ! svUsSes !
- +------------------+---------------------------------------------------------+
- !Descricao ! Salva o vendedor logado no arquivo de controle de !
- ! ! session do dia !
- +------------------+---------------------------------------------------------+
- !Autor ! Pedro A. de Souza !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 08/02/2021 !
- +----------------------------------------------------------------------------+
- */
- user function svUsSes(cCodVend)
- local oObjSess := LogSMS():new()
- local cSession := cValToChar(HttpSession->SESSIONID)
- local aSessions := {}
- local dData := ctod("")
- oObjSess:setFileName(getArqSess())
- oObjSess:saveMsg(";"+cSession+";"+cCodVend)
- // Tratamento por variáveis globais
- GetGlbVars(SESSHTTP, dData, aSessions)
- if empty(dData)
- aSessions := {}
- dData := date()
- elseif dData <> date()
- ClearGlbValue(SESSHTTP)
- aSessions := {}
- dData := date()
- Endif
- if valtype(aSessions) <> "A"
- aSessions := {}
- endif
- aadd(aSessions, {cSession, cCodVend})
- PutGlbVars(SESSHTTP, dData, aSessions)
- return
- /*
- +----------------------------------------------------------------------------+
- ! FICHA TECNICA DO PROGRAMA !
- +----------------------------------------------------------------------------+
- ! DADOS DO PROGRAMA !
- +------------------+---------------------------------------------------------+
- !Tipo ! Portal SMS !
- +------------------+---------------------------------------------------------+
- !Modulo ! Portal SMS - Insite !
- +------------------+---------------------------------------------------------+
- !Nome ! checkSess !
- +------------------+---------------------------------------------------------+
- !Descricao ! Verificar se o vendedor logado no arquivo de controle de!
- ! ! session do dia !
- +------------------+---------------------------------------------------------+
- !Autor ! Pedro A. de Souza !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 08/02/2021 !
- +----------------------------------------------------------------------------+
- */
- static function checkSess()
- local lOk := .t.
- local aSessions := {}
- local dData := ctod("")
- local aParm
- local cParm1 := cParm2 := ""
- if empty(HttpSession->SESSIONID)
- lOk := .f.
- endif
- if empty(HttpSession->CodVend)
- lOk := .f.
- endif
- if lOk
- // oObjSess:setFileName(getArqSess())
- // aInfo := oObjSess:readLog()
- // lOk := .f.
- // for nI := 1 to len(aInfo)
- // aDadSess := StrTokArr(aInfo[nI], ";")
- // if len(aDadSess) > 2
- // if aDadSess[2] == HttpSession->SESSIONID .and. aDadSess[3] == HttpSession->CodVend
- // lOk := .t.
- // exit
- // endif
- // endif
- // next
- // Tratamento por variáveis globais
- // GetGlbVars(SESSHTTP, dData, aSessions)
- // if empty(dData) .or. dData <> date() .or. valtype(aSessions) <> "A"
- // lOk := .f.
- // Endif
- // if lOk
- // lOk := !empty(ascan(aSessions, {|x| x[1] == HttpSession->SESSIONID .and. x[2] == HttpSession->CodVend}))
- // Endif
- lOk := .f.
- if !empty(HttpGet->PR)
- aParm := STRTOKARR(DECODE64(httpget->PR), "/")
- if len(aParm) >= 2
- cParm1 := aParm[1]
- cParm2 := aParm[2]
- if !empty(cParm2) .and. len(cParm1) = 16 .and. substr(cParm1, 11) = ":" .and. substr(cParm1, 14) = ":"
- if left(cParm1,8) = dtos(date()) .and. elaptime(right(cParm1,8), time()) <= "00:60:00"
- lOk := .t.
- endif
- endif
- endif
- endif
- endif
- return lOk
- /*
- +----------------------------------------------------------------------------+
- ! FICHA TECNICA DO PROGRAMA !
- +----------------------------------------------------------------------------+
- ! DADOS DO PROGRAMA !
- +------------------+---------------------------------------------------------+
- !Tipo ! Portal SMS !
- +------------------+---------------------------------------------------------+
- !Modulo ! Portal SMS - Insite !
- +------------------+---------------------------------------------------------+
- !Nome ! GetUsrPR !
- +------------------+---------------------------------------------------------+
- !Descricao ! Retorna o usuario do portal a partir do parametro get !
- ! ! PR !
- +------------------+---------------------------------------------------------+
- !Autor ! Pedro A. de Souza !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 08/02/2021 !
- +----------------------------------------------------------------------------+
- */
- user function GetUsrPR()
- local aParm
- local cRet := ""
- if type("httpget->PR") <> "U"
- aParm := STRTOKARR(DECODE64(httpget->PR), "/")
- if len(aParm) >= 2
- cRet := aParm[2]
- endif
- Endif
- return cRet
- /*
- +----------------------------------------------------------------------------+
- ! FICHA TECNICA DO PROGRAMA !
- +----------------------------------------------------------------------------+
- ! DADOS DO PROGRAMA !
- +------------------+---------------------------------------------------------+
- !Tipo ! Portal SMS !
- +------------------+---------------------------------------------------------+
- !Modulo ! Portal SMS - Insite !
- +------------------+---------------------------------------------------------+
- !Nome ! setParPR !
- +------------------+---------------------------------------------------------+
- !Descricao ! Setar o parametro de "session" do usuario vendedor !
- ! ! !
- +------------------+---------------------------------------------------------+
- !Autor ! Pedro A. de Souza !
- +------------------+---------------------------------------------------------+
- !Data de Criacao ! 08/02/2021 !
- +----------------------------------------------------------------------------+
- */
- user function SetParPR(cVend)
- return ESCAPE(ENCODE64(DTOS(DATE())+TIME()+"/"+cVend))
|