Jump to content

First post, First script: Server Audit v1.0


Recommended Posts

Hey all, just messing around with AutoIT and made a script that checks a list of servers to make sure they all are responsive. If the audited server does not respond, then an event log is written and an email notification is sent. Here it is:

Server Audit v1.0

The script configures these options on first run:

-SMTP server/port/SSL settings of notification sender

-From: (sender mail settings)

-TO: list

-CC: list (optional)

-BCC: list (optional)

-List of servers you want to monitor

-Audit frequency

-Max number of failures before a notification is sent

Throw these to scripts into a folder with each other and run!

This script requires _INetSmtpMailCom.au3, here it is:

#include-once
#Include <file.au3>
#include <INet.au3>
Global $o_Error = ObjEvent("AutoIt.Error", "ErrFunc")
Global $o_ReturnMsg[2]
;##################################
; Variables
;##################################
;$s_SmtpServer = "MailServer"              ; address for the smtp-server to use - REQUIRED
;$s_FromName = "Name"                      ; name from who the email was sent
;$s_FromAddress = "your@Email.Address.com" ;  address from where the mail should come
;$s_ToAddress = "your@Email.Address.com"   ; destination address of the email - REQUIRED
;$s_Subject = "Userinfo"                   ; subject from the email - can be anything you want it to be
;$as_Body = ""                             ; the messagebody from the mail - can be left blank but then you get a blank mail
;$s_AttachFiles = ""                       ; the file you want to attach- leave blank if not needed
;$s_CcAddress = "CCaddress1@test.com"       ; address for cc - leave blank if not needed
;$s_BccAddress = "BCCaddress1@test.com"     ; address for bcc - leave blank if not needed
;$s_Username = "******"                    ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
;$s_Password = "********"                  ; password for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
;$v_IPPort = 25                              ; port used for sending the mail
;$v_SSL = 0                                  ; enables/disables secure socket layer sending - put to 1 if using httpS
;~ $v_IPPort=465                             ; GMAIL port used for sending the mail
;~ $v_SSL=1                                  ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################
; Script
;##################################
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password,$v_IPPort, $v_SSL)
    $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_description = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
        $objEmail.HTMLBody = $as_Body 
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                $i_Error_description = $i_Error_description & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
                SetError(1)
                return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $v_IPPort
;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $v_SSL Then 
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    Else
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
    EndIf
;Update settings
    $objEmail.Configuration.Fields.Update
; Sent the Message
    $objEmail.Send
    if @error then 
        SetError(2)
        return $o_ReturnMsg[1]
    EndIf
EndFunc ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func ErrFunc()
    $o_ReturnMsg[0] = Hex($o_Error.number, 8)
    $o_ReturnMsg[1] ="COM Error!  Error code: " & $o_ReturnMsg[0] & " - " & StringStripWS($o_Error.description,3) & " Notification failed!"
    ConsoleWrite("### COM Error!  Error code: " & $o_ReturnMsg[0] & "   ScriptLine: " & $o_Error.scriptline & "   Description: " & StringStripWS($o_Error.description,3) & @LF) 
    SetError(1); something to check for when this function returns
    Return
EndFunc ;==>ErrFunc

here's the code for Server Audit:

[autoit];~ ----------------------------------------------------------------------------

;~ AutoIt Version: 3.2.10.0

;~

;~ Author: Dave Snyder 01/2008

;~

;~ Script Function: This script checks a list of servers to verify that they

;~ are accessible from the network and sends a notification

;~ e-mail if the check fails using SMTP.

;~

;~ Script name: Server Audit v1.0

;~ ----------------------------------------------------------------------------

;~ Make sure the user account has administrator rights

If Not IsAdmin() Then

MsgBox(0x41040, "", "Administrator rights are required to run this application.")

exit

EndIf

;~ Run only one instance

if _Singleton("ServerAudit",1) = 0 Then

TraySetState(1)

; Msgbox(0,"Server Audit","Server Audit is already running!")

Exit

EndIf

;~ Globals and includes

Opt("OnExitFunc", "ExitScript")

Opt("TrayOnEventMode",1) ; Enables event driven scripting

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

Opt("TrayAutoPause",0) ; Script will not be paused when clicking the tray icon.

Opt("GUIDataSeparatorChar",";") ;"|" is the default

#include "Misc.au3"

#include <GUIConstants.au3>

#include <GUIListBox.au3>

#include <array.au3>

#include "_INetSmtpMailCom.au3"

#Include <file.au3>

#include <INet.au3>

#include <Constants.au3>

#NoTrayIcon

global $answer, $list, $writelog

global $s_Path, $s_ini, $s_SMTP, $s_From, $s_Name, $s_UserName, $s_Password, $s_EmailSubject, $s_EmailAttachment, $s_EmailBody

global $csv_ServerList, $csv_ToList, $csv_CCList, $csv_BCCList, $csv_EditServerList

global $n_Port, $n_AuditFrequency, $n_FailLimit

global $b_Pause, $b_SSL, $b_Auth

global $c_timescale = 60000 ;~ constant- 60000 miliseconds in one minute

;~ Get Application path and path to .ini file

If @compiled = 1 Then

$s_Path = StringTrimRight(@AutoItExe, 4) & ".exe"

Else

$s_Path = StringTrimRight(@ScriptFullPath, 4) & ".au3"

EndIf

$s_ini = @ScriptDir & "\" & "ServerAudit.ini"

;~ Check if INI exists, Configure the application if it doesn't

If Not FileExists($s_ini) Then

_FileCreate (@ScriptDir & "\" & "ServerAudit.log")

MsgBox(0x41040, "Server Audit", "Server Audit.ini is not found. Click OK to run the configurator.")

Call("EditMailerSettings")

Call("EditNotificationSettings")

Global $as_ToList[1]

MsgBox(0x41040, "Server Audit", "Enter a notification recipient in the input box on the"&@CRLF&"next window and click the 'Add' button. When you"&@CRLF&"are done, click 'Done', or click 'Cancel' to exit.")

call("EditToList")

$answer = MsgBox(0x41023, "Mailing list - CC:", "Do you want to configure carbon copy notifications?")

If $answer = 2 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

Exit

Else

If $answer = 6 Then

Global $as_CCList[1]

MsgBox(0x41040, "Server Audit", "Enter a notification recipient in the input box on the"&@CRLF&"next window and click the 'Add' button. When you"&@CRLF&"are done, click 'Done', or click 'Cancel' to exit.")

call("EditCCList")

Else

EndIf

EndIf

$answer = MsgBox(0x41023, "Mailing list - BCC:", "Do you want to configure blind carbon copy notifications?")

If $answer = 2 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

Exit

Else

If $answer = 6 Then

Global $as_BCCList[1]

MsgBox(0x41040, "Server Audit", "Enter a notification recipient in the input box on the"&@CRLF&"next window and click the 'Add' button. When you"&@CRLF&"are done, click 'Done', or click 'Cancel' to exit.")

call("EditBCCList")

Else

EndIf

EndIf

Call("EditAuditSettings")

Global $as_ServerList[1]

MsgBox(0x41040, "Server Audit", "Enter a host name or IP address in the input box on the"&@CRLF&"next window and click the 'Add' button. When you"&@CRLF&"are done, click 'Done', or click 'Cancel' to exit.")

call("EditServerList")

;~ Write the variables to the .ini file

IniWrite($s_ini, "MailServer", "SMTP", $s_SMTP)

IniWrite($s_ini, "MailServer", "Port", $n_Port)

IniWrite($s_ini, "MailServer", "SSL", $b_SSL)

IniWrite($s_ini, "MailServer", "Name", $s_Name)

IniWrite($s_ini, "MailServer", "From", $s_From)

IniWrite($s_ini, "MailServer", "Authentication", $b_Auth)

IniWrite($s_ini, "MailServer", "UserName", $s_UserName)

IniWrite($s_ini, "MailServer", "Password", $s_Password)

FileWrite($s_ini, chr(13))

IniWrite($s_ini, "MailList", "ToList", $csv_ToList)

IniWrite($s_ini, "MailList", "CCList", $csv_CCList)

IniWrite($s_ini, "MailList", "BCCList", $csv_BCCList)

FileWrite($s_ini, chr(13))

IniWrite($s_ini, "Audit", "AuditFrequency", $n_AuditFrequency)

IniWrite($s_ini, "Audit", "FailLimit", $n_FailLimit)

FileWrite($s_ini, chr(13))

IniWrite($s_ini, "ServerList", "ServerList", $csv_ServerList)

FileClose($s_ini)

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Endif

;~ Main

;~ Read .INI variables from the file

$s_SMTP = IniRead($s_ini, "MailServer", "SMTP", "")

$n_Port = IniRead($s_ini, "MailServer", "Port", "")

$s_Name = IniRead($s_ini, "MailServer", "Name", "")

$s_From = IniRead($s_ini, "MailServer", "From", "")

$b_SSL = IniRead($s_ini, "MailServer", "SSL", "")

$b_Auth = IniRead($s_ini, "MailServer", "Authentication", "")

$s_UserName = IniRead($s_ini, "MailServer", "UserName", "")

$s_Password = IniRead($s_ini, "MailServer", "Password", "")

$csv_ToList = IniRead($s_ini, "MailList", "ToList", "")

$csv_CCList = IniRead($s_ini, "MailList", "CCList", "")

$csv_BCCList = IniRead($s_ini, "MailList", "BCCList", "")

$n_AuditFrequency = IniRead($s_ini, "Audit", "AuditFrequency", "")

$n_FailLimit = IniRead($s_ini, "Audit", "FailLimit", "")

$csv_ServerList = IniRead($s_ini, "ServerList", "ServerList", "")

FileClose($s_ini)

;~ Initialize arrays

$as_ServerList = StringSplit($csv_ServerList, ";", 1)

$as_ToList=StringSplit($csv_ToList, ";", 1)

$as_CCList=StringSplit($csv_CCList, ";", 1)

$as_BCCList=StringSplit($csv_BCCList, ";", 1)

;~ Other globals

Global $an_FailCount[$as_ServerList[0]+1]

Global $an_FailCode[$as_ServerList[0]+1]

Global $as_FailMessage[$as_ServerList[0]+1]

;~ Initialize tray menu

TraySetIcon("Shell32.dll",19)

TraySetToolTip("Server Audit - Active")

TraySetClick(16) ; Only secondary mouse button will show the tray menu.

$showitem = TrayCreateItem("View Log")

TrayItemSetState($showitem, $TRAY_DEFAULT)

TrayItemSetOnEvent($showitem,"ShowLog")

$audititem = TrayCreateItem("Force Audit")

TrayItemSetOnEvent($audititem,"ForceAudit")

$pauseitem = TrayCreateItem("Pause Audit")

TrayItemSetOnEvent($pauseitem,"PauseAudit")

$resetitem = TrayCreateItem("Reset Error Status")

TrayItemSetOnEvent($resetitem,"ResetAudit")

$clearitem = TrayCreateItem("Clear Log File")

TrayItemSetOnEvent($clearitem,"ClearLog")

TrayCreateItem("")

$settingsitem = TrayCreateMenu("Settings")

$maileritem = TrayCreateItem("Mail Server Settings", $settingsitem)

TrayItemSetOnEvent($maileritem,"EditMailerSettings")

$notificationitem = TrayCreateItem("Notification Settings", $settingsitem)

TrayItemSetOnEvent($notificationitem,"EditNotificationSettings")

$toitem = TrayCreateItem("To: List", $settingsitem)

TrayItemSetOnEvent($toitem,"EditToList")

$ccitem = TrayCreateItem("CC: List", $settingsitem)

TrayItemSetOnEvent($ccitem,"EditCCList")

$bccitem = TrayCreateItem("BCC: List", $settingsitem)

TrayItemSetOnEvent($bccitem,"EditBCCList")

$audititem = TrayCreateItem("Audit Settings", $settingsitem)

TrayItemSetOnEvent($audititem,"EditAuditSettings")

$serverlistitem = TrayCreateItem("Server List", $settingsitem)

TrayItemSetOnEvent($serverlistitem,"EditServerList")

TrayCreateItem("")

$infoitem = TrayCreateItem("About...")

TrayItemSetOnEvent($infoitem,"ShowInfo")

$exititem = TrayCreateItem("Exit")

TrayItemSetOnEvent($exititem,"ExitScript")

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"ShowLog")

TraySetState(1)

While 1 ;~ here's where we put the action items while we idle for input

Sleep($n_AuditFrequency * $c_timescale) ; Idle loop

if $b_Pause = 0 Then

call ("Audit")

EndIf

WEnd

;~ The End

exit

;~ Functions

;~ Pause the audit

Func PauseAudit()

If $b_Pause = 0 Then

$b_Pause = 1

TrayItemSetText($pauseitem,"Resume Audit")

TraySetToolTip("Server Audit - Paused")

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Monitoring paused.")

;~ MsgBox(0x41040,"Server Audit", "Monitoring paused.")

Else

$b_Pause = 0

TrayItemSetText($pauseitem,"Pause Audit")

TraySetToolTip("Server Audit - Active")

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Monitoring resumed.")

;~ MsgBox(0x41040,"Server Audit", "Monitoring resumed.")

EndIf

EndFunc

;~ Show the logfile

Func ShowLog()

ShellExecute("ServerAudit.log", "", @ScriptDir & "\", "open")

EndFunc

;~ Erase the logfile

Func ClearLog()

$answer = MsgBox(0x41021, "Clear log file", "Are you sure you want to clear the log file?")

If $answer = 1 Then

_FileCreate (@ScriptDir & "\" & "ServerAudit.log")

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Log file erased.")

FileClose(@ScriptDir & "\" & "ServerAudit.log")

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Error creating logfile!")

Return

Else

MsgBox(0x41040,"Server Audit", "Log file has been erased.")

EndIf

EndIf

EndFunc

;~ Audit the server(s)

; this is the business end of the whole script- to monitor other things, add the code here

Func Audit()

For $x = 1 To $as_ServerList[0]

Ping($as_ServerList[$x],250)

$an_failcode[$x] = @error

If $an_failcode[$x] = 0 Then

$as_failmessage[$x] = ""

If $an_failcount[$x] >= $n_FailLimit Then

$s_emailsubject="Server " & $as_ServerList[$x] & " is back online"

$s_EmailBody=$s_emailsubject & " after " & $an_failcount[$x] & " failure(s)."

$an_failcount[$x] = 0

$writelog = $s_emailbody & " Notification sent."

_FileWriteLog(@ScriptDir & "\ServerAudit.log",$writelog)

FileClose(@ScriptDir & "\ServerAudit.log")

call ("Notify")

Else

If $an_failcount[$x] > 0 Then

$s_emailsubject="Server " & $as_ServerList[$x] & " is back online"

$s_EmailBody=$s_emailsubject & " after " & $an_failcount[$x] & " failure(s)."

$an_failcount[$x] = 0

$writelog = $s_emailbody

_FileWriteLog(@ScriptDir & "\ServerAudit.log",$writelog)

FileClose(@ScriptDir & "\ServerAudit.log")

EndIf

EndIf

Else

$an_failcount[$x] = $an_failcount[$x] + 1

If $an_failcode[$x] = 1 Then $as_failmessage[$x] = "Host is offline"

If $an_failcode[$x] = 2 Then $as_failmessage[$x] = "Host is unreachable"

If $an_failcode[$x] = 3 Then $as_failmessage[$x] = "Bad Destination"

If $an_failcode[$x] >= 4 Then $as_failmessage[$x] = "Unspecified error"

$s_emailsubject="Server " & $as_ServerList[$x] & " is offline!"

$s_EmailBody=$s_emailsubject & " Error Code: " & $an_failcode[$x] & " - " & $as_failmessage[$x] & " after " & $an_failcount[$x] & " failure(s)."

If $an_failcount[$x] = $n_FailLimit Then

$writelog = $s_emailbody & " Notification sent."

_FileWriteLog(@ScriptDir & "\ServerAudit.log",$writelog)

FileClose(@ScriptDir & "\ServerAudit.log")

call ("Notify")

Else

$writelog = $s_emailbody

_FileWriteLog(@ScriptDir & "\ServerAudit.log",$writelog)

FileClose(@ScriptDir & "\ServerAudit.log")

EndIf

EndIf

Next

EndFunc

Func ForceAudit()

if $b_Pause = 1 Then

call("PauseAudit")

_FileWriteLog(@ScriptDir & "\ServerAudit.log","User Initiated Audit.")

FileClose(@ScriptDir & "\ServerAudit.log")

call("Audit")

call("PauseAudit")

MsgBox(0x41040,"Server Audit", "User initiated Audit complete.")

Else

_FileWriteLog(@ScriptDir & "\ServerAudit.log","User Initiated Audit.")

FileClose(@ScriptDir & "\ServerAudit.log")

call("Audit")

MsgBox(0x41040,"Server Audit", "User initiated Audit complete.")

EndIf

EndFunc

;~ Send SMTP mail notification

Func Notify()

$retmsg = _INetSmtpMailCom($s_Smtp, $s_Name, $s_From, $csv_ToList, $s_EmailSubject, $s_EmailBody, $s_EmailAttachment, $csv_CcList, $csv_BccList, $s_Username, $s_Password,$n_Port, $b_SSL)

If @error > 0 Then

_FileWriteLog(@ScriptDir & "\ServerAudit.log",$RetMsg)

FileClose(@ScriptDir & "\ServerAudit.log")

Else

EndIf

EndFunc

;~ Reset the failure counts

Func ResetAudit()

For $x = 1 To $as_ServerList[0]

$an_FailCount[$x] = 0

Next

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Error status reset.")

FileClose(@ScriptDir & "\ServerAudit.log")

MsgBox(0x41040,"Server Audit", "Error Status reset.")

If $b_pause = 1 Then

$answer = MsgBox(0x41024, "Server Audit", "Would you like to resume monitoring?")

If $answer = 6 Then

$b_Pause = 0

TrayItemSetText($pauseitem,"Pause Audit")

TraySetToolTip("Server Audit - Active")

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Monitoring resumed.")

FileClose(@ScriptDir & "\ServerAudit.log")

Else

EndIf

Else

EndIf

EndFunc

;~ These functions edit the .ini file

Func EditMailerSettings()

;~ rewrite with this

If Not FileExists($s_ini) Then

$s_SMTP="smtp.host.com"

$n_Port=25

$b_SSL=0

Else

EndIf

$s_SMTPEdit = InputBox("Mail Server Settings", "Enter the notification mailer's SMTP address", $s_SMTP)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$n_PortEdit = InputBox("Mail Server Settings", "Enter SMTP server's port number", $n_Port)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$b_SSLEdit = MsgBox(0x41023, "Mail Server Settings", "Does this server require SSL? (current setting: " & $b_SSL & ")")

If $b_SSLEdit = 2 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

If $b_SSLEdit = 6 Then

$b_SSLEdit = 1

Else

$b_SSLEdit = 0

EndIf

EndIf

$s_SMTP = $s_SMTPEdit

$n_Port = $n_PortEdit

$b_SSL = $b_SSLEdit

If FileExists($s_ini) Then

IniWrite($s_ini, "MailServer", "SMTP", $s_SMTP)

IniWrite($s_ini, "MailServer", "Port", $n_Port)

IniWrite($s_ini, "MailServer", "SSL", $b_SSL)

FileClose($s_ini)

_FileWriteLog(@ScriptDir & "\ServerAudit.log","SMTP server changed to: " & $s_SMTP & ":" & $n_Port & ", SSL = " & $b_SSL)

FileClose(@ScriptDir & "\ServerAudit.log")

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

EndIf

EndFunc

Func EditNotificationSettings()

If Not FileExists($s_ini) Then

$s_Name="Sender"

$s_From="sender@host.com"

$b_Auth=0

$s_UserName="username"

$s_Password="password"

Else

EndIf

$s_NameEdit = InputBox("Notification e-mail", "Enter the server status notification sender's name", $s_Name)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$s_FromEdit = InputBox("Notification e-mail", "Enter server status notification sender's e-mail address", $s_From)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$b_AuthEdit = MsgBox(0x41023, "SMTP Authentication", "Does the SMTP server require authentication? (current setting: " & $b_Auth & ")")

If $b_AuthEdit = 2 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

If $b_AuthEdit = 6 Then

$b_AuthEdit = 1

$s_UserNameEdit = InputBox("Notification e-mail", "Enter the mail account user name.", $s_UserName)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$s_PasswordEdit = InputBox("Notification e-mail", "Enter the mail account password.", $s_Password)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

Else

$b_AuthEdit = 0

$s_UserNameEdit = ""

$s_PasswordEdit = ""

EndIf

EndIf

$s_Name = $s_NameEdit

$s_From = $s_FromEdit

$b_Auth = $b_AuthEdit

$s_UserName = $s_UserNameEdit

$s_Password = $s_PasswordEdit

If FileExists($s_ini) Then

IniWrite($s_ini, "MailServer", "Name", $s_Name)

IniWrite($s_ini, "MailServer", "From", $s_From)

IniWrite($s_ini, "MailServer", "Authentication", $b_Auth)

IniWrite($s_ini, "MailServer", "UserName", $s_UserName)

IniWrite($s_ini, "MailServer", "Password", $s_Password)

FileClose($s_ini)

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Notification sender changed to: " & $s_Name & "<" & $s_From & ">, Authentication = "& $b_Auth)

FileClose(@ScriptDir & "\ServerAudit.log")

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

EndIf

EndFunc

Func EditAuditSettings()

If Not FileExists($s_ini) Then

$n_AuditFrequency=5

$n_FailLimit=3

Else

EndIf

$n_AuditFrequencyEdit = InputBox("Audit Settings", "Enter the audit interval in minutes", $n_AuditFrequency)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$n_FailLimitEdit = InputBox("Audit Settings", "Enter the max. number of times an audit query can fail before it is reported", $n_FailLimit)

If @error > 0 Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

If FileExists($s_ini) Then

Return

else

exit

EndIf

Else

EndIf

$n_AuditFrequency = $n_AuditFrequencyEdit

$n_FailLimit = $n_FailLimitEdit

If FileExists($s_ini) Then

IniWrite($s_ini, "Audit", "AuditFrequency", $n_AuditFrequency)

IniWrite($s_ini, "Audit", "FailLimit", $n_FailLimit)

FileClose($s_ini)

_FileWriteLog(@ScriptDir & "\ServerAudit.log","Audit frequency changed to " & $n_AuditFrequency & " minute(s) with a failure limit of " & $n_FailLimit & " attempt(s).")

FileClose(@ScriptDir & "\ServerAudit.log")

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

EndIf

EndFunc

Func EditToList()

;~ Get the vars to edit

$as_EditToList = $as_ToList

$csv_EditToList = $csv_ToList

$n_EntryIndex = 0

;~ Make the edit box and buttons

$id_EditWindow=GUICreate("To: List",344,280,@DesktopWidth/2-172, @DesktopHeight/2-172,$WS_DLGFRAME,$WS_EX_TOPMOST)

$id_AddEntry=GUICtrlCreateButton ("Add", 16,16,72,24)

$id_DeleteEntry=GUICtrlCreateButton ("Delete",16,64,72,24)

$id_ClearList=GUICtrlCreateButton ("Clear", 16,112,72,24)

$id_Done=GUICtrlCreateButton ("Done", 16, 224,72,24)

$id_Cancel=GUICtrlCreateButton ("Cancel", 256,224,72,24)

$id_InputBox = GUICtrlCreateInput ("", 108,16,220,24)

$id_ListBox=GUICtrlCreateList ("", 108,64,220,156,$WS_VSCROLL)

GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling

;~ Enumerate the listbox with the server list

GUICtrlSetData($id_listbox,$csv_EditToList)

GUISetState ()

;~ Edit the item list

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE then $msg = $id_Cancel

If $msg = $id_InputBox then $msg = $id_AddEntry

Select

case $msg = $id_AddEntry

$NewEntry = GUICtrlRead($id_InputBox)

if $NewEntry <> "" then

GUICtrlSetData($id_InputBox,"")

$as_EditToList[0] = $as_EditToList[0] + 1

Redim $as_EditToList[$as_EditToList[0]+1]

$as_EditToList[$as_EditToList[0]] = $NewEntry

If $csv_EditToList = "" Then

$csv_EditToList=$as_EditToList[$as_EditToList[0]]

Else

$csv_EditToList=$csv_EditToList & ";" & $as_EditToList[$as_EditToList[0]]

EndIf

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditToList)

Else

endif

case $msg = $id_DeleteEntry

$n_EntryIndex=_GUICtrlListBox_GetCurSel($id_listbox)+1

If $n_EntryIndex > 0 Then

_ArrayDelete( $as_EditToList,$n_EntryIndex)

$as_EditToList[0]=$as_EditToList[0]-1

$csv_EditToList = ""

for $x = 1 to $as_EditToList[0]

If $csv_EditToList = "" Then

$csv_EditToList=$as_EditToList[$x]

Else

$csv_EditToList=$csv_EditToList & ";" & $as_EditToList[$x]

EndIf

next

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditToList)

Else

EndIf

case $msg = $id_ClearList

$answer = MsgBox(0x41021, "Clear To: List", "Are you sure you want to clear the To: list?")

If $answer = 1 Then

$csv_EditToList=""

For $x = 1 To $as_EditToList[0]

$as_EditToList[$x] = ""

Next

$as_EditToList[0]=0

GUICtrlSetData($id_listbox,$csv_EditToList)

Else

EndIf

Case $msg = $id_Done

$csv_ToList=$csv_EditToList

$as_ToList=$as_EditToList

$csv_EditToList=""

For $x = 1 To $as_EditToList[0]

$as_EditToList[$x] = ""

Next

$as_EditToList[0]=0

If FileExists($s_ini) Then

IniWrite($s_ini, "MailList", "ToList", $csv_ToList)

FileClose($s_ini)

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

GUISetState (@SW_HIDE,$id_editwindow)

EndIf

return

Case $msg = $id_Cancel

If Not FileExists($s_ini) Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

Exit

Else

EndIf

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

return

EndSelect

Wend

EndFunc

Func EditCCList()

;~ Get the vars to edit

$as_EditCCList = $as_CCList

$csv_EditCCList = $csv_CCList

$n_EntryIndex = 0

;~ Make the edit box and buttons

$id_EditWindow=GUICreate("CC: List",344,280,@DesktopWidth/2-172, @DesktopHeight/2-172,$WS_DLGFRAME,$WS_EX_TOPMOST)

$id_AddEntry=GUICtrlCreateButton ("Add", 16,16,72,24)

$id_DeleteEntry=GUICtrlCreateButton ("Delete",16,64,72,24)

$id_ClearList=GUICtrlCreateButton ("Clear", 16,112,72,24)

$id_Done=GUICtrlCreateButton ("Done", 16, 224,72,24)

$id_Cancel=GUICtrlCreateButton ("Cancel", 256,224,72,24)

$id_InputBox = GUICtrlCreateInput ("", 108,16,220,24)

$id_ListBox=GUICtrlCreateList ("", 108,64,220,156,$WS_VSCROLL)

GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling

;~ Enumerate the listbox with the server list

GUICtrlSetData($id_listbox,$csv_EditCCList)

GUISetState ()

;~ Edit the item list

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE then $msg = $id_Cancel

If $msg = $id_InputBox then $msg = $id_AddEntry

Select

case $msg = $id_AddEntry

$NewEntry = GUICtrlRead($id_InputBox)

if $NewEntry <> "" then

GUICtrlSetData($id_InputBox,"")

$as_EditCCList[0] = $as_EditCCList[0] + 1

Redim $as_EditCCList[$as_EditCCList[0]+1]

$as_EditCCList[$as_EditCCList[0]] = $NewEntry

If $csv_EditCCList = "" Then

$csv_EditCCList=$as_EditCCList[$as_EditCCList[0]]

Else

$csv_EditCCList=$csv_EditCCList & ";" & $as_EditCCList[$as_EditCCList[0]]

EndIf

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditCCList)

Else

endif

case $msg = $id_DeleteEntry

$n_EntryIndex=_GUICtrlListBox_GetCurSel($id_listbox)+1

If $n_EntryIndex > 0 Then

_ArrayDelete( $as_EditCCList,$n_EntryIndex)

$as_EditCCList[0]=$as_EditCCList[0]-1

$csv_EditCCList = ""

for $x = 1 to $as_EditCCList[0]

If $csv_EditCCList = "" Then

$csv_EditCCList=$as_EditCCList[$x]

Else

$csv_EditCCList=$csv_EditCCList & ";" & $as_EditCCList[$x]

EndIf

next

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditCCList)

Else

EndIf

case $msg = $id_ClearList

$answer = MsgBox(0x41021, "Clear CC: List", "Are you sure you want to clear the CC: list?")

If $answer = 1 Then

$csv_EditCCList=""

For $x = 1 To $as_EditCCList[0]

$as_EditCCList[$x] = ""

Next

$as_EditCCList[0]=0

GUICtrlSetData($id_listbox,$csv_EditCCList)

Else

EndIf

Case $msg = $id_Done

$csv_CCList=$csv_EditCCList

$as_CCList=$as_EditCCList

$csv_EditCCList=""

For $x = 1 To $as_EditCCList[0]

$as_EditCCList[$x] = ""

Next

$as_EditCCList[0]=0

If FileExists($s_ini) Then

IniWrite($s_ini, "MailList", "CCList", $csv_CCList)

FileClose($s_ini)

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

GUISetState (@SW_HIDE,$id_editwindow)

EndIf

return

Case $msg = $id_Cancel

If Not FileExists($s_ini) Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

Exit

Else

EndIf

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

return

EndSelect

Wend

EndFunc

Func EditBCCList()

;~ Get the vars to edit

$as_EditBCCList = $as_BCCList

$csv_EditBCCList = $csv_BCCList

$n_EntryIndex = 0

;~ Make the edit box and buttons

$id_EditWindow=GUICreate("BCC: List",344,280,@DesktopWidth/2-172, @DesktopHeight/2-172,$WS_DLGFRAME,$WS_EX_TOPMOST)

$id_AddEntry=GUICtrlCreateButton ("Add", 16,16,72,24)

$id_DeleteEntry=GUICtrlCreateButton ("Delete",16,64,72,24)

$id_ClearList=GUICtrlCreateButton ("Clear", 16,112,72,24)

$id_Done=GUICtrlCreateButton ("Done", 16, 224,72,24)

$id_Cancel=GUICtrlCreateButton ("Cancel", 256,224,72,24)

$id_InputBox = GUICtrlCreateInput ("", 108,16,220,24)

$id_ListBox=GUICtrlCreateList ("", 108,64,220,156,$WS_VSCROLL)

GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling

;~ Enumerate the listbox with the server list

GUICtrlSetData($id_listbox,$csv_EditBCCList)

GUISetState ()

;~ Edit the item list

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE then $msg = $id_Cancel

If $msg = $id_InputBox then $msg = $id_AddEntry

Select

case $msg = $id_AddEntry

$NewEntry = GUICtrlRead($id_InputBox)

if $NewEntry <> "" then

GUICtrlSetData($id_InputBox,"")

$as_EditBCCList[0] = $as_EditBCCList[0] + 1

Redim $as_EditBCCList[$as_EditBCCList[0]+1]

$as_EditBCCList[$as_EditBCCList[0]] = $NewEntry

If $csv_EditBCCList = "" Then

$csv_EditBCCList=$as_EditBCCList[$as_EditBCCList[0]]

Else

$csv_EditBCCList=$csv_EditBCCList & ";" & $as_EditBCCList[$as_EditBCCList[0]]

EndIf

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditBCCList)

Else

endif

case $msg = $id_DeleteEntry

$n_EntryIndex=_GUICtrlListBox_GetCurSel($id_listbox)+1

If $n_EntryIndex > 0 Then

_ArrayDelete( $as_EditBCCList,$n_EntryIndex)

$as_EditBCCList[0]=$as_EditBCCList[0]-1

$csv_EditBCCList = ""

for $x = 1 to $as_EditBCCList[0]

If $csv_EditBCCList = "" Then

$csv_EditBCCList=$as_EditBCCList[$x]

Else

$csv_EditBCCList=$csv_EditBCCList & ";" & $as_EditBCCList[$x]

EndIf

next

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditBCCList)

Else

EndIf

case $msg = $id_ClearList

$answer = MsgBox(0x41021, "Clear BCC: List", "Are you sure you want to clear the BCC: list?")

If $answer = 1 Then

$csv_EditBCCList=""

For $x = 1 To $as_EditBCCList[0]

$as_EditBCCList[$x] = ""

Next

$as_EditBCCList[0]=0

GUICtrlSetData($id_listbox,$csv_EditBCCList)

Else

EndIf

Case $msg = $id_Done

$csv_BCCList=$csv_EditBCCList

$as_BCCList=$as_EditBCCList

$csv_EditBCCList=""

For $x = 1 To $as_EditBCCList[0]

$as_EditBCCList[$x] = ""

Next

$as_EditBCCList[0]=0

If FileExists($s_ini) Then

IniWrite($s_ini, "MailList", "BCCList", $csv_BCCList)

FileClose($s_ini)

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

GUISetState (@SW_HIDE,$id_editwindow)

EndIf

return

Case $msg = $id_Cancel

If Not FileExists($s_ini) Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

Exit

Else

EndIf

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

return

EndSelect

Wend

EndFunc

Func EditServerList()

;~ Get the vars to edit

$as_EditServerList = $as_ServerList

$csv_EditServerList = $csv_ServerList

$n_EntryIndex = 0

;~ Make the edit box and buttons

$id_EditWindow=GUICreate("Server List",236,280,@DesktopWidth/2-118, @DesktopHeight/2-118,$WS_DLGFRAME,$WS_EX_TOPMOST)

$id_AddEntry=GUICtrlCreateButton ("Add", 16,16,72,24)

$id_DeleteEntry=GUICtrlCreateButton ("Delete",16,64,72,24)

$id_ClearList=GUICtrlCreateButton ("Clear", 16,112,72,24)

$id_Done=GUICtrlCreateButton ("Done", 16, 224,72,24)

$id_Cancel=GUICtrlCreateButton ("Cancel", 148,224,72,24)

$id_InputBox = GUICtrlCreateInput ("", 108,16,112,24)

$id_ListBox=GUICtrlCreateList ("", 108,64,112,156,$WS_VSCROLL)

GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling

;~ Enumerate the listbox with the server list

GUICtrlSetData($id_listbox,$csv_EditServerList)

GUISetState ()

;~ Edit the server list

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE then $msg = $id_Cancel

If $msg = $id_InputBox then $msg = $id_AddEntry

Select

case $msg = $id_AddEntry

$NewEntry = GUICtrlRead($id_InputBox)

if $NewEntry <> "" then

GUICtrlSetData($id_InputBox,"")

$as_EditServerList[0] = $as_EditServerList[0] + 1

Redim $as_EditServerList[$as_EditServerList[0]+1]

$as_EditServerList[$as_EditServerList[0]] = $NewEntry

If $csv_EditServerList = "" Then

$csv_EditServerList=$as_EditServerList[$as_EditServerList[0]]

Else

$csv_EditServerList=$csv_EditServerList & ";" & $as_EditServerList[$as_EditServerList[0]]

EndIf

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditServerList)

Else

endif

case $msg = $id_DeleteEntry

$n_EntryIndex=_GUICtrlListBox_GetCurSel($id_listbox)+1

If $n_EntryIndex > 0 Then

_ArrayDelete( $as_EditServerList,$n_EntryIndex)

$as_EditServerList[0]=$as_EditServerList[0]-1

$csv_EditServerList = ""

for $x = 1 to $as_EditServerList[0]

If $csv_EditServerList = "" Then

$csv_EditServerList=$as_EditServerList[$x]

Else

$csv_EditServerList=$csv_EditServerList & ";" & $as_EditServerList[$x]

EndIf

next

GUICtrlSetData($id_ListBox,"")

GUICtrlSetData($id_ListBox,$csv_EditServerList)

Else

EndIf

case $msg = $id_ClearList

$answer = MsgBox(0x41021, "Clear server list", "Are you sure you want to clear the server list?")

If $answer = 1 Then

$csv_EditServerList=""

For $x = 1 To $as_EditServerList[0]

$as_EditServerList[$x] = ""

Next

$as_EditServerList[0]=0

GUICtrlSetData($id_listbox,$csv_EditServerList)

Else

EndIf

Case $msg = $id_Done

$csv_ServerList=$csv_EditServerList

$as_ServerList=$as_EditServerList

$csv_EditServerList=""

For $x = 1 To $as_EditServerList[0]

$as_EditServerList[$x] = ""

Next

$as_EditServerList[0]=0

If FileExists($s_ini) Then

IniWrite($s_ini, "ServerList", "ServerList", $csv_ServerList)

FileClose($s_ini)

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41040,"Server Audit", "Configuraion updated.")

Else

GUISetState (@SW_HIDE,$id_editwindow)

EndIf

return

Case $msg = $id_Cancel

If Not FileExists($s_ini) Then

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

Exit

Else

EndIf

GUISetState (@SW_HIDE,$id_editwindow)

MsgBox(0x41010, "Server Audit", "Server Audit configuration cancelled.")

return

EndSelect

Wend

EndFunc

;~ About this script

Func ShowInfo()

Msgbox(0x41040,"Server Audit","Server Audit v1.0 for Windows 2000, XP or 2003.

Link to comment
Share on other sites

Thanks guys =)

I'm reading the changelog for the beta right now, this scripting language is pretty nice.. I checked it out because I'd been wishing I had something like this at work.. The learning curve seems not so bad =D

-Dave

PS- I don't clearly know who wrote _INetSmtpMailCom.au3 (I didn't), but thanks very much to them! =D

Edited by ShminkyBoy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...