Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ability to add/delete servers

  • Loading branch information...
commit bd5afd8ed335e44dbde10902a6e78fdf2f9e5fb4 1 parent d9c2a17
@lattera lattera authored
View
24 sites/all/modules/wayfair/vulnscan/helpers.inc
@@ -0,0 +1,24 @@
+<?php
+
+function get_all_servers() {
+ return db_query('SELECT * FROM {vulnscan_server}');
+}
+
+function get_all_servers_assoc() {
+ $servers = array();
+ $result = get_all_servers();
+
+ foreach ($result as $record)
+ $servers[$record->name] = $record->name;
+
+ return $servers;
+}
+
+function delete_servers($servers = array()) {
+ /* $servers array needs to be an associative array (e.g. array('servername' => 'servername') */
+ foreach ($servers as $key => $value) {
+ db_delete('vulnscan_server')
+ ->condition('name', $value)
+ ->execute();
+ }
+}
View
41 sites/all/modules/wayfair/vulnscan/vulnscan.admin.inc
@@ -1,6 +1,10 @@
<?php
+require_once('helpers.inc');
+
function vulnscan_admin_settings($form, &$form_state) {
+ $servers = get_all_servers_assoc();
+
/* Main settings */
$form['vulnscan_skipfish_settings'] = array(
'#type' => 'fieldset',
@@ -24,10 +28,20 @@ function vulnscan_admin_settings($form, &$form_state) {
'#collapsed' => FALSE,
);
- $form['vulnscan_server_settings']['servers'] = array(
- '#type' => 'select',
- '#title' => t('Existing Servers'),
- '#options' => array('None' => t('None')),
+ if (count($servers) > 0) {
+ $form['vulnscan_server_settings']['servers'] = array(
+ '#type' => 'select',
+ '#title' => t('Existing Servers'),
+ '#multiple' => TRUE,
+ '#description' => 'Select one or more servers to delete upon saving the form.',
+ '#options' => $servers,
+ );
+ }
+
+ $form['vulnscan_server_settings']['new_server'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Add a New Server'),
+ '#size' => 30
);
$form['submit'] = array(
@@ -40,4 +54,23 @@ function vulnscan_admin_settings($form, &$form_state) {
function vulnscan_admin_settings_submit($form, &$form_state) {
variable_set('vulnscan_skipfish_location', $form_state['values']['skipfish_location']);
+
+ /* Save the new server */
+ if (isset($form_state['values']['new_server']) && strlen($form_state['values']['new_server'])) {
+ $name = strtoupper($form_state['values']['new_server']);
+ $servers = get_all_servers_assoc();
+
+ if (array_key_exists($name, $servers)) {
+ form_set_error('new_server', t('Server @server already exists.', array('@server' => $name)));
+ } else {
+ db_insert('vulnscan_server')->fields(array(
+ 'name' => $name
+ ))->execute();
+ }
+ }
+
+ /* Delete selected servers */
+ if (isset($form_state['values']['servers'])) {
+ delete_servers(array_filter($form_state['values']['servers']));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.