forked from hugowetterberg/sshkey
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sshkey.admin.inc
67 lines (57 loc) · 2.09 KB
/
sshkey.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
function sshkey_settings_form() {
$form = array();
$form['sshkey_key_directory'] = array(
'#type' => 'textfield',
'#title' => t('Key directory'),
'#description' => t('The directory in the filesystem that is used to store public keys.'),
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => sshkey_get_key_directory(),
);
$form['sshkey_ssh_vulnkey'] = array(
'#type' => 'textfield',
'#title' => t('Vulnerable key check'),
'#description' => t('The path to ssh-vulnkey that can check a key against a blacklist of compromised keys, make sure that you\'ve installed openssh-blacklist.'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => variable_get('sshkey_ssh_vulnkey', ''),
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function sshkey_settings_form_validate(&$form, $form_state) {
$values = $form_state['values'];
if (file_exists($values['sshkey_key_directory'])) {
if (!is_writable($values['sshkey_key_directory'])) {
form_set_error('sshkey_key_directory', t('The key directory is not writeable'));
}
}
else {
if (!mkdir($values['sshkey_key_directory'])) {
form_set_error('sshkey_key_directory', t('The key directory doesn\'t exist and cannot be created automatically.'));
}
else {
drupal_set_message(t('The directory @dir has been created', array(
'@dir' => $values['sshkey_key_directory'],
)));
}
}
if (!empty($values['sshkey_ssh_vulnkey'])) {
if (!file_exists($values['sshkey_ssh_vulnkey'])) {
form_set_error('sshkey_ssh_vulnkey', t('The ssh-vulnkey executable doesn\'t exist'));
}
else if (!is_executable($values['sshkey_ssh_vulnkey'])) {
form_set_error('sshkey_ssh_vulnkey', t('The ssh-vulnkey executable isn\'t executable'));
}
}
}
function sshkey_settings_form_submit($form, $form_state) {
$values = $form_state['values'];
variable_set('sshkey_ssh_vulnkey', $values['sshkey_ssh_vulnkey']);
variable_set('sshkey_key_directory', $values['sshkey_key_directory']);
}