View source
<?php
function hostmaster_profile_modules() {
return array(
'block',
'color',
'filter',
'help',
'menu',
'node',
'system',
'user',
'install_profile_api',
'hosting',
'hosting_task',
'hosting_client',
'hosting_db_server',
'hosting_package',
'hosting_platform',
'hosting_site',
'hosting_web_server',
);
}
function hostmaster_profile_details() {
return array(
'name' => 'Hostmaster',
'description' => 'Select this profile to manage the installation and maintenance of hosted Drupal sites.',
);
}
function pr($var) {
echo "<pre>";
print_r($var);
echo "</pre>";
}
function hostmaster_profile_task_list() {
return array(
'intro' => st('Getting started'),
'webserver' => st('Web server'),
'filesystem' => st('Filesystem'),
'dbserver' => st('Database server'),
'features' => st('Features'),
'init' => st('Initialize system'),
'verify' => st('Verify settings'),
'import' => st('Import sites'),
);
}
function hostmaster_get_task($task, $offset = 0) {
static $tasks;
static $keys;
if (!$tasks) {
$tasks = hostmaster_profile_task_list();
$keys = array_keys($tasks);
}
if ($task == $keys[sizeof($keys) - 1] && $offset > 0) {
return 'profile-finished';
}
if (($tid = array_search($task, $keys)) === FALSE) {
$tid = 0;
}
$tid = $tid + $offset;
if ($tid < 0) {
$tid = 0;
}
return $keys[$tid];
}
function hostmaster_profile_tasks(&$task, $url) {
include_once dirname(__FILE__) . '/hostmaster.forms.inc';
define("HOSTMASTER_FORM_REDIRECT", $url);
if ($task == 'profile') {
hostmaster_bootstrap();
}
include_once drupal_get_path('module', 'node') . '/node.pages.inc';
$task = hostmaster_get_task($task, variable_get('hostmaster_wizard_offset', 0));
variable_del('hostmaster_wizard_offset');
define("HOSTMASTER_CURRENT_TASK", $task);
install_include(hostmaster_profile_modules());
$func = sprintf("hostmaster_task_%s", $task);
if (function_exists($func)) {
return drupal_get_form($func);
}
return $task;
return "123";
if ($tid == sizeof($keys) - 1) {
}
}
function hostmaster_requirement_help($requirement, $options = array()) {
$form = array_merge(_element_info('requirement_help'), $options);
$form['#requirement'] = $requirement;
$form['#help'] = hosting_get_requirement($requirement);
$form['#value'] = theme_requirement_help($form);
return $form;
}
function hostmaster_form($form) {
global $task;
$form['#redirect'] = HOSTMASTER_FORM_REDIRECT;
$form['#prefix'] = '<div id="hosting-wizard-form">';
$form['#suffix'] = '</div>';
$form['wizard_form'] = array(
'#prefix' => '<div id="hosting-wizard-form-buttons">',
'#suffix' => '</div>',
'#weight' => 100,
);
if (HOSTMASTER_CURRENT_TASK != 'intro') {
$button = array(
'#type' => 'submit',
'#value' => '<- Previous',
);
$button['#submit'][] = 'hostmaster_form_previous';
$form['wizard_form']['back'] = $button;
}
$button = array(
'#type' => 'submit',
'#value' => 'Next ->',
);
$button['#validate'] = $form['#validate'];
$button['#validate'][] = 'hostmaster_form_validate';
unset($form['#validate']);
if ($form['#node']) {
$button['#submit'][] = 'node_form_submit';
}
$button['#submit'][] = 'hostmaster_form_next';
$form['wizard_form']['submit'] = $button;
return $form;
}
function hostmaster_form_next($form, $form_state) {
variable_set('hostmaster_wizard_offset', 1);
}
function hostmaster_form_previous($form, $form_state) {
variable_set('hostmaster_wizard_offset', -1);
}
function hostmaster_form_validate($form, &$form_state) {
}
function hostmaster_bootstrap() {
$types = node_types_rebuild();
variable_set('install_profile', 'hostmaster');
global $user;
hosting_init();
$node = new stdClass();
$node->uid = 1;
$node->type = 'client';
$node->email = $user->mail;
$node->client_name = $user->name;
$node->status = 1;
node_save($node);
variable_set('hosting_default_client', $node->nid);
global $db_url;
$url = parse_url($db_url);
$node = new stdClass();
$node->uid = 1;
$node->type = 'db_server';
$node->title = $url['host'];
$node->db_type = $url['scheme'];
$node->db_user = $url['user'];
$node->db_passwd = $url['pass'];
$node->status = 1;
node_save($node);
variable_set('hosting_default_db_server', $node->nid);
variable_set('hosting_own_db_server', $node->nid);
$node = new stdClass();
$node->uid = 1;
$node->type = 'web_server';
$node->title = $_SERVER['HTTP_HOST'];
$node->script_user = HOSTING_DEFAULT_SCRIPT_USER;
$node->web_group = HOSTING_DEFAULT_WEB_GROUP;
$node->status = 1;
node_save($node);
variable_set('hosting_default_web_server', $node->nid);
$node = new stdClass();
$node->uid = 1;
$node->title = 'Drupal';
$node->type = 'package';
$node->package_type = 'platform';
$node->short_name = 'drupal';
$node->status = 1;
node_save($node);
$package_id = $node->nid;
$node = new stdClass();
$node->uid = 1;
$node->type = 'platform';
$node->title = $_SERVER['HTTP_HOST'] . ' (Drupal ' . VERSION . ')';
$node->publish_path = $_SERVER['DOCUMENT_ROOT'];
$node->web_server = variable_get('hosting_default_web_server', 3);
$node->status = 1;
node_save($node);
variable_set('hosting_default_platform', $node->nid);
variable_set('hosting_own_platform', $node->nid);
$instance = new stdClass();
$instance->rid = $node->nid;
$instance->version = VERSION;
$instance->schema_version = drupal_get_installed_schema_version('system');
$instance->package_id = $package_id;
$instance->status = 0;
hosting_package_instance_save($instance);
variable_set('site_frontpage', 'hosting/sites');
variable_set('user_register', 0);
variable_set('install_url', $GLOBALS['base_url']);
}
function hostmaster_profile_final() {
hostmaster_install_add_block('hosting', 'hosting_summary', 'garland', 1, 10, 'left');
hostmaster_install_add_block('hosting', 'hosting_queues', 'garland', 1, 0, 'right');
hostmaster_install_add_block('hosting', 'hosting_queues_summary', 'garland', 1, 2, 'right');
hostmaster_setup_theme('eldir');
hostmaster_setup_optional_modules();
hostmaster_install_set_permissions(hostmaster_install_get_rid('anonymous user'), array(
'access content',
'access all views',
));
hostmaster_install_set_permissions(hostmaster_install_get_rid('authenticated user'), array(
'access content',
'access all views',
));
hostmaster_install_create_role('aegir client');
hostmaster_install_set_permissions(hostmaster_install_get_rid('aegir client'), array(
'access content',
'access all views',
'edit own client',
'view client',
'create site',
'delete site',
'view site',
'create backup task',
'create delete task',
'create disable task',
'create enable task',
'create restore task',
'view own tasks',
'view task',
));
hostmaster_install_create_role('aegir account manager');
hostmaster_install_set_permissions(hostmaster_install_get_rid('aegir account manager'), array(
'create client',
'edit client users',
'view client',
));
menu_rebuild();
node_access_rebuild();
drupal_goto('hosting/wizard');
}
function hostmaster_install_set_permissions($rid, $perms) {
db_query('DELETE FROM {permission} WHERE rid = %d', $rid);
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', $perms));
}
function hostmaster_setup_theme($name) {
if (!is_array($name)) {
$name = array(
$name,
);
}
$themes = system_theme_data();
foreach ($name as $theme) {
if (array_key_exists($theme, $themes)) {
system_initialize_theme_blocks($theme);
db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%theme'", array(
'%theme' => $theme,
));
variable_set('theme_default', $theme);
}
}
}
function hostmaster_setup_optional_modules() {
$optional = array(
'admin_menu',
);
foreach ($optional as $name) {
$exists = db_result(db_query("SELECT name FROM {system} WHERE type='module' and name='%s'", $name));
drupal_install_modules(array(
$name,
));
if ($exists == $name) {
switch ($name) {
case 'admin_menu':
variable_set('admin_menu_margin_top', 1);
variable_set('admin_menu_position_fixed', 1);
variable_set('admin_menu_tweak_menu', 0);
variable_set('admin_menu_tweak_modules', 0);
variable_set('admin_menu_tweak_tabs', 0);
$menu_mid = hostmaster_create_menu(t('Administration'));
$admin_mid = hostmaster_menu_get_mid('admin');
hostmaster_update_menu_item($admin_mid, array(
'pid' => $menu_mid,
));
hostmaster_disable_menu_item($admin_mid);
break;
}
}
}
}
function _hostmaster_clean_node_form(&$form) {
$form['revision_information']['revision']['#type'] = 'value';
$form['revision_information']['log']['#type'] = 'value';
$form['revision_information']['#type'] = 'markup';
$form['author']['name']['#type'] = 'value';
$form['author']['date']['#type'] = 'value';
$form['author']['#type'] = 'markup';
$form['options']['sticky']['#type'] = 'value';
$form['options']['status']['#type'] = 'value';
$form['options']['promote']['#type'] = 'value';
$form['options']['#type'] = 'markup';
unset($form['buttons']);
}