Advertisement
EIKA_inc

LimitDownloadsPerIP.vbs

Jun 21st, 2022
1,633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'SCRIPT:    LimitDownloadsPerIP.vbs
  2. 'VERSION:   0.2
  3. 'AUTHOR:    CodSpirit
  4. 'DATE:      2004/11/04
  5. 'DESC:      LimitTransferPerIP
  6. 'NOTE:      Gene6FTP v3.2+ required
  7.  
  8. '*** Notes
  9.  
  10. ' Table strucure expected : (MySQL example)
  11. '  CREATE TABLE IF NOT EXISTS TransfersPerIP (
  12. '   Num MEDIUMINT(9) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  13. '   IP VARCHAR(255) NOT NULL,
  14. '   LastUpdate VARCHAR(255) NOT NULL,
  15. '   Files BIGINT(11) NOT NULL,
  16. '   Bytes BIGINT(11) NOT NULL
  17. '  );
  18.  
  19. ' Table strucure expected : (Access example)
  20. 'CREATE TABLE TransfersPerIP (
  21. '   Num AUTOINCREMENT  NOT NULL  PRIMARY KEY,
  22. '   IP VARCHAR(255) NOT NULL,
  23. '   LastUpdate VARCHAR(255) NOT NULL,
  24. '   Files INT NOT NULL,
  25. '   Bytes INT NOT NULL
  26. ');
  27.  
  28. '*** Settings
  29.  
  30. '* ConnectionString : same meaning as in G6 autentication
  31. '      Mysql example
  32. 'Const ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Port=3306;Option=131072;Stmt=;Database=G6_logs;Uid=G6;Pwd=;"
  33. '      Access example
  34. Const ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""D:\!FTPCONFIG\G6\MYDB\database.mdb"";"
  35.  
  36. '* How often should we reset the counter ? (In minutes)
  37. Const ResetEvery = 10800
  38.  
  39. '* How many files a user can download ?
  40. Const MaxFiles = 25
  41.  
  42. '* How many megabytes a user can download ?
  43. Const MaxMBytes = 200
  44.  
  45. '* Should we display debug messages/error notices ?
  46. Const DebugMode = False
  47.  
  48. '************************************************************************************
  49. '*** Let's the show begin :p
  50. '*** You shouldn't have to modify things under this point
  51. '************************************************************************************
  52.  
  53. Dim fso : Set fso = CreateObject("Scripting.fileSystemObject")
  54. Dim vbCrLf : vbCrLf = Chr(13) & Chr(10)
  55.  
  56. Sub OnFileDownloaded()
  57.  
  58.     Set Co = CreateObject("ADODB.Connection")
  59.     Co.open ConnectionString
  60.     If co.State = 1 Then
  61.         Set rs = co.execute("select * from TransfersPerIP where IP = """ & Client.PeerIP & """")
  62.         If not rs.eof Then
  63.             If DebugMode Then
  64.                 Client.post "You have downloaded " & rs.fields("Files") & " files, that is " & Tools.FormatSize( rs.fields("Bytes") )
  65.             end if
  66.         End If
  67.         Co.close
  68.         Set Co = Nothing
  69.         Set rs = Nothing
  70.     Else
  71.         If DebugMode Then
  72.             client.post "Failed to open data connection !"
  73.         End If
  74.     End If
  75.        
  76.  
  77. End Sub
  78.  
  79. Sub HookRetrieve(FileName, FileNameReal)
  80.  
  81.     Set Co = CreateObject("ADODB.Connection")
  82.     Co.open ConnectionString
  83.     If co.State = 1 Then
  84.        
  85.         Set rs = co.execute("select * from TransfersPerIP where IP = """ & Client.PeerIP & """")
  86.        
  87.         If rs.eof Then
  88.             req = "Insert into TransfersPerIP( IP, Lastupdate, Files, Bytes ) values ( """ & Client.PeerIP & """, """ & now() & """, 0,0 )"
  89.             Co.Execute req
  90.             req = "update TransfersPerIP set Files = Files + 1, Bytes = Bytes + " & fso.getfile(FileNameReal).Size & " where IP = """ & Client.PeerIP & """"
  91.             Co.Execute req
  92.             Hook.Result = 0
  93.         Else
  94.            
  95.             If DateDiff( "n", rs.fields("Lastupdate"), now()) < ResetEvery Then
  96.                          
  97.                 If rs.fields("Files") > MaxFiles or rs.fields("Bytes") > ( MaxMBytes * 1024^2 ) Then
  98.                     Hook.Result = 1
  99.                     Hook.SetReply 550, "Server too busy to process you request. Please try again later."
  100.                 Else
  101.                     req = "update TransfersPerIP set Files = Files + 1, Bytes = Bytes + " & fso.getfile(FileNameReal).Size & " where IP = """ & Client.PeerIP & """"
  102.                     Co.Execute req
  103.                    
  104.                     Hook.Result = 0
  105.                 End If
  106.            
  107.             Else
  108.            
  109.                 req = "update TransfersPerIP set LastUpDate = """ & Now() & """ , Files = 1, Bytes = " & fso.getfile(FileNameReal).Size & " where IP = """ & Client.PeerIP & """"
  110.                 Co.Execute req
  111.                
  112.                 Hook.Result = 0
  113.                
  114.             End If
  115.                        
  116.         End If
  117.        
  118.         Co.close
  119.         Set Co = Nothing
  120.         Set rs = Nothing
  121.     Else
  122.         If DebugMode Then
  123.             client.post "Failed to open data connection !"
  124.         End If
  125.         Hook.Result = 1
  126.         Hook.SetReply 550, "The server encountered an error"
  127.     End If
  128.    
  129.  
  130. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement