06 December, 2013

Energy Bytes live

I am particularly pleased with the bespoke email subscription 'plugin' that I wrote for this site. Since all the hard work is done invisibly, I'll describe it here. User enters his/her email. This is validated on the site as being email-like with some regex and MX tests. Then, assuming these pass, the email address is stored and a probe email sent to the user with a code embedded in a link. If the user validates using the link, they receive an email of all the new posts to the site which is fired by a cronjob once a week. Every email is individual and has a unique unsubscribe link. I also wrote some admin tools the keep the list neat and tidy. Perhaps I didn't look hard enough; but I could not find an existing Wordpress plugin to do all that I wanted.

Please visit the site for an up to date independent resource on energy efficiency policy.

RoundCube Password

With some trepidation, I must admit, I followed Acmeous's tip here on enabling users of RoundCube to change their own password without access to cPanel. The instructions were extremely clear and they worked. Thank you Acmeous.

25 November, 2013

Search basics

Found this on Google and have 're-tweeted' the gist of it here. NB When using an 'operator', don't add any spaces between the operator and your query.
  • Search for an exact word or phrase eg "search query"
  • Exclude a word eg -word You can also exclude results based on other operators, like excluding all results from a specific site.
  • Search within a site or domain eg site:domain.org You can also search within a specific top-level domain eg site:.co.uk
  • Search for pages that link to a URL eg link:query You can also search for links to specific pages, eg link:google.com/images
  • Search for pages that are similar to a URL: eg related:query
  • Include a "fill in the blank": eg query * query an asterisk in a query is a placeholder for any unknown or wildcard terms
  • Search for either word: eg query OR query NB CAPS world cup location 2014 OR 2018 
  • Search for a number range: eg number..number
  • Complex queries: eg (google +yahoo) OR (google +bing) +compare

22 November, 2013

Energy Bytes in Beta

My first full on experience with WordPress. Leaving the question of whether I should migrate this blog to that platform. Hmm... Leave that for another day.

I based the design on TwentyTwenty, one of the default themes. I was able to achieve a satisfactory look and feel, just. Still a few niggles to resolve. Mighty difficult to unravel someone else's CSS!

In terms of functionality, after quite a lot of searching, I resorted to making a few of my own "widgets" - advanced search, weekly subscriber email with admin panel, smart contact page, bespoke archive. That proved more straightforward than the CSS.

Site is currently in Beta testing, going live next week

17 May, 2012

Server uptime monitoring

For a while now I had wanted to monitor in real time my web server's availability.  But how?  Anything on the server itself would fail - because, if the server was down, the script would not work. After the event, the logs would show what's happened of course; but I wanted instant notification of a problem. Lots of companies offer this service at a price.  I wanted it free!  The solution turns out to be quite simple.  Sign up to a free web server service.  I picked http://www.000webhost.com/ and created a script on that machine that runs every five minutes to look up a small file on my main server.  If it fails to find the file, the script sends me an alert email.  This does generate the occasional 'false negative' but that is better than the main site being down for hours unbeknown to me.  If the script is successful this is recorded on a database.  Once a day the script records the stats for day, purges the database table and sends me a summary.  I think that is quite neat...

20 January, 2012

Form submission with alert/confirm

This has been a perennial issue for me. I'd have a form with multiple submit buttons; and on one or more - but not all - of the submit buttons I would want a confirm dialogue. 'Save' or 'Amend' might go straight through but 'Delete' would be intercepted for a confirmation. I used to put a section in the form response page setting up another form with a confirm button. But I think I have found a more elegant solution, below (though it does rely on JavaScript being enabled).

In the form add a hidden field and submit button as follows:
<input type="hidden" name="confirm_delete" id="confirm_delete" value="0" />

<input type="submit" name="delete" value="Delete" onClick="confirmDelete(this.form);" />

Add a JavaScript function like this:
function confirmDelete(form) {
var answer = confirm("Are you sure you want to deleted this?");
if (answer == true) {
form.confirm_delete.value = 1;
form.submit();
}
}
Then you can handle the confirmed deletion by testing the hidden field
if($_POST['confirm_delete'] == 1){
// do whatever needs doing
}

19 December, 2011

SEO advice

Gave some today that is worth capturing:

Use title and description meta-tags, ideally varied page by page. Google has an issue with multiple use of the same text for some reason.

Google ignores the 'keywords' meta tag but other search engines pay it some attention so it is worth keeping.

A good 'description' meta-tag is essential.

Also title could be a bit longer (up to 65 characters including spaces)

Get as many people as you can to link to you from blogs, other websites, articles and so on.

Let's see if that elevates c-a-mayer-memorial.org.uk

03 December, 2011

Yesterday's outage

Apologies to anyone inconvenienced by last night's short outage. GoDaddy said they had a communications issue with a number of servers so I am relieved that it was not a user error or a DOS attack. In all it lasted less than ah hour I think.

30 November, 2011

Lysandra Press now live

Today we launch the site of a new ebook publisher, lysandrapress.com. Please go have a look and buy some books...

03 November, 2011

Ajax

How brilliant is this. I cannot believe I have not found this solution before. I have so many pages that depend on a user input to connect the client and server sides of a site, now Ajax can do all of that for them, so fewer clicks. Now to remember where they were and go upgrade them...

30 September, 2011

cPanel

With some trepidation I am moving my server and control panel. So Bye-bye Arizona and Plesk and Hello Europe (still not sure where GoDaddy's base is!) and cPanel. No doubt there will be teething troubles, but Plesk has never been that friendly to me and the newer fancier server will assist now that I am hosting more sites and more particularly for paying customers/partners.

05 August, 2011

New client

Today saw the first steps towards building a new site for Portsmere, with the purchase of the domain name portsmere.com. Now to make a great site for them.

03 March, 2011

Morethanpictures.co.uk

Is now live. I am rather pleased with it; but, more important, so is the client. I had fun working with images in a bit more depth and applying dynamic drive's Ultimate Fade-in Slideshow and Lightbox 2. See it here

28 July, 2010

Secure MySQL connection on Godaddy virtual dedicated server

The Godaddy instructions on this are pretty hard to find and the default settings for open_basedir and directory permissions make it hard to do; so here is what I have done that works. You will need to be using SSH and your control panel (I use Plesk, but I doubt this is much different with cPanel and others).

The key security point is that your access codes to your MySQL database really should not be in your httpdocs directory. That is accessible to the world and although it is hard to grab the information from a .php file, it is not impossible. If the file sits above the httpdocs folder, it cannot be seen from the web.

So using SSH create a folder (one per domain, but if you use only one database for a number of sites it could be one for all) called mysql with

mkdir mysql

then still in SSH change the ownership to the normal owner of the domain with

chown [user] mysql

Now open up the conf directory to the same user with

chown [user] conf

Go to your control panel and create these two files

1. a file in conf called vhost.conf (content below) and

2. a file in mysql called mysql.php (content below)

Finally, either in SSH Restart the server with

/usr/local/psa/admin/bin/websrvmng -a -v

or you can do it from control panel.

content of vhost.conf (where x is the domain)

<directory /var/www/vhosts/x/httpdocs>

php_admin_value open_basedir "/var/www/vhosts/x/httpdocs:/tmp:/var/www/vhosts/x/mysql:"

</directory>

content of mysql.php

<?php

/*

THIS IS THE MASTER DATABASE CONNECTION FILE

IT SHOULD BE STORED ABOVE THE ROOT DIRECTORY IN MYSQL

AND SHOULD BE USED FOR ALL MYSQL CONNECTIONS

*/

mysql_connect("localhost", "[username]", "[password]") or die (mysql_error());

mysql_select_db("[database_name]") or die(mysql_error());

?>

To connect to the database add this in the relevant php scripts

include '/var/www/vhosts/[domain]/mysql/mysql.php';

Hope that helps someone save the time it took me to work it out...

27 March, 2010

Tjsoft.info revamp

Started a major rewrite of this site using a lot more CSS and fewer tables. Still a lot to do but the base is now there.

Server upgrades

Latest server configuration:
  • httpd 2.2.8-1.fc7
  • mailman 2.1.9-5.3
  • mod_perl 2.0.3-9.1.fc7
  • mod_python 3.3.1-3
  • mysql 5.0.45-6.fc7
  • perl-Apache-ASP 2.59-0.93298
  • php 5.2.6-2.fc7
  • plesk 9.3.0
  • postgresql-server 8.2.9-1.fc7
  • ruby 1.8.6.114-1.fc7
  • samba 3.0.28a-1.fc7
  • spamassassin 3.2.4-1.fc7
  • SSHTerm 0.2.2-9.278624
  • tomcat 5.5.26-1jpp.2.fc7
  • webalizer 2.01_10-32

21 March, 2010

IE non-compliance

Right, that's it. I am no longer going to support IE as a suitable browser for my sites. Microsoft's continuing lack of acceptance of internationally agreed standards makes the developer's life a misery and, while it may be cool to know all the little work-arounds needed to make your site work, just, with IE, why should we? There are much better browsers that do accept the agreed standards that work, are free, are faster, more secure - need I go on.

So I have developed a little code to spot IE users and give them a warning. They can accept the limitations of IE or switch browser. I rather like it and think all web developers should follow suit...

04 October, 2009

Upgrade to PHP5

I decided to upgrade to the latest version of MyGedView, which has some nice features over the previous version, and to do this I needed PHP5. This in turn meant a server rebuild to Fedora Core 7, so basically I had to start from scratch. The server is now re-built and running sweetly, but I am still part way through restoring all the previous material/sites. It is a good way of giving the server a good spring clean!

12 February, 2008

crontab tips on GoDaddy

This was nowhere in the GoDaddy documentation so, I though I would share a working solution.

The objective was to create a single php script which a set of scheduled crontab tasks could execute from my GoDaddy virtual dedicated server. I wanted something that ran hourly, daily, weekly and monthly.

The steps I used were:

1. Create your script in the normal way. The key element is the $_SERVER['argv']['1'] variable, which is passed from the crontab line. You could pass more than one. The second would be $_SERVER['argv']['2']. You might add this for a checksum to prevent the script running if the search engines find it. I then used the first variable in a switch group to establish the start and end date for a MySQL query that runs later. So:

switch ($_SERVER['argv']['1']) {

case "hourly": // RUNS AT *:00
$d2 = date("Y-m-d H",time()).":00:00";
$d1 = date("Y-m-d H",strtotime($d2) - 3600).":00:00";
$num = 1;
break;

case "daily": // RUNS AT 00:20
$d2 = date("Y-m-d",time() - 24 * 3600);
$d1 = date("Y-m-d",strtotime($d2) - 24 * 3600);
$num = 2;
break;

case "weekly": // RUNS AT 00:40
$d2 = date("Y-m-d",time() - 24 * 3600);
$d1 = date("Y-m-d",strtotime($d2) - 7 * 24 * 3600);
$num = 3;
break;

case "monthly": // RUNS AT 01:00
$d2 = date("Y-m-d",time() - 24 * 3600);
$d1 = date("Y-m-d",strtotime($d2) - 24 * 3600 * 365.25 / 12);
$num = 4;
break;

}

$query2 = "SELECT *
FROM `".$type[$j]."`
WHERE DATE(`".$col[$j]."`) > '".$d1."'
AND DATE(`".$col[$j]."`) <= '".$d2."'";

2. Chmod this file to 'rwx r-x r-x' to allow it to be executed by the server.

3. Add a scheduled task like this:

10 0 * * * /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php hourly
20 0 * * * /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php daily
30 0 * * 1 /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php weekly
40 1 1 * * /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php monthly

I have the file in a directory called cron, but you can put it where you like.

Any HTML output your script creates will then be sent to the email address set in the preferences tab where you set up scheduled tasks. This is for error reporting so make your script produce no HTML if it is working fine.

17 November, 2007

Server migration complete for garfagnana-food and soane.net

I have closed the old server. Some, non-active, sites still need to be loaded on the new server, but I took the decision to complete the move as an incentive to get everything in order. All the domain routing now works, but some of the sites have to be loaded. I am gradually working my way through them.