WooCommerce Email Verification WordPress Code

Ok, i though this will be available since Woocommerce is pretty popular but HOW COME NO ONE ACTUALLY MAKE THIS CODE AND OPEN SOURCE IT?! Holy cow! I search it everywhere and couldn't find WooCommerce verifying user email before allowing the user to access WordPress without verifying whether their email is authentic. In the end i wrote it myself and i'm gonna throw it out for people to use.

Basically the code has to be placed within function.php in your theme, you can also make this into a WordPress plugin and fine tune it if you like. However, please share the code out cause mine isn't the most perfect out there. I am just gonna throw it out and see what other improvement can others suggest or create. Cheers!

// this is just to prevent the user log in automatically after register
function wc_registration_redirect( $redirect_to ) {
        wp_logout();
        wp_redirect( '/sign-in/?q=');
        exit;
}
// when user login, we will check whether this guy email is verify
function wp_authenticate_user( $userdata ) {
        $isActivated = get_user_meta($userdata->ID, 'is_activated', true);
        if ( !$isActivated ) {
                $userdata = new WP_Error(
                                'inkfool_confirmation_error',
                                __( '<strong>ERROR:</strong> Your account has to be activated before you can login. You can resend by clicking <a href="/sign-in/?u='.$userdata->ID.'">here</a>', 'inkfool' )
                                );
        }
        return $userdata;
}
// when a user register we need to send them an email to verify their account
function my_user_register($user_id) {
        // get user data
        $user_info = get_userdata($user_id);
        // create md5 code to verify later
        $code = md5(time());
        // make it into a code to send it to user via email
        $string = array('id'=>$user_id, 'code'=>$code);
        // create the activation code and activation status
        update_user_meta($user_id, 'is_activated', 0);
        update_user_meta($user_id, 'activationcode', $code);
        // create the url
        $url = get_site_url(). '/sign-in/?p=' .base64_encode( serialize($string));
        // basically we will edit here to make this nicer
        $html = 'Please click the following links <br/><br/> <a href="'.$url.'">'.$url.'</a>';
        // send an email out to user
        wc_mail($user_info->user_email, __('Please activate your account'), $html);
}
// we need this to handle all the getty hacks i made
function my_init(){
        // check whether we get the activation message
        if(isset($_GET['p'])){
                $data = unserialize(base64_decode($_GET['p']));
                $code = get_user_meta($data['id'], 'activationcode', true);
                // check whether the code given is the same as ours
                if($code == $data['code']){
                        // update the db on the activation process
                        update_user_meta($data['id'], 'is_activated', 1);
                        wc_add_notice( __( '<strong>Success:</strong> Your account has been activated! ', 'inkfool' )  );
                }else{
                        wc_add_notice( __( '<strong>Error:</strong> Activation fails, please contact our administrator. ', 'inkfool' )  );
                }
        }
        if(isset($_GET['q'])){
                wc_add_notice( __( '<strong>Error:</strong> Your account has to be activated before you can login. Please check your email.', 'inkfool' ) );
        }
        if(isset($_GET['u'])){
                my_user_register($_GET['u']);
                wc_add_notice( __( '<strong>Succes:</strong> Your activation email has been resend. Please check your email.', 'inkfool' ) );
        }
}
// hooks handler
add_action( 'init', 'my_init' );
add_filter('woocommerce_registration_redirect', 'wc_registration_redirect');
add_filter('wp_authenticate_user', 'wp_authenticate_user',10,2);
add_action('user_register', 'my_user_register',10,2);

Ok, i have tested this code with the latest Woocommerce and WordPress 4.2.2. Now, just modify this to suit your needs. It's not perfect yet but i'll leave the perfect version for you guys. Enjoy!

How to List Images on Proxmox Ceph with RBD

Ok, Ceph, its a pretty new file storage for me which assist in Proxmox clustering. As much as i like it, there are a lot of things that isn't readily available on the internet. Especially for novice user like myself. Thing such as listing all the images out of a particular Proxmox machine that are using Ceph. If you look at the Ceph documentation, it will link you to rbd which said,

rbd is a utility for manipulating rados block device (RBD) images, used by the Linux rbd driver and the rbd storage driver for Qemu/KVM. RBD images are simple block devices that are striped over objects and stored in a RADOS object store. The size of the objects the image is striped over must be a power of two.

If you are looking on how to resize or list an image, the block device commands documentation on RBD might helps.

Now, to list out all your proxmox ceph images (so you can resize etc.), you will need to do login to the machine and do the following,

rbd list  --pool twopiz

where twopiz is the pool i created on proxmox database as shown below,
Screen Shot 2015-07-06 at 4.36.39 PM
if you have another pool, you'll just need to let it know how what pool to list them out. Once you do that, destorying, creating and etc. will be simple.

Dell Powerconnect 6224 reset but no internet connection

Things to take note on the dell powerconnect 6224 configuration. Upon reloading with your serial connection, it will prompt you to reset your web interface, once you configure the network, you will be able to access your web management interface. However, your whole switch won't have access to the internet even if you have reset your Dell Powerconnect 6224 switch!

If you try to ping anywhere around the world within the console, you will get a "DNS LOOKUP FAILING" and all your servers won't get any internet connection! You'll need to go to the web interface or in the console, but for my case, i did it on web interface, add the following dns into your router

Screen Shot 2015-05-04 at 2.23.26 AM

and remember to enable http server so that you could access your web management

enable
config 
ip http server

Once you done all these, save your configuration!

copy running-config startup-config

and you are as good as new!

Easy Install nagios vshell on Centos

If you have setup your nagios on your server and you want to install vshell so that it looks better, just follow the guide here!

Download vShell

First thing you need to do is to download vshell

wget http://assets.nagios.com/downloads/exchange/nagiosvshell/vshell.tar.gz

you can do it anywhere as long as gets download

Install vShell

Now you need to install vshell

tar -zxvf vshell.tar.gz
cd vshell

Before you start installing, check your configuration

vi install.php

make sure that the path is correct

// ***********MODIFY THE DIRECTORY LOCATIONS BELOW TO MATCH YOUR NAGIOS INSTALL*********************

//target directory where vshell's web files will be stored  
define('TARGETDIR',"/usr/local/vshell");
//target directory where your current apache configuration directory is located
define('APACHECONF',"/etc/httpd/conf.d");
//default for ubuntu/debian installs 
//define('APACHECONF',"/etc/apache2/conf.d"); 

since i'm on centos and installed with apache, mine is by default correct! So all i did was installing this way

./install.php

And done! you can access your vshell similar to nagios by typing http://localhost/vshell

Screen Shot 2015-03-30 at 7.06.43 PM

Important vShell path

There are a few things you need to know since everything above are quiet abstract.

/etc/httpd/conf.d/vshell.conf  #apache vshell setup
/etc/vshell.conf #vshell configuration

Now make sure that the vshell.conf file has the same as your nagios htpasswd.users or else you might not be able to login to vshell!

Troubleshooting

Once you done above, you might face a few problem like

Unable to login to vshell

Open up /etc/httpd/conf.d/vshell.conf and /etc/httpd/conf.d/nagios.conf
change your vshell.conf AuthUserFile to nagios.conf one
from

AuthUserFile /user/local/nagios/passwd

to

AuthUserFile /etc/nagios/passwd

above might vary but keep that in mind.

Unable to open '/usr/local/nagios/var/objects.cache' file!

Once you login you see the above error and you might want to open up the file /etc/vshell.conf and /etc/nagios/nagios.cfg and change vshell.conf from

; Full filesystem path to the Nagios object cache file
OBJECTSFILE = "/usr/local/nagios/var/objects.cache"

to

; Full filesystem path to the Nagios object cache file
OBJECTSFILE = "/var/log/nagios/objects.cache"

where the correct value should be the same as nagios one

Unable to open '/usr/local/nagios/var/status.dat' file!

Once you login you see the above error and you might want to open up the file /etc/vshell.conf and /etc/nagios/nagios.cfg and change vshell.conf from

; Full filesystem path to the Nagios status file
STATUSFILE = "/usr/local/nagios/var/status.dat"

to

; Full filesystem path to the Nagios status file
STATUSFILE = "/var/log/nagios/status.dat"

where the correct value should be the same as nagios one

Unable to open '/usr/local/nagios/etc/cgi.cfg' file!

Once you login you see the above error and you might want to open up the file /etc/vshell.conf and /etc/nagios/nagios.cfg and change vshell.conf from

; Full filesystem path to the Nagios CGI permissions configuration file
CGICFG = "/usr/local/nagios/etc/cgi.cfg"

to

; Full filesystem path to the Nagios CGI permissions configuration file
CGICFG = "/etc/nagios/cgi.cfg"

where the correct value should be the same as nagios one

Easy Install Nagios in Centos 6 via yum

Ok, i used to write the longer version when i was still using Centos 5, recently i went back to the article and found out that there is actually a shorter way to setup EVERYTHING. So here i am writing a shorter version to setup nagios on centos 6.

Setup Nagios Server

This is the server that will have vshell and nagios web interface. All you have to do is to install epel-release for your centos

yum install -y epel-release

and starts install nagios via yum

yum install -y nagios nagios-devel nagios-plugins* gd gd-devel httpd php gcc glibc glibc-common openssl

Now we need to make sure nagiosadmin is our username and password is set

htpasswd -c /etc/nagios/passwd nagiosadmin

which you can setup all the configuration at /etc/nagios/cgi.cfg and if you would like to change the configuration on apache, it is located at /etc/httpd/conf.d/nagios.conf

Once you have installed nagios, remember to startup nagios and apache whenever you restart!

service httpd restart
chkconfig httpd on

service nagios restart
chkconfig nagios on

and you can access it via http://localhost/nagios with username and password you have just setup above!!! Pretty easy ya!

Screen Shot 2015-03-30 at 6.38.04 PM

Now you might want to install nrpe on each server you wish to monitor next,

Installing nrpe with nagios-plugins on each server

Now, you really want to just have all these in yum when you have like 20 servers? It will be a nightmare if you just build all these by source (which i did last time instead of writing a scripts, yeah i'm dumb, i know). All you need to do via yum is

yum install nrpe nagios-plugins-all

And configure nrpe via

vi /etc/nagios/nrpe.cfg

adding your nagios ip into it so that your nagios server is allowed to penetrate each 'slave' you have lol.

allowed_hosts=127.0.0.1, 192.168.1.110

Now all you need to do is to setup all the services you wish to let your man to do on your 'slaves'.

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200 

and these can be setup at the same path as /etc/nagios/nrpe.cfg and you should be able to add more 'action' to it if you want.

and remember to setup nrpe to run on startup

service nrpe start
chkconfig nrpe on