InSite_.apl.bak 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #INCLUDE "TOTVS.CH"
  2. #INCLUDE "APWEBEX.CH"
  3. #DEFINE SESSHTTP "GlbSessions"
  4. /*
  5. +----------------------------------------------------------------------------+
  6. ! FICHA TECNICA DO PROGRAMA !
  7. +----------------------------------------------------------------------------+
  8. ! DADOS DO PROGRAMA !
  9. +------------------+---------------------------------------------------------+
  10. !Tipo ! Portal SMS !
  11. +------------------+---------------------------------------------------------+
  12. !Modulo ! Portal SMS - Insite !
  13. +------------------+---------------------------------------------------------+
  14. !Nome ! InSite !
  15. +------------------+---------------------------------------------------------+
  16. !Descricao ! Abre comunicacao com o servidor Protheus e as tabelas !
  17. ! ! que serao utilizadas !
  18. +------------------+---------------------------------------------------------+
  19. !Autor ! Anderson Jose Zelenski !
  20. +------------------+---------------------------------------------------------+
  21. !Data de Criacao ! 19/09/2013 !
  22. +----------------------------------------------------------------------------+
  23. +------------------+---------------------------------------------------------+
  24. !Descricao ! Tratamento para verificar se a sessao do usuario esta ok!
  25. +------------------+---------------------------------------------------------+
  26. !Autor ! Pedro A. de Souza !
  27. +------------------+---------------------------------------------------------+
  28. !Data de Criacao ! 08/02/2021 !
  29. +----------------------------------------------------------------------------+
  30. */
  31. User Function InSite(lCheckSess)
  32. Local cHtml := ""
  33. Local cSrvEmpresa := ""
  34. Local cSrvFilial := ""
  35. Local cWebModulo := "SIGAFIN"
  36. Local lConectar := .T.
  37. local oObjLog := LogSMS():new()
  38. local oObjSess := LogSMS():new()
  39. Local nI := 0
  40. Local aInfo
  41. Local aDadSess
  42. Local lOk
  43. default lCheckSess := .t.
  44. Public cEmpAnt
  45. Public cFilAnt
  46. cHtml:= '<META HTTP-EQUIV="Refresh" CONTENT="0 ; URL=u_PortalLogin.apw">'
  47. // Salvar o log da requisicao
  48. oObjLog:setFileName("\temp\"+Procname(1)+"_"+dtos(date())+".txt")
  49. oObjLog:saveMsg("("+ltrim(str(procline(1)))+") *** Portal ")
  50. if !empty(HTTPHEADIN->REMOTE_ADDR)
  51. oObjLog:saveMsg('HTTPHEADIN REMOTE_ADDR -> '+HTTPHEADIN->REMOTE_ADDR)
  52. endif
  53. if !empty(HTTPHEADIN->REMOTE_PORT)
  54. oObjLog:saveMsg('HTTPHEADIN REMOTE_PORT -> '+cValToChar(HTTPHEADIN->REMOTE_PORT))
  55. endif
  56. if !empty(HTTPCOOKIES->SESSIONID)
  57. oObjLog:saveMsg('HTTPCOOKIES SESSIONID -> '+HTTPCOOKIES->SESSIONID)
  58. endif
  59. if !empty(HttpSession->SESSIONID)
  60. oObjLog:saveMsg('SESSION SESSIONID -> '+HttpSession->SESSIONID)
  61. endif
  62. aInfo := HttpGet->aGets
  63. if valtype(aInfo) = "A"
  64. For nI := 1 to len(aInfo)
  65. oObjLog:saveMsg('GET '+str(nI,3)+' = '+aInfo[nI]+' -> '+&("HTTPGET->"+aInfo[nI]))
  66. Next
  67. endif
  68. aInfo := HttpPost->aPost
  69. if valtype(aInfo) = "A"
  70. For nI := 1 to len(aInfo)
  71. oObjLog:saveMsg('POST '+str(nI,3)+' = '+aInfo[nI]+' -> '+&("HTTPPOST->"+aInfo[nI]))
  72. Next
  73. endif
  74. if !empty(HttpSession->Tipo)
  75. oObjLog:saveMsg('SESSION = Tipo -> '+HttpSession->Tipo)
  76. endif
  77. If !empty(HttpSession->Superv)
  78. oObjLog:saveMsg('SESSION = Superv -> '+HttpSession->Superv)
  79. endif
  80. if !empty(HttpSession->CodVend)
  81. oObjLog:saveMsg('SESSION = CodVend -> '+HttpSession->CodVend)
  82. endif
  83. // Verificar filial logada
  84. if empty(HttpSession->Empresa)
  85. cSrvEmpresa := "01"
  86. else
  87. cSrvEmpresa := HttpSession->Empresa
  88. EndIf
  89. if empty(HttpSession->Filial)
  90. cSrvFilial := "01"
  91. else
  92. cSrvFilial := HttpSession->Filial
  93. endIf
  94. if (cEmpAnt == cSrvEmpresa) .and. (cFilAnt == cSrvFilial) .and. Select("SX2") > 0 // valida se a empresa logada é a mesma passada
  95. lConectar := .F.
  96. endIf
  97. if lConectar
  98. RpcClearEnv()
  99. //Tabelas a serem abertas
  100. 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"}
  101. RPCSetType(3) //Nao come licença
  102. if !RPCSETENV(cSrvEmpresa, cSrvFilial, , , cWebModulo, , aSrvTabelas)
  103. conout("Falha ao conectar na empresa/filial "+cSrvEmpresa+"/"+cSrvFilial+" - "+DtoC(dDatabase)+" "+time())
  104. return (cHtml)
  105. else
  106. HttpSession->Empresa:= cSrvEmpresa
  107. HttpSession->Filial:= cSrvFilial
  108. cEmpAnt:= HttpSession->Empresa
  109. cFilAnt:= HttpSession->Filial
  110. conout("Logado na empresa/filial "+cSrvEmpresa+"/"+cSrvFilial+" - "+DtoC(dDatabase)+" "+time())
  111. endif
  112. endIf
  113. // Verificar se o vendedor da sessao esta correto
  114. if lCheckSess
  115. // if empty(HttpSession->SESSIONID)
  116. // return cHtml
  117. // endif
  118. // if empty(HttpSession->CodVend)
  119. // return cHtml
  120. // endif
  121. // oObjSess:setFileName(getArqSess())
  122. // aInfo := oObjSess:readLog()
  123. // lOk := .f.
  124. // for nI := 1 to len(aInfo)
  125. // aDadSess := StrTokArr(aInfo[nI], ";")
  126. // if len(aDadSess) > 2
  127. // if aDadSess[2] == HttpSession->SESSIONID .and. aDadSess[3] == HttpSession->CodVend
  128. // lOk := .t.
  129. // exit
  130. // endif
  131. // endif
  132. // next
  133. // if !lOk
  134. // return cHtml
  135. // Endif
  136. if !checkSess()
  137. oObjLog:saveMsg('Deu Erro Vai Limpar -> HttpSession->CodVend')
  138. HttpSession->CodVend := nil
  139. // return cHtml
  140. endif
  141. endif
  142. return
  143. /*
  144. +----------------------------------------------------------------------------+
  145. ! FICHA TECNICA DO PROGRAMA !
  146. +----------------------------------------------------------------------------+
  147. ! DADOS DO PROGRAMA !
  148. +------------------+---------------------------------------------------------+
  149. !Tipo ! Portal SMS !
  150. +------------------+---------------------------------------------------------+
  151. !Modulo ! Portal SMS - Insite !
  152. +------------------+---------------------------------------------------------+
  153. !Nome ! getArqSess !
  154. +------------------+---------------------------------------------------------+
  155. !Descricao ! Retorna o nome do arquivo de controle de session do dia !
  156. +------------------+---------------------------------------------------------+
  157. !Autor ! Pedro A. de Souza !
  158. +------------------+---------------------------------------------------------+
  159. !Data de Criacao ! 08/02/2021 !
  160. +----------------------------------------------------------------------------+
  161. */
  162. static function getArqSess()
  163. return "\temp\session_"+dtos(date())+".txt"
  164. /*
  165. +----------------------------------------------------------------------------+
  166. ! FICHA TECNICA DO PROGRAMA !
  167. +----------------------------------------------------------------------------+
  168. ! DADOS DO PROGRAMA !
  169. +------------------+---------------------------------------------------------+
  170. !Tipo ! Portal SMS !
  171. +------------------+---------------------------------------------------------+
  172. !Modulo ! Portal SMS - Insite !
  173. +------------------+---------------------------------------------------------+
  174. !Nome ! svUsSes !
  175. +------------------+---------------------------------------------------------+
  176. !Descricao ! Salva o vendedor logado no arquivo de controle de !
  177. ! ! session do dia !
  178. +------------------+---------------------------------------------------------+
  179. !Autor ! Pedro A. de Souza !
  180. +------------------+---------------------------------------------------------+
  181. !Data de Criacao ! 08/02/2021 !
  182. +----------------------------------------------------------------------------+
  183. */
  184. user function svUsSes(cCodVend)
  185. local oObjSess := LogSMS():new()
  186. local cSession := cValToChar(HttpSession->SESSIONID)
  187. local aSessions := {}
  188. local dData := ctod("")
  189. oObjSess:setFileName(getArqSess())
  190. oObjSess:saveMsg(";"+cSession+";"+cCodVend)
  191. // Tratamento por variáveis globais
  192. GetGlbVars(SESSHTTP, dData, aSessions)
  193. if empty(dData)
  194. aSessions := {}
  195. dData := date()
  196. elseif dData <> date()
  197. ClearGlbValue(SESSHTTP)
  198. aSessions := {}
  199. dData := date()
  200. Endif
  201. if valtype(aSessions) <> "A"
  202. aSessions := {}
  203. endif
  204. aadd(aSessions, {cSession, cCodVend})
  205. PutGlbVars(SESSHTTP, dData, aSessions)
  206. return
  207. /*
  208. +----------------------------------------------------------------------------+
  209. ! FICHA TECNICA DO PROGRAMA !
  210. +----------------------------------------------------------------------------+
  211. ! DADOS DO PROGRAMA !
  212. +------------------+---------------------------------------------------------+
  213. !Tipo ! Portal SMS !
  214. +------------------+---------------------------------------------------------+
  215. !Modulo ! Portal SMS - Insite !
  216. +------------------+---------------------------------------------------------+
  217. !Nome ! checkSess !
  218. +------------------+---------------------------------------------------------+
  219. !Descricao ! Verificar se o vendedor logado no arquivo de controle de!
  220. ! ! session do dia !
  221. +------------------+---------------------------------------------------------+
  222. !Autor ! Pedro A. de Souza !
  223. +------------------+---------------------------------------------------------+
  224. !Data de Criacao ! 08/02/2021 !
  225. +----------------------------------------------------------------------------+
  226. */
  227. static function checkSess()
  228. local lOk := .t.
  229. local aSessions := {}
  230. local dData := ctod("")
  231. local aParm
  232. local cParm1 := cParm2 := ""
  233. if empty(HttpSession->SESSIONID)
  234. lOk := .f.
  235. endif
  236. if empty(HttpSession->CodVend)
  237. lOk := .f.
  238. endif
  239. if lOk
  240. // oObjSess:setFileName(getArqSess())
  241. // aInfo := oObjSess:readLog()
  242. // lOk := .f.
  243. // for nI := 1 to len(aInfo)
  244. // aDadSess := StrTokArr(aInfo[nI], ";")
  245. // if len(aDadSess) > 2
  246. // if aDadSess[2] == HttpSession->SESSIONID .and. aDadSess[3] == HttpSession->CodVend
  247. // lOk := .t.
  248. // exit
  249. // endif
  250. // endif
  251. // next
  252. // Tratamento por variáveis globais
  253. // GetGlbVars(SESSHTTP, dData, aSessions)
  254. // if empty(dData) .or. dData <> date() .or. valtype(aSessions) <> "A"
  255. // lOk := .f.
  256. // Endif
  257. // if lOk
  258. // lOk := !empty(ascan(aSessions, {|x| x[1] == HttpSession->SESSIONID .and. x[2] == HttpSession->CodVend}))
  259. // Endif
  260. lOk := .f.
  261. if !empty(HttpGet->PR)
  262. aParm := STRTOKARR(DECODE64(httpget->PR), "/")
  263. if len(aParm) >= 2
  264. cParm1 := aParm[1]
  265. cParm2 := aParm[2]
  266. if !empty(cParm2) .and. len(cParm1) = 16 .and. substr(cParm1, 11) = ":" .and. substr(cParm1, 14) = ":"
  267. if left(cParm1,8) = dtos(date()) .and. elaptime(right(cParm1,8), time()) <= "00:60:00"
  268. lOk := .t.
  269. endif
  270. endif
  271. endif
  272. endif
  273. endif
  274. return lOk
  275. /*
  276. +----------------------------------------------------------------------------+
  277. ! FICHA TECNICA DO PROGRAMA !
  278. +----------------------------------------------------------------------------+
  279. ! DADOS DO PROGRAMA !
  280. +------------------+---------------------------------------------------------+
  281. !Tipo ! Portal SMS !
  282. +------------------+---------------------------------------------------------+
  283. !Modulo ! Portal SMS - Insite !
  284. +------------------+---------------------------------------------------------+
  285. !Nome ! GetUsrPR !
  286. +------------------+---------------------------------------------------------+
  287. !Descricao ! Retorna o usuario do portal a partir do parametro get !
  288. ! ! PR !
  289. +------------------+---------------------------------------------------------+
  290. !Autor ! Pedro A. de Souza !
  291. +------------------+---------------------------------------------------------+
  292. !Data de Criacao ! 08/02/2021 !
  293. +----------------------------------------------------------------------------+
  294. */
  295. user function GetUsrPR()
  296. local aParm
  297. local cRet := ""
  298. If Type("httpget->PR") <> "U"
  299. aParm := STRTOKARR(DECODE64(httpget->PR), "/")
  300. if len(aParm) >= 2
  301. cRet := aParm[2]
  302. endif
  303. endif
  304. return cRet
  305. /*
  306. +----------------------------------------------------------------------------+
  307. ! FICHA TECNICA DO PROGRAMA !
  308. +----------------------------------------------------------------------------+
  309. ! DADOS DO PROGRAMA !
  310. +------------------+---------------------------------------------------------+
  311. !Tipo ! Portal SMS !
  312. +------------------+---------------------------------------------------------+
  313. !Modulo ! Portal SMS - Insite !
  314. +------------------+---------------------------------------------------------+
  315. !Nome ! setParPR !
  316. +------------------+---------------------------------------------------------+
  317. !Descricao ! Setar o parametro de "session" do usuario vendedor !
  318. ! ! !
  319. +------------------+---------------------------------------------------------+
  320. !Autor ! Pedro A. de Souza !
  321. +------------------+---------------------------------------------------------+
  322. !Data de Criacao ! 08/02/2021 !
  323. +----------------------------------------------------------------------------+
  324. */
  325. user function SetParPR(cVend)
  326. return ESCAPE(ENCODE64(DTOS(DATE())+TIME()+"/"+cVend))