View source
<?php
function drd_agent_settings($form, $form_state) {
$form['drd_agent_debug_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Debug mode'),
'#default_value' => variable_get('drd_agent_debug_mode', FALSE),
);
return system_settings_form($form);
}
function drd_agent_setup($values) {
$values = _drd_agent_setup_decode($values);
$authorised = variable_get('drd_agent_authorised', array());
$values['timestamp'] = REQUEST_TIME;
$values['ip'] = ip_address();
$authorised[$values['uuid']] = $values;
variable_set('drd_agent_authorised', $authorised);
return $values;
}
function drd_agent_authorize($form, $form_state) {
if (empty($_SESSION['drd_agent_authorization_values'])) {
$form['token'] = array(
'#type' => 'textarea',
'#title' => t('Authentication token'),
'#description' => t('Paste the token for this domain from the DRD dashboard, which you want to authorize.'),
'#default_value' => '',
'#required' => TRUE,
);
$submit = t('Validate');
}
else {
$form['attention'] = array(
'#markup' => t('You are about to grant admin access to the Drupal Remote Dashboard on the following domain:'),
'#prefix' => '<div>',
'#suffix' => '</div>',
);
$form['domain'] = array(
'#markup' => _drd_agent_get_domain($_SESSION['drd_agent_authorization_values']),
'#prefix' => '<div class="domain">',
'#suffix' => '</div>',
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
);
$submit = t('Grant admin access');
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => $submit,
);
$form['#attributes'] = array(
'class' => array(
'drd-agent-auth',
),
);
drupal_add_css(drupal_get_path('module', 'drd_agent') . '/drd_agent.css');
return $form;
}
function drd_agent_authorize_submit($form, &$form_state) {
if (empty($_SESSION['drd_agent_authorization_values'])) {
$_SESSION['drd_agent_authorization_values'] = $form_state['values']['token'];
}
else {
if ($form_state['values']['op'] == $form['submit']['#value']) {
$values = drd_agent_setup($_SESSION['drd_agent_authorization_values']);
$form_state['redirect'] = $values['redirect'];
}
unset($_SESSION['drd_agent_authorization_values']);
}
}
function _drd_agent_setup_decode($values) {
$values = strtr($values, array(
'-' => '+',
'_' => '/',
));
return json_decode(base64_decode($values), TRUE);
}
function _drd_agent_get_domain($values) {
$values = _drd_agent_setup_decode($values);
return parse_url($values['redirect'], PHP_URL_HOST);
}