Commit 4f8cc180 authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Initial code for edit/add on all forms

parent a20d5a84
......@@ -40,6 +40,54 @@
$app->render('edit-server.tpl', $smarty_data);
});
$app->post('/edit-server', $isauthenticated(), function() use ($app) {
$req = $app->request();
// Retrieve parameters from the form
// TODO : These need to be validated
$id = $req->params('id');
$server_ip = ip2long($req->params('server_ip'));
$ssh_key = $req->params('ssh_key');
$gpg_key = $req->params('gpg_key');
$ssh_username = $req->params('ssh_username');
$config_dir = $req->params('config_dir');
$output_dir = $req->params('output_dir');
$contact_frequency = $req->params('contact_frequency');
$description = $req->params('description');
if ($req->params('disabled')) {
$disabled = 1;
} else {
$disabled = 0;
}
// Insert/Update array
$rowArray = array(
'server_ip' => $server_ip,
'ssh_key' => $ssh_key,
'gpg_key' => $gpg_key,
'ssh_username' => $ssh_username,
'config_dir' => $config_dir,
'output_dir' => $output_dir,
'contact_frequency' => $contact_frequency,
'disabled' => $disabled,
'description' => $description,
'last_modified' => null
);
if ($id) {
$app->db->table('cloud')
->where('id', $id)
->update($rowArray);
} else {
$app->db->table('cloud')
->insert($rowArray);
}
//$smarty_data['querylog'] = $app->db->connection()->getQueryLog();
$app->flash('success', 'Form Submitted');
$app->redirect('/servers');
});
// Edit Target Item
$app->get('/edit-target', $isauthenticated(), function () use ($app) {
global $smarty_data;
......@@ -63,6 +111,44 @@
$app->render('edit-target.tpl', $smarty_data);
});
$app->post('/edit-target', $isauthenticated(), function() use ($app) {
$req = $app->request();
// Retrieve parameters from the form
// TODO : These need to be validated
$id = $req->params('id');
$address = ip2long($req->params('address'));
$cidr = $req->params('cidr');
$description = $req->params('description');
if ($req->params('disabled')) {
$disabled = 1;
} else {
$disabled = 0;
}
// Insert/Update array
$rowArray = array(
'address' => $address,
'cidr' => $cidr,
'disabled' => $disabled,
'description' => $description,
'last_modified' => null
);
if ($id) {
$app->db->table('target')
->where('id', $id)
->update($rowArray);
} else {
$app->db->table('target')
->insert($rowArray);
}
//$smarty_data['querylog'] = $app->db->connection()->getQueryLog();
$app->flash('success', 'Form Submitted');
$app->redirect('/targets');
});
// Edit Scan Type Item
$app->get('/edit-scantype', $isauthenticated(), function () use ($app) {
global $smarty_data;
......@@ -87,6 +173,48 @@
$app->render('edit-scantype.tpl', $smarty_data);
});
$app->post('/edit-scantype', $isauthenticated(), function() use ($app) {
$req = $app->request();
// Retrieve parameters from the form
// TODO : These need to be validated
$id = $req->params('id');
$options = $req->params('options');
$description = $req->params('description');
if ($req->params('override')) {
$override = 1;
} else {
$override = 0;
}
if ($req->params('disabled')) {
$disabled = 1;
} else {
$disabled = 0;
}
// Insert/Update array
$rowArray = array(
'options' => $options,
'override' => $override,
'disabled' => $disabled,
'description' => $description,
'last_modified' => null
);
if ($id) {
$app->db->table('spawn')
->where('id', $id)
->update($rowArray);
} else {
$app->db->table('spawn')
->insert($rowArray);
}
//$smarty_data['querylog'] = $app->db->connection()->getQueryLog();
$app->flash('success', 'Form Submitted');
$app->redirect('/scantypes');
});
// Edit Schedule Item
$app->get('/edit-schedule', $isauthenticated(), function () use ($app) {
global $smarty_data;
......@@ -111,4 +239,51 @@
$app->render('edit-schedule.tpl', $smarty_data);
});
$app->post('/edit-schedule', $isauthenticated(), function() use ($app) {
$req = $app->request();
// Retrieve parameters from the form
// TODO : These need to be validated
$id = $req->params('id');
$cloud_id = $req->params('cloud_id');
$spawn_id = $req->params('spawn_id');
$target_id = $req->params('target_id');
$hour = $req->params('hour');
$minute = $req->params('minute');
$day = $req->params('day');
$month = $req->params('month');
$description = $req->params('description');
if ($req->params('disabled')) {
$disabled = 1;
} else {
$disabled = 0;
}
// Insert/Update array
$rowArray = array(
'cloud_id' => $cloud_id,
'spawn_id' => $spawn_id,
'target_id' => $target_id,
'hour' => $hour,
'minute' => $minute,
'day' => $day,
'month' => $month,
'disabled' => $disabled,
'description' => $description,
'last_modified' => null
);
if ($id) {
$app->db->table('timers')
->where('id', $id)
->update($rowArray);
} else {
$app->db->table('timers')
->insert($rowArray);
}
//$smarty_data['querylog'] = $app->db->connection()->getQueryLog();
$app->flash('success', 'Form Submitted');
$app->redirect('/schedule');
});
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment