Beispiel #1
0
/**
 * Installation task; configure settings for the new site.
 *
 * @param $form_state
 *   An associative array containing the current state of the form.
 * @param $install_state
 *   An array of information about the current installation state.
 * @return
 *   The form API definition for the site configuration form.
 */
function install_configure_form($form, &$form_state, &$install_state)
{
    if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) {
        // Site already configured: This should never happen, means re-running the
        // installer, possibly by an attacker after the 'install_task' variable got
        // accidentally blown somewhere. Stop it now.
        throw new Exception(install_already_done_error());
    }
    drupal_set_title(st('Configure site'));
    // Warn about settings.php permissions risk
    $settings_dir = './' . conf_path();
    $settings_file = $settings_dir . '/settings.php';
    if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) {
        drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'error');
    } else {
        drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file)));
    }
    // Add JavaScript validation.
    _user_password_dynamic_validation();
    drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
    // Add JavaScript time zone detection.
    drupal_add_js('misc/timezone.js');
    // We add these strings as settings because JavaScript translation does not
    // work on install time.
    drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting');
    drupal_add_js('jQuery(function () { Drupal.cleanURLsInstallCheck(); });', 'inline');
    // Add JS to show / hide the 'Email administrator about site updates' elements
    drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline');
    // Build menu to allow clean URL check.
    menu_rebuild();
    // Cache a fully-built schema. This is necessary for any invocation of
    // index.php because: (1) setting cache table entries requires schema
    // information, (2) that occurs during bootstrap before any module are
    // loaded, so (3) if there is no cached schema, drupal_get_schema() will
    // try to generate one but with no loaded modules will return nothing.
    //
    // This logically could be done during the 'install_finished' task, but the
    // clean URL check requires it now.
    drupal_get_schema(NULL, TRUE);
    // Return the form.
    return _install_configure_form($form, $form_state, $install_state);
}
Beispiel #2
0
/**
 * Tasks performed after the database is initialized.
 */
function install_tasks($profile, $task)
{
    global $base_url, $install_locale;
    // Bootstrap newly installed Drupal, while preserving existing messages.
    $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : '';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    $_SESSION['messages'] = $messages;
    // URL used to direct page requests.
    $url = $base_url . '/install.php?locale=' . $install_locale . '&profile=' . $profile;
    // Build a page for final tasks.
    if (empty($task)) {
        variable_set('install_task', 'profile-install');
        $task = 'profile-install';
    }
    // We are using a list of if constructs here to allow for
    // passing from one task to the other in the same request.
    // Install profile modules.
    if ($task == 'profile-install') {
        $modules = variable_get('install_profile_modules', array());
        $files = module_rebuild_cache();
        variable_del('install_profile_modules');
        $operations = array();
        foreach ($modules as $module) {
            $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
        }
        $batch = array('operations' => $operations, 'finished' => '_install_profile_batch_finished', 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_name())), 'error_message' => st('The installation has encountered an error.'));
        // Start a batch, switch to 'profile-install-batch' task. We need to
        // set the variable here, because batch_process() redirects.
        variable_set('install_task', 'profile-install-batch');
        batch_set($batch);
        batch_process($url, $url);
    }
    // We are running a batch install of the profile's modules.
    // This might run in multiple HTTP requests, constantly redirecting
    // to the same address, until the batch finished callback is invoked
    // and the task advances to 'locale-initial-import'.
    if ($task == 'profile-install-batch') {
        include_once 'includes/batch.inc';
        $output = _batch_page();
    }
    // Import interface translations for the enabled modules.
    if ($task == 'locale-initial-import') {
        if (!empty($install_locale) && $install_locale != 'en') {
            include_once 'includes/locale.inc';
            // Enable installation language as default site language.
            locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE);
            // Collect files to import for this language.
            $batch = locale_batch_by_language($install_locale, '_install_locale_initial_batch_finished');
            if (!empty($batch)) {
                // Remember components we cover in this batch set.
                variable_set('install_locale_batch_components', $batch['#components']);
                // Start a batch, switch to 'locale-batch' task. We need to
                // set the variable here, because batch_process() redirects.
                variable_set('install_task', 'locale-initial-batch');
                batch_set($batch);
                batch_process($url, $url);
            }
        }
        // Found nothing to import or not foreign language, go to next task.
        $task = 'configure';
    }
    if ($task == 'locale-initial-batch') {
        include_once 'includes/batch.inc';
        include_once 'includes/locale.inc';
        $output = _batch_page();
    }
    if ($task == 'configure') {
        if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) {
            // Site already configured: This should never happen, means re-running
            // the installer, possibly by an attacker after the 'install_task' variable
            // got accidentally blown somewhere. Stop it now.
            install_already_done_error();
        }
        $form = drupal_get_form('install_configure_form', $url);
        if (!variable_get('site_name', FALSE) && !variable_get('site_mail', FALSE)) {
            // Not submitted yet: Prepare to display the form.
            $output = $form;
            drupal_set_title(st('Configure site'));
            // Warn about settings.php permissions risk
            $settings_dir = './' . conf_path();
            $settings_file = $settings_dir . '/settings.php';
            if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) {
                drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, please consult the <a href="@handbook_url">on-line handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/getting-started')), 'error');
            } else {
                drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file)));
            }
            // Add JavaScript validation.
            _user_password_dynamic_validation();
            drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module');
            // We add these strings as settings because JavaScript translation does not
            // work on install time.
            drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')), 'cleanURL' => array('success' => st('Your server has been successfully tested to support this feature.'), 'failure' => st('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.'), 'testing' => st('Testing clean URLs...'))), 'setting');
            drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    Drupal.cleanURLsInstallCheck();
    Drupal.setDefaultTimezone();
  });
}', 'inline');
            // Build menu to allow clean URL check.
            menu_rebuild();
        } else {
            $task = 'profile';
        }
    }
    // If found an unknown task or the 'profile' task, which is
    // reserved for profiles, hand over the control to the profile,
    // so it can run any number of custom tasks it defines.
    if (!in_array($task, install_reserved_tasks())) {
        $function = $profile . '_profile_tasks';
        if (function_exists($function)) {
            // The profile needs to run more code, maybe even more tasks.
            // $task is sent through as a reference and may be changed!
            $output = $function($task, $url);
        }
        // If the profile doesn't move on to a new task we assume
        // that it is done.
        if ($task == 'profile') {
            $task = 'profile-finished';
        }
    }
    // Profile custom tasks are done, so let the installer regain
    // control and proceed with importing the remaining translations.
    if ($task == 'profile-finished') {
        if (!empty($install_locale) && $install_locale != 'en') {
            include_once 'includes/locale.inc';
            // Collect files to import for this language. Skip components
            // already covered in the initial batch set.
            $batch = locale_batch_by_language($install_locale, '_install_locale_remaining_batch_finished', variable_get('install_locale_batch_components', array()));
            // Remove temporary variable.
            variable_del('install_locale_batch_components');
            if (!empty($batch)) {
                // Start a batch, switch to 'locale-remaining-batch' task. We need to
                // set the variable here, because batch_process() redirects.
                variable_set('install_task', 'locale-remaining-batch');
                batch_set($batch);
                batch_process($url, $url);
            }
        }
        // Found nothing to import or not foreign language, go to next task.
        $task = 'finished';
    }
    if ($task == 'locale-remaining-batch') {
        include_once 'includes/batch.inc';
        include_once 'includes/locale.inc';
        $output = _batch_page();
    }
    // Display a 'finished' page to user.
    if ($task == 'finished') {
        drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
        $messages = drupal_set_message();
        $output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>';
        $output .= '<p>' . (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>';
        $task = 'done';
    }
    // The end of the install process. Remember profile used.
    if ($task == 'done') {
        // Rebuild menu to get content type links registered by the profile,
        // and possibly any other menu items created through the tasks.
        menu_rebuild();
        // Register actions declared by any modules.
        actions_synchronize();
        // Randomize query-strings on css/js files, to hide the fact that
        // this is a new install, not upgraded yet.
        _drupal_flush_css_js();
        variable_set('install_profile', $profile);
    }
    // Set task for user, and remember the task in the database.
    install_task_list($task);
    variable_set('install_task', $task);
    // Output page, if some output was required. Otherwise it is possible
    // that we are printing a JSON page and theme output should not be there.
    if (isset($output)) {
        print theme('maintenance_page', $output);
    }
}
function guifi_user_form($form_state, $params = array())
{
    _user_password_dynamic_validation();
    guifi_log(GUIFILOG_TRACE, 'function guifi_user_form()', $form_state);
    guifi_validate_js("#guifi-user-form");
    if (empty($form_state['values'])) {
        if (is_numeric($params)) {
            $form_state['values'] = guifi_user_load($params);
        } else {
            $form_state['values'] = $params;
        }
    }
    if (isset($form_state['values']['id'])) {
        $f['id'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']);
        drupal_set_title(t('edit user') . ' ' . $form_state['values']['username']);
    } else {
        $f['new'] = array('#type' => 'hidden', '#value' => TRUE);
        drupal_set_title(t('add user') . ' @ ' . guifi_get_nodename($form_state['values']['nid']));
    }
    $f['firstname'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 128, '#title' => t('Firstname'), '#required' => TRUE, '#attributes' => array('class' => 'required'), '#default_value' => $form_state['values']['firstname'], '#description' => t('The real user name (Firstname), ' . 'will be used while building the username.<br />' . 'If username results duplicated, add more words ' . '(i.e. middle initial).<br />' . 'Please enter real data, if fake information is entered, ' . 'administrators might <strong>remove</strong> this user.'));
    $f['lastname'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 128, '#title' => t('Lastname'), '#required' => TRUE, '#attributes' => array('class' => 'required'), '#default_value' => $form_state['values']['lastname'], '#description' => t('The real user name (Lastname).'));
    if (!empty($form_state['values']['username'])) {
        $f['username'] = array('#type' => 'item', '#value' => $form_state['values']['username'], '#description' => t('The resulting username.'));
    }
    if (user_access('administer guifi users')) {
        $f['status'] = array('#type' => 'select', '#title' => t('Status'), '#options' => guifi_types('user_status'), '#default_value' => $form_state['values']['status']);
        $f['node'] = array('#type' => 'textfield', '#title' => t('Node'), '#maxlength' => 60, '#default_value' => $form_state['values']['nid'] . '-' . guifi_get_zone_nick(guifi_get_zone_of_node($form_state['values']['nid'])) . ', ' . guifi_get_nodename($form_state['values']['nid']), '#autocomplete_path' => 'guifi/js/select-node', '#element_validate' => array('guifi_nodename_validate'), '#description' => t('Select the node where the user is.<br />' . 'You can find the node by introducing part of the node id number, ' . 'zone name or node name. A list with all matching values ' . 'with a maximum of 50 values will be created.<br />' . 'You can refine the text to find your choice.'));
    } else {
        $f['status'] = array('#type' => 'item', '#title' => t('Status'), '#value' => $form_state['values']['status']);
        $f['node'] = array('#type' => 'item', '#title' => t('Node'), '#value' => $form_state['values']['nid'] . '-' . guifi_get_zone_nick(guifi_get_zone_of_node($form_state['values']['nid'])) . ', ' . guifi_get_nodename($form_state['values']['nid']));
        if (!isset($f['new'])) {
            $f['previous_pwd'] = array('#type' => 'password', '#title' => t('Current password'), '#description' => t('To proceed for any change, you have to ' . 'know the current password.'));
        }
        if (!isset($f['new'])) {
            $f['resetPwd'] = array('#type' => 'submit', '#value' => t('Reset password'));
        }
    }
    $f['nid'] = array('#type' => 'hidden', '#value' => $form_state['values']['nid']);
    $f['pass'] = array('#type' => 'password_confirm', '#required' => isset($f['new']), '#title' => t('Set a new password'), '#description' => t('To change/set the current user password, enter the new password in both fields.'), '#size' => 25);
    $f['notification'] = array('#type' => 'textfield', '#size' => 60, '#maxlength' => 1024, '#title' => t('contact'), '#required' => TRUE, '#element_validate' => array('guifi_emails_validate'), '#default_value' => $form_state['values']['notification'], '#description' => t('Mailid where changes on this user will be notified, ' . 'if many, separated by \',\'<br />' . 'Also where the user can be contacted.'));
    // services
    $f['services'] = array('#type' => 'fieldset', '#title' => t('services'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE);
    if (user_access('administer guifi users')) {
        $f['services']['proxystr'] = array('#type' => 'textfield', '#title' => t('proxy'), '#maxlength' => 60, '#default_value' => guifi_service_str($form_state['values']['services']['proxy']), '#autocomplete_path' => 'guifi/js/select-service/proxy', '#element_validate' => array('guifi_service_name_validate', 'guifi_user_proxy_validate'));
    } else {
        $f['services']['proxystr'] = array('#type' => 'item', '#title' => t('proxy'), '#value' => guifi_service_str($form_state['values']['services']['proxy']));
    }
    $f['services']['proxy'] = array('#type' => 'hidden', '#value' => $form_state['values']['services']['proxy']);
    $f['services']['filters'] = array('#type' => 'checkboxes', '#parents' => array('content_filters'), '#title' => t('content filters'), '#options' => guifi_types('filter'), '#multiple' => TRUE, '#description' => t('Content to be filtered.<br />Check the type of content ' . 'which will be filtered to this user. ' . 'Note that this filters will work only on those sites ' . 'which have enabled this feature, ' . 'so don\'t think that is safe to rely on this.'));
    if (!empty($form_state['values']['content_filters'])) {
        $f['services']['filters']['#default_value'] = $form_state['values']['content_filters'];
    }
    $f['author'] = array('#type' => 'fieldset', '#access' => user_access('administer guifi users'), '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $f['author']['username_created'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $form_state['values']['username_created'], '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))));
    $f['submit'] = array('#type' => 'submit', '#value' => t('Save'));
    if (!isset($f['new'])) {
        $f['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
    }
    return $f;
}