Saturday, September 7, 2024

PHP Ban IP to Cloudflare API Script

Usage:
Run the script periodically using a cron job (Linux) or Task Scheduler (Windows) to handle blocking and removal of expired blocks.

Ensure paths to logs and other configurations are updated to reflect your actual setup.

<?php
// Cloudflare API settings
$apiKey = "your_cloudflare_api_key"; // Global API Key
$authEmail = "your_cloudflare_email"; // Cloudflare account email
$zoneID = "your_zone_id"; // Zone ID
$logPath = "C:pathtoaccess.log"; // Path to Apache access log
$blockLogPath = "C:pathtoblock.log"; // Path to log block actions
$blockRemoveLogPath = "C:pathtoblock_remove.log"; // Path to log block removal actions
$threshold = 10; // Number of 404s to trigger a block
$timeWindowMinutes = 10; // Time window in minutes for analysis
$blockDurationHours = 1; // Duration to block IP in hours

// Current timestamp minus time window (in seconds)
$timeWindow = time() - ($timeWindowMinutes * 60);

// Function to log messages to a file
function logMessage($message, $logFilePath) {
    $timestamp = date('Y-m-d H:i:s');
    file_put_contents($logFilePath, "[$timestamp] $message" . PHP_EOL, FILE_APPEND);
}
[Read more...]

Monday, August 24, 2020

CloneFileInfo

CloneFileInfo [Delphi]

function CloneFileInfoA(sSource: String; sDestin: String): Bool;
var
  dwRes:        DWORD;
  dwFile:       DWORD;
  dwSize:       DWORD;
  dwLangID:     DWORD;
  dwSrcSize:    DWORD;
  dwDestSize:   DWORD;
  bSrcData:     TBytes;
  bDestData:    TBytes;
  ptrBuffer:    Pointer;
begin
  Result := True;
  dwRes:= 0;
  dwLangID := 0;
  dwSrcSize := 0;
  dwDestSize := 0;
 
  dwSrcSize := GetFileVersionInfoSize(PChar(sSource), dwFile);
 
  if dwSrcSize = 0 then
  begin
    Result := False;
    Exit;
  end;
 
  SetLength(bSrcData, dwSrcSize);
  GetFileVersionInfo(PChar(sSource), dwFile, dwSrcSize, @bSrcData[0]);
 
  dwDestSize := GetFileVersionInfoSize(PChar(sSource), dwFile);
 
  if dwDestSize = 0 then
  begin
    Result := False;
    Exit;
  end;
 
  SetLength(bDestData, dwDestSize);
  GetFileVersionInfo(PChar(sDestin), dwFile, dwDestSize, @bDestData[0]);
 
  VerQueryValue(@bDestData[0], PChar('VarFileInfoTranslation'), ptrBuffer, dwSize);
  dwRes := BeginUpdateResource(PChar(sDestin), False);
 
  CopyMemory(@dwLangID, ptrBuffer, 2);
  UpdateResource(dwRes, RT_VERSION, PChar(VS_VERSION_INFO), dwLangID, @bSrcData[0], dwSrcSize);
  EndUpdateResource(dwRes, False);
end;

Tuesday, July 21, 2020

Test User’s Internet Connection in VB

Declare API

Private Declare Function InternetGetConnectedState Lib "wininet" (ByRef dwflags As Long, _
  ByVal dwReserved As Long) As Long
Private Const CONNECT_LAN As Long = &H2
  Private Const CONNECT_MODEM As Long = &H1
  Private Const CONNECT_PROXY As Long = &H4
  Private Const CONNECT_OFFLINE As Long = &H20
  Private Const CONNECT_CONFIGURED As Long = &H40

Function:

Public Function IsWebConnected(Optional ByRef ConnType As String) As Boolean
      Dim dwflags As Long
      Dim WebTest As Boolean
      ConnType = ""
      WebTest = InternetGetConnectedState(dwflags, 0&)
      Select Case WebTest
          Case dwflags And CONNECT_LAN: ConnType = "LAN"
          Case dwflags And CONNECT_MODEM: ConnType = "Modem"
          Case dwflags And CONNECT_PROXY: ConnType = "Proxy"
          Case dwflags And CONNECT_OFFLINE: ConnType = "Offline"
          Case dwflags And CONNECT_CONFIGURED: ConnType = "Configured"
          Case dwflags And CONNECT_RAS: ConnType = "Remote"
      End Select
      IsWebConnected = WebTest
  End Function
  Private Sub Command1_Click()
      Dim msg As String
      If IsWebConnected(msg) Then
          msg = "You are connected to the Internet via: " & msg
      Else
          msg = "You are not connected to the Internet."
      End If
      
      MsgBox msg, vbOKOnly, "Internet Connection Status"
  End Sub

[Read more…]

Tuesday, July 14, 2020

ການນຳໃຊ້ CreateObject ໃນ Go

ເປັນຕົວຢ່າງການນຳໃຊ້ CreateObject ໃນ Go

Namespace/Package Name: github.com/go-ole/com

func Example_msxml_rssreader() {
com.CoInitialize()
defer com.CoUninitialize()
var unknown *iunknown.Unknown
var xmlhttp *Dispatch
err := com.CreateObject("Microsoft.XMLHTTP", &unknown)
unknown.QueryInterface(com.IDispatchInterfaceID, &xmlhttp)
defer xmlhttp.Release()
MustCallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
MustCallMethod(xmlhttp, "send", nil)
[Read more...]

Thursday, June 18, 2020

compresses a file or folder

Public Function ShellZip(ByRef Source As String, ByRef DestZip As String) As Boolean
    CreateNewZip DestZip
    On Error Resume Next
    With CreateObject("Shell.Application")  'Late-bound
   'With New Shell                          'Referenced
        If Right$(Source, 1&) = "" Then
            .NameSpace(CVar(DestZip)).CopyHere .NameSpace(CVar(Source)).Items
        Else
            .NameSpace(CVar(DestZip)).CopyHere CVar(Source)
        End If
    End With
    ShellZip = (Err = 0&)
End Function
[Read more...]

A Base64 Encoder/Decoder

Declare:

Private InitDone  As Boolean
Private Map1(0 To 63)  As Byte
Private Map2(0 To 127) As Byte

Function:
[Read more…]

AntiDebug

API:
Private Declare Function NtQueryInformationProcess Lib "NTDLL.DLL" (ByVal hProcess As Long, ByVal ProcessInformationClass As Long, ProcessInformation As Any, ByVal ProcessInformationLength As Long, ReturnLength As Long) As Long
Function:
Public Function ImBeingDebugged() As Boolean
    Call NtQueryInformationProcess(-1, &H1E, ImBeingDebugged, ByVal 4, ByVal 0&)
End Function

Subscribe

  • RSS Atom

ອອນລາຍ: 1 | ມື້ນີ້: 11 | ວານນີ້: 25 | ທິດນີ້: 91 | ເດືອນນີ້: 870 | ປີນີ້: 11830 | ລວມ: 78933