Plesk 10.2.0 and SSL Certificates part II

Tracking down the actual location of the SSL certificate in a Plesk subscription is a process I hope never to use again. But… I am getting an error while trying to install a certificate manually on the site.

Error: Some fields are empty or contain an improper value.

Certificate Name*

I wasted an hour before I realised that I still had a partial certificate setup in the old sub-domain that I could not use. I deleted that certificate restarted Apache. Generated a new certificate request and revised the certificate via RapidSSL. The install of the certificate in Plesk still reported an error with the signing Authority. I ended up at https://knowledge.rapidssl.com/support/ssl-certificate-support/index?page=content&id=SO16226 to find the correct Intermediate certificates for Plesk Apache.

And while Plesk seemed to settle down after adding them, using IE or Chrome to visit the site gave me errors that the Certificate was invalid.

I used http://www.sslshopper.com/ssl-checker.html to confirm the certificate and it came back as self-signed.

The penny dropped that I had not re-started the web service and the Apache config would still be using the default Plesk certificate.

A quick restart and it’s all good.

Plesk 10.2.0 and SSL Certificates

One of the servers I manage has a Plesk control panel. I am not familiar with it having used cpanel/whm for the last 11 years since I first got a hosted server.

I was setting up what I thought would be an easy SSL certificate install. I’ve started this post because I am now delving into the core of the server <supposition>as the damn GUI hates me.</supposition>

Before you even start, if you want to have an SSL certificate on a sub-domain site, forget it unless you a) make it a wildcard certificate or b) are prepared to have the only ip address attached to that certificate.

Plesk 10.x only allows one IP address per subscription and that is set for all the sub-domains as well as the domain attached to the subscription.

So to apply a certificate that works for the subscription it must be a wildcard certificate. i.e.

[code]
subscription_domain.tld
[/code]
sub-domains exist for
[code]
site1.subscription_domain.tld
site2.subscription_domain.tld
[/code]
certificate is for
[code]
subscription_domain.tld
[/code]
it will be applied to all the domains
[code]
https://subscription_domain.tld
https://site1.subscription_domain.tld
https://site2.subscription_domain.tld
[/code]

While the option to have a specific SSL for
[code]
site1.subscription_domain.tld
and
site2.subscription_domain.tld
[/code]
as it is not possible to split the IP addresses to isolate the SSL per IP address.

Stylesheet Automation in osCmax

So my question was how to automate the stylesheet loading and in particular how to load a stylesheet that is not known about until after the header section of the page has already been written. This post could also be called ‘How to load stylesheets in the body of a page via PHP and Javascript’.

To test this copy the compromise template directory as compromise-sl or similar. In an earlier post I described some changes to copy and modify configure_bts.php to address the handling of core file modification. I am working from that base in this.

Most of the code is contained in two files loadstylesheets.php and its partner loadstylesheets.js. The link to a download is at the bottom of this post. Read through first and then try it.

Copy the includes directory from the zip to your template directory so that the files appear under an includes and includes/javascript directories respectively. This copies the core structure. Included is a modified configure_bts.php to simplify things.

In the template directory you should have a main_page.code.php file and it will have something like this at the top in the {stylesheet} section.

[php]
//begin{stylesheet}
?>
<link rel="stylesheet" type="text/css" href="<?php echo (bts_select(‘stylesheet’,’stylesheet.css’)); // BTSv1.5 ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo (bts_select(‘stylesheet’,’print.css’)); // BTSv1.5 ?>" media="print" />
<?php
//end{stylesheet}
[/php]

The example above is from the Compromise template in osCmax.
[php]
//begin{stylesheet}
require_once(DIR_WS_TEMPLATES.’includes/loadstylesheets.php’);
$stylesheetArray = getAllStylesheets();
$loadStylesheetArray = array();
$loadStylesheetArray = includeStylesheet(‘stylesheets.css’);
$loadStylesheetArray = includeStylesheet(‘print.css’);
$loadStylesheetArray = includeStylesheet(basename($PHP_SELF,’.php’). ‘.css’);
$loadStylesheetString = implode(":#:",$loadStylesheetArray);
$loadStylesheetArray = array(); // ready for re-use
?>

<script type="text/javascript">
var stylesheetArray = "<? print $loadStylesheetString; ?>";
</script>
<script type="text/javascript" src="<?php echo DIR_WS_TEMPLATES_JAVASCRIPT . ‘loadstylesheets.js’;?>"></script>

<?php
//end{stylesheet}
[/php]

It starts by including the php file and then building the array that finds all the stylesheets that exist in the template directory structure. This is so that you don’t need to declare a path just the unique stylesheet file name. Obviously this implies that you only have unique filenames. store.css in the root and store.css in a sub-directory will clash and one will be ignored.

Next using the includeStylesheet() function to add the required stylesheets that are going to be used for the page. This is still within the header stylesheet section so that these styles are displayed as the page is being rendered in the browser.

Finally the php code is done and the control swaps to the javascript. It is run when the page loads and it adds all the requested stylesheets from the array into the page.

So what next?

The bonus here is that this can be used again at the end of the body of the page to apply any stylesheets that were not ‘known’ about until later in the page.

Somewhere near the bottom of the main_page.code.php file will be the footer entry.

[php]
//end{footer}

//begin{banner}
[/php]

Updated: In the {footer} section place the additional StyleSheetLoader code. This was updated for a fix to the footer section post the release of v2.5 of osCmax.

[php]
//begin{footer}
// BOF Added: Down for Maintenance Hide footer.php if not to show
if (DOWN_FOR_MAINTENANCE == ‘false’ or DOWN_FOR_MAINTENANCE_FOOTER_OFF ==’false’) {
echo ‘<!– footer //–>’;
echo FOOTER_TEXT_BODY;
echo ‘<!– footer_eof //–>’;
// box and other stylesheets loaded after the header info need to be included
$loadStylesheetString = implode(":#:",$loadStylesheetArray);
$loadStylesheetArray = array();
?>
<script type="text/javascript">
var stylesheetArray = "<? print $loadStylesheetString; ?>";
</script>
<script type="text/javascript" src="<?php echo DIR_WS_TEMPLATES_JAVASCRIPT . ‘loadstylesheets.js’;?>"></script>
<?php
}
//end{footer}
[/php]

This code will run just the same as the one in the header and will include the any other stylesheets that have been loaded.

The final piece of the puzzle is to add the following into the box scripts or any other file that is loading as a part of your page or template. In this case I added it into the column_left.php file which is a core file in /includes but only after I copied it to the /templates/compromise-sl/includes/ directory to retain the core files for normal templates.

In column_left.php
[php]
if ( file_exists(DIR_WS_BOXES . $column[‘cfgtitle’] . ‘.php’) ) {
require(DIR_WS_BOXES . $column[‘cfgtitle’] . ‘.php’);
}
[/php]

Change to:

[php]
if ( file_exists(DIR_WS_BOXES . $column[‘cfgtitle’] . ‘.php’) ) {
$loadStylesheetArray = includeStylesheet($column[‘cfgtitle’] . ‘.css’);
require(DIR_WS_BOXES . $column[‘cfgtitle’] . ‘.php’);
}
[/php]

This means that if a box has a specific stylesheet it will be included in the load that is done at the end of the main_page.code.php execution.

Download the StylesheetLoader zip file and install into a template in osCmax or download the Blueprint template with the StylesheetLoader embedded as examples.

Having two stylesheets with the same name will load both files possibly creating a mess in the layout.

When it came to using this with the Blueprint framework there was a clash of file names with blueprint/print.css clashing with the default print.css and screen.css appearing in the plug-in directories. I have renamed the blueprint framework files to prevent the clash of file names.

blueprint/print.css -> blueprint/bp-print.css
blueprint/plugins/fancy-type/screen.css -> blueprint/plugins/fancy-type/fancy-type.css
etc.