EWEA navigation script

This solution is to create a local HTML file from the dynamic www.ewea.org/navigation-file generated by Typo3, that can be rsync’d to other servers so that they may include it in their templates as local files, speeding up the page creation process (and bypassing a huge latency issue we had with the EWEA 2015 programme pages).

#!/bin/sh
curl -L -o /var/www/html/sites/www.ewea.org/navigation http://www.ewea.org/navigation-file
rsync -avze "ssh -p 10022 -i /root/.ssh/main_prv_key" /var/www/html/sites/www.ewea.org/navigation [email protected]:/var/www/html/
rsync -avze "ssh -p 10022 -i /root/.ssh/main_prv_key" /var/www/html/sites/www.ewea.org/navigation [email protected]:/var/www/html/
rsync -avze "ssh -p 10022 -i /root/.ssh/main_prv_key" /var/www/html/sites/www.ewea.org/navigation [email protected]:/var/www/html/

This is scheduled to run daily at midnight via cron

On the receiving server, the following code is then used to display the navigation on the website.

<div id="navigation">
	<?php // INCLUDE EWEA MENU
	include("/var/www/html/navigation");
	?>
</div><!-- end #navigation -->

What “System Load” actually means

Today we wanted to find out what System Load on Monitorix actually meant and where it takes its figures from.

system1z.1day

So I actually emailed the developer of Monitorix and asked him the question!
Here is his reply:

Dear Jason,

I'm very glad to know that you are using and enjoying Monitorix.

As you might already know, UNIX, GNU/Linux, BSD systems, MacOSX and other UNIX-like systems have a command line called 'uptime' that shows three values called 'load average' (among other things). These numbers tell you how busy your system is, they are not self-explanatory at first, but shouldn't be difficult to become familiar with them.
Since you aren't familiar with them yet, I'd suggest you to search on Google something like 'understanding UNIX/Linux CPU load average values' and you'll end up with tons of results pointing with different blogs, articles, HOWTOs, etc. that should clear up things to you.

I've done myself that search and I've found a result pretty explanatory:
http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages
Besides all this, what Monitorix does is read these numbers from your system and create a graph in order to have a more visual representation of them.

I hope that helped you.

Best regards.

Jordi Sanfeliu
FIBRANET Network Services Provider
http://www.fibranet.cat

--

On 11/09/2015 01:06 PM, Jason Bickley wrote:
> Dear Jordi,

> My name is Jason Bickley and I am the webmaster for the European Wind
> Energy Association in Brussels.

> Firstly, please let me thank you for the amazing tool Monitorix – I
> have it running on 7 web servers and love the ease of installation and use.

> I have been discussing internally with our Web Developer this morning
> about the first graph "System Load" because we are trying to
> understand what it actually is.

> How are the figures obtained? Is there an algorithm taking into
> account all the things happening on the server to determine the final
> load figure? Or is it a more CPU-related thing?

> Any light shed upon the topic is highly appreciated!

> Best regards,

> *Jason Bickley*
> Senior Web Manager
> *EWEA - The European Wind Energy Association asbl/vzw*
> Rue d'Arlon 80, B-1040 Brussels, Belgium
> Tel: +32 2 213 18 19 | Fax: +32 2 213 18 90 | VAT: BE 0476 915 445
> Email: [email protected] | Web: http://www.ewea.org

Force download on PDF files

Placing the following snippet in an .htaccess file in a directory will force all pdfs (.PDF and .pdf) there to be downloaded to the computer rather than opened in the browser. This is good for occasions when IE is caching the PDF and users aren’t seeing the latest version.

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

Displaying content of a WordPress Form


<html>
<head>
<meta charset="utf-8" />
<style type="text/css">
* {font-family: "franklin gothic book"; font-size: small;}
h2 {font-size: 150%;}
table,td,th {border-collapse: collapse; border: 1px dotted #afafff; padding: 3px 5px;}
th {background: #efefff;}
</style>
</head>
<body>


<?php


// STATE YOUR VARIABLES
////////////////////////////////////////////////////////////////////
	$user  = "annual2015";
	$pass  = "tuYPLUY44DxjRCNB";
	$db    = "annual2015";
	$table = "wp_a15_fm_data_22";
	$sql   = "SELECT * FROM $table ORDER BY `timestamp` DESC LIMIT 0, 500";


// ESTABLISH THE CONNECTION
////////////////////////////////////////////////////////////////////
	$cxn=mysqli_connect("localhost","$user","$pass","$db");
	$cxn->set_charset("utf8");
	if (mysqli_connect_errno())
	{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}
	$result = mysqli_query($cxn,"$sql");


// GET NUMBER OF ATTENDEES
////////////////////////////////////////////////////////////////////
	$rows = mysqli_num_rows($result);
	printf("<h2>Current number of registered attendees: <span style=\"background: #ff0; font-size: 20px;\">%d</span></h2>",$rows);


// CREATE THE TABLE
////////////////////////////////////////////////////////////////////
echo "<table>
	<tr>
	<th>First name</th>
	<th>Last name</th>
	<th>Job title</th>
	<th>Organisation</th>
	<th>Email address</th>
	<!-- <th>Food requirements</th> -->
	<th>Date registered</th>
	</tr>\n";
while($row = mysqli_fetch_array($result))
	{
	echo "	<tr>\n";
	echo "	<td>" . "<b>" . $row['text-56275de811d4e'] . "</b>" . "</td>\n";
	echo "	<td>" . "<b>" . $row['text-56275dea2cd60'] . "</b>" . "</td>\n";
	echo "	<td>" . $row['text-56275dfd39f14'] . "</td>\n";
	echo "	<td>" . $row['text-56275dfb697d7'] . "</td>\n";
	echo "	<td>" . "<a href=\"mailto:" .$row['text-56275df9b2872'] . "\">" .$row['text-56275df9b2872'] . "</a>" . "</td>\n";
//	echo "	<td>" . $row[''] . "</td>\n";
	echo "	<td>" . $row['timestamp'] . "</td>\n";
	echo "	</tr>\n";
	}
echo "</table>";


// CLOSE THE CONNECTION
////////////////////////////////////////////////////////////////////
mysqli_close($cxn);
?>
</body>
</html>


ReverseProxy, IP Address Restriction & htaccess

There was an issue with IP address restriction on the events server.
The events server sits behind the main EWEA server (ReverseProxy).

Adding the following lines in yellow allowed the IP addresses to be passed through.

# Deny all but allow EWEA
Order deny,allow
Deny from all
#
SetEnvIF X-Forwarded-For "mail.ewea.org" AllowIP
SetEnvIF X-Forwarded-For "home.jasonbickley.net" AllowIP
Allow from env=AllowIP
# Allow EWEA
Allow from mail.ewea.org
# Allow Jason
Allow from home.jasonbickley.net

 


Original reference article here

Empty swap and clear memory cache

Just because I was curious, I looked up how to empty swap and memory cache today.

To clear the memory cache:

echo 1 > /proc/sys/vm/drop_caches

 

To empty the swap:

swapoff -a
swapon -a

Update Gandi Modules

A couple of my Gandi servers refused to restart the firewall due to missing modules (modules didn’t match the kernel version).
Here is a list of commands to rectify this problem.

Update modules:

  • Change directory to root: cd /
  • Download the modules’ archive: wget http://mirrors.gandi.net/kernel/$(uname -r)-modules.tar.gz
  • Move the existing modules: mv -f /lib/modules/$(uname -r) /lib/modules/$(uname -r).old
  • Uncompress the archive: tar xzf $(uname -r)-modules.tar.gz
  • Then: depmod $(uname -r)
  • You can list loaded modules: lsmod
  • You can check all the previous version of kernel for your server here.

Referenced from here: http://wiki.gandi.net/en/iaas/references/server/kernel_modules?s[]=modules

How to share content to Twitter and LinkedIn

Here are some examples I crafted today for EWEA 2015 registration:

Twitter

https://twitter.com/intent/tweet?text=I've just registered for EWEA 2015! Have you? :-) %0A&url=http://www.ewea.org/annual2015/information/&hashtags=EWEA2015&via=EWEA2015Annual

Gives:
Twitter-share

LinkedIn

http://www.linkedin.com/shareArticle?mini=true&url=http://www.ewea.org/annual2015/registration/&summary=I've just registered for EWEA 2015! Have you? :-)

Gives:
LinkedIn-Share

Reference:
https://dev.twitter.com/web/tweet-button
https://developer.linkedin.com/docs/share-on-linkedin

Adding a line-break in a Twitter share

So sometimes you want to format your Twitter share by adding a line break.
You can with the unicode string: %0A

e.g. https://twitter.com/intent/tweet?text=I%27ve%20just%20registered%20for%20EWEA%202015!%20You%20should%20too!%0A&url=http://www.ewea.org/annual2015/registration/&hashtags=EWEA2015

Will result in:

Twitter-share-line-break

Redirecting an old domain name to a web page

I needed to redirect globalwindday.org to www.ewea.org/globalwindday

A normal Apache redirect did not work.

For example:
globalwindday.org/faq would redirect to www.ewea.org/globalwindday/faq
This was a page that did not exist so therefore resulted in a 404 error.

Here are the lines added to vhosts.conf to make it work (stripping sub pages):

<VirtualHost *:80>
        ServerName  globalwindday.org
        ServerAlias www.globalwindday.org
        # Redirect permanent / http://www.ewea.org/globalwindday/   <-- This did not work
        RewriteEngine On
        RewriteCond %{HTTP_HOST} globalwindday.org [NC]
        RewriteRule ^(.*)$  http://www.ewea.org/globalwindday/ [R=301,NC]
</VirtualHost>

 

As constructed from this reference page:
https://gist.github.com/ScottPhillips/1721489