Medya Blue

Windows Server Family Developer Center

  • hMail Smtp Limit 2013

    hMail server kullanmak istediğimizde karşımıza çıkan en büyük sorun kullanıcıların günlük gönderimini kısıtlıyamıyor olmamızdır, bu scriptle bu sorunu ortadan kaldırıp smtp kullanımına limit koyabiliyoruz.

    Hmail Server da günlük mail gönderimine kota koymak ve dışarıdan gelen saldırılara karşı bloke koymak için hazırlanmış bir script.

    Smtp Limit scriptinin çalışabilmesi için Hmail kurulumu sırasında veri tabanı olarak MySQL seçmelisiniz.

    1Vbs İçeriği

    Public ObjAPP
    Public DomainBuffer
    Public Const LocalHostIP = "0.0.0.0"
    Public Const AdminName = "Administrator"
    Public Const AdminPass = "XXXXXXX"
    Public Const UserLimit = 250
    Public Const SpamLimit = 250
    Public Const MsgFrom = "XXXXXXXXXXXXX CO."
    Public Const MsgAddr = "xxxx@xxxxxxx.com"

    ' Hmailserver Eventhandlers

    Sub OnAcceptMessage(oClient, oMessage)
    Dim obDatabase
    Set obDatabase = GetDatabaseObject
    Dim sSQL
    dim iID
    Dim SendDate
    Dim AliciSayisi
    SendDate = Get_Date
    Result.Value = 0
    Set ObjAPP = CreateObject("hMailServer.Application")
    Call ObjAPP.Authenticate(AdminName, AdminPass)
    If User_Authenticated(oClient) Then
    AliciSayisi = omessage.Recipients.count
    sSQL = "insert into ex_outgoing (Gonderen, IPName, AliciSayisi,SendDate) values ('" & oCLient.username & "', '" & oClient.IPAddress & "', '" & AliciSayisi & "','" & SendDate & "')"
    Call obDatabase.ExecuteSQL(sSQL)
    -
    Set Bag = CreateObject("ADODB.Connection")
    Set Rs = CreateObject("ADODB.Recordset")
    Bag.Open "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=localhost; DATABASE=XXXXXXXX; UID=XXXXXX; PWD=XXXXXX; PORT=3306;"
    gCount = 0
    sorgu = "SELECT * FROM ex_outgoing where SendDate = '" & SendDate & "' and Gonderen='"& oCLient.username &"'"
    Rs.open Sorgu, bag, 3, 1
    Do while not rs.eof
    sy = rs("AliciSayisi")
    gCount = gCount + sy
    rs.movenext
    loop
    rs.close
    bag.close
    set rs=nothing
    set bag=Nothing
    -
    SendLimitMessage oClient, oMessage, gCount, UserLimit
    if gCount >= UserLimit Then
    Result.Message = "Gunluk Mail Gonderim Limiti Dolu"
    Result.Value = 2
    End If
    Else
    dim obRecipients
    set obRecipients = oMessage.Recipients
    dim iRecipientCount
    iRecipientCount = omessage.Recipients.count
    dim i
    for i = 0 to iRecipientCount -1
    dim sRecipientAddress
    sRecipientAddress = obrecipients.Item(i).Address
    sRecipientAddress = Escape(obDatabase, sRecipientAddress)
    sSQL = "insert into ex_incoming (Gonderen, Alici, IPName,SendDate) values ('" & omessage.fromaddress & "', '" & sRecipientAddress & "', '" & oClient.IPAddress & "','" & SendDate & "')"
    Call obDatabase.ExecuteSQL(sSQL)
    Next


    sSQL = "SELECT COUNT(*) FROM ex_incoming Where SendDate = '" & SendDate & "' and Gonderen = '"& omessage.fromaddress &"'"


    iID = obDatabase.ExecuteSQLWithReturn(sSQL)
    If iID > SpamLimit then
    Result.Message = "Spam Filter Active"
    Result.Value = 2
    End If
    End If
    End Sub
    ----
    ' Kullanıcı Dogrulama
    ----
    Function User_Authenticated(oclient)
    User_Authenticated = false
    If oCLient.username <> "" Or InStr(1," " & LocalHostIP, oClient.IPAddress) > 0 Then
    User_Authenticated = true
    End if
    End Function
    ----
    ' Limit Mesajı Gönder
    ----
    Sub SendLimitMessage(oClient, oMessage, UserSendMSG, UserLimitMax)
    Dim TextMsg
    Dim TextSbj
    Dim UserAddr
    If oclient.username <> "" then
    UserAddr = oclient.username
    Else
    UserAddr = oMessage.FromAddress
    End If
    TextSbj = "UYARI : MAIL GONDERIM DURDURURLDU"
    TextMsg = TextMsg & "HESAP MAIL GONDERIM LIMITI DOLDU." & NewLine
    TextMsg = TextMsg & "GONDERILEN : " & UserSendMSG & " LIMIT : " & UserLimitMax & NewLine
    Set nMessage = CreateObject("hMailServer.Message")
    nMessage.From = MsgFrom
    nMessage.FromAddress = MsgAddr
    nMessage.AddRecipient UserAddr, UserAddr
    nMessage.Subject = TextSbj
    nMessage.Body = TextMsg
    nMessage.Save
    End Sub
    ----
    ' Get Date
    ----
    Function Get_Date
    Dim tmp
    Dim erg
    tmp = Year(Date)
    erg = CStr(tmp)
    If Month(Date) < 10 Then
    tmp = "0" & Month(Date)
    Else
    tmp = Month(Date)
    End If
    erg = erg & tmp
    If day(Date) < 10 Then
    tmp = "0" & day(Date)
    Else
    tmp = day(Date)
    End If
    erg = erg & tmp
    Get_Date = erg
    End Function
    ----
    '
    ----
    Function GetDatabaseObject()
    Dim obApp
    Set obApp = CreateObject("hMailServer.Application")
    Call obApp.Authenticate(AdminName, AdminPass)
    Set GetDatabaseObject = obApp.Database
    End Function
    ----
    '
    ----
    Function Escape(obDatabase, value)
    value = Replace(value, "'", "''")
    Select Case obDatabase.DatabaseType
    Case 1: ' MySQL
    value = Replace(value, "", "")
    Case 3: ' PGSQL
    value = Replace(value, "", "")
    End Select
    Escape = value
    End Function
    ----
    '
    ----
    Function GetTimestamp(obDatabase)
    Select Case obDatabase.DatabaseType
    Case 1: ' MySQL
    GetTimestamp = "NOW()"
    Case 2: ' MSSQL
    GetTimestamp = "GETDATE()"
    Case 3: ' PGSQL
    GetTimestamp = "current_timestamp"
    Case 4: ' SQL CE
    GetTimestamp = "GETDATE()"
    End Select
    End Function

    2Veri Tabanı Bilgisi (Ex_incoming.sql)

    # MySQL-Front 5.0 (Build 1.0)

    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
    /*!40101 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
    /*!40103 SET SQL_NOTES='ON' */;


    # Host: localhost:3307 Database: hmail
    # --------------
    # Server version 5.1.42-community

    #
    # Table structure for table ex_incoming
    #

    DROP TABLE IF EXISTS `ex_incoming`;
    CREATE TABLE `ex_incoming` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `Gonderen` varchar(255) DEFAULT NULL,
    `Alici` varchar(255) DEFAULT NULL,
    `IPName` varchar(255) DEFAULT NULL,
    `SendDate` varchar(10) DEFAULT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

    3Veri Tabanı Bilgisi (Ex_outgoing.sql)

    # MySQL-Front 5.0 (Build 1.0)

    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
    /*!40101 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
    /*!40103 SET SQL_NOTES='ON' */;


    # Host: localhost:3307 Database: hmail
    # --------------
    # Server version 5.1.42-community

    #
    # Table structure for table ex_outgoing
    #

    DROP TABLE IF EXISTS `ex_outgoing`;
    CREATE TABLE `ex_outgoing` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `Gonderen` varchar(255) DEFAULT NULL,
    `IPName` varchar(255) DEFAULT NULL,
    `AliciSayisi` int(11) DEFAULT '0',
    `SendDate` varchar(10) DEFAULT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

    Yüklemeler
    hMail Smtp Limit 2013
    Hmail Limit Smtp 2013
    rar
    Tasarım Deep Design Group
    Copyright ® 2013 MEDYA BLUE