Peace & Protection 4.00 — File Browser

PeaceProtection4.00v4.0 / PeaceProtection4.00v4.0 / ADDONS / LOGIN.MRC

LOGIN.MRC — 16.34 KB — Download this file

; #= rawlogin -rs
; ########################################
; Peace & Protection
; Simple raw connection login (addon)
; ########################################

; Need to add-
; 1) Listening for connections?
;;; 2) Logging
;;; 3) "Disconnect" and "Reconnect" popups
;;; 4) Recognize packets without newlines
; 5) send packets without newlines if desired
;;; 6) bugs in titlebars of multiple windows screwing up
; 7) login to nickname

;
; Logging in to a site
;
alias login {
  if ($2 == $null) _qhelp $_s2f(/login,+address,+port,!An,address,and,port,to,connect,to) $1
  var %num
  :loop
  if ($window(@Login [ $+ [ %num ] ] )) { if (%num == $null) inc %num | inc %num | goto loop }
  _window 1 -e + @Login $+ %num $_winpos(15,15,12,12) @Login
  _windowreg @Login $+ %num _logonclose
  sockopen LOGIN. $+ %num $1-
  sockmark LOGIN. $+ %num @Login $+ %num
  echo $colour(ctcp) @Login $+ %num Connecting to: $1 on port $2
  titlebar @Login - $1 $+ : $+ $2 - 0/0 (Connecting)
}
on *:SOCKOPEN:LOGIN.*:{
  if ($sockerr) { echo $colour(ctcp) $sock($sockname,1).mark Error connecting! | titlebar @Login $gettok($window(@Login).title,1-4,32) (Error) }
  else { echo $colour(ctcp) $sock($sockname,1).mark Connection established | titlebar @Login $gettok($window(@Login).title,1-4,32) }
}
on *:SOCKCLOSE:LOGIN.*:updt $sock($sockname,1).mark $sockname | echo $colour(ctcp) $sock($sockname,1).mark Connection closed! | titlebar @Login $gettok($window(@Login).title,1-4,32) (Closed)
alias _logonclose var %socket = LOGIN. $+ $mid($1,7,99) | if ($sock(%socket,1)) sockclose %socket
alias _dc@Login disps test
alias -l updt titlebar $1 $gettok($window($1).title,1-2,32) - $sock($2,1).sent $+ / $+ $sock($2,1).rcvd
on *:INPUT:@Login*:{
  var %socket = LOGIN. $+ $mid($target,7,99)
  if ($sock(%socket,1).status == connecting) echo $colour(ctcp) $target Connection not made yet!
  elseif ($sock(%socket,1)) { sockwrite -tn %socket $1- | echo $colour(act) -i2 $target < $1- }
  halt
}
on *:SOCKWRITE:LOGIN.*:{
  updt $sock($sockname,1).mark $sockname
  if ($sockerr) {
    echo $colour(ctcp) $sock($sockname,1).mark Error sending data!
    titlebar @Login $gettok($window(@Login).title,1-4,32) (Error)
    sockclose $sockname
  }
}
on *:SOCKREAD:LOGIN.*:{
  if ($sockerr) {
    updt $sock($sockname,1).mark $sockname
    echo $colour(ctcp) $sock($sockname,1).mark Error receiving data!
    titlebar @Login $gettok($window(@Login).title,1-4,32) (Error)
    sockclose $sockname
    halt
  }
  var %data
  :next
  sockread %data
  if ($sockbr) {
    if (%data == $null) var %data
    echo $colour(norm) -i2 $sock($sockname,1).mark > %data
    goto next
  }
  updt $sock($sockname,1).mark $sockname
}
;
; Listening for connection(s)
;

;
; Portup
;
alias portup {
  if ($1 == $null) _qhelp $_s2f(/portup,+targetport,!Desired,local,port,(below 4900)) $1
  if ($1 > 4900) _doerror Warning- Target port must be below 4900Winsock usually wraps around before 5000
  set %_portup.targ $1
  sockclose portup?
  sockclose portupTG?
  socklisten portupTGt 38270
  sockopen portupZ 127.0.0.1 38270
  halt
}
alias -l _portup² {
  sockclose portupZ
  sockclose portupX
  sockclose portupTGt
  if ($1 >= %_portup.targ) { dispa Local port is already above $:t(%_portup.targ) $+ . (currently $:t($1) $+ ) | unset %_portup.targ | sockclose portupTGt | halt }
  _progress.1 Increasing local port from $1 $+ ...
  %_portup.1st = $1
  socklisten portupTGf 38270
  socklisten portupTGu 38271
  sockopen portup1 127.0.0.1 38271 | sockopen portup2 127.0.0.1 38271 | sockopen portup3 127.0.0.1 38271 | sockopen portup4 127.0.0.1 38271
  sockopen portup5 127.0.0.1 38271 | sockopen portup6 127.0.0.1 38271 | sockopen portup7 127.0.0.1 38271 | sockopen portup8 127.0.0.1 38271
  sockopen portupZ 127.0.0.1 38270
  halt
}
alias -l _portup³ {
  sockclose portupZ
  sockclose portupX
  _progress.2 $int($calc(($1 - %_portup.1st) / (%_portup.targ - %_portup.1st) * 100)) ...to $1
  if ($1 < %_portup.targ) {
    sockclose portup?
    sockopen portup1 127.0.0.1 38271 | sockopen portup2 127.0.0.1 38271 | sockopen portup3 127.0.0.1 38271 | sockopen portup4 127.0.0.1 38271
    sockopen portup5 127.0.0.1 38271 | sockopen portup6 127.0.0.1 38271 | sockopen portup7 127.0.0.1 38271 | sockopen portup8 127.0.0.1 38271
    sockopen portupZ 127.0.0.1 38270
    .timer.justincase -m 0 200 sockclose portupZ $chr(124) sockopen portupZ 127.0.0.1 38270
    halt
  }
  sockclose portup?
  sockclose portupTGf
  sockclose portupTGu
  unset %_portup.1st %_portup.targ
  .timer.justincase off
}
on *:SOCKLISTEN:portupTGt:sockaccept portupX | _portup² $sock(portupX,1).port
on *:SOCKLISTEN:portupTGf:.timer.justincase off | sockaccept portupX | _portup³ $sock(portupX,1).port
on *:SOCKLISTEN:portupTGu:return

;
; Nuke stat check
;
alias nukes {
  if ($dialog(nukedet)) did -b nukedet 101
  else dispa Detecting IP statistics...
  .remove $_temp(nss)
  .write -c $_temp(nsd) 1
  run -n " $+ $scriptdirloginns.bat $+ " $_temp(nss) $_temp(nsd)
  .timer.nukedetect -om 0 200 if ($exists( $+ $_temp(nsd) $+ ) == $!false) _nukes2 $iif($1 isnum,$1)
}
alias -l _finnuke return $gettok($gettok($line(@.nuke1,$fline(@.nuke1,$1,1)),2,61),1,32)
alias -l _finnuke2 return $gettok($line(@.nuke1,$fline(@.nuke1,$1,1)),$2,32)
alias -l _nukes2 {
  .timer.nukedetect off
  if ($1 isnum) .timer.nukerepeat -o 1 $1 nukes $1
  window -c @.nuke1
  window -hln @.nuke1
  filter -fw $_temp(nss) @.nuke1 * * *
  .remove $_temp(nss)
  if ($dialog(nukedet) == $null) dialog -dm nukedet nukedet
  _updnuke 3 $_finnuke2(*Destination Unreachable*,3) 71 2
  _updnuke 5 $_finnuke2(*Echos*,2) 72 2
  _updnuke 7 $_finnuke2(*Echo replies*,3) 73 2
  _updnuke 9 $_finnuke(*No ports*) 74 2
  _updnuke 11 $_finnuke(*Reassembly Required*) 75 1
  _updnuke 16 $_finnuke2(*Messages*,2) 76 2
  _updnuke 17 $_finnuke2(*Messages*,3) 81 2
  _updnuke 19 $_finnuke(*Datagrams Received*) 77 5
  _updnuke 20 $_finnuke(*Datagrams Sent*) 82 5
  _updnuke 22 $_finnuke(*Segments Received*) 78 5
  _updnuke 23 $_finnuke(*Segments Sent*) 83 5
  _updnuke 25 $_finnuke(*Passive Opens*) 79 1
  _updnuke 26 $_finnuke(*Active Opens*) 84 1
  _updnuke 28 $_finnuke(*Packets Received*) 80 5
  _updnuke 29 $_finnuke(*Output Requests*) 85 5
  did -o nukedet 60 1 $ticks
  did -e nukedet 101
  if ($1 isnum) {
    did -c nukedet 50
    did -o nukedet 51 1 $1
  }
  window -c @.nuke1
}
alias -l _updnuke {
  var %old = $did(nukedet,$1)
  if ((%old isnum) && (%old < $2)) {
    var %time = $calc(($ticks - $did(nukedet,60)) / 1000),%persec = $int($calc(($2 - %old) / %time / $4))
    if (%persec > 2) %persec = 2
    did -o nukedet $3 1 $str(%`popupmark,$calc(%persec + 1))
  }
  else did -r nukedet $3
  did -o nukedet $1 1 $2
}
dialog nukedet {
  title "Nuke Detect / IP Statistics"
  size -1 -1 510 230

  box "Possible packet attacks:", 1, 10 10 195 173
  text "Packets", 30, 125 30 60 20
  text "Dest. unreachable:", 2, 20 55 90 20, right
  edit "", 3, 115 51 60 22, autohs read right
  text "ICMP pings:", 4, 20 80 90 20, right
  edit "", 5, 115 76 60 22, autohs read right
  text "ICMP ping replies:", 6, 20 105 90 20, right
  edit "", 7, 115 101 60 22, autohs read right
  text "UDPs with no port:", 8, 20 130 90 20, right
  edit "", 9, 115 126 60 22, autohs read right
  text "Packet fragments:", 10, 20 155 90 20, right
  edit "", 11, 115 151 60 22, autohs read right

  text "", 71, 179 54 20 22
  text "", 72, 179 79 20 22
  text "", 73, 179 104 20 22
  text "", 74, 179 129 20 22
  text "", 75, 179 154 20 22

  box "IP statistics:", 12, 215 10 285 173
  text "In", 13, 330 30 60 20
  text "Out", 14, 420 30 60 20
  text "ICMP packets:", 15, 225 55 90 20, right
  edit "", 16, 320 51 60 22, autohs read right
  edit "", 17, 410 51 60 22, autohs read right
  text "UDP packets:", 18, 225 80 90 20, right
  edit "", 19, 320 76 60 22, autohs read right
  edit "", 20, 410 76 60 22, autohs read right
  text "TCP packets:", 21, 225 105 90 20, right
  edit "", 22, 320 101 60 22, autohs read right
  edit "", 23, 410 101 60 22, autohs read right
  text "TCP connects:", 24, 225 130 90 20, right
  edit "", 25, 320 126 60 22, autohs read right
  edit "", 26, 410 126 60 22, autohs read right
  text "Total IP packets:", 27, 225 155 90 20, right
  edit "", 28, 320 151 60 22, autohs read right
  edit "", 29, 410 151 60 22, autohs read right

  text "", 76, 384 54 20 22
  text "", 77, 384 79 20 22
  text "", 78, 384 104 20 22
  text "", 79, 384 129 20 22
  text "", 80, 384 154 20 22
  text "", 81, 474 54 20 22
  text "", 82, 474 79 20 22
  text "", 83, 474 104 20 22
  text "", 84, 474 129 20 22
  text "", 85, 474 154 20 22

  check "Automatic refresh:", 50, 105 197 110 22
  edit "", 51, 215 197 50 22
  text "seconds apart", 52, 269 201 75 20

  check "On top", 53, 353 197 50 22

  edit "", 60, 1 1 1 1, hide autohs

  button "&Close", 100, 10 195 80 25, cancel default
  button "&Refresh", 101, 420 195 80 25
}
on *:DIALOG:nukedet:sclick:53:dialog $iif($did(53).state,-o,-n) nukedet
on *:DIALOG:nukedet:sclick:101:{
  did -tf nukedet 100
  nukes
}
on *:DIALOG:nukedet:sclick:100:{
  .timer.nukedetect off
  .timer.nukerepeat off
}
on *:DIALOG:nukedet:sclick:50:_chkref
on *:DIALOG:nukedet:edit:51:_chkref
alias -l _chkref {
  if (($did(50).state) && ($did(51) isnum)) .timer.nukerepeat -o 1 $did(51) nukes $did(51)
  else .timer.nukerepeat off
}

;
; Connection detection
;
;;; needs to resolve IPs
;;; popups
alias arp {
  .remove $_temp(ars)
  .write -c $_temp(ard) 1
  if ($active != @ARP) dispa Detecting TCP/UDP connections...
  close -@ @.nuke2 @ARP
  if (($longip($server) == $null) && ($server)) _Q.dns _arp3 _arp4 -h $server
  else _arp4
  run -n " $+ $scriptdir $+ loginarp.bat $+ " $_temp(ars) $_temp(ard)
  .timer.arpdetect -om 0 200 if ($exists( $+ $_temp(ard) $+ ) == $!false) _arp2
}
alias _arp3 {
  window -hln @.nuke2
  titlebar @.nuke2 $iaddress
  if ($line(@.nuke2,1)) _arp5
}
alias _arp4 {
  window -hln @.nuke2
  titlebar @.nuke2 ?
  if ($line(@.nuke2,1)) _arp5
}
alias -l _arp2 {
  .timer.arpdetect off
  window -hln @.nuke2
  filter -fwtu 2 58 $_temp(ars) @.nuke2 *:*
  .remove $_temp(ars)
  if ($line(@.nuke2,1) == $null) aline @.nuke2 (none)
  if ($window(@.nuke2).title) _arp5
}
alias -l _arp5 {
  _window 2. -hln -t23,63,86 @ARP -1 -1 -1 -1 @ARP
  var %num = $line(@.nuke2,0),%tcp = 1,%listen = 1,%udp = 1
  :loop
  if (%num) {
    tokenize 32 $line(@.nuke2,%num)
    if ($1 == TCP) {
      if (($4 == ESTABLISHED) || ($4 == TIME_WAIT)) {
        iline @ARP %tcp $_service($1,$gettok($2,2,58)) $+ 	 $+ $gettok($3,1,58) $+ 	 $+ $_service($1,$gettok($3,2,58)) $+ 	 $+ $iif($4 == TIME_WAIT,(connecting)) $_arpinfo($gettok($2,2,58),$gettok($3,2,58),$gettok($3,1,58))
        inc %listen
        inc %udp
      }
      else {
        var %addr = $gettok($2,1,58)
        if (%addr == 0.0.0.0) %addr = (any)
        iline @ARP %listen $_service($1,$gettok($2,2,58)) $+ 	 $+ %addr $+ 	 $+ (listening) $_listeninfo(tcp,$gettok($2,2,58))
        inc %udp
      }
    }
    elseif ($1 == UDP) {
      iline @ARP %udp $_service($1,$gettok($2,2,58)) $+ 	 $+ (listening) $_listeninfo(udp,$gettok($2,2,58))
    }
    dec %num | goto loop
  }
  window -c @.nuke2
  iline @ARP %tcp $_ultab(10,14,11,5)
  iline @ARP %tcp Local port	Remote address	Remote port	Notes
  iline @ARP %tcp  
  iline @ARP %tcp Active TCP connections-
  inc %listen 4
  iline @ARP %listen $_ultab(10,13,5)
  iline @ARP %listen Local port	Local address	Notes
  iline @ARP %listen  
  iline @ARP %listen Ports waiting for TCP connections-
  iline @ARP %listen  
  iline @ARP %listen  
  inc %udp 10
  iline @ARP %udp $_ultab(10,5)
  iline @ARP %udp Local port	Notes
  iline @ARP %udp  
  iline @ARP %udp UDP ports waiting for data-
  iline @ARP %udp  
  iline @ARP %udp  
  window -aw @ARP
}
; $_service(proto,port/name) returns port (name)
alias -l _service {
  if ($2 == *) return *
  var %port,%name
  if ($2 isnum) {
    %port = $2
    var %find = -nw" $+ $2 & $1 $+ ",%found = $read %find $scriptdirservices.txt
    if (%found) %name = $gettok(%found,2,32)
  }
  else {
    %name = $2
    var %find = -nw"& $2 $1 $+ ",%found = $read %find $scriptdirservices.txt
    if (%found) %port = $gettok(%found,1,32)
  }
  if (%port == $null) %port = ??
  if (%name) return %port ( $+ %name $+ )
  return %port
}
; $_arpinfo(local,remote,addr) data for a TCP connection
alias -l _arpinfo {
  if ((($3 == $server) || ($3 == $window(@.nuke2).title)) && ($2 == $port)) return IRC connection
  var %num = $sock(*,0)
  :loop1
  if (%num) {
    if (($sock(*,%num).ip == $3) && ($sock(*,%num).type == tcp) && (($sock(*,%num).port == $1) || ($sock(*,%num).port == $2))) return Socket $sock(*,%num)
    dec %num | goto loop1
  }
  if (($3 == $ip) || ($3 == 127.0.0.1)) return (yourself)
  var %num = 1
  :loop2
  var %chat = $chat(%num).ip,%send = $send(%num).ip,%get = $get(%num).ip,%fserv = $fserv(%num).ip
  if (%chat == $3) return $chat(%num) (chat)
  if (%get == $3) return $get(%num) (dcc get)
  if (%send == $3) return $send(%num) (dcc send)
  if (%fserv == $3) return $fserv(%num) (fserve)
  if ((%chat) || (%send) || (%get) || (%fserv)) { inc %num | goto loop2 }
  var %ial = *!*@ $+ $3
  if ($ial(%ial,1).nick) return $ifmatch
}
; $_listeninfo(type,local) sees if any sockets are listening on that port; type = udp/tcp
; also returns info for ddeserver, finger, ident, if they are open
alias -l _listeninfo {
  var %num = $sock(*,0)
  :loop
  if (%num) {
    if (($sock(*,%num).status == listening) && ($sock(*,%num).type == $1) && ($sock(*,%num).port == $2)) return Socket $sock(*,%num)
    dec %num | goto loop
  }
  if ($1 == tcp) {
    if (($2 == 79) && ($_optn(3,29))) return mIRC finger server
    var %opt = $readini -n $mircini dccserver n0
    if (($2 == $dccport) && ($gettok(%opt,1,44))) return mIRC DCC server
    if (($2 == $readini -n $mircini ident port) && (yes == $readini -n $mircini ident active)) return mIRC identd server
  }
}

;
; Port listening and connections
;
dialog portlisten {
  title "Port Listening"
  size -1 -1 360 250

  box "Ports:", 1, 10 10 150 180
  list 2, 20 30 130 150

  box "Configure port:", 9, 170 10 180 180

  text "&Protocol:", 3, 175 55 55 20, right
  text "P&ort:", 4, 175 79 55 20, right
  text "A&ction:", 5, 175 103 55 20, right

  combo 6, 235 52 100 200, drop
  combo 7, 235 76 100 200, drop edit
  combo 8, 235 100 100 200, drop

  button "&Add", 10, 180 152 75 25
  button "&Remove", 11, 265 152 75 25

  list 12, 1 1 1 1, hide
  list 13, 1 1 1 1, hide

  button "OK", 100, 40 210 80 25, ok default
  button "Cancel", 101, 140 210 80 25, cancel
  button "Help", 102, 240 210 80 25, disable
}
on *:DIALOG:portlisten:init:*:{
  window -hln @.ports
  filter -fw " $+ $scriptdir $+ services.txt $+ " @.ports *
  var %num = 1,%line,%max = $line(@.ports,0)
  :loop
  %line = $line(@.ports,%num)
  did -a $dname $iif($gettok(%line,3,32) == tcp,12,13) $gettok(%line,1,32) ( $+ $gettok(%line,2,32) $+ )
  if (%num < %max) { inc %num | goto loop }
  window -c @.ports
  did -ac $dname 6 TCP
  did -a $dname 6 UDP
  did -ac $dname 8 Popup warning
  did -a $dname 8 Note in status
  did -a $dname 8 Accept connection
}
on *:DIALOG:portlisten:*:7:did -t $dname 10
on *:DIALOG:portlisten:sclick:6:_seltu $gettok($did(7),1,32)
alias -l _seltu {
  did -r $dname 7
  filter -io $dname $iif($did(6).sel == 1,12,13) $dname 7
  if ($_finddid($dname,7,$1)) did -c $dname 7 $ifmatch
  elseif ($1 isnum) did -ac $dname 7 $1
}
on *:DIALOG:portlisten:sclick:10,11:{
  var %prev = $did(2).sel
  if ($gettok($did(7),1,32) isnum) {
    var %where = $ifmatch $did(6),%num = $did(2).lines
    :loop
    if (%num) {
      if ($gettok($did(2,%num),1-2,32) == %where) did -d $dname 2 %num
      dec %num | goto loop
    }
    if ($did == 10) did -ac $dname 2 %where ( $+ $gettok(warn note connect,$did(8).sel,32) $+ )
    else {
      if ($did(2).lines < %prev) %prev = $ifmatch
      if (%prev) {
        did -c $dname 2 %prev
        _selit
      }
    }
  }
  did -t $dname 100
}
on *:DIALOG:portlisten:sclick:2:_selit
alias -l _selit {
  var %it = $did(2,$did(2).sel)
  if (%it) {
    did -c $dname 6 $findtok(tcp udp,$gettok(%it,2,32),1,32)
    _seltu $gettok(%it,1,32)
    did -c $dname 8 $findtok((warn) (note) (connect),$gettok(%it,3,32),1,32)
  }
}