EWEA Navigation include

Here’s how to include the EWEA navigation file in templates for microsites:

<div id="navigation">
<?php
// INCLUDE EWEA MENU
$naviURL = "http://www.ewea.org/navigation-file/";
if ($fh = fopen($naviURL,"r"))  {
   fpassthru($fh);
} else {
   echo "<p>Unable to load menu.</p>\n";
}
?>
</div><!-- end #navigation -->

Postfix doesn’t start after a re-install

Perhaps this might be the solution. Check if there are the necessary sendmail files below.
If you do not have /usr/sbin/sendmail, check if after installing postfix package, you have:

/usr/sbin/sendmail.postfix

If you do, simply make a symlink:

ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail

Find out which services are using which ports

netstat -tulpn

[root@main www.ewea.org]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 95.142.174.150:10022        0.0.0.0:*                   LISTEN      1289/sshd
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      6325/mysqld
tcp        0      0 0.0.0.0:10000               0.0.0.0:*                   LISTEN      25106/perl
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      6360/vsftpd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      469/master
tcp        0      0 0.0.0.0:10080               0.0.0.0:*                   LISTEN      5944/monitorix-http
tcp        0      0 :::842                      :::*                        LISTEN      1247/xinetd
tcp        0      0 :::80                       :::*                        LISTEN      1750/httpd
tcp        0      0 ::1:25                      :::*                        LISTEN      469/master
udp        0      0 95.142.174.150:123          0.0.0.0:*                               1297/ntpd
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1297/ntpd
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1297/ntpd
udp        0      0 0.0.0.0:10000               0.0.0.0:*                               25106/perl
udp        0      0 2001:4b98:dc0:51:216:3ef:123 :::*                                    1297/ntpd
udp        0      0 ::1:123                     :::*                                    1297/ntpd
udp        0      0 fe80::216:3eff:fead:9e49:123 :::*                                    1297/ntpd
udp        0      0 :::123                      :::*                                    1297/ntpd

PHP cURL to save remote RSS feed to local xml file

Here’s a script I found to get a remote RSS feed, for example the Feedburner feed, and save it to a local XML file.
This would be useful for moments when you cannot connect to the RSS feed directly in a plugin or application.
You could then try and load the local file instead. Obviously a cron task would be added to run this script to reload the RSS feed a couple of times a day.

<?php
$ch = curl_init("http://feeds.feedburner.com/EWEABlog?format=xml");
$fp = fopen("feedburner.xml", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

This script would then write the contents of the RSS feed to the local file “feedburner.xml”

Google Analyticator

I have installed the WordPress plugin “Google Analyticator” on all the WordPress-based websites.
However, for those that have the “EWEA Master Code” installed, I needed to edit the plugin code.

<script type="text/javascript">
var _gaq = _gaq || [];

// This website code here:
_gaq.push(['_setAccount', '<?php echo $uid; ?>']);
<?php if ($need_to_annon == '1' ): ?>
_gaq.push(['_gat._anonymizeIp']);
<?php endif; ?>
<?php

    # Add any tracking code before the trackPageview
    do_action('google_analyticator_extra_js_before');
    if ( '' != $extra )
            echo "$extra\n";

    # Add the track pageview function
    echo "_gaq.push(['_trackPageview']);\n\n";

    # Disable page tracking if admin is logged in
    if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
            echo "_gaq.push(['_setCustomVar', 'admin']);\n";

    # Add any tracking code after the trackPageview
    do_action('google_analyticator_extra_js_after');
    if ( '' != $extra_after )
            echo "$extra_after\n";

    # Add the final section of the tracking code
    ?>

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Now we add the EWEA Master Code in the plugin settings area:

EWEA Master

For copying/pasting:

// EWEA's master code here:
  _gaq.push(['_setAccount', 'UA-4609386-40']);
  _gaq.push(["_setDomainName", "none"]);
  _gaq.push(["_setAllowLinker", true]);
  _gaq.push(["_trackPageview"]);

 

Create a local copy of a web page

Using the following command on linux, you can create a local copy of a web page with all images and files saved:

wget --page-requisites http://example.com/

 

MySQL commands

Backup server data and rsync to offsite server

This is the current backup script used on all the web servers.
(Last updated 26 May, 2016)

#!/bin/bash
# srv.sh
# Backup of files to offsite server
# Jason Bickley, Senior Web Manager, WindEurope
# 26 MAY 2016

#==== RECEIVE VARIABLES FROM COMMAND LINE ====#
FREQ=$1
SERVER=$2
EXCLUDE="--exclude-from=/root/backup/excludelist"
OPTION=$3
DEST=backup.ewea.org
DATE=$(date +"%Y%m%d %T")
LOG=/var/log/backupSRV_log

#==== SET TIMESTAMP =============#
touch /root/.timestamp /etc/.timestamp /var/.timestamp

#==== DAILY BACKUP OF SERVER ====#
rsync -avzhe "ssh -p 10022 -i /root/.ssh/"$SERVER"_prv_key" $EXCLUDE $OPTION / root@$DEST:/backups/$FREQ/$SERVER/

#=== CONFIRM SUCCESS IN LOG FILE ====#
echo $DATE Backup successful! $DEST:/backups/$FREQ/$SERVER/ >> $LOG


To use it, you just have to run: srv.sh {freq} {servername} {option}
For example:

cd /root/Scripts/backup/
./srv.sh daily web1 --delete

Contents of /root/backup/excludelist


/bin
/boot
/cgroup
/db
/dev
/lib
/lib64
/lost+found
/media
/mnt
/opt
/proc
/run
/sbin
/selinux
/srv
/sys
/tmp
/usr
/var/cache
/var/db
/var/empty
/var/ftp
/var/games
/var/gandi
/var/local
/var/lock
/var/lost+found
/var/mail
/var/nis
/var/opt
/var/lib/php/session
/var/preserve
/var/run
/var/tmp
/var/www/html/sites/events
/var/www/html/sites/globalwindday.org
/var/www/html/sites/solutionwind.com
/var/www/html/sites/stats.ewea.org
/var/www/html/sites/testing.ewea.org
/var/www/html/sites/www.ewea.org
/var/www/html/sites/www.ewea.org/fileadmin/videos/health-and-safety
/var/yp

Extracting one database from a large dump file

Use the following command:

sed -n '/^-- Current Database: `test`/,/^-- Current Database: `/p' fulldump.sql > oneDB.sql

Using “SED” command to replace URL strings in SQL files

We want to change all references of events.ewea.org to www.ewea.org in an SQL dump, so a sed command line for this may be:

sed 's/OLDPHRASE/NEWPHRASE/g' database.sql > database.new.sql

sed 's/events\.ewea\.org/www\.ewea\.org/g' event.sql > event.new.sql

Note: We have to escape the periods and any slashes.

This is particularly useful when migrating a WordPress website off the development server and onto the production server.