ADE IPBLOCKER WITH COMMAND

Which hub software is the best? Where can I find script XXX? Discuss it here...(no, this is not for advertising your hub...)

Moderator: Moderators

Locked
InnerCity
Posts: 105
Joined: 2003-05-17 00:35

ADE IPBLOCKER WITH COMMAND

Post by InnerCity » 2003-06-16 06:52

could it be possible to have the ade ipblocker script but having a command entry to add ip ranges by any oper?
just an utility to ban ip ranges not being the owner of the hub or editing the ipblocker.cfg by the owner
Hi hi hoo

Paul_Don
Posts: 146
Joined: 2003-01-29 06:41
Location: uk
Contact:

Post by Paul_Don » 2003-06-16 13:46

you could do it with a script that writes to txt files. by pointing to the cfg
i was thinkin exactly like u,
but hten i though of the other probs which would be the ip range would have to be wrote exact and failing to do so could ban alot of people form the hub. and there not the option to delete the range either other than the hub runner. but ask someone nicely they might wipe a modded version up for ya :)

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-06-16 18:15

ok, i prefer to have some fails by other opers than to be the only one who can ban ip ranges, i can't always be vigilant of my hub
i will look for that script
Hi hi hoo

aDe
Forum Moderator
Posts: 138
Joined: 2003-01-07 09:14
Location: SE
Contact:

Post by aDe » 2003-06-17 02:43

I updated the script to include the add function now, I can't test it here myself, it probably has a bug or two, here's a test version... oh, and I'm going to go away for a couple of weeks soon, so, if someone finds a bug and fixes it, just post the updated script here, and i'll put it up on my website later.

how to add: type the command, and the same syntax as in the cfg file, that means;

Code: Select all

+banrange DESCRIPTION:FIRSTIP-LASTIP
or

Code: Select all

+banrange DESCRIPTION:FIRSTIP
here's the script...

Code: Select all

' IPBlocker ver. 4 - aDe / ButterflySoul - 2003
' [email protected]
' Latest version should be found @ http://dc.ade.se/tools/IPBlocker.zip
' Enjoy

Option Explicit
Sub Main()
'-----------------------------------------------------------------------------
'  EDITABLE OPTIONS/SETUP HERE!
'-----------------------------------------------------------------------------

sCmdReload = "+reloadbadips" '<-- The command operators type to reload the IPs
sCmdAdd = "+banrange"        '<-- The command to ban a range with (make sure it's enabled below)
sChatName = "IPBlocker"      '<-- The name used when sending chat to ops
bNotify = True               '<-- Tell ops when a user is kicked? (true/false)
bNotifyALL = False           '<-- Tell all users in hub when a user is kicked?
bAllowAdd = True             '<-- Allow operators to add ranges?

'-- Filename of the config file, you probably need to edit this.
'   If you don't know where the hub is installed, just use ".\Scripts\IPBlocker.cfg"
sFile = "C:\Program Files\Direct Connect Hub\Scripts\IPBlocker.cfg"


'-----------------------------------------------------------------------------
'  DO NOT MODIFY THE REST OF THE SCRIPT BELOW...
'-----------------------------------------------------------------------------
LoadIPs
End Sub

Dim ipCheck(), ipEnts, sCmdReload, sChatName, sFile, bNotify, bNotifyALL, bLoaded, bAllowAdd, sCmdAdd

Sub NewUserConnected (curUser)
Dim iRet, sIP
If bLoaded <> True Then Exit Sub
sIP = curUser.IP
iRet = BadIP(sIP)
If iRet > -1 Then
  curUser.Kick
  frmHub.DoEventsForMe
  If bNotifyALL Then
    colUsers.SendToAll "<" & sChatName & "> " & "A bad user (" & ipCheck(iRet, 0) & ") was kicked from 

the hub. IP: " & sIP
  Else
    If bNotify = True Then SendChatToOps sChatName, "A bad user (" & ipCheck(iRet, 0) & ") was kicked 

from the hub. IP: " & sIP
  End if
End If
End sub

Sub DataArival (curUser, sCurData)
If curUser.bOperator Then
  If Left(sCurData, 1) = "<" Then
    If Instr(1, sCurData, sCmdReload) Then
      LoadIPs
    End If
    If bAllowAdd Then
      If Instr(1, sCurData, sCmdAdd & " ") Then
        Dim sAddIP
        sAddIP = AfterLast(Trim(sCurdata), " ")
        If Instr(1, sAddIP, ":") Then
          AddIP sAddIP
        End If
      End If
    End If
  End If
End If
End Sub

Sub AddIP(sLine)
ipEnts = ipEnts + 1
Redim Preserve ipCheck(ipEnts, 2)
If Instr(1, sLine, "-") Then
  ipCheck(ipEnts, 0) = BeforeFirst(sLine, ":")
  ipCheck(ipEnts, 1) = ip2Cur(BeforeFirst(AfterFirst(sLine, ":"),"-"))
  ipCheck(ipEnts, 2) = ip2Cur(AfterFirst(sLine, "-"))
Else
  ipCheck(ipEnts, 0) = BeforeFirst(sLine, ":")
  ipCheck(ipEnts, 1) = ip2Cur(AfterFirst(sLine, ":"))
  ipCheck(ipEnts, 2) = ipCheck(ipEnts, 1)
End if

SaveIPs

SendChatToOps sChatName, "IP/range: " & sLine & " saved."
End Sub

Sub SaveIPs()
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(sFile, True)
For d = 0 to ipEnts
  a.WriteLine(ipCheck(d,0) & ":" & ipCheck(d, 1) & ":" & ipCheck(d, 2))
Next
a.Close
End Sub

Sub LoadIPs()
Dim oFS, oFile, sLine, nFile, tIPCheck(256, 2), i
ipEnts = -1
Set oFS = CreateObject("Scripting.FileSystemObject")
If Not oFS.FileExists(sFile) Then
  If Not oFS.FileExists(".\Scripts\IPBlocker.cfg") Then
    SendChatToOps sChatName, "The IPs could not be loaded: the cfg file was not found! Please edit the 

path specified in the script."
    Exit Sub 
  Else
    sFile = ".\Scripts\IPBlocker.cfg"
  End If
End If
Set oFile = oFS.OpenTextFile(sFile, 1, False)
While Not oFile.AtEndOfStream
  sLine = oFile.ReadLine
  If Instr(1, sLine, ":") Then
    ipEnts = ipEnts + 1
    If Instr(1, sLine, "-") Then
      tipCheck(ipEnts, 0) = BeforeFirst(sLine, ":")
      tipCheck(ipEnts, 1) = ip2Cur(BeforeFirst(AfterFirst(sLine, ":"),"-"))
      tipCheck(ipEnts, 2) = ip2Cur(AfterFirst(sLine, "-"))
    Else
      tipCheck(ipEnts, 0) = BeforeFirst(sLine, ":")
      tipCheck(ipEnts, 1) = ip2Cur(AfterFirst(sLine, ":"))
      tipCheck(ipEnts, 2) = tipCheck(ipEnts, 1)
    End if
  End if
Wend
oFile.Close
If ipEnts > -1 Then ReDim ipCheck(ipEnts, 2)
For i = 0 To ipEnts
  ipCheck(i, 0) = tIPCheck(i, 0)
  ipCheck(i, 1) = tIPCheck(i, 1)
  ipCheck(i, 2) = tIPCheck(i, 2)
Next
SendChatToOps sChatName, "The bad IPs have been reloaded. " & (ipEnts + 1) & " entries loaded."
bLoaded = True
End Sub

Function BadIP(sIp)
Dim cIP, i
cIP = ip2Cur(sIp)
For i = 0 To ipEnts
  If cIP <= ipCheck(i, 2) Then
    If cIP >= ipCheck(i, 1) Then
      BadIP = i
      Exit Function
    Else
      BadIP = -1
    End If
  Else
    BadIP = -1
  End If
Next
End Function

Function ip2Cur(sIp)
  Dim pIP(3)
  pIP(0) = Format(BeforeFirst(sIp, "."))
  pIP(1) = Format(BeforeFirst(AfterFirst(sIp, "."), "."))
  pIP(2) = Format(AfterLast(BeforeLast(sIp, "."), "."))
  pIP(3) = Format(AfterLast(sIp, "."))
  ip2Cur = CCur(pIP(0) & pIP(1) & pIP(2) & pIP(3))
End Function

Function Format(sNum)
If Len(sNum) = 1 then
  Format = "00" & sNum
ElseIf len(sNum) = 2 Then
  Format = "0" & sNum
Else
  Format = sNum
end if
End Function

Sub SendChatToOps(sName, dMessage) 
Dim sOPName
For Each sOPName in frmHub.lstOps.ListItems 
   If colUsers.Online(cStr(sOPName.Text)) Then 
      With colUsers.ItemByName(cstr(sOPName.Text)) 
         If .bOperator Then .SendData cStr("<" & sName & "> " & dMessage) 
      End With 
   End If 
Next 
End Sub

Function BeforeFirst(sIn, sFirst)
    If InStr(1, sIn, sFirst) Then
        BeforeFirst = Left(sIn, InStr(1, sIn, sFirst) - 1)
    Else
        BeforeFirst = ""
    End If
End Function

Function AfterFirst(sIn, sFirst)
    If InStr(1, sIn, sFirst) Then
        AfterFirst = Right(sIn, Len(sIn) - InStr(1, sIn, sFirst) - (Len(sFirst) - 1))
    Else
        AfterFirst = ""
    End If
End Function

Public Function AfterLast(sFrom, sAfterLast)
    If InStr(1, sFrom, sAfterLast) Then
        AfterLast = Right(sFrom, Len(sFrom) - InStrRev(sFrom, sAfterLast) - (Len(sAfterLast) - 1))
    Else
        AfterLast = ""
    End If
End Function

Public Function BeforeLast(sFrom, sBeforeLast)
    If InStr(1, sFrom, sBeforeLast) Then
        BeforeLast = Left(sFrom, InStrRev(sFrom, sBeforeLast) - 1)
    Else
        BeforeLast = ""
    End If
End Function

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-06-17 09:47

testing testing testing
THANKS
Hi hi hoo

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-06-17 10:42

i have this windows error:
Error 1033: Constante de cadena sin terminar
it could be translated as: constant string value not finished
where is wally?
Hi hi hoo

aDe
Forum Moderator
Posts: 138
Joined: 2003-01-07 09:14
Location: SE
Contact:

Post by aDe » 2003-06-19 13:13

It either means i made a typo (cant find it) or something went wrong when you copied it...

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-06-19 23:13

i supose that when you say typo you mean a type error
(i don't know about developer's expressions)
is there any script editor to find that kind of errors?
one of them that make easy the visualization/comprehension of the code?
Hi hi hoo

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2003-06-21 10:09

InnerCity wrote:i supose that when you say typo you mean a type error
Typo = typographical error.

ie. you mistyped the script then copying it to a file


If you have an editor with VB SCript syntax highlighting, you should be able to see the problem visually... probably. I don't know VB Script and just jumped into this thread to point out the above error.

ButterflySoul
Posts: 210
Joined: 2003-01-23 17:24
Location: Nevada
Contact:

Post by ButterflySoul » 2003-06-21 23:31

is there any script editor to find that kind of errors?
one of them that make easy the visualization/comprehension of the code?

There's AEdiX, which has syntax highlighting for 24 languages, many built-in tools, and can be reconfigured entirely via Pascal (so you could add DC objects, functions and properties to the highlight list without too much trouble, or even go as far as adding pascal scripted actions).

I hear VBSEditor (which, as its name indicates is dedicated to VBS editing) is pretty good as well, eventhough it doesn't appear to offer reconfiguration options such as custom highlights.

Both of them are, of course, free =) Personally, I use AEdiX, which is the one I'd recommend.
[CoZ] Children of Zeus
-----
Shadows DC Hub - VBS and JS scripting at their best

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-06-22 05:42

thanks, i will report the typo if i find it
i think it exists cos i tried the two methods that refer Ade in the old ipblocker to run the script and had the same windows error
Hi hi hoo

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-06-30 08:53

there was no typo, it was only a stupid error that it made, i forgot to change this kind of broken lines
--------------------
SendChatToOps sChatName, "The IPs could not be loaded: the cfg file was not found! Please edit the

path specified in the script."
--------------------------------
now it's all ok, i have no windows error, but the script doesn't work, doesn't accept any entry by command +banrange pop:213.12.......
sure
did someone else try to make it work?
Hi hi hoo

aDe
Forum Moderator
Posts: 138
Joined: 2003-01-07 09:14
Location: SE
Contact:

Post by aDe » 2003-07-01 14:53

If you're lucky i'll have some time over this weekend to fix it, but don't count on it...

InnerCity
Posts: 105
Joined: 2003-05-17 00:35

Post by InnerCity » 2003-07-02 07:45

if you have time to do it i'll be your grateful tester
Hi hi hoo

Locked