Sample WHM Plugin – Hello World

January 31st, 2011 by tech No comments »

#!/usr/bin/perl
#WHMADDON:helloworld:Hello World <b>Example</b>

###############################################################################
# This is an example hello world WHM plugin feel free to modify it as you see fit
###############################################################################
# Load general use case perl modules
use lib '/usr/local/cpanel';
use Cpanel::cPanelFunctions ();
use Cpanel::Form ();
use Cpanel::Config ();
use Whostmgr::HTMLInterface ();

use Whostmgr::ACLS ();
###############################################################################
print "Content-type: text/html\r\n\r\n";
# Check user has root permissions
Whostmgr::ACLS::init_acls();
if ( !Whostmgr::ACLS::hasroot() ) {
# User is not root, tell them where to go
print "You need to be root to see the hello world example.\n";

exit();
}

# Parse input parameters from GET and POST into $FORM{} for later use
my %FORM = Cpanel::Form::parseform();

# Print a WHM Header
Whostmgr::HTMLInterface::defheader( "Hello World Example Plugin",'/path/to/logo.gif', '/cgi/addon_helloworld.cgi' );

# Print General Output
print "<p>Hello world indeed...</p>";

# End Example

1;

Source

Share

Suggest Topics for cPanelAdmins Articles

January 27th, 2011 by tech No comments »

It’s been a while since our last update, and we’re curious what topics people would like to see detailed on cPanelAdmins.com. Leave a quick comment, and we’ll consider your topic.

Share

WatchMySQL Plugin for WHM

November 21st, 2010 by tech No comments »

http://www.ndchost.com/cpanel-whm/scripts/watchmysql/

Installation

cd /sbin
rm -f watchmysql
wget http://www.ndchost.com/cpanel-whm/scripts/watchmysql/download.php
chown root.root watchmysql
chmod 0750 watchmysql

Configuration

Before you run the script you must first configure it. Use edit to open the watchmysql script and set the options.

#Sets the maximum concurrent connections per MySQL user.
my $max_concurrent_connections = '15';

#Who to tell about this user... (email)
my $warning_email = 'your@email.address';

#Kill Abuser's MySQL Connections (0 = no, 1 = yes)
my $kill_user = '0';

#MySQL polling in seconds (600 = 10 minutes)
my $check_interval = '600';

Running

To start this script simply run the following command
/sbin/watchmysql &
If you want the script to start when the system boots you need to add the above line to /etc/rc.local

Share

Manually Rotate Logs with logrotate

September 8th, 2010 by tech No comments »

The individual configuration files for logrotate are located in /etc/logrotate.d:

# cd /etc/logrotate.d/

Then, to manually rotate the logs for exim, simply run the following.

# logrotate exim

Note: you won’t see any output, but you will notice that the exim logs in /var/log are now rotated out.

Share

How to Uninstall Servlets from a cPanel Account

September 7th, 2010 by tech No comments »

You can remove Tomcat support for sites via /scripts/remservlets, which uses the following syntax:

/scripts/remservlets --domain=domain-you-want-to-remove-jsp-and-servlets.com
Share

How to Install ffmpeg

September 1st, 2010 by tech 1 comment »

This post will provide you with the instructions to download and install ffmpeg, ffmpeg-php, flvtool, lame, mplayer, libogg, libvorbis, mencoder, and other codecs used with ffmpeg.

# cd /usr/local/src
wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
wget http://downloads.sourceforge.net/project/lame/lame/3.98.4/lame-3.98.4.tar.gz
wget http://www.mplayerhq.hu/MPlayer/releases/mplayer-export-snapshot.tar.bz2
wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.2.0.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.1.tar.gz
wget http://www.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
wget http://ffmpeg.org/releases/ffmpeg-0.6.tar.gz
tar xvzf flvtool2-1.0.6.tgz
tar xvzf lame-3.98.4.tar.gz
tar jxvf ffmpeg-php-0.6.0.tbz2
tar xvzf libogg-1.2.0.tar.gz
tar xvzf libvorbis-1.3.1.tar.gz
tar jxvf essential-20071007.tar.bz2
tar jxvf mplayer-export-snapshot.tar.bz2
tar xvzf ffmpeg-0.6.tar.gz 

Make a directory to store all the codecs:

# mkdir /usr/local/lib/codecs/

Install any necessary packages:

yum install gcc gmake make libcpp libgcc libstdc++ gcc4 gcc4-c++  ncurses-devel

Copy codecs for mplayer:

mv /usr/local/src/essential-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/

Installing Lame:

cd /usr/local/src/lame-3.98.4
./configure
make && make install

Installing Libogg:

cd /usr/local/src/libogg*
./configure && make && make install
Installing libvorbis:
cd /usr/local/src/libvorbis*
./configure && make && make install

Installing flvtool2:

cd /usr/local/src/flvtool*
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
# cd /usr/local/src/mplayer*
./configure && make && make install

Installing ffmpeg PHP module

cd /usr/local/src/ffmpeg-*
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared

(If you need to customize your install, run “./configure –help” to see a complete list of the available flags)

make && make install
ln -s /usr/local/lib/libavformat.so.50 /usr/lib/libavformat.so.50
ln -s /usr/local/lib/libavcodec.so.51 /usr/lib/libavcodec.so.51
ln -s /usr/local/lib/libavutil.so.49 /usr/lib/libavutil.so.49
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.51 /usr/lib/libavformat.so.51

Installing ffmpeg-php:

# cd /usr/local/src/ffmpeg-php*
phpize
./configure

There’s a small issue in this version of ffmpeg-php which, when “make” is run, will cause the following error:

 gcc -I. -I/usr/local/src/ffmpeg-php-0.6.0 -DPHP_ATOM_INC -I/usr/local/src/ffmpeg-php-0.6.0/include -I/usr/local/src/ffmpeg-php-0.6.0/main -I/usr/local/src/ffmpeg-php-0.6.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include/libavcodec/ -I/usr/local/include/libavformat/ -I/usr/local/include/libavutil/ -I/usr/local/include/libswscale/ -I/usr/local/include/libavfilter/ -I/usr/local/include/libavdevice/ -I/usr/include/php -DHAVE_CONFIG_H -g -O2 -Wall -fno-strict-aliasing -c /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c  -fPIC -DPIC -o .libs/ffmpeg_frame.o
/usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function 'zim_ffmpeg_frame_toGDImage':
/usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: 'PIX_FMT_RGBA32' undeclared (first use in this function)
/usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: (Each undeclared identifier is reported only once
/usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: for each function it appears in.)
/usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function 'zim_ffmpeg_frame_ffmpeg_frame':
/usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:421: error: 'PIX_FMT_RGBA32' undeclared (first use in this function)
make: *** [ffmpeg_frame.lo] Error 1

To correct this issue, we’ll update ffmpeg_frame.c and replace every instance of PIX_FMT_RGBA32 with PIX_FMT_RGB32

vi ffmpeg_frame.c
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32

:w :q!

Now we can proceed with compiling:

make
make install

Now that we’ve compiled, let’s make sure that ffmpeg.so is in the proper extensions directory:

php -i | grep extensions
/usr/local/lib/php/extensions/no-debug-non-zts-20060613

Now we’ll tell PHP that it needs to load our module:

 echo 'extension=ffmpeg.so' >> /usr/local/lib/php.ini

Restart apache:

service httpd restart

Now we’ll do a quick list of the modules to ensure that ffmpeg-php is loaded:

php -m | grep ffmpeg
ffmpeg

All done!

Share

How to extract a .war file

August 11th, 2010 by tech No comments »

How to extract a .war file

If your hosting provider supports Tomcat, but not .war files, you can extract your .war file in your public_html folder to run your Tomcat application from there.

# jar xvf filename.war

Share

Securing SSH

July 29th, 2010 by tech No comments »

Best Security Practice
The ideal ssh daemon would only allow login via SSH keys. This setup can easily be configured within WHM >> Manage SSH Keys, where you’ll create a SSH key for you to login with. Once you’ve created your key, and verified that you can login with it, you’ll want to go to WHM >> SSH Password Authorization Tweak, which will disable PasswordAuthentication in /etc/ssh/sshd_config.

Medium-security Configuration
If you have clients on your server that require PasswordAuthentication, you can still lock down SSH pretty well.

    Open /etc/ssh/sshd_config in your favorite editor
 # vi /etc/ssh/sshd_config
    Disable direct root login

First, be sure that you have an alternate user configured in your environment that you can use to login via SSH. This user must also have privileges to “su” to root.

Then, set the “PermitRootLogin” directive to “no”.

PermitRootLogin no
    Change the port that sshd listens on
Port 221

Be sure to use a port equal to or less than 1024, as these are privileged ports that only root or a super-user can set daemons to listen on. If you were to configure sshd to listen on port 11223, and a user was able to take down sshd, they could then start their own sshd daemon in place of yours.

    State which users may login via SSH

If you want to only allow certain users to login via SSH, implement the “AllowUsers” directive:

AllowUsers bob frank

This will only allow ‘bob’ and ‘frank’ to login via SSH.

    Save and Restart SSH

Now save the file and restart the sshd service:

service sshd restart
Share

Locate command not found

July 29th, 2010 by tech No comments »

Error:

# locate filename
-bash: locate: command not found

This indicates that the “slocate” package is not installed. Install it with:

yum -y install slocate

Then update the database with:

# updatedb
Share

cPanel Log Locations

July 29th, 2010 by tech No comments »

cPanel Log File Locations

This is a shortlist of various log files for various applications on your Cpanel VPS.

cPanel Installation Logs:
/var/log/cpanel-install-thread0.log

Apache:
/usr/local/apache/logs/access_log
/usr/local/apache/logs/error_log

Apache domlogs:
/usr/local/apache/domlogs/example.com

Apache SUEXEC Logs:
/usr/local/apache/logs/suexec_log

MySQL
/var/lib/mysql/hostname.err

BIND (named) Log:
/var/log/messages

Exim
/var/log/exim_mainlog
/var/log/exim_paniclog
/var/log/exim_rejectlog

Courier or Dovecot IMAP
/var/log/maillog

Tomcat Logs:
/usr/local/jakarta/tomcat/logs/catalina.err
/usr/local/jakarta/tomcat/logs/catalina.out

cPanel Access Log:
/usr/local/cpanel/logs/access_log

cPanel Error Log:
/usr/local/cpanel/logs/error_log

cPanel License Log:
/usr/local/cpanel/logs/license_log

Stats Execution Logs:
/usr/local/cpanel/logs/stats_log

ChkServd (cPanel Monitoring Daemon) Logs:
/var/log/chkservd.log

cPHulkd
/usr/local/cpanel/logs/cphulkd.log

cPanel Backup Logs:
/usr/local/cpanel/logs/cpbackup/*.log

Pure-FTP
/var/log/messages
/var/log/xferlog (symlinked to /usr/local/apache/domlogs/ftpxferlog)

Cron Logs:
/var/log/cron

SSH Logs:
/var/log/secure

ModSecurity:
/usr/local/apache/logs/modsec_audit.log
/usr/local/apache/logs/modsec_debug_log

Share

cPanel Web Site Hosting by IntraHost