;---------------------------------------------------------------------------- ; File : IEMSI.PPS ; Original by : LONE RUNNER on 02/06/1995 at 15:51:06 - T'was AGSLOG 2 :) ; Last update by : LONE RUNNER on 09/17/1995 at 19:11:43 ;---------------------------------------------------------------------------- ; Boolean StuffAll ; StuffAll = True ; ; ^^^^ Set this to False if you don't want to Kbdstuff the User's ; Name & Password! In this case, you will have to modify your ; normal login PPE so it opens the IEMSI log file and retrieve ; informations from it! See IEMSI.DOC for more details... ; ;---------------------------------------------------------------------------- Declare Function TickNow() Long Declare Function CodeHiascii(bigstr str) BigStr Declare Function DecodeHiascii(bigstr str) BigStr Declare Function DosToUnix(Date curdat, Time curtim) UNSIGNED Declare Procedure UnixToDos(unsigned dat, Date newDate var, Time NewTime Var) Declare Procedure WriteLog() Declare Procedure MakeISI() ;---------------------------------------------------------------------------- BigStr EMSI_REQ BigStr EMSI_IRQ BigStr EMSI_ACK BigStr EMSI_NAK BigStr EMSI_IIR BigStr EMSI_ICI BigStr EMSI_ISI BigStr EMSI_ISM boolean EMSIOK String CR String IemsiCopyright ;---------------------------------------------------------------------------- ; Please, let this in place, as it will appear NOWHERE! IemsiCopyright = "í AEGiS CoRP iEMSI iNTERFACE v1.1 í By Lone Runner / AGS'95 í" CR = Chr(13) EMSI_REQ = "**EMSI_REQA77E"+CR EMSI_IRQ = "**EMSI_IRQ8E08"+CR EMSI_ACK = "**EMSI_ACKA490"+CR EMSI_NAK = "**EMSI_NAKEEC3"+CR EMSI_IIR = "**EMSI_IIR61E2"+CR EMSI_ICI = "**EMSI_ICI" ;---------------------------------------------------------------------------- Integer Timer1 Integer Timer2 Integer Tries ;---------------------------------------------------------------------------- unsigned t integer RcvTries Date newdat Time newtim word c String k BigStr RcvString BigStr TempString Integer Count Integer A String ClientName String ClientPassword string ClientAlias string ClientLocation string ClientDataPhone string ClientVoicePhone string ClientBirthdate string ClientSoftware Boolean CrkTe unsigned unixdate String Temp long crc long crc2 long xorot String File ;---------------------------------------------------------------------------- String BoardName String SysopName String BoardLocation ;---------------------------------------------------------------------------- String Msg(12) ;---------------------------------------------------------------------------- if (!onlocal()) gosub tryiemsi ; Gosub sux ;) sorry, it's a Copy/Paste end ; from an old code :> ; I sould have take the time to change that ; but hey... booring ;) :tryiemsi File = PPEPATH()+"IEMSI."+STRING(PCBNODE()) If (Exist(File)) Delete File Fopen 1, PPEPath() + "IEMSI.MSG", O_RD, S_DN For a = 1 to 12 FGet 1, Msg(a) next FClose 1 BoardName = ReadLine(PPEPath()+"IEMSI.CFG",1) BoardLocation = ReadLine(PPEPath()+"IEMSI.CFG",2) SysopName = ReadLine(PPEPath()+"IEMSI.CFG",3) FClose -1 SprintLn Msg(12) while (outbytes() != 0) do endwhile xorot = S2i("FFFFFFFF",16) ; Init var XOR SPrintLn Msg(1) ; Advance session info Print "" Print CR MPrint EMSI_IRQ ; Send IEMSI request MPrint " "+CR ; Clear it in case no Iemsi is supported Tries = 0 ; Try #0! RcvString = "" ; Reset Buffer ; Wait for Iemsi answer MakeISI() ; Create EMSI_ISI packet (we user the delay ; to lose as less time as possible) ;while (tickNow() < t + 36) do ; If the packet creation took less that 2s ;endwhile ; we complete the waiting ; ; ---> This seems to be unnecessary :GetICI Inc Tries ; New try If (Tries > 3) Goto EMSIFailed ; If more that 3 tries IEMSI failure t = ticknow() ; # of 1/18.2 since midnight While (1) Do k = MInkey() ; Read modem buffer RcvString = RcvString + k ; Add to the answer string If (k = CR) Break ; If CR received, we have all ! if ((t+36 < TickNow()) && inbytes() = 0 ) break ; Goto nak1 ; No ? So we continue ; with a timeout of 1s & a condition : no more ; chars in the modem buffer EndWhile If (RcvString = "") Goto noIemsi If (len(RcvString) < 49) Then ; If the length is < 49 we take the following Goto GetICI ; part of it (49 = len of an empty packet) endif ; Handle received Packet :handleICI SprintLn Msg(3) ; Advance session info A = s2i(mid(RcvString,11,4),16) ; Get the CRC ; TempString = mid(RcvString,3,a+12) ; crc = s2i(mid(RcvString,15+a,8),16) ; crc2 = CRC32(CRC_STR,TempString) ; Calculate real CRC from received pckt crc2 = XOR(crc2,xorot) ; if (crc != crc2) goto nak1 ; Compare them TempString = RcvString ; Temporary string TempString = DecodeHiascii(TempString) ; Decode Hiascii ("\00" = Chr(0)) A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientName = Left(TempString,A-1) ; User's Name ! A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientAlias = Left(TempString,A-1) ; User's Alias ! A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientLocation = Left(TempString,A-1) ; User's Location ! A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientDataPhone = Left(TempString,A-1) ; User's Dataphone ! A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientVoicePhone = Left(TempString,A-1) ; User's Voicephone ! A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientPassword = Left(TempString,A-1) ; User's Password ! A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientBirthdate = Left(TempString,A-1) ; User's Date of Birth ! if (ClientBirthdate != "") Then unixdate=S2i(ClientBirthdate,16) ; Convert UnixDate -> DosDate UnixToDos(unixdate,newdat,newtim) ClientBirthdate = String(newdat) ; End Convertion endif ; Didn't use a loop here so you can do exactly what you want with ; the received packet. \/ A = Instr(TempString,"{") ; Jump one field TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"{") ; Jump one field TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"{") ; Jump one field TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"{") ; Jump one field TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"{") TempString = Mid(TempString,A+1,Len(TempString)-A) A = Instr(TempString,"}") ClientSoftware = Left(TempString,A-1) ; User's Software ! if (instr(Chr(0)+"ÿ.",Right(ClientName,1))) then ; Does the name ends ClientName = Left(ClientName, Len(ClientName)-1); with a "." ? CrkTe = True ; Yes, so it's a endif ; cracked terminate :) If (Trim(ClientName, " ") = "") Then ; If the User's Name = "" so : Goto emsiFailed ; IEMSI failed else ; Else, display received ; informations on the local ; screen only! SPrintLn "******************************************************************************" If (ClientName != "") SPrintLn "Name : " + mid(ClientName,1,62) If (ClientPassword != "") SPrintLn "Password : " + mid(ClientPassword,1,62) If (ClientAlias != "") SPrintLn "Alias : " + mid(ClientAlias,1,62) If (ClientLocation != "") SPrintLn "Location : " + mid(ClientLocation,1,62) If (ClientDataPhone != "") SPrintLn "Data Phone : " + mid(ClientDataphone,1,62) If (ClientVoicePhone != "") SPrintLn "Voice Phone: " + mid(ClientVoicePhone,1,62) If (ClientBirthdate != "") SPrintLn "Birthdate : " + mid(ClientBirthdate,1,62) If (ClientSoftware != "") SPrintLn "Software : " + mid(ClientSoftware,1,62) If (CrkTe) SprintLn "Using Cracked Version of Terminate !" SPrintLn "******************************************************************************" Goto replyISI ; and go to answer! endif :nak1 ; CRC were different ! SprintLn Msg(5) ; Advance session info MPrint EMSI_NAK ; Send a NAK ! Goto GetICI ; Go back to receive the packet :replyISI ; Client packet received, sending ; the server packet SprintLn Msg(6) ; Advance session info Tries = 0 ; Try #0 ; Begin sending :SendISI SprintLn Msg(7) ; Advance session info MPrint EMSI_ISI ; Send EMSI_ISI (server package) ;Delay 25 ; ---> This was unnecessary... Inc Tries ; Inc tries If (Tries > 3) Goto EMSIFailed ; If tries > 3 so IEMSI failed! RcvString = "" ; Reset reception buffer t = TickNow() ; # of 1/18.2 since midnight rcvTries=1 ; Reception try #1 :waitACK ; Waiting for ACK (EMSI ACKNOLEDGE) While (1) Do k = MInkey() ; Take an incoming modem char RcvString = RcvString + k ; Add it to the buffer If (k = CR) Break ; If CR, so we have all If ((t+36 < TickNow()) && inbytes() = 0) break ; If no CR, we wait ; with a timeout of ; 4s & condition: ; modem buffer empty EndWhile if (len(RcvString) < 15) then ; If len(buffer) < 15 (len of NAK & ACK) Inc rcvTries ; so inc RcvTries if (rcvTries < 4) then ; If no 3 tries to receive, goto waitACK ; so we go back to wait for the ACK else goto SendISI ; Else, resend the ISI packet endif endif If (Instr(RcvString,EMSI_NAK) != 0) Then ; Did we get a NAK ? SprintLn Msg(8) ; Yes! so advance session info MakeIsi() Goto SendISI ; and resend ISI packet endif if (Instr(RcvString,EMSI_ACK) != 0) Then ; Did we get an ACK ? :finiemsi SprintLn Msg(9) ; Yes! So advance session info SprintLn Msg(10) ; Advance session info (again, sorry ;) delay 4 ; delay 4/18.2s (the users has an IEMSI) ; window showing the server informations) ; ---> This is optionnal of course. EMSIOK = True If (StuffAll) Then ; Stuff datas ? if (U_RecNum(upper(ClientName)) = -1) then ; If the user does not exist KbdStuff + Clientname + CR ; so only stuff its name WriteLog() ; Write the log. while (inbytes() > 0) do ; Flush incoming buffer k = minkey() ; just in case... endwhile Return ; Go back to normal login Else ; If the user exists KbdStuff ClientName + CR + ClientPassword + CR ; We stuff Name & Pwd WriteLog() ; Write the log while (inbytes() > 0) do ; Flush modem k = minkey() endwhile Return endif else ; If we don't stuff, WriteLog() ; only write the log while (inbytes() > 0) do ; & flush modem k = minkey() endwhile endif else ; Did not get the ACK ? Goto SendISI ; so resend ISI! EndIf :EMSIFailed ; IEMSI Failed ; Writing log ; WARNING: We do not write ; in the CALLERx. system log, ; it's not possible at this ; location of PCB... so ; we write all in a file and ; we'll handle it in another ; PPE... (if you want ;) FOPEN 1,File,O_WR,S_DN fputln 1, "**************************************************************" fputln 1, "IEMSI HANDSHAKE FAILURE" fputln 1, "**************************************************************" fclose 1 SprintLn Msg(11) ; Advance session info delay 5 while (inbytes() > 0) do ; Flush the modem k = minkey() ; should have done a proc endwhile ; for that... ;) Return ; Return to normal login :NoIemsi ; No IEMSI Capabilities ; Write the log FOPEN 1,File,O_WR,S_DN fputln 1, "**************************************************************" fputln 1, "NO IEMSI CAPABILITIES" fputln 1, "**************************************************************" fclose 1 SprintLn Msg(4) ; Advance session info delay 5 Return ; Return to normal login End ; End of code! ;---------------------------------------------------------------------------- ; This function returns the # of CPU ticks since midnight ; Function TickNow() LONG TickNow = PeekDW(MKADDR(0040h,006Ch)) EndFunc ;---------------------------------------------------------------------------- ; This function codes Hiascii's (Chr(0) -> "\00") ; Function CodeHiascii(Bigstr str) BigStr Temp = "" for c = 1 to len(str) if (asc(mid(str,c,1)) <= 127 || mid(str,c,1) = "\") then Temp = Temp + mid(str,c,1) else Temp = Temp + "\"+i2s(asc(mid(str,c,1)),16) endif Next CodeHiascii = Temp Endfunc ;---------------------------------------------------------------------------- ; This function decodes Hiascii's ("\00"->Chr(0)) ; Function DecodeHiascii(Bigstr str) BigStr Temp = "" for c = 1 to len(str) if (mid(str,c,1) != "\") then Temp = Temp + mid(str,c,1) else Temp = Temp + chr(S2i(mid(str,c+1,2),16)) c = c + 2 endif Next DecodeHiascii = Temp Endfunc ;---------------------------------------------------------------------------- ; Write the log in a temporary file because it's not possible to write ; in the log at this location of PCB... ; Procedure WriteLog() Fcreate 1,File,O_WR,S_DN fputln 1, "**************************************************************" If (ClientName != "") fputln 1, "Name : " + ClientName If (ClientPassword != "") fputln 1, "Password : " + ClientPassword If (ClientAlias != "") fputln 1, "Alias : " + ClientAlias If (ClientLocation != "") fputln 1, "Location : " + ClientLocation If (ClientDataPhone != "") fputln 1, "Data Phone : " + ClientDataphone If (ClientVoicePhone != "") fputln 1, "Voice Phone: " + ClientVoicePhone If (ClientBirthdate != "") fputln 1, "Birthdate : " + ClientBirthdate If (ClientSoftware != "") fputln 1, "Software : " + ClientSoftware If (CrkTe) fputln 1, "Using Cracked Version of Terminate !" fputln 1, "**************************************************************" fclose 1 EndProc ;-------------------------------------------------------------------------- ; DOSdate&time -> UNIXdate&time ; Function DosToUnix(Date curdat, Time curtim) UNSIGNED int annee int jour int mois unsigned dat Jour = Day(curdat) Mois = Month(curdat) Annee = Year(curdat)-1968 if (annee % 4 = 0) then select case Mois case 2 jour = jour + 31 case 3 jour = jour + 60 case 4 jour = jour + 91 case 5 jour = jour + 121 case 6 jour = jour + 152 case 7 jour = jour + 182 case 8 jour = jour + 213 case 9 jour = jour + 244 case 10 jour = jour + 274 case 11 jour = jour + 305 case 12 jour = jour + 335 end select else select case Mois case 2 jour = jour + 31 case 3 jour = jour + 59 case 4 jour = jour + 90 case 5 jour = jour + 120 case 6 jour = jour + 151 case 7 jour = jour + 181 case 8 jour = jour + 212 case 9 jour = jour + 243 case 10 jour = jour + 273 case 11 jour = jour + 304 case 12 jour = jour + 334 end select end if dat = jour * 86400 + (annee - 2) * 365 * 86400 + (annee/4)*86400 + curtim DosToUnix = dat EndFunc ;---------------------------------------------------------------------------- ; UNIX Date&time -> DOSdate&time ; Procedure UnixToDos(unsigned dat, Var Date newDate, Var Time NewTime) int annee int jour int heure int minute int mois unsigned seconde seconde = dat % 86400 dat = dat / 86400 annee = (dat / 365)+2 jour = dat % 365 - annee/4 inc jour NewDate = Jour + (Annee+68) * 365 + 17 NewTime = Seconde EndProc ;---------------------------------------------------------------------------- ; Making of the EMSI_ISI packet (SERVER PACKAGE) ; Procedure MakeISI() EMSI_ISI = "EMSI_ISI" TempString = "{PCBoard v"+ left(string(Ver()),2)+"."+mid(string(Ver()),3,1) if (mid(string(Ver()),4,1) != "0") TempString = Tempstring + mid(string(Ver()),4,1) TempString = TempString + "/"+string(MaxNode()) + "}{" + Boardname + "}{" + BoardLocation + "}{" + SysOpName + "}{"+ I2s(DosToUnix(Date(), Time()),16) + "}{AEGiS CoRP iEMSi iNTeRFaCE}{\01}{}" TempString = CodeHiascii(TempString) Temp = I2S(Len(TempString)+TempString,16) While (len(Temp) < 4) do Temp = "0"+Temp EndWhile EMSI_ISI = EMSI_ISI + Temp + TempString crc=CRC32(CRC_STR,EMSI_ISI) crc=XOR(crc,xorot) EMSI_ISI = "**" + EMSI_ISI + I2S(crc,16)+CR EndProc