Home
dedicated provision check
- Details
########################################################################
# Dedicated Server Provision Check
# Version .1
# Created by: Mell Rosandich
########################################################################
Param([switch]$showdebug) #shows all the vars at the end of the script - not a true debug
#Define Global vars etc.
#Result Vars
[array]$global:g_ResultString = ""
[array]$global:g_ResultFailLevel = ""
[array]$global:g_ResultFixText = ""
#Information Retrived about the System
$global:g_PSA_DB_SA = $null
$global:g_PSA_DB_Admin = $null
$global:g_ClientLogin = $null
$global:g_ClientDomain = $null
$global:g_ClientFullName = $null
$global:g_ClientPassword = $null
$global:g_NS1Name = $null
$global:g_NS2Name = $null
$global:g_NS1IP = $null
$global:g_NS2IP = $null
$global:g_ServerIP = $null
$global:g_ServerHostName = $null
$global:g_ServerHostIP = $null #Ipv6 address from
$global:g_ServerIPS = @()
#Key Look ups
$global:g_PSA_MS_User = "sa"
$global:g_PSA_My_User = "admin"
#Internal Vars
$global:g_ClientPath = $Env:plesk_bin + '\plesksrvclient.exe'
$global:g_BinPath = $Env:plesk_bin + '\dbclient.exe'
$global:g_MySQLBin = $Env:plesk_dir + '\Databases\MySQL51\bin\mysql.exe'
$global:g_MySQLAdmin = $Env:plesk_dir + '\Databases\MySQL51\bin\mysqladmin.exe'
$global:g_SmarterMailBase = "C:\SmarterMail\Domains\"
$global:g_isGoodProvision = $false
$global:cookie = $null
function BuildErrorList($TestResult,$BadText,$GoodText,$FailLevel ){
# $FailLevel
# 1-10 . 1 Ok, 10 Critcal Stop, 0=seperator for display
if( $FailLevel -eq 0 ){ $TestResult=$null;$BadText="----------------------";$GoodText="----------------------"; }
if( ($TestResult -eq $null) -or ($TestResult -eq $false) ){$global:g_ResultString += $BadText;$global:g_ResultFailLevel+= $FailLevel }else{$global:g_ResultString += $GoodText;$global:g_ResultFailLevel+= 1}
Write-Host "." -NoNewline
}
function ErrorListSeperator{
BuildErrorList "" "" "" 0
}
function BuildFixitList($TextIn){
$global:g_ResultFixText += $TextIn
}
#Lets Get the Admin User and password for MS SQL and MYSQL
function PSA_GetDBADMIN()
{
$oPSALoginDBInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select admin_login, admin_password from databaseservers;'"
foreach ($sSQlReturnItem in $oPSALoginDBInfo)
{
if( $sSQlReturnItem -ne $null){
$sTemp = $sSQlReturnItem.split()
if( $sTemp[0] -eq $global:g_PSA_MS_User){ $global:g_PSA_DB_SA = $sTemp[1].trim();}
if( $sTemp[0] -eq $global:g_PSA_My_User){ $global:g_PSA_DB_Admin = $sTemp[1].trim()}
}
}
$global:g_PSA_DB_SA = getpass-mssql
$global:g_PSA_DB_Admin = getpass-mysql
BuildErrorList $global:g_PSA_DB_SA "Plesk MS SQL ADMIN Bad" "Plesk MS SQL ADMIN OK" 10
BuildErrorList $global:g_PSA_DB_Admin "Plesk MY SQL ADMIN Bad" "Plesk MY SQL ADMIN OK" 10
}
function Get-ClipboardText()
{
$command =
{
add-type -an system.windows.forms
[System.Windows.Forms.Clipboard]::GetText()
}
powershell -sta -noprofile -command $command
}
#Check Plesk user and domain
function CheckPleskDomainAndUser()
{
#For Plesk to work you need 1 account with type admin
$sAdminID = $null
$sPrimaryDomain = $null
$sAdminName = $null
$oPSADomainName = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select cl_id,displayName from domains;'"
foreach ($oTemp in $oPSADomainName)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -ne ""){$sPrimaryDomain = $sTemp[1].trim();$sAdminID = $sTemp[0]}
}
$oPSAAdminAccount = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,login,account_id,pname from clients;'"
foreach ($oTemp in $oPSAAdminAccount)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -eq $sAdminID ){$sAdminName = $sTemp[1].trim()}
if( $sTemp[0] -eq $sAdminID ){$global:g_ClientFullName = $sTemp[3].trim()}
if( $sTemp[0] -eq $sAdminID ){$global:g_ClientPassword = $sTemp[2].trim()}
}
$oPleskLogin = Invoke-Expression "& '$global:g_ClientPath' -get -nogui"
$global:g_ClientPassword = Get-ClipboardText
$oHostInnfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select param,val from misc where param=''FullHostName'';'"
foreach ($oTemp in $oHostInnfo)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -eq "FullHostName" ){$global:g_ServerHostName = $sTemp[1].trim()}
}
$ping = new-object System.Net.NetworkInformation.Ping
$pingoptions = new-object System.Net.NetworkInformation.PingOptions
if( $global:g_ServerHostName -ne $null ){
$rslt = $ping.send($global:g_ServerHostName)
if ($rslt.status.tostring() –eq "Success") {
$global:g_ServerHostIP = $rslt.Address
}
}
$global:g_ClientLogin = $sAdminName
$global:g_ClientDomain = $sPrimaryDomain
BuildErrorList $sAdminID "Plesk Admin Bad" "Plesk Admin OK" 10
BuildErrorList $sPrimaryDomain "Plesk Primary Domain Bad" "Plesk Primary Domain OK" 10
#Resolution
if( $sAdminID -eq $null){BuildFixitList "Plesk is missing the user account for the customer. Recommend reprovision";}
if( $sPrimaryDomain -eq $null){BuildFixitList "Plesk is missing the default user domain for the customer. Recommend reprovision";}
}
function CheckMSSQLAccess{
if( $global:g_PSA_DB_SA -eq $null ){
return
}
$MLMconnection = $null
$MLMcommand = $null
$MLMresult = $null
$MLMconnection = New-Object System.Data.Odbc.OdbcConnection
$MLMcommand = New-Object System.Data.Odbc.OdbcCommand
$MLMcommand.Connection = $MLMconnection
$MLMconnection.ConnectionString = "Driver={SQL Server};Server=localhost;database=master;UID=$global:g_PSA_MS_User;PWD=$global:g_PSA_DB_SA;"
try{
$MLMconnection.Open()
}
catch{}
if($MLMconnection.State -ne [System.Data.ConnectionState]::Open)
{
BuildErrorList $null "MSSQL connection as SA Password Bad" "MSSQL connection as SA Password OK" 10
BuildFixitList "Plesk component MSSQL has a differnt password then the MS SQL server. Resolution: login to plesk and set password"
}
else
{
BuildErrorList "Good SA PASS" "MSSQL connection as SA Password Bad" "MSSQL connection as SA Password OK" 10
$MLMcommand.CommandType = [System.Data.CommandType]::Text
$MLMcommand.CommandText = "CREATE DATABASE ProvisionTestDB"
try{
$DBCreateResult = $MLMcommand.ExecuteNonQuery()
}
catch{
BuildErrorList $null "MSSQL connection as SA DB Create Bad" "MSSQL connection as SA DB Create OK" 10
BuildFixitList "Plesk component MSSQL has a differnt password then the MS SQL server. Resolution: login to plesk and set password"
}
if( $DBCreateResult -eq "-1" ){
BuildErrorList "Good DB" "MSSQL connection as SA DB Create Bad" "MSSQL connection as SA DB Create OK" 10
}
else
{
BuildErrorList $null "MSSQL connection as SA DB Create Bad" "MSSQL connection as SA DB Create OK" 10
BuildFixitList "SA User in MSSQL has bad permissions. Resolution: open sql manager and give SA DB owner in system db"
}
$MLMcommand.CommandText = "DROP DATABASE ProvisionTestDB"
try{
$DBCreateResult = $MLMcommand.ExecuteNonQuery()
}
catch{
BuildErrorList $null "MSSQL connection as SA DB DROP Bad" "MSSQL connection as SA DB DROP OK" 10
}
if( $DBCreateResult -eq "-1" ){
BuildErrorList "Good Drop" "MSSQL connection as SA DB DROP Bad" "MSSQL connection as SA DB DROP OK" 10
}
}
}
function CheckMYSQLAccess{
if( $global:g_PSA_DB_Admin -eq $null ){
return
}
$oMySQLTest = $null
#we are going to just verify that we can connect with dbclient since it writes back on error
$SQLVersion = '--direct-sql --sql="select version();"'
$oMySQLTest = Invoke-Expression "& '$global:g_BinPath' $SQLVersion --login=admin --port=3306 --password='$global:g_PSA_DB_Admin' --db=mysql"
if( $oMySQLTest -eq "Failed to connect to database: Access denied for user 'admin'@'localhost' (using password: YES)" ){
BuildErrorList $null "MySQL connection as Admin Password Bad" "MySQL connection as Admin Password OK" 10
}
else
{
BuildErrorList "Good Login" "MySQL connection as Admin Password Bad" "MySQL connection as AdminPassword OK" 10
$oMySQLTest = Invoke-Expression "& '$global:g_MySQLAdmin' create ProvisionTestDB -uadmin -p$global:g_PSA_DB_Admin -s"
$oMySQLTest = Invoke-Expression "& '$global:g_MySQLAdmin' drop ProvisionTestDB -uadmin -p$global:g_PSA_DB_Admin -f -s"
if( $oMySQLTest -eq 'Database "ProvisionTestDB" dropped' ){
BuildErrorList "Good Drop" "MySQL connection as Admin DB DROP Bad" "MySQL connection as Admin DB CREATE/DROP OK" 10
}
else
{
BuildErrorList $null "MySQL connection as Admin DB CREATE/DROP Bad" "MySQL connection as Admin DB DROP OK" 10
}
}
}
function SmaterMailDomainCheck{
$TestPath = $global:g_SmarterMailBase + $global:g_ClientDomain + "\domainConfig.xml"
$bValidBin = Test-Path $TestPath
$sTemptest = $null
if( $bValidBin ){$sTemptest="Found COnfig"}
BuildErrorList $sTemptest "SmarterMail config not found BAD" "SmarterMail config found OK" 8
#Check the ports for all services!
foreach ($SmarterMailIP in $global:g_ServerIPS) {
$SMPort25 = TestIConnections $SmarterMailIP 25 3000
BuildErrorList $SMPort25 "SmarterMail SMTP PORT $SmarterMailIP BAD" "SmarterMail SMTP PORT $SmarterMailIP OK" 10
$SMPort26 = TestIConnections $SmarterMailIP 26 3000
BuildErrorList $SMPort25 "SmarterMail SMTP-26 PORT $SmarterMailIP BAD" "SmarterMail SMTP-26 PORT $SmarterMailIP OK" 10
$SMPort110 = TestIConnections $SmarterMailIP 110 3000
BuildErrorList $SMPort110 "SmarterMail POP3 PORT $SmarterMailIP BAD" "SmarterMail POP3 PORT $SmarterMailIP OK" 10
$SMPort143 = TestIConnections $SmarterMailIP 143 3000
BuildErrorList $SMPort143 "SmarterMail IMAP PORT $SmarterMailIP BAD" "SmarterMail IMAP PORT $SmarterMailIP OK" 10
$SMPort9998 = TestIConnections $SmarterMailIP 9998 3000
BuildErrorList $SMPort9998 "SmarterMail Web PORT $SmarterMailIP BAD" "SmarterMail Web PORT $SmarterMailIP OK" 10
if($SMPort25 -eq $false){BuildFixitList "SmarterMail entire Service is off or Smartermail smtp is disable (ip: $SmarterMailIP). Login SM admin/service IP address.verify listening."}
if($SMPort110 -eq $false){BuildFixitList "SmarterMail entire Service is off or Smartermail smtp is disable (ip: $SmarterMailIP). Login SM admin/service IP address.verify listening."}
if($SMPort143 -eq $false){BuildFixitList "SmarterMail entire Service is off or Smartermail smtp is disable (ip: $SmarterMailIP). Login SM admin/service IP address.verify listening."}
if($SMPort9998 -eq $false){BuildFixitList "SmarterMail Web Service is off or IIS has no bindings for pot 9998 (ip: $SmarterMailIP). Login SM admin/service IP address.verify listening."}
}
}
function DNSCheckSettings{
$aNS = @()
$oDNSNS = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select type,val from dns_recs where type=''NS'' limit 2;'"
foreach ($oTemp in $oDNSNS)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -eq "NS"){$aNS += $sTemp[1].trim();}
}
$global:g_NS1Name,$global:g_NS2Name = $aNS
BuildErrorList $global:g_NS1Name "NS-1 BAD" "NS-1 $global:g_NS1Name OK" 10
BuildErrorList $global:g_NS2Name "NS-2 BAD" "NS-2 $global:g_NS2Name OK" 10
$ping = new-object System.Net.NetworkInformation.Ping
if( $global:g_NS1Name -ne $null ){
try{
$rslt = $ping.send($global:g_NS1Name)
if ($rslt.status.tostring() –eq "Success") {
$global:g_NS1IP = $rslt.Address
$global:g_ServerIP = $rslt.Address
BuildErrorList $global:g_NS1Name "NS-1 PING BAD" "NS-1 $global:g_NS1IP PING OK" 5
}else {
BuildErrorList $null "NS-1 PING BAD" "NS-1 PING OK" 5
}
}
catch{
BuildErrorList $global:g_NS1Name "NS-1 PING BAD" "NS-1 $global:g_NS1IP PING OK" 5
}
}
if( $global:g_NS2Name -ne $null ){
try{
$rslt = $ping.send($global:g_NS2Name)
if ($rslt.status.tostring() –eq "Success") {
$global:g_NS2IP = $rslt.Address
BuildErrorList $global:g_NS1Name "NS-2 PING BAD" "NS-2 $global:g_NS2IP PING OK" 5
}else {
BuildErrorList $null "NS-2 PING BAD" "NS-2 PING OK" 5
}
}catch{
BuildErrorList $null "NS-2 PING BAD" "NS-2 PING OK" 5
}
}
$cmdns1 = "nslookup " + $global:g_NS1Name + " localhost"
$cmdns2 = "nslookup " + $global:g_NS2Name + " localhost"
try{
$result1 = Invoke-Expression ($cmdns1)
}catch{
BuildErrorList $null "NS-lookup NS-1 BAD" "NSLOOKUP NS-1 $global:g_NS1IP OK" 10
}
try{
$result2 = Invoke-Expression ($cmdns2)
}catch{
BuildErrorList $null "NS-lookup NS-1 BAD" "NSLOOKUP NS-1 $global:g_NS1IP OK" 10
}
[string]$NewR1 = $result1.SyncRoot[4]
[string]$NewR2 = $result2.SyncRoot[4]
$aNewR1 = $NewR1.split()
$aNewR2 = $NewR2.split()
if( $aNewR1[2] -match "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b" )
{
$global:g_NS1IP = $aNewR1[2]
$global:g_ServerIP =$aNewR1[2]
BuildErrorList $global:g_NS1Name "NS-lookup NS-1 BAD" "NSLOOKUP NS-1 $global:g_NS1IP OK" 10
}
else
{
BuildErrorList $null "NS-lookup NS-1 BAD" "NSLOOKUP NS-1 $global:g_NS1IP OK" 10
}
if( $aNewR2[2] -match "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b" )
{
$global:g_NS2IP = $aNewR2[2]
BuildErrorList $global:g_NS2Name "NS-lookup NS-2 BAD" "NSLOOKUP NS-2 $global:g_NS2IP OK" 10
}
else
{
BuildErrorList $null "NS-lookup NS-2 BAD" "NSLOOKUP NS-2 $global:g_NS2IP OK" 10
}
}
function DNSRecTemplate{
#values to verify:
$ns1 = $null #Name Server
$ns2 = $null #Name Server
$a1 = $null # domain - ip
$a2 = $null # webmail
$a3 = $null #mail
$a4 = $null # mssql
$mx = $null
$cn1 = $null
$cn2 = $null
$mx2 = $null
#lets compare that the template is there and looks right.
$oDNSNS = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select type,host,val from dns_recs_t;'"
foreach ($oTemp in $oDNSNS)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -eq "NS" -and $ns1 -eq $null ){if( $sTemp[1].trim() -eq "<domain>." -and ($global:g_NS1Name -eq $sTemp[2].trim() -or $global:g_NS2Name -eq $sTemp[2].trim()) ){$ns1 = $true} ;}
if( $sTemp[0] -eq "NS" -and $ns2 -eq $null ){if( $sTemp[1].trim() -eq "<domain>." -and ($global:g_NS1Name -eq $sTemp[2].trim() -or $global:g_NS2Name -eq $sTemp[2].trim()) ){$ns2 = $true} ;}
if( $sTemp[0] -eq "A" -and $a1 -eq $null ){if( $sTemp[1].trim() -eq "<domain>." -and $sTemp[2].trim() -eq "<ip>"){ $a1 = $true } }
if( $sTemp[0] -eq "A" -and $a2 -eq $null ){if( $sTemp[1].trim() -eq "webmail.<domain>." -and $sTemp[2].trim() -eq "<ip>"){ $a2 = $true } }
if( $sTemp[0] -eq "A" -and $a3 -eq $null ){if( $sTemp[1].trim() -eq "mail.<domain>." -and $sTemp[2].trim() -eq "<ip>"){ $a3 = $true } }
if( $sTemp[0] -eq "A" -and $a4 -eq $null ){if( $sTemp[1].trim() -eq "mssql.<domain>." -and $sTemp[2].trim() -eq "<ip>"){ $a4 = $true } }
if( $sTemp[0] -eq "MX" -and $mx -eq $null ){if( $sTemp[1].trim() -eq "<domain>." -and $sTemp[2].trim() -eq "mail.<domain>."){ $mx = $true } }
if( $sTemp[0] -eq "TXT" -and $mx2 -eq $null ){
$TempText = $sTemp[2] + " " + $sTemp[3] + " " + $sTemp[4] + " " + $sTemp[5]
if( $sTemp[1].trim() -eq "<domain>." -and $TempText -eq 'v=spf1 a mx ~all'){ $mx2 = $true }
}
if( $sTemp[0] -eq "CNAME" -and $cn1 -eq $null ){if( $sTemp[1].trim() -eq "ftp.<domain>." -and $sTemp[2].trim() -eq "<domain>."){ $cn1 = $true } }
if( $sTemp[0] -eq "CNAME" -and $cn2 -eq $null ){if( $sTemp[1].trim() -eq "www.<domain>." -and $sTemp[2].trim() -eq "<domain>."){ $cn2 = $true } }
#Write-Host $sTemp[0] $sTemp[1] $sTemp[2] $sTemp[3]
}
BuildErrorList $ns1 "DNS Template NS BAD" "DNS Template NS OK" 10
BuildErrorList $ns2 "DNS Template NS BAD" "DNS Template NS OK" 10
BuildErrorList $a1 "DNS Template AName domain BAD" "DNS Template AName domain OK" 10
BuildErrorList $a2 "DNS Template AName webmail BAD" "DNS Template AName webmail OK" 10
BuildErrorList $a3 "DNS Template AName mail BAD" "DNS Template AName mail OK" 10
BuildErrorList $a4 "DNS Template AName mssql BAD" "DNS Template AName mssql OK" 10
BuildErrorList $mx "DNS Template MX BAD" "DNS Template MX OK" 10
BuildErrorList $mx2 "DNS Template TXT BAD" "DNS Template TXT OK" 10
BuildErrorList $cn1 "DNS Template CNAME FTP BAD" "DNS Template CNAME FTP OK" 10
BuildErrorList $cn2 "DNS Template CNAME WWW BAD" "DNS Template CNAME WWW OK" 10
if($ns1 -eq $null -or $ns2 -eq $null -or $a1 -eq $null -or $a2 -eq $null -or $a3 -eq $null -or $a4 -eq $null -or $mx -eq $null -or $cn1 -eq $null -or $cn2 -eq $null )
{
BuildFixitList "Login To Plesk and Correct DNS Template. You will probally need to rebuild the DNS for the Main Domain as well";
}
}
function StartMessage{
Write-Host "-----------------------------------------------------------------";Write-Host " _________ .__ __ .__ ";Write-Host " \_ ___ \| |__ ____ ____ | | _|__| ____ ____ ";Write-Host " / \ \/| | \_/ __ \_/ ___\| |/ / |/ \ / ___\ ";Write-Host " \ \___| Y \ ___/\ \___| <| | | \/ /_/ >";Write-Host " \______ /___| /\___ >\___ >__|_ \__|___| /\___ / ";Write-Host " \/ \/ \/ \/ \/ \//_____/ ";Write-Host "-----------------------------------------------------------------"
}
function OverAllMessage{
$OverAllStatus = 1
foreach( $nItems in $global:g_ResultFailLevel ){
if($nItems -eq 10){$OverAllStatus = 10}
}
if( $OverAllStatus -eq 10 ){
#failed
$global:g_isGoodProvision = $false
Write-Host "------------------------------" -foregroundcolor Red;Write-Host " __________ .__.__ " -foregroundcolor Red;Write-Host " \_ _____/____ |__| | " -foregroundcolor Red;Write-Host " | __) \__ \ | | | " -foregroundcolor Red;Write-Host " | \ / __ \| | |__" -foregroundcolor Red;Write-Host " \___ / (____ /__|____/" -foregroundcolor Red;Write-Host " \/ \/ " -foregroundcolor Red;Write-Host "------------------------------" -foregroundcolor Red
}
else
{
#pass
$global:g_isGoodProvision = $true
Write-Host "---------------------------------------" -foregroundcolor Green;Write-Host " __________ " -foregroundcolor Green;Write-Host " \______ \_____ ______ ______" -foregroundcolor Green;Write-Host " | ___/\__ \ / ___// ___/" -foregroundcolor Green;Write-Host " | | / __ \_\___ \ \___ \ " -foregroundcolor Green;Write-Host " |____| (____ /____ >____ >" -foregroundcolor Green;Write-Host " \/ \/ \/ " -foregroundcolor Green;Write-Host "---------------------------------------" -foregroundcolor Green
}
}
function WelcomeEmailCB{
$welcomeemail = "$global:g_ClientFullName, Welcome to the HostGator family!`n`nYour Primary Domain: $global:g_ServerHostName`nYour Server IP address: $global:g_ServerIP`n`nYour name servers that must be registered are:`nns1.$global:g_ClientDomain - $global:g_NS1IP`nns2.$global:g_ClientDomain - $global:g_NS2IP`n`nPlease visit http://www.hostgator.com/privatenameservers.shtml for more`ninformation on registering private nameservers if you need further help.`n`nRemote Desktop Connection:`n=================`n`nComputer : $global:g_ServerIP`nUsername : serveradmin`nPassword : $global:g_ClientPassword`n`nTo access Remote Desktop Connection Utility on your computer, navigate to`nStart > All Programs > Accessories > Remote Desktop Connection`n`n`nPlesk Admin Control Panel (complete Plesk management):`n============`nPlesk Login URL : https://" + $global:g_ServerIP + ":8443 <https://" + $global:g_ServerIP + ":8443>`nPlesk Username : admin`nPlesk Password : $global:g_ClientPassword`n`n`nPlesk Client Control Panel (only your domain,ftp,etc):`n============`nPlesk Login URL : https://" + $global:g_ServerIP + ":8443 <https://" + $global:g_ServerIP + ":8443>`nPlesk Username : $global:g_ClientLogin `nPlesk Password : $global:g_ClientPassword`n`n`nSmarterMail Administration:`n============`nSmarterMail Login URL : http://" + $global:g_ServerIP + ":9998 <http://" + $global:g_ServerIP + ":9998>`nSmarterMail Username : admin`nSmarterMail Password : $global:g_ClientPassword`n`n`nPlease note: You have 2 logins for Plesk.`nThe admin login will allow you to create clients and adjust settings server wide as well as imitate any client.`nSince you have a domain in Plesk you also have a client login. This is a limited login where you only manage items`nrelating to your domain such as FTP, email address, sub domains, etc. If you wanted to FTP files to your server;`nadmin would not work but your client user and password would work.`n`nHere are some steps we recommend for you and your new Windows Server:`n`nSetup Scheduled Backups: One of the first steps we recommend is to`nconfigure your new server with scheduled backups. If you do not already`nhave a custom backup solution or need assistance in setting up your`nscheduled backups, please let us know, and we will be more than happy to`nassist you in configuring an acceptable backup solution.`n`nView Our Video Tutorials: Learn the basics in how to manage and`nconfigure server applications such as Plesk Control Panel which may save`nyou a phone call or ticket. You can view our over 500+ video tutorials`nat http://www.hostgator.com/tutorials.shtml`n`nVisit Our Support Portal: Need to upgrade your server (e.g. additional`nHard Drive)? Need to manage your billing or contact us via Ticket, Chat,`nor Phone? Check out our HostGator Support Portal at`nhttp://support.hostgator.com/`n`nIf you would like us to move your files over from an existing account,`nplease fill out this form:`nhttps://secure.hostgator.com/resellertransferdedicated.php`n`nIf you have any problems or questions please email us at`
new-alias Out-Clipboard $env:SystemRoot\system32\clip.exe
$welcomeemail | Out-Clipboard
}
function ResolutionsCB{
new-alias Out-Clipboard $env:SystemRoot\system32\clip.exe
$FixitList = $global:g_ResultFixText -join "`n"
$FixitList | Out-Clipboard
}
function TestIConnections([string]$srv,$port=135,$timeout=3000){
$ErrorActionPreference = "SilentlyContinue"
$tcpclient = new-Object system.Net.Sockets.TcpClient
$iar = $tcpclient.BeginConnect($srv,$port,$null,$null)
$wait = $iar.AsyncWaitHandle.WaitOne($timeout,$false)
if(!$wait)
{
# Close the connection and report timeout
$tcpclient.Close()
Return $false
}
else
{
# Close the connection and report the error if there is one
$error.Clear()
$tcpclient.EndConnect($iar) | out-Null
if(!$?){$failed = $true}
$tcpclient.Close()
}
if($failed){return $false}else{return $true}
}
function GetServerGoodIPs{
$TempIpList= Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq $true } | Foreach-Object { $_.IPAddress } | Foreach-Object { [IPAddress]$_ } | Where-Object { $_.AddressFamily -eq 'Internetwork' } | Foreach-Object { $_.IPAddressToString }
foreach ($ipdr in $TempIpList) {
if( $ipdr.StartsWith("10.") -ne $true -or $ipdr.EndsWith(".0") -eq $true ){
$global:g_ServerIPS += $ipdr
}
}
}
function GetURLData( [string]$InURL,[string]$PostData){
#Since thbis is local host lets remove the security warning for any CERT
$netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])
IF($netAssembly) {
$bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic"
$settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal")
$instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @())
if($instance) {
$bindingFlags = "NonPublic","Instance"
$useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags)
if($useUnsafeHeaderParsingField) {
$useUnsafeHeaderParsingField.SetValue($instance, $true)
}
}
}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$wc = new-object system.net.WebClient;
if( $PostData -ne "nopost" ){
#Send login credentials
$wc.Headers.Add("Content-Type","application/x-www-form-urlencoded")
[byte[]]$byteArray = [System.Text.Encoding]::ASCII.GetBytes($PostData)
$wc.Headers.Add( "User-Agent", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0;)" )
$webpage = $wc.UploadData($InURL,"POST",$byteArray);
$global:cookie = $wc.ResponseHeaders["Set-Cookie"]
$global:cookie = ($global:cookie.Split(',') -match '^\S+=\S+;' -replace ';.*','') -join '; '
}
else
{
$wc.Headers.Add( "User-Agent", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0;)" )
$wc.Headers.Add("Cookie", $global:cookie)
$webpage = $wc.DownloadData($InURL);
Write-Host "Cookie: "$global:cookie
}
$webpage = [System.Text.Encoding]::ASCII.GetString($webpage)
return $webpage;
}
function ValidatePleskSite{
#http://127.0.0.1:9998/Login.aspx?email=HGSMAdmin&password=Xb2k05wWHh0Zm
$WebURL = "https://localhost:8443/login_up.php3";
$PulledDataAsc = GetURLData $WebURL "login_name=admin&passwd=$global:g_ClientPassword"
#check for redir page
Write-Host $PulledDataAsc
if($PulledDataAsc -contains "top.location='/';" -or 1 -eq 1){
$PulledDataAsc = GetURLData "https://localhost:8443/index.php" "nopost"
}
Write-Host $PulledDataAsc
#The license key is invalid
}
function CheckPleskWeb{
#Since thbis is local host lets remove the security warning for any CERT
$netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])
IF($netAssembly) {
$bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic"
$settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal")
$instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @())
if($instance) {
$bindingFlags = "NonPublic","Instance"
$useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags)
if($useUnsafeHeaderParsingField) {
$useUnsafeHeaderParsingField.SetValue($instance, $true)
}
}
}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$wc = new-object system.net.WebClient;
#initial login get session cookie
$wc.Headers.Add("Content-Type","application/x-www-form-urlencoded")
[byte[]]$byteArray = [System.Text.Encoding]::ASCII.GetBytes("login_name=admin&passwd=$global:g_ClientPassword")
$wc.Headers.Add( "User-Agent", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0;)" )
$webpage = $wc.UploadData("https://localhost:8443/login_up.php3","POST",$byteArray);
$global:cookie = $wc.ResponseHeaders["Set-Cookie"]
$global:cookie = ($global:cookie.Split(',') -match '^\S+=\S+;' -replace ';.*','') -join '; '
$wc.Headers.Add( "User-Agent", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0;)" )
$wc.Headers.Add("Cookie", $global:cookie)
$webpage = $wc.DownloadData($InURL);
}
function DebuggOutPut{
Write-Host "---------- DEBUG VAR DUMP -----------"
Write-Host "MSSQL - PASS "$global:g_PSA_DB_SA
Write-Host "MySQL PASS "$global:g_PSA_DB_Admin
Write-Host "----------"
Write-Host "Client Loin "$global:g_ClientLogin
Write-Host "Client Domain "$global:g_ClientDomain
Write-Host "Client Name "$global:g_ClientFullName
Write-Host "Client Password "$global:g_ClientPassword
Write-Host "----------"
Write-Host "NS1 NAME "$global:g_NS1Name
Write-Host "NS2 NAME "$global:g_NS2Name
Write-Host "NS1 IP "$global:g_NS1IP
Write-Host "NS2 IP "$global:g_NS2IP
Write-Host "----------"
Write-Host "Server HostName "$global:g_ServerHostName
Write-Host "Server Host IP "$global:g_ServerHostIP
Write-Host "Server Main IP "$global:g_ServerIP
}
function CheckForPleskBin(){
$bValidBin = Test-Path $global:g_BinPath
$sTemptest = $null
if( $bValidBin ){$sTemptest="Found Bin"}
BuildErrorList $bValidBin "Plesk Bin Bad" "Plesk Bin OK" 10
if($bValidBin -eq $false){BuildFixitList "Plesk BIN is missing, recommend running provsion script. If you already ran the provsion. OS reload then reprovision";}
return $bValidBin
}
function CheckForMySQLBins(){
$bValidBin = Test-Path $global:g_MySQLBin
$sTemptest = $null
if( $bValidBin ){$sTemptest="Found Bin"}
BuildErrorList $bValidBin "MySQL Bin Bad" "MySQL Bin OK" 10
if($bValidBin -eq $false){BuildFixitList "MySQL BIN is missing, recommend running provsion script. If you already ran the provsion. OS reload then reprovision";}
return $bValidBin
}
#--------------------------------------------------------------------------------------------
# RUN - TIME!
#--------------------------------------------------------------------------------------------
StartMessage #send start message
Write-Host "Checking." -nonewline
ErrorListSeperator #output seperator
$CheckPleskBinFile = CheckForPleskBin #Check to verify the the plesk bin exsits
$CheckMySQLBin = CheckForMySQLBins
if( ($CheckPleskBinFile -eq $True) -and $CheckMySQLBin -eq $True ){
GetServerGoodIPs #get the good IPs into a global array
PSA_GetDBADMIN #Get Admin and SA password: set global scope
CheckPleskDomainAndUser #Get Domain Name and User for that Domain,user info: set global scope
CheckMSSQLAccess #Login to MS SQL with credential provided by plesk: create DB, verify, drop DB
CheckMYSQLAccess #Login to MY SQL with credential provided by plesk: create DB, verify, drop DB
ErrorListSeperator #output seperator
SmaterMailDomainCheck #Check Smartermail config and other SM items
ErrorListSeperator #output seperator
DNSCheckSettings #Check DNS Name servers and Plesk DNS Information
DNSRecTemplate #Check DNS Template
ErrorListSeperator #output seperator
#ValidatePleskSite #HTTP to URL and make sure we dont get expired license must be the dashboard page
}
#Write Out Report
Write-Host "`n"
Write-Host "Report:" -nonewline
for( $idex=0;$idex -lt $global:g_ResultString.length;$idex++ ){
if( $global:g_ResultFailLevel[$idex] -eq 10 ){
Write-Host $global:g_ResultString[$idex] -foregroundcolor Yellow
}
else
{
Write-Host $global:g_ResultString[$idex]
}
}
#Show Pass Fail Message
OverAllMessage
if($global:g_isGoodProvision -eq $true){
$sRepling = read-host "Would you like to copy the welcome email to your clipboard [y/n]?"
if($sRepling -eq "y" -or $sRepling -eq "Y" ){Write-Host "Welcome email Copied to Clipboard";WelcomeEmailCB}
}
else
{
$sRepling = read-host "Would you like to copy the resolution list clipboard [y/n]?"
if($sRepling -eq "y" -or $sRepling -eq "Y" ){Write-Host "Resolutions Copied to Clipboard";ResolutionsCB}
}
#pass -showdebug to get results of collected data
if( $showdebug ){
DebuggOutPut
}
Load Mell PS
- Details
-------------------------------------------------------
Load mell path: \\SDC01\Documents\mrosandich\Documents\WindowsPowerShell\Modules\Load-Mell\load-mell.psm1
Import-Module Load-Mell -DisableNameChecking
Import-Module \\tsclient\C\Users\mrosandich\Desktop\PSM1\Load-Mell\Load-Mell -DisableNameChecking
Write-Host " _____ .__ .__ .____ .___ .___._."
Write-Host " / \ ____ | | | | | | _________ __| _/____ __| _/| |"
Write-Host " / \ / \_/ __ \| | | | | | / _ \__ \ / __ |/ __ \ / __ | | |"
Write-Host "/ Y \ ___/| |_| |__ | |__( <_> ) __ \_/ /_/ \ ___// /_/ | \|"
Write-Host "\____|__ /\___ >____/____/ |_______ \____(____ /\____ |\___ >____ | __"
Write-Host " \/ \/ \/ \/ \/ \/ \/ \/"
Write-Host "---------------------------------------------------------------------------"
Write-Host "Commands:"
Write-Host "Add-WhiteListIP -client pleskname -service mysql -ip x.x.x.x"
Write-Host "Add-WhiteListIP -domain pleskname.com -service mssql -ip x.x.x.x"
Write-Host " "
Write-Host "Check-Ports -ip x.x.x.x -ports 25"
Write-Host "Check-Ports -ip x.x.x.x -ports common"
Write-Host "Check-Ports -ip x.x.x.x -ports `"25,51,80`""
Write-Host "Check-Ports -ip x.x.x.x -ports `"email,51,80`""
Write-Host " "
Write-Host "Check-RDPLogins -days 10"
Write-Host "Check-RDPLogins -hours 12"
Write-Host "Check-RDPLogins -hours 12 -failed"
Write-Host " "
Write-Host "Check-Spamhaus -ip 8.7.5.6"
Write-Host "Check-Spamhaus -ip ifaces"
Write-Host " "
Write-Host "Delete-SpamSmarterMail -action show|delete -pattern `"*v_i_a-g-r-a*`" -directory path -check eml|hdr"
Write-Host " "
Write-Host "Check-Spamhaus -ip 8.7.5.6"
Write-Host "Check-Spamhaus -ip ifaces"
Write-Host " "
Write-Host " ---------- End of Load-Mell commands ---------- "
########################################################################
#Check-Port
# Version 1.0
# Created by: Mell Rosandich
########################################################################
function Load-Mell {
<#
.SYNOPSIS
This loads all my Powershell modules
.DESCRIPTION
This loads all my Powershell modules: Load-Mell
Module Listed:
Add-WhiteListIP
Check-Ports
Delete-SpamSmarterMail
.EXAMPLE
Load-Mell
.NOTES
This loads Mell Stuff
#>
[CmdletBinding()]
param (
)
PROCESS{
Write-Host " _____ .__ .__ .____ .___ .___._."
Write-Host " / \ ____ | | | | | | _________ __| _/____ __| _/| |"
Write-Host " / \ / \_/ __ \| | | | | | / _ \__ \ / __ |/ __ \ / __ | | |"
Write-Host "/ Y \ ___/| |_| |__ | |__( <_> ) __ \_/ /_/ \ ___// /_/ | \|"
Write-Host "\____|__ /\___ >____/____/ |_______ \____(____ /\____ |\___ >____ | __"
Write-Host " \/ \/ \/ \/ \/ \/ \/ \/"
Write-Host "---------------------------------------------------------------------------"
Write-Host "Commands:"
Write-Host "Add-WhiteListIP -client pleskname -service mysql -ip x.x.x.x"
Write-Host "Add-WhiteListIP -domain pleskname.com -service mssql -ip x.x.x.x"
Write-Host " "
Write-Host "Check-Ports -ip x.x.x.x -ports 25"
Write-Host "Check-Ports -ip x.x.x.x -ports common"
Write-Host "Check-Ports -ip x.x.x.x -ports `"25,51,80`""
Write-Host "Check-Ports -ip x.x.x.x -ports `"email,51,80`""
Write-Host " "
Write-Host "Check-RDPLogins -days 10"
Write-Host "Check-RDPLogins -hours 12"
Write-Host "Check-RDPLogins -hours 12 -failed"
Write-Host " "
Write-Host "Check-Spamhaus -ip 8.7.5.6"
Write-Host "Check-Spamhaus -ip ifaces"
Write-Host " "
Write-Host "Delete-SpamSmarterMail -action show|delete -pattern `"*v_i_a-g-r-a*`" -directory path -check eml|hdr"
Write-Host " "
Write-Host "Check-Spamhaus -ip 8.7.5.6"
Write-Host "Check-Spamhaus -ip ifaces"
Write-Host " "
Write-Host " ---------- End of Load-Mell commands ---------- "
}#end process
}#end Check-Ports
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Check-Ports
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function Check-Ports {
<#
.SYNOPSIS
Checks the port or ports of a local or remote host
.DESCRIPTION
This is used to check if a port is open on a local or remote host. You can specify 1 or many.
The port can be a list of ports or verbs. Below is a list of verbs and what ports will be used.
Verb Ports
common 21,22,23,25,53,80,110,115,143,443,1443,3306,3389,8172,8306,8443
all 21,22,23,25,26,43,53,67,80,110,115,123,135,137,143,161,443,445,465,993,995,1443,3306,3389,8172,8443
email 25,26,110,143,465,993,995
mail 25,26,110,143,465,993,995
db 3306,1443
vpn 1701,1723
.PARAMETER ip
This is optional. Not setting will use local host
.PARAMETER port
This is optional. Not setting will use the common ports for windows. you can speificy just 1 port or a list "25,90" or verb vpn
.EXAMPLE
check ports on a remote host for common ports
Check-Ports -ip 192.168.1.1 -port common
.EXAMPLE
Check ports 80 and 25
Check-Ports -ip 192.168.1.1 -port "25,80"
.EXAMPLE
Check ports 25 and vpn ports
Check-Ports -ip 192.168.1.1 -port "25,vpn"
.NOTES
Any list of ports must be in quotes "25,vpn"
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[string[]]$ip,
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[string[]]$port
)
PROCESS{
if($ip){}else{Write-Host "IP not specified -ip: using localhost";$ip="localhost"}
if( $port){}else{Write-Host "Port not specified -port: using common";$port="common"}
#Add new ip ports from largest to smallest since we do a string replace: why cos 8080 and 80 colide
$global:aPortmaps = @{8443="Plesk";8306="PSA";8172="WebMatrix";3389="RDP";3306="MySQL";1443="MSSQL";1723="PPTP";1701="L2TP";995="POP3-Secure";993="IMAP-Secure";465="SMTP-Secure";445="ActiveDir";443="SSL";161="SNMP";110="POP";115="SFTP";123="NTP";135="RPC";137="NetBios";143="IMAP";21="FTP";22="SSH";23="TelNet";25="SMTP";43="WHOIS";53="DNS";67="DHCP";80="WEB";26="SMTP-ALT";}
function ChangeNamesToNumbers([string]$port)
{
#define some groups
$port = $port.Replace("common","21,22,23,25,53,80,110,115,143,443,1443,3306,3389,8172,8306,8443")
$port = $port.Replace("all","21,22,23,25,26,43,53,67,80,110,115,123,135,137,143,161,443,445,465,993,995,1443,3306,3389,8172,8443")
$port = $port.Replace("email","25,26,110,143,465,993,995")
$port = $port.Replace("mail","25,26,110,143,465,993,995")
$port = $port.Replace("db","3306,1443")
$port = $port.Replace("vpn","1701,1723")
foreach ($portnumber in @($global:aPortmaps.keys))
{
$port = $port.Replace($global:aPortmaps[$portnumber],$portnumber)
}
return $port
}
function NiceNames([string]$InPhrase){
$temp = $InPhrase
foreach ($portnumber in @($global:aPortmaps.keys))
{
if( $portnumber -eq $InPhrase){
$InPhrase = $global:aPortmaps[$portnumber]
}
}
if( $temp -ne $InPhrase){
return $InPhrase
}else{
return "---"
}
}
function TestIConnections([string]$srv,$port=135,$timeout=3000){
try{
$ErrorActionPreference = "SilentlyContinue"
$tcpclient = new-Object system.Net.Sockets.TcpClient
$iar = $tcpclient.BeginConnect($srv,$port,$null,$null)
$wait = $iar.AsyncWaitHandle.WaitOne($timeout,$false)
if(!$wait)
{
# Close the connection and report timeout
$tcpclient.Close()
Return $false
}
else
{
# Close the connection and report the error if there is one
$error.Clear()
$tcpclient.EndConnect($iar) | out-Null
if(!$?){$failed = $true}
$tcpclient.Close()
}
if($failed){return $false}else{return $true}
}
catch{
return $false;
}
}
[String]$port = $port;
$port = ChangeNamesToNumbers($port);
$aPorts = $port.ToString().Split(",")
Write-Host " "
Write-Host "Port `t Service Name `tStatus"
Write-Host "------------------------------------"
for($idex=0;$idex -lt $aPorts.length;$idex++){
if( $aPorts[$idex] -match "[0-9]" ){
$bPortValid = TestIConnections $ip $aPorts[$idex] 4000
$ServiceNamePort = NiceNames $aPorts[$idex]
if( $ServiceNamePort.length -le 5 ){
$ServiceNamePort = $ServiceNamePort + "`t"
}
if($bPortValid){
Write-Host $aPorts[$idex] "`t" $ServiceNamePort "`tGood!" -foregroundcolor Green
}else{
Write-Host $aPorts[$idex] "`t" $ServiceNamePort "`tBAD!" -foregroundcolor Yellow
}
}
else
{
Write-Host $aPorts[$idex] "is not recognized"
}
}
}#end process
}#end Check-Ports
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Add-WhiteListIP
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function Add-WhiteListIP {
<#
.SYNOPSIS
Add a ip address to the whitelist and updates firewall
.DESCRIPTION
The Delete-SpamSmarterMail is used to search through file types .eml and .hdr and match against a regular expression. If the regular expression matches The 2 files for that message will be deleted if you are using the action delete. The only optional paramet is directory. When not set it will use what every directoryyou are in. This is recursive, so if you use it in the main spool directory it will search subdirectories as well.
Sample: Delete-SpamSmarterMail -pattern ".*me@me\.com.*" -check hdr -action delete
.PARAMETER ip
Required IP address to be added to the firewall
.PARAMETER service
Required Service name: MySQL MSSQL
.PARAMETER domain
Clients domain. Used to lookup the client ID
.PARAMETER client
Client user name. Used to look up the client ID
.EXAMPLE
Add the IP address 8.8.8.8 to the firewall for MySQL client id that owns test.com
Add-WhiteListIP -ip 8.8.8.8 -service MySQL -domain test.com
.EXAMPLE
Add the IP address 8.8.8.8 to the firewall for MSSQL client id that uses testpleskid
Add-WhiteListIP -ip 8.8.8.8 -service MSSQL -client testpleskid
.NOTES
This is recursive so make sure you use the correct directory
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$ip,
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$service,
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[string[]]$client,
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[string[]]$domain
)#End param
PROCESS{
[string]$domain = $domain;
[string]$client = $client;
[string]$ip = $ip;
[string]$service = $service;
$global:ServiceName = $service.ToLower()
if( $global:ServiceName -ne "mysql" -and $global:ServiceName -ne "mssql"){Write-Host "-service must be MySQL or MSSQL. help for more information";return}
#Information Retrived about the User
[string]$global:cmdflag_domain = $domain
[string]$global:cmdflag_client = $client
[string]$global:ClientID = $null
[string]$global:ClientName = $null
[string]$global:ClientCName = $null
[string]$global:ClientEmail = $null
[array]$global:DomainsNames = $null
[array]$global:DomainsIDs = $null
#Internal Vars
$global:g_BinPath = $Env:plesk_bin + '\dbclient.exe'
#Get Client IDs and domains
function GetClientInfo()
{
if( $global:cmdflag_domain -ne $null -and $global:cmdflag_domain -ne "" )
{
Write-Host "Searching Domain" $global:cmdflag_domain
$oDomainsInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select cl_id,name from domains where name=''$global:cmdflag_domain'';'"
foreach ($oTemp in $oDomainsInfo)
{
$sTemp = $oTemp.split()
if( $sTemp[1] -eq $global:cmdflag_domain ){ $global:ClientID = $sTemp[0].trim()}
}
if( $global:ClientID -eq $null )
{
Write-Host "Could Not Find Domain" -foregroundcolor Yellow
return $False
}
if( $global:ClientID -ne "" -and $global:ClientID -ne "" ){
#set client logon ID
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select login,id from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split()
if( $sTemp[1] -eq $global:ClientID )
{
$global:cmdflag_client = $sTemp[0].trim();
}
}
#set client name
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,pname from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split('',2)
if( $sTemp[0] -eq $global:ClientID )
{
$global:ClientName = $sTemp[1].trim();
}
}
#set company name
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,cname from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split('',2)
if( $sTemp[0] -eq $global:ClientID )
{
$global:ClientCName = $sTemp[1].trim();
}
}
#set email
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,email from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split('',2)
if( $sTemp[0] -eq $global:ClientID )
{
$global:ClientEmail = $sTemp[1].trim();
}
}
}
}
if( $global:cmdflag_client -ne $null )
{
Write-Host "Searching Client" $global:cmdflag_client
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select login,id from clients where login=''$global:cmdflag_client'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -eq $global:cmdflag_client ){$global:ClientID = $sTemp[1].trim()}
}
if( $global:ClientID -eq $null )
{
Write-Host "Could Not Find Client" -foregroundcolor Yellow
return $False
}
else
{
Write-Host "Found Client ID:" $global:ClientID
}
#Lets get all the domains
$oDomainsInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select name,id from domains where cl_id=''$global:ClientID'';'"
foreach ($oTemp in $oDomainsInfo)
{
$sTemp = $oTemp.split()
if( $sTemp[0] -ne "" -and $sTemp[0] -ne $null -and $sTemp[0] -ne "name")
{
$global:DomainsNames += $sTemp[0]
$global:DomainsIDs += $sTemp[1]
}
}
#set client name
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,pname from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split('',2)
if( $sTemp[0] -eq $global:ClientID )
{
$global:ClientName = $sTemp[1].trim();
}
}
#set company name
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,cname from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split('',2)
if( $sTemp[0] -eq $global:ClientID )
{
$global:ClientCName = $sTemp[1].trim();
}
}
#set email
$oClientInfo = Invoke-Expression "& '$global:g_BinPath' --direct-sql --sql='select id,email from clients where id=''$global:ClientID'';'"
foreach ($oTemp in $oClientInfo)
{
$sTemp = $oTemp.split('',2)
if( $sTemp[0] -eq $global:ClientID )
{
$global:ClientEmail = $sTemp[1].trim();
}
}
}
#Before we regex away lets make sure we got valid data
if( $global:ClientID -ne $null -and $global:ClientID -ne "" -and $global:ClientID -ne 0 )
{
return $TRUE
}
else
{
return $False
}
}
function CheckForPleskBin(){
$bValidBin = Test-Path $global:g_BinPath
$sTemptest = $null
if( !$plain ){
if( $bValidBin ){write-host "Found Plesk Bin"}
if($bValidBin -eq $false){write-host "Missing Plesk Bin: Can't continiue"}
}
return $bValidBin
}
#--------------------------------------------------------------------------------------------
# RUN - TIME!
#--------------------------------------------------------------------------------------------
$FoundPleskBin = CheckForPleskBin
if( $FoundPleskBin ){
$FoundClientInfo = GetClientInfo #get the information about the client based on -domain or -client
if($FoundClientInfo)
{
if( $global:ClientCName -eq $null -or $global:ClientCName -eq "" ){ $global:ClientCName = "none";}
Write-Host "Search Domain used:" $global:cmdflag_domain
Write-Host "Search Client used:" $global:cmdflag_client
Write-Host "Found Client ID:" $global:ClientID
Write-Host "Found Client Name:" $global:ClientName
Write-Host "Found Company Name:" $global:ClientCName
Write-Host "Found EMail as :" $global:ClientEmail
Write-Host "-----------------------------------------------";
#[array]$global:DomainsNames = $null
#[array]$global:DomainsIDs = $null
Write-Host "performing add-hgclient"
$DidAdd = add-hgclient -id $global:ClientID -name $global:ClientName -email $global:ClientEmail -company $global:ClientCName
if( $DidAdd -eq "TRUE" ){write-host "Added client to Database";}else{Write-Host "client was alread in Database";}
$AddFirewall = Add-Whitelist -id $global:ClientID -servicename $global:ServiceName -ip $ip
Write-Host "Added firewall:" $AddFirewall
$PushFirewall = Push-Firewall
Write-Host "Pushing new firewall rules:" $PushFirewall
}
}
}#end process
}#end Add-WhiteListIP
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Delete-SpamSmarterMail
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function Delete-SpamSmarterMail {
<#
.SYNOPSIS
Deletes emails from the smartermail spools that contain spam based on -pattern. This will delete both files of an email (.eml, .hdr)
.DESCRIPTION
The Delete-SpamSmarterMail is used to search through file types .eml and .hdr and match against a regular expression. If the regular expression matches The 2 files for that message will be deleted if you are using the action delete. The only optional paramet is directory. When not set it will use what every directoryyou are in. This is recursive, so if you use it in the main spool directory it will search subdirectories as well.
Sample: Delete-SpamSmarterMail -pattern ".*me@me\.com.*" -check hdr -action delete
.PARAMETER directory
This is optional. Not setting this will check the current working directory. Otherwise specify path to spools or spool sub folder
.PARAMETER check
This is either eml or hdr. This is what file part of the email will be checked against the pattern
an example of this: -check eml
.PARAMETER pattern
This is the regex that will be used to check a file for a match. This will be matched in the file type passed in check.
an example of this: -pattern ".*vigra.*"
.PARAMETER action
What to do with the emails that are found: show or delete. Show is none destructive and will list each file found as spam and stop after 20
This is basiaclly used to test you pattern
.EXAMPLE
Check email header for the address
Delete-SpamSmarterMail -pattern ".*me@me\.com.*" -check hdr -action delete
.EXAMPLE
Check email message for the word viagra and delete them.
Delete-SpamSmarterMail -pattern ".*vigra.*" -check eml -action delete -directory "c:\smartermail\spool"
.NOTES
This is recursive so make sure you use the correct directory
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[AllowEmptyString()]
[string[]]$directory,
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$pattern,
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$check,
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$action
)#End param
PROCESS{
#Give user feed back for switches and help
if( $pattern.ToString().length -lt 4){ Write-Host "-pattern is required and should be a regex. help for more information";return}
if( $check -ne "eml" -and $check -ne "hdr"){Write-Host "-check must be hdr or eml. help for more information";return}
if( $action -ne "show" -and $action -ne "delete"){Write-Host "-acion must be show or delete. help for more information";return}
#This function does 2 things
#returns 0|1 if found spam in file
#Deletes or shows files found
function Check-ForSpam($file){
if($file){
$RetVal = 0
$ShowCount = 0
$data = Get-Content $file
foreach( $line in $data )
{
if ($line -match $pattern)
{
$RetVal = 1
}
}
if( $RetVal -eq 1 ){
if( $check -eq "hdr" ){
$tempFile = $file -replace ".hdr$" , ".eml"
}
if( $check -eq "eml" ){
$tempFile = $file -replace ".eml$" , ".hdr"
}
if( $action -eq "delete" ){
#file may be missing .eml or .hdr or inuse ot missing at this time
#Try to delete them and move on.
try{
Remove-Item $file
}catch{}
try{
Remove-Item $tempFile
}catch{}
}
if( $action -eq "show" ){
Write-Host "Would Delete:" $file
Write-Host "Would Delete:" $tempFile
$ShowCount++
if( $ShowCount -gt 20 ){
exit
}
}
}
}
return $RetVal
}
if($directory){
$bValidBin = Test-Path $directory
if( $bValidBin ){
$directory = (Get-Item $directory);
write-host "Using -direcoty Path" $directory
}else{
Write-Host "Directory specified doesn't exsist";
Write-Host "You Entered: -diectory" $directory
Write-Host "Please Try again. You can cd into the spool directory then not specify -diretory"
return;
}
}
else
{
$wdirectory = (Get-Location);
$directory = (Get-Item $wdirectory);
write-host "Using CWD Path" $directory
}
$counter = 0
$NotSPam = 0
$IsSPam = 0
if( $check -eq "hdr" ){
[regex] $filter = ".*\.hdr"
}
if( $check -eq "eml" ){
[regex] $filter = ".*\.eml"
}
#This can take some time to load this object
$files = (Get-ChildItem -recurse $directory | where { !$_.PSIsContainer -and $_.FullName -match $filter })
#This stops the division by zero error for some cases
[int]$FileCount = $files.Count
if( $FileCount -lt 1 ){ $FileCount = 1 }
foreach ( $file in $files ) {
#Since $files might be giant
#We offer another soultion to exit the script
#it is still [control] c but we are not requiring the break on update for console
#this will exit more often then not when used vs not having it at all
if ([console]::KeyAvailable)
{
$key = [system.console]::readkey($true)
if (($key.modifiers -band [consolemodifiers]"control") -and (($key.key -eq "C") -or ($key.key -eq "c") ))
{
write-host "Terminating..."
return
}
}
#Just count what is spam and what isn't
#this will get the full path to the file we went to regex
$file = $file.FullName;
if( Check-ForSpam( $file) -eq 1 ){
$counter++
$isSpam++;
write-Progress -activity "$activity $file" -status "checking emails" -percentComplete ($counter / $FileCount)
}
else
{
$counter++
$NotSPam++
write-Progress -activity "Ignoring $file" -status "No Spam: " -percentComplete ($counter / $FileCount)
}
}
write-host "Total Not Spam: $NotSPam"
write-host "Total Is Spam: $isSpam"
write-host "--------------------------"
write-host "Total Items: $counter"
}#End process
}#End Function
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Check-RDPLogins
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function Check-RDPLogins {
<#
.SYNOPSIS
List all RDP logins
.DESCRIPTION
This will generate a list of good logins that have recently RDPd into the server. no swtiches is 1 day back
.PARAMETER days
optional: How many days to go back from now default is 1 day
.PARAMETER hours
optional: How many hours to go back from now. no default.
.PARAMETER failed
optional: show only failed logins. Default is to show good logins
.EXAMPLE
Check-RDPLogins -days 30
.NOTES
Pretty output don't pipe
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[int]$days,
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[switch]$failed,
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[int]$hours
)#End param
PROCESS{
[int]$intDays = 1;
if($days)
{
$intDays= [int]$days
Write-Host "Going back $intDays";
[Double]$NewDay = -1*$intDays;
$DT = [DateTime]::Now.AddDays($NewDay)
}
else
{
if($hours){
Write-Host "Going back $hours hours"
[Double]$NewHours = -1*$hours;
$DT = [DateTime]::Now.AddHours($NewHours)
}
else
{
Write-Host "Days not specified going back 1 day";
$intDays=1
[Double]$NewDay = -1*$intDays;
$DT = [DateTime]::Now.AddDays($NewDay)
}
}
$IPColmn = 18;
if($failed){
$IPColmn = 19;
Write-Host "Checking Failed Logins"
$evt = Get-WinEvent -FilterXpath "*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and (EventID=4625)] and EventData[Data[@Name='LogonType']='10']]" | Where-Object {$_.TimeCreated -ge $DT }
}
else
{
Write-Host "Checking Good Logins"
$evt = Get-WinEvent -FilterXpath "*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and (EventID=4624)] and EventData[Data[@Name='LogonType']='10']]" | Where-Object {$_.TimeCreated -ge $DT }
}
$groups = $evt | group {$_.properties[5].value}
Write-Host "Last login for users:"
$groups | Foreach {$_.group[0]} | select @{n="UserName";e={$_.properties[5].value}},@{n="LogOn";e={$_.TimeCreated}},@{n="IP Address";e={$_.properties[$IPColmn].value}}
#,@{n="IP Address3";e={$_.properties[3].value}},@{n="IP Address4";e={$_.properties[4].value}},@{n="IP Address5";e={$_.properties[5].value}},@{n="IP Address6";e={$_.properties[6].value}},@{n="IP Address7";e={$_.properties[7].value}},@{n="IP Address8";e={$_.properties[8].value}},@{n="IP Address9";e={$_.properties[9].value}},@{n="IP Address10";e={$_.properties[10].value}},@{n="IP Address11";e={$_.properties[11].value}},@{n="IP Address12";e={$_.properties[12].value}},@{n="IP Address13";e={$_.properties[13].value}},@{n="IP Address";e={$_.properties[13].value}},@{n="IP Address14";e={$_.properties[14].value}},@{n="IP Address15";e={$_.properties[15].value}},@{n="IP Address16";e={$_.properties[16].value}},@{n="IP Address17";e={$_.properties[17].value}},@{n="IP Address19";e={$_.properties[19].value}},@{n="IP Address20";e={$_.properties[20].value}},@{n="IP Address21";e={$_.properties[21].value}}
Write-Host " "
Write-Host "List of logins and times:"
"" | Foreach {$evt} | select @{n="UserName";e={$_.properties[5].value}},@{n="LogOn";e={$_.TimeCreated}},@{n="IP Address";e={$_.properties[$IPColmn].value}}
}#End Process
}#End Fucntion Check-RDPLogins
########################################################################
# Check-Spamhaus
# Version 1.0
# Created by: Mell Rosandich
########################################################################
function Check-Spamhaus {
<#
.SYNOPSIS
Checks an IP address against DNSBLS
.DESCRIPTION
This command will check an IP or all IPv4 Address against a list of DNSBLs
.PARAMETER ip
The ip address you want to check or use ifaces for all IPv4 ip addresses on server
.EXAMPLE
check an ip address
Check-Spamhaus -ip 8.8.8.8
.EXAMPLE
check all ipv4 address on host
Check-Spamhaus -ip ifaces
.NOTES
Only works for IPv4
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true)]
[string[]]$ip
)
PROCESS{
[String]$ip = $ip;
if( $ip.length -lt 3 ){Write-Host "IP not specified -ip: using localhost";$ip="localhost"}
function CheckDNSBL($ip) {
Write-Host "Checking IP:" $ip
$reverseIP = ($ip.split("."))[3..0]
[string[]]$newIP = [string]::join(".",$reverseIP)
[string[]]$dnsbl = @(
"b.barracudacentral.org";
"bl.deadbeef.com";
"bl.emailbasura.org";
"bl.spamcannibal.org";
"bl.spamcop.net";
"blackholes.five-ten-sg.com";
"blacklist.woody.ch";
"bogons.cymru.com";
"cbl.abuseat.org";
"cdl.anti-spam.org.cn";
"combined.abuse.ch";
"combined.rbl.msrbl.net";
"db.wpbl.info";
"dnsbl-1.uceprotect.net";
"dnsbl-2.uceprotect.net";
"dnsbl-3.uceprotect.net";
"dnsbl.ahbl.org";
"dnsbl.cyberlogic.net";
"dnsbl.inps.de";
"dnsbl.njabl.org";
"dnsbl.sorbs.net";
"drone.abuse.ch";
"drone.abuse.ch";
"duinv.aupads.org";
"dul.dnsbl.sorbs.net";
"dul.ru";
"dyna.spamrats.com";
"dynip.rothen.com";
"http.dnsbl.sorbs.net";
"images.rbl.msrbl.net";
"ips.backscatterer.org";
"ix.dnsbl.manitu.net";
"korea.services.net";
"misc.dnsbl.sorbs.net";
"noptr.spamrats.com";
"ohps.dnsbl.net.au";
"omrs.dnsbl.net.au";
"orvedb.aupads.org";
"osps.dnsbl.net.au";
"osrs.dnsbl.net.au";
"owfs.dnsbl.net.au";
"owps.dnsbl.net.au";
"pbl.spamhaus.org";
"phishing.rbl.msrbl.net";
"probes.dnsbl.net.au";
"proxy.bl.gweep.ca";
"proxy.block.transip.nl";
"psbl.surriel.com";
"rbl.interserver.net";
"rdts.dnsbl.net.au";
"relays.bl.gweep.ca";
"relays.bl.kundenserver.de";
"relays.nether.net";
"residential.block.transip.nl";
"ricn.dnsbl.net.au";
"rmst.dnsbl.net.au";
"sbl.spamhaus.org";
"short.rbl.jp";
"smtp.dnsbl.sorbs.net";
"socks.dnsbl.sorbs.net";
"spam.abuse.ch";
"spam.dnsbl.sorbs.net";
"spam.rbl.msrbl.net";
"spam.spamrats.com";
"spamlist.or.kr";
"spamrbl.imp.ch";
"t3direct.dnsbl.net.au";
"tor.ahbl.org";
"tor.dnsbl.sectoor.de";
"torserver.tor.dnsbl.sectoor.de";
"ubl.lashback.com";
"ubl.unsubscore.com";
"virbl.bit.nl";
"virus.rbl.jp";
"virus.rbl.msrbl.net";
"web.dnsbl.sorbs.net";
"wormrbl.imp.ch";
"xbl.spamhaus.org";
"zen.spamhaus.org";
"zombie.dnsbl.sorbs.net"
)
[string[]]$newDNSBL =@()
foreach ($hash in $dnsbl)
{
$newDNSBL += [string]$newIP+'.'+$hash
}
[String]$temp = @()
for ($i=1;$i -lt $newDNSBL.Count; $i++) {
try{
$temp = [System.Net.Dns]::GetHostAddresses($newDNSBL[$i]) | select-object IPAddressToString -expandproperty IPAddressToString
}
catch{
$temp = ''
}
switch($temp){
'127.0.0.10'{
Write-Host "IP $ip is listed in DNSBL " , ($newDNSBL[$i]).Replace("$newIP","") -foregroundcolor "Red"
}
''{
"IP $ip is NOT listed in DNSBL " + ($newDNSBL[$i]).Replace("$newIP","")
}
} # End Switch
} # End of For Loop
} # End of Function CheckDNSBL
if( $ip -ne 'ifaces' )
{
CheckDNSBL $ip
}
else
{
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration | where{$_.IPAddress -like '*.*.*.*'}
foreach($objItem in $colItems) {
$IPColl = $objItem.IPAddress
foreach($IpV4Addy in $IPColl){
if( $IpV4Addy.StartsWith("10.") ){
#ignore
}
else
{
if( $IpV4Addy -like '*.*.*.*'){
#Write-Host "IP Address:" $objItem.IPAddress[0]
CheckDNSBL $IpV4Addy
#CheckDNSBL $objItem.IPAddress[1]
}
}
}
}
}#end if
}#end process
}#end Check-Spamhaus
Tools from OurAce.com - Check Multi Sites
- Details
Check Multi Sites
This tool will take a list of URLs (from the same or different sites) and fetch the HTML for it. This will store the report so you can do things with it.
After you make the first request, you will get a report ID and a URL to revisit the report. Once you revisit the report you can run a compare between the versions of the sites you listed.
You will at the time get an option to "Save Compare", once you have done save compare you can actually view the thumb nails of the sites
Location:
http://sitepreview.ourace.com/validsites.php
Screenshots
Initial Scan:
Initial scan using URL with Report ID
Compare of both using save Compare option
Looking at saved report via report URL. Clicking on 1 to see the diff
Tools from OurAce.com - plot server
- Details
Plot Server
A nice tool for pinging a server and checking RDP and port 80. If you are rebooting a server and want to track it go up and down and be alerted when the server state changes. This is the tool for you. It will provide an audio queue when services and the server goes up and down
Location:
http://sitepreview.ourace.com/plotserver.php
Screenshot
Page 16 of 40