Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'SCRIPT: LimitDownloadsPerIP.vbs
- 'VERSION: 0.2
- 'AUTHOR: CodSpirit
- 'DATE: 2004/11/04
- 'DESC: LimitTransferPerIP
- 'NOTE: Gene6FTP v3.2+ required
- '*** Notes
- ' Table strucure expected : (MySQL example)
- ' CREATE TABLE IF NOT EXISTS TransfersPerIP (
- ' Num MEDIUMINT(9) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
- ' IP VARCHAR(255) NOT NULL,
- ' LastUpdate VARCHAR(255) NOT NULL,
- ' Files BIGINT(11) NOT NULL,
- ' Bytes BIGINT(11) NOT NULL
- ' );
- ' Table strucure expected : (Access example)
- 'CREATE TABLE TransfersPerIP (
- ' Num AUTOINCREMENT NOT NULL PRIMARY KEY,
- ' IP VARCHAR(255) NOT NULL,
- ' LastUpdate VARCHAR(255) NOT NULL,
- ' Files INT NOT NULL,
- ' Bytes INT NOT NULL
- ');
- '*** Settings
- '* ConnectionString : same meaning as in G6 autentication
- ' Mysql example
- 'Const ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Port=3306;Option=131072;Stmt=;Database=G6_logs;Uid=G6;Pwd=;"
- ' Access example
- Const ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""D:\!FTPCONFIG\G6\MYDB\database.mdb"";"
- '* How often should we reset the counter ? (In minutes)
- Const ResetEvery = 10800
- '* How many files a user can download ?
- Const MaxFiles = 25
- '* How many megabytes a user can download ?
- Const MaxMBytes = 200
- '* Should we display debug messages/error notices ?
- Const DebugMode = False
- '************************************************************************************
- '*** Let's the show begin :p
- '*** You shouldn't have to modify things under this point
- '************************************************************************************
- Dim fso : Set fso = CreateObject("Scripting.fileSystemObject")
- Dim vbCrLf : vbCrLf = Chr(13) & Chr(10)
- Sub OnFileDownloaded()
- Set Co = CreateObject("ADODB.Connection")
- Co.open ConnectionString
- If co.State = 1 Then
- Set rs = co.execute("select * from TransfersPerIP where IP = """ & Client.PeerIP & """")
- If not rs.eof Then
- If DebugMode Then
- Client.post "You have downloaded " & rs.fields("Files") & " files, that is " & Tools.FormatSize( rs.fields("Bytes") )
- end if
- End If
- Co.close
- Set Co = Nothing
- Set rs = Nothing
- Else
- If DebugMode Then
- client.post "Failed to open data connection !"
- End If
- End If
- End Sub
- Sub HookRetrieve(FileName, FileNameReal)
- Set Co = CreateObject("ADODB.Connection")
- Co.open ConnectionString
- If co.State = 1 Then
- Set rs = co.execute("select * from TransfersPerIP where IP = """ & Client.PeerIP & """")
- If rs.eof Then
- req = "Insert into TransfersPerIP( IP, Lastupdate, Files, Bytes ) values ( """ & Client.PeerIP & """, """ & now() & """, 0,0 )"
- Co.Execute req
- req = "update TransfersPerIP set Files = Files + 1, Bytes = Bytes + " & fso.getfile(FileNameReal).Size & " where IP = """ & Client.PeerIP & """"
- Co.Execute req
- Hook.Result = 0
- Else
- If DateDiff( "n", rs.fields("Lastupdate"), now()) < ResetEvery Then
- If rs.fields("Files") > MaxFiles or rs.fields("Bytes") > ( MaxMBytes * 1024^2 ) Then
- Hook.Result = 1
- Hook.SetReply 550, "Server too busy to process you request. Please try again later."
- Else
- req = "update TransfersPerIP set Files = Files + 1, Bytes = Bytes + " & fso.getfile(FileNameReal).Size & " where IP = """ & Client.PeerIP & """"
- Co.Execute req
- Hook.Result = 0
- End If
- Else
- req = "update TransfersPerIP set LastUpDate = """ & Now() & """ , Files = 1, Bytes = " & fso.getfile(FileNameReal).Size & " where IP = """ & Client.PeerIP & """"
- Co.Execute req
- Hook.Result = 0
- End If
- End If
- Co.close
- Set Co = Nothing
- Set rs = Nothing
- Else
- If DebugMode Then
- client.post "Failed to open data connection !"
- End If
- Hook.Result = 1
- Hook.SetReply 550, "The server encountered an error"
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement