View source
<?php
define('HOSTING_SSL_DISABLED', 0);
define('HOSTING_SSL_ENABLED', 1);
define('HOSTING_SSL_REQUIRED', 2);
include_once 'hosting_ssl.nodeapi.inc';
function hosting_ssl_hosting_service() {
return array(
'apache_ssl' => 'http',
);
}
function hosting_ssl_perm() {
return array(
'create ssl certificate',
);
}
function hosting_ssl_get_servers() {
$servers = hosting_get_servers('http');
$ssl_servers = array();
foreach ($servers as $nid => $title) {
$node = node_load($nid);
if ($node->services['http']->ssl_enabled) {
$ssl_servers[] = $nid;
}
}
return $ssl_servers;
}
function hosting_ssl_get_platforms() {
$servers = hosting_ssl_get_servers();
$ssl_platforms = array();
$platforms = _hosting_get_platforms();
foreach ($platforms as $nid => $title) {
$platform = node_load($nid);
if (in_array($platform->web_server, $servers)) {
$ssl_platforms[] = $nid;
}
}
return $ssl_platforms;
}
function hosting_ssl_get_profiles() {
$platforms = hosting_ssl_get_platforms();
$ssl_profiles = array();
foreach ($platforms as $nid) {
$platform = node_load($nid);
$ssl_profiles = array_merge($ssl_profiles, array_keys($platform->profiles));
}
return array_unique($ssl_profiles);
}
function hosting_ssl_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'site_node_form') {
hosting_ssl_site_form($form, $form_state, $form_id);
}
}
function hosting_ssl_menu() {
$items = array();
$items['node/%hosting_ssl_cert_node/ssl'] = array(
'title' => 'Certificates',
'description' => 'SSL certificates deployed on this server',
'page callback' => 'hosting_ssl_server_cert_list',
'page arguments' => array(
1,
),
'type' => MENU_LOCAL_TASK,
'access arguments' => array(
'view server',
),
);
return $items;
}
function hosting_ssl_cert_node_load($arg) {
if (!is_numeric($arg)) {
return FALSE;
}
if ($node = node_load($arg)) {
if ($node->type == 'server') {
return $node;
}
}
return FALSE;
}
function hosting_ssl_server_cert_list($node) {
$args = array(
$node->nid,
);
drupal_set_title(t('Certificates installed on server @server', array(
'@server' => $node->title,
)));
$header = array(
array(
'data' => t('Domain'),
'field' => 'domain',
),
array(
'data' => t('IP address'),
'field' => 'ip_address',
),
array(
'data' => t('Client'),
'field' => 'client',
),
);
$sql = 'SELECT ips.ip_address, cert.ssl_key AS domain, cert.status, client.title AS client
FROM {hosting_ip_addresses} ips
INNER JOIN {hosting_ssl_cert_ips} cert_ip ON cert_ip.ip_address = ips.id
INNER JOIN {hosting_ssl_cert} cert ON cert.cid = cert_ip.cid
INNER JOIN {node} client ON client.nid = cert.client
WHERE ips.nid = %d';
$sql .= tablesort_sql($header);
$result = pager_query(db_rewrite_sql($sql, 'cert'), 25, 2, null, $args);
$rows = array();
while ($cert = db_fetch_object($result)) {
$row = array();
$row[] = $cert->domain;
$row[] = $cert->ip_address;
$row[] = filter_xss($cert->client);
$rows[] = $row;
}
return theme('table', $header, $rows, array(
'class' => 'hostign-table',
)) . theme('pager', null, 25, 2);
}