Friday, September 27, 2013

How to install Logwatch on cPanel servers running CentOS 6

Logwatch isn't included by default in CentOS 6 & cPanel installs. You can install it manually by following these instructions:
  1. Go get the latest version of logwatch by going to: http://sourceforge.net/projects/logwatch/
    Make sure you download the NOARCH rpm file.
  2. Log into your cPanel server, and run the command as root or with appropriate sudo permissions:
    $ rpm -Uvh logwatch-7.3.6-1.noarch.rpm
  3. Now you need to edit the logwatch.conf file to add some lines to get it working:
    $ nano -w /usr/share/logwatch/default.conf/logwatch.conf
  4. Add the following lines after tmpdir = /var/cache/logwatch:
    #Output/Format Options
    #By default Logwatch will print to stdout in text with no encoding.
    #To make email Default set Output = mail to save to file set Output = file
    Output = mail
    #To make Html the default formatting Format = html
    Format = text
    #To make Base64 [aka uuencode] Encode = base64
    Encode = 0
  5. Save the file.
That is it. You can test your changes immediately by running the following command or wait until the daily cronjob is run.
$ perl /etc/cron.daily/0logwatch > /root/output.txt
$ less /root/output

Monday, August 12, 2013

Fix MySQL Databases that won't delete on cPanel

If you get a customer who tries to add a MySQL database or restore a database with a . (period) mark in the name, the database will fail to be created, but under the customer's cPanel MySQL Databases, it will show up as a database. Clicking delete doesn't remove the database.

To delete this database, log into the server via SSH and run the following as root:
$ cd /var/cpanel/databases
$ nano -w customerusername.yaml

Then delete the line with the name of the broken database. Save and exit.

Optionally, you can run the following command to make sure it is working.

/usr/local/cpanel/bin/setupdbmap

Thursday, May 23, 2013

Count how many times your Wordpress login page has been requested

With all of the hacking and botnet activity probing Wordpress sites the past few months, you might wonder how many times your Wordpress login page (wp-login.php) has been requested. Here's a command that you can run from the terminal prompt to see:

/home/user $ grep -c wp-login access.log
On my personal Wordpress site, I found the following results:
  • May 5th to 12th - 598 http requests 
  • May 12th to 19th - 7,555 http requests
  •  May 19th to 22nd - 55 http requests
Very interesting indeed.

Thursday, May 16, 2013

VBS Script to pull Computer/Server Model information

SystemName = "localhost"

set tmpObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & SystemName & "\root\cimv2").InstancesOf ("Win32_ComputerSystem")
for each tmpItem in tmpObj
  MakeModel = trim(tmpItem.Manufacturer) & " " & trim(tmpItem.Model)
next
Set tmpObj = Nothing: Set tmpItem = Nothing

msgbox MakeModel

Wednesday, April 10, 2013

Send e-mail alert when Windows Server reboots

Here is how you can send an e-mail alert when a Windows Server reboots. This has been tested on Server 2008, Small Business Server 2008, and Small Business Server 2012. It should work for Server 2012, but I have not had a chance to test this.

  1. Download sendemail.exe file and save it to a folder on server. I like to save it to a folder called C:\Scripts
  2. Open Notepad/Wordpad/Text Editor and add the following:
    c:\Scripts\sendemail.exe -f localadmin@domain.com -t alerts@yourdomain.com;alerts2@yourdomain.com -u "SERVERNAME rebooted" -m "SERVERNAME has rebooted!" -s smtp.ispsmarthost.com
  3. Save the file as rebootalert.cmd in the C:\Scripts folder.
  4. Open Task Scheduler.
  5. Add a new Task and call it Reboot Alert. Set the User to be SYSTEM. Set Trigger to be At System Startup. Set Actions to be Start a Program and add the path C:\Scripts\rebootalert.cmd.
Test the script by rebooting the server. You should receive an e-mail alert that the server rebooted.

Other helpful links:
http://glazenbakje.wordpress.com/2012/12/30/exchange-2013-how-to-configure-an-internal-relay-connector/

http://www.bluecompute.co.uk/blogposts/configure-email-notification-for-windows-server-backup/

Steps to upgrade Wordpress to latest version

Here are the steps to upgrade Wordpress to the latest version using SSH terminal.
  1. Download the latest version of Wordpress:
    http://wordpress.org/download/
  2. Backup Wordpress install:
    [/home/user/public_html] $ tar -cz wordpress > wordpress.tar.gz
  3. Backup MySQL database:
    [/home/user/] $ mysqldump --add-drop-table -h localhost -u username -p databasename > mysql-backup-datehere.sql
  4. Compress the sql backup file and store elsewhere:
    [/home/user/] $ tar -cz mysql-backup-datehere.sql > mysql-backup-datehere.sql.tar.gz
  5. Extract new Wordpress files overwriting existing files:
    [/home/user/] $ tar -zxvf wordpress-version.tar.gz
  6. Visit the Wordpress upgrade page and perform database upgrade:
    http://www.domain.com/wp-admin/upgrade.php
Fin.

Wednesday, February 27, 2013

Query domain computers for Dell & other Service Tags

Create a VBS script and enter the following:
On Error Resume Next
Const ForWriting = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
strDomain = InputBox("Please Enter the local DNS Domain  ie:  blat.local  ","Hostname"," ")
strPCsFile = "Service_Tag.txt"
strPath = "C:\scripts\" ' Create this folder
strWorkstationID = "C:\scripts\Service_Tag.txt"
i = 0
'#########
Set objFSO3 = CreateObject("Scripting.FileSystemObject")
If objFSO3.FileExists(strPath & strPCsFile) Then
 Set objFolder = objFSO3.GetFile(strPath & strPCsFile)
Else
  Set objFSOf = CreateObject("Scripting.FileSystemObject")
  If objFSOf.FolderExists(strPath) Then
   Set objFolder = objFSOf.GetFolder(strPath)
  Else
   Set objFolder = objFSO3.CreateFolder(strPath)
  End If
 Set objFile1 = objFSO3.CreateTextFile(strPath & strPCsFile)
 objFile1.Close
End If
'#########
Wscript.Echo "This program will return the Dell Service Tag on remote computer(s)"
strMbox = MsgBox("Would you like info for the entire domain: " & strDOmain & " ?",4,"Hostname")
If strMbox = 6 Then
'Set objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)
Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not work
objDomain.Filter = Array("Computer")
For Each pcObject In objDomain
objDictionary.Add i, pcObject.Name
'Wscript.Echo objDictionary(i)
i = i + 1
Next
For each DomainPC in objDictionary
strComputer = objDictionary.Item(DomainPC)
GetWorkstationID()
Next
Set objFilesystem = Nothing
WScript.echo "Finished Scanning Network check : " & strPath & " If the file is empty you entered an incorrect DNS domain"
Else
strHost = InputBox("Enter the computer you wish to find the Dell Service Tag from","Hostname"," ")
GetWorkstationID2()
End If
Sub GetWorkstationID()
On Error Resume Next
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
 
      strWriteFile = strComputer &"   Dell Service Tag: " & objitem.serialnumber
Next
'#############
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strPath & strPCsFile, ForWriting, True)
objOutputFile.WriteLine(strWriteFile)
objOutputFile.Close
'#############
End Sub
Sub GetWorkstationID2()
On Error Resume Next
Wscript.echo strComputer & ": " & objitem.serialnumber
Set objWMIservice = GetObject("winmgmts:\\" & strHost & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
      Wscript.echo "Computer: " & strHost & "   Dell Service Tag: " & objitem.serialnumber
   strWriteFile = "Computer: " & strHost &"   Dell Service Tag: " & objitem.serialnumber
   Next
'%%%%%%%%%%
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strPath & strPCsFile, ForWriting, True)
objOutputFile.WriteLine(strWriteFile)
objOutputFile.Close
'%%%%%%%%%%
End Sub

Tuesday, January 15, 2013

Rename a Windows domain connected workstation remotely

From the server/domain controller, run NetDom which will rename the workstation to what you want.
You need to reboot the workstation after running this command.
netdom renamecomputer old_name  /newname:new_name  /userd:domain_admin_login /passwordd:domain_admin_pwd
Sources: http://support.microsoft.com/kb/298593/en-US and http://technet.microsoft.com/en-us/library/cc788029.aspx

Another way to rename a computer is to use Powershell from a server or domain controller.
Rename-computer -computername “targetcomputer” -newname “newcomputername” -domaincredential domain\domain_admin -force -restart
 Source: http://technet.microsoft.com/en-us/library/hh849792.aspx

Links to .Net Frameworks Installers

.Net Framework Installers