coding standards

Coding Standards.
pull/63/head
Noud de Brouwer 2013-01-25 12:58:19 +00:00
parent 6afc1e993f
commit 940df96aa5
2 changed files with 265 additions and 265 deletions

View File

@ -1,124 +1,124 @@
<div class="attributes form"> <div class="attributes form">
<?php echo $this->Form->create('Attribute');?> <?php echo $this->Form->create('Attribute');?>
<fieldset> <fieldset>
<legend><?php echo __('Add Attribute'); ?></legend> <legend><?php echo __('Add Attribute'); ?></legend>
<?php <?php
echo $this->Form->hidden('event_id'); echo $this->Form->hidden('event_id');
echo $this->Form->input('category', array( echo $this->Form->input('category', array(
'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeCategoryDiv')), 'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeCategoryDiv')),
'empty' => '(choose one)' 'empty' => '(choose one)'
)); ));
echo $this->Form->input('type', array( echo $this->Form->input('type', array(
'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeTypeDiv')), 'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeTypeDiv')),
'empty' => '(first choose category)' 'empty' => '(first choose category)'
)); ));
if ('true' == Configure::read('CyDefSIG.sync')) { if ('true' == Configure::read('CyDefSIG.sync')) {
if ('true' == Configure::read('CyDefSIG.private')) { if ('true' == Configure::read('CyDefSIG.private')) {
echo $this->Form->input('distribution', array('label' => 'Distribution', 'selected' => $maxDist, echo $this->Form->input('distribution', array('label' => 'Distribution', 'selected' => $maxDist,
'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeDistributionDiv')) 'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeDistributionDiv'))
)); ));
} else { } else {
echo $this->Form->input('private', array( echo $this->Form->input('private', array(
'before' => $this->Html->div('forminfo', isset($attrDescriptions['private']['formdesc']) ? $attrDescriptions['private']['formdesc'] : $attrDescriptions['private']['desc']), 'before' => $this->Html->div('forminfo', isset($attrDescriptions['private']['formdesc']) ? $attrDescriptions['private']['formdesc'] : $attrDescriptions['private']['desc']),
)); ));
} }
} }
echo $this->Form->input('to_ids', array( echo $this->Form->input('to_ids', array(
'checked' => true, 'checked' => true,
'before' => $this->Html->div('forminfo', isset($attrDescriptions['signature']['formdesc']) ? $attrDescriptions['signature']['formdesc'] : $attrDescriptions['signature']['desc']), 'before' => $this->Html->div('forminfo', isset($attrDescriptions['signature']['formdesc']) ? $attrDescriptions['signature']['formdesc'] : $attrDescriptions['signature']['desc']),
'label' => 'IDS Signature?' 'label' => 'IDS Signature?'
)); ));
echo $this->Form->input('value', array( echo $this->Form->input('value', array(
'type' => 'textarea', 'type' => 'textarea',
'error' => array('escape' => false), 'error' => array('escape' => false),
)); ));
echo $this->Form->input('batch_import', array( echo $this->Form->input('batch_import', array(
'type' => 'checkbox', 'type' => 'checkbox',
'after' => $this->Html->div('forminfo', 'Create multiple attributes one per line'), 'after' => $this->Html->div('forminfo', 'Create multiple attributes one per line'),
)); ));
// link an onchange event to the form elements // link an onchange event to the form elements
$this->Js->get('#AttributeCategory')->event('change', 'formCategoryChanged("#AttributeCategory")'); $this->Js->get('#AttributeCategory')->event('change', 'formCategoryChanged("#AttributeCategory")');
$this->Js->get('#AttributeType')->event('change', 'showFormInfo("#AttributeType")'); $this->Js->get('#AttributeType')->event('change', 'showFormInfo("#AttributeType")');
$this->Js->get('#AttributeDistribution')->event('change', 'showFormInfo("#AttributeDistribution")'); $this->Js->get('#AttributeDistribution')->event('change', 'showFormInfo("#AttributeDistribution")');
?> ?>
</fieldset> </fieldset>
<?php echo $this->Form->end(__('Submit'));?> <?php echo $this->Form->end(__('Submit'));?>
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<?php echo $this->element('actions_menu'); ?> <?php echo $this->element('actions_menu'); ?>
</ul> </ul>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
// //
//Generate Category / Type filtering array //Generate Category / Type filtering array
// //
var category_type_mapping = new Array(); var category_type_mapping = new Array();
<?php <?php
foreach ($categoryDefinitions as $category => $def) { foreach ($categoryDefinitions as $category => $def) {
echo "category_type_mapping['" . addslashes($category) . "'] = {"; echo "category_type_mapping['" . addslashes($category) . "'] = {";
$first = true; $first = true;
foreach ($def['types'] as $type) { foreach ($def['types'] as $type) {
if ($first) $first = false; if ($first) $first = false;
else echo ', '; else echo ', ';
echo "'" . addslashes($type) . "' : '" . addslashes($type) . "'"; echo "'" . addslashes($type) . "' : '" . addslashes($type) . "'";
} }
echo "}; \n"; echo "}; \n";
} }
?> ?>
function formCategoryChanged(id) { function formCategoryChanged(id) {
showFormInfo(id); // display the tooltip showFormInfo(id); // display the tooltip
// fill in the types // fill in the types
var options = $('#AttributeType').prop('options'); var options = $('#AttributeType').prop('options');
$('option', $('#AttributeType')).remove(); $('option', $('#AttributeType')).remove();
$.each(category_type_mapping[$('#AttributeCategory').val()], function(val, text) { $.each(category_type_mapping[$('#AttributeCategory').val()], function(val, text) {
options[options.length] = new Option(text, val); options[options.length] = new Option(text, val);
}); });
// enable the form element // enable the form element
$('#AttributeType').prop('disabled', false); $('#AttributeType').prop('disabled', false);
} }
// //
// Generate tooltip information // Generate tooltip information
// //
var formInfoValues = new Array(); var formInfoValues = new Array();
<?php <?php
foreach ($typeDefinitions as $type => $def) { foreach ($typeDefinitions as $type => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc']; $info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes
} }
foreach ($categoryDefinitions as $category => $def) { foreach ($categoryDefinitions as $category => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc']; $info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['" . addslashes($category) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes echo "formInfoValues['" . addslashes($category) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes
} }
foreach ($distributionDescriptions as $type => $def) { foreach ($distributionDescriptions as $type => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc']; $info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes
} }
?> ?>
function showFormInfo(id) { function showFormInfo(id) {
idDiv = id+'Div'; idDiv = id+'Div';
// LATER use nice animations // LATER use nice animations
//$(idDiv).hide('fast'); //$(idDiv).hide('fast');
// change the content // change the content
var value = $(id).val(); // get the selected value var value = $(id).val(); // get the selected value
$(idDiv).html(formInfoValues[value]); // search in a lookup table $(idDiv).html(formInfoValues[value]); // search in a lookup table
// show it again // show it again
$(idDiv).fadeIn('slow'); $(idDiv).fadeIn('slow');
} }
// hide the formInfo things // hide the formInfo things
$('#AttributeTypeDiv').hide(); $('#AttributeTypeDiv').hide();
$('#AttributeCategoryDiv').hide(); $('#AttributeCategoryDiv').hide();
$('#AttributeType').prop('disabled', true); $('#AttributeType').prop('disabled', true);
$('#AttributeDistributionDiv').hide(); $('#AttributeDistributionDiv').hide();
</script> </script>
<?php echo $this->Js->writeBuffer(); // Write cached scripts <?php echo $this->Js->writeBuffer(); // Write cached scripts

View File

@ -1,143 +1,143 @@
<div class="attributes form"> <div class="attributes form">
<?php echo $this->Form->create('Attribute', array('enctype' => 'multipart/form-data','onSubmit' => 'document.getElementById("AttributeMalware").removeAttribute("disabled");'));?> <?php echo $this->Form->create('Attribute', array('enctype' => 'multipart/form-data','onSubmit' => 'document.getElementById("AttributeMalware").removeAttribute("disabled");'));?>
<fieldset> <fieldset>
<legend><?php echo __('Add Attachment'); ?></legend> <legend><?php echo __('Add Attachment'); ?></legend>
<?php <?php
echo $this->Form->hidden('event_id'); echo $this->Form->hidden('event_id');
echo $this->Form->input('category', array('between' => $this->Html->div('forminfo', '', array('id' => 'AttributeCategoryDiv')))); echo $this->Form->input('category', array('between' => $this->Html->div('forminfo', '', array('id' => 'AttributeCategoryDiv'))));
echo $this->Form->file('value', array( echo $this->Form->file('value', array(
'error' => array('escape' => false), 'error' => array('escape' => false),
)); ));
echo $this->Form->input('malware', array( echo $this->Form->input('malware', array(
'type' => 'checkbox', 'type' => 'checkbox',
'checked' => false, 'checked' => false,
'after' => '<br>Tick this box to neutralize the sample. Every malware sample will be zipped with the password "infected"', 'after' => '<br>Tick this box to neutralize the sample. Every malware sample will be zipped with the password "infected"',
)); ));
if ('true' == Configure::read('CyDefSIG.sync')) { if ('true' == Configure::read('CyDefSIG.sync')) {
if ('true' == Configure::read('CyDefSIG.private')) { if ('true' == Configure::read('CyDefSIG.private')) {
echo $this->Form->input('distribution', array('label' => 'Distribution', 'selected' => $maxDist, echo $this->Form->input('distribution', array('label' => 'Distribution', 'selected' => $maxDist,
'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeDistributionDiv')) 'between' => $this->Html->div('forminfo', '', array('id' => 'AttributeDistributionDiv'))
)); ));
//'before' => $this->Html->div('forminfo', isset($attrDescriptions['distribution']['formdesc']) ? $attrDescriptions['distribution']['formdesc'] : $attrDescriptions['distribution']['desc']),)); //'before' => $this->Html->div('forminfo', isset($attrDescriptions['distribution']['formdesc']) ? $attrDescriptions['distribution']['formdesc'] : $attrDescriptions['distribution']['desc']),));
} else { } else {
echo $this->Form->input('private', array( echo $this->Form->input('private', array(
'before' => $this->Html->div('forminfo', isset($attrDescriptions['private']['formdesc']) ? $attrDescriptions['private']['formdesc'] : $attrDescriptions['private']['desc']),)); 'before' => $this->Html->div('forminfo', isset($attrDescriptions['private']['formdesc']) ? $attrDescriptions['private']['formdesc'] : $attrDescriptions['private']['desc']),));
} }
} }
// link an onchange event to the form elements // link an onchange event to the form elements
$this->Js->get('#AttributeType')->event('change', 'showFormInfo("#AttributeType")'); $this->Js->get('#AttributeType')->event('change', 'showFormInfo("#AttributeType")');
$this->Js->get('#AttributeCategory')->event('change', 'showFormInfo("#AttributeCategory")'); $this->Js->get('#AttributeCategory')->event('change', 'showFormInfo("#AttributeCategory")');
$this->Js->get('#AttributeDistribution')->event('change', 'showFormInfo("#AttributeDistribution")'); $this->Js->get('#AttributeDistribution')->event('change', 'showFormInfo("#AttributeDistribution")');
?> ?>
</fieldset> </fieldset>
<?php echo $this->Form->end(__('Upload'));?> <?php echo $this->Form->end(__('Upload'));?>
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<?php echo $this->element('actions_menu'); ?> <?php echo $this->element('actions_menu'); ?>
</ul> </ul>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var formInfoValues = new Array(); var formInfoValues = new Array();
<?php <?php
foreach ($categoryDefinitions as $category => $def) { foreach ($categoryDefinitions as $category => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc']; $info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['$category'] = \"$info\";\n"; echo "formInfoValues['$category'] = \"$info\";\n";
} }
foreach ($distributionDescriptions as $type => $def) { foreach ($distributionDescriptions as $type => $def) {
$info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc']; $info = isset($def['formdesc']) ? $def['formdesc'] : $def['desc'];
echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes echo "formInfoValues['" . addslashes($type) . "'] = \"" . addslashes($info) . "\";\n"; // as we output JS code we need to add slashes
} }
?> ?>
var formZipTypeValues = new Array(); var formZipTypeValues = new Array();
<?php <?php
foreach ($categoryDefinitions as $category => $def) { foreach ($categoryDefinitions as $category => $def) {
$types = $def['types']; $types = $def['types'];
$alreadySet = false; $alreadySet = false;
foreach ($types as $type) { foreach ($types as $type) {
if (in_array($type, $zippedDefinitions) && !$alreadySet) { if (in_array($type, $zippedDefinitions) && !$alreadySet) {
$alreadySet = true; $alreadySet = true;
echo "formZipTypeValues['$category'] = \"true\";\n"; echo "formZipTypeValues['$category'] = \"true\";\n";
} }
} }
if (!$alreadySet) { if (!$alreadySet) {
echo "formZipTypeValues['$category'] = \"false\";\n"; echo "formZipTypeValues['$category'] = \"false\";\n";
} }
} }
?> ?>
var formAttTypeValues = new Array(); var formAttTypeValues = new Array();
<?php <?php
foreach ($categoryDefinitions as $category => $def) { foreach ($categoryDefinitions as $category => $def) {
$types = $def['types']; $types = $def['types'];
$alreadySet = false; $alreadySet = false;
foreach ($types as $type) { foreach ($types as $type) {
if (in_array($type, $uploadDefinitions) && !$alreadySet) { if (in_array($type, $uploadDefinitions) && !$alreadySet) {
$alreadySet = true; $alreadySet = true;
echo "formAttTypeValues['$category'] = \"true\";\n"; echo "formAttTypeValues['$category'] = \"true\";\n";
} }
} }
if (!$alreadySet) { if (!$alreadySet) {
echo "formAttTypeValues['$category'] = \"false\";\n"; echo "formAttTypeValues['$category'] = \"false\";\n";
} }
} }
?> ?>
function showFormType(id) { function showFormType(id) {
idDiv = id+'Div'; idDiv = id+'Div';
// LATER use nice animations // LATER use nice animations
//$(idDiv).hide('fast'); //$(idDiv).hide('fast');
// change the content // change the content
var value = $(id).val(); // get the selected value var value = $(id).val(); // get the selected value
//$(idDiv).html(formInfoValues[value]); // search in a lookup table //$(idDiv).html(formInfoValues[value]); // search in a lookup table
// do checkbox un/ticked when the document is changed // do checkbox un/ticked when the document is changed
if (formZipTypeValues[value] == "true") { if (formZipTypeValues[value] == "true") {
document.getElementById("AttributeMalware").setAttribute("checked", "checked"); document.getElementById("AttributeMalware").setAttribute("checked", "checked");
if (formAttTypeValues[value] == "false") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled"); if (formAttTypeValues[value] == "false") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled");
else document.getElementById("AttributeMalware").removeAttribute("disabled"); else document.getElementById("AttributeMalware").removeAttribute("disabled");
} else { } else {
document.getElementById("AttributeMalware").removeAttribute("checked"); document.getElementById("AttributeMalware").removeAttribute("checked");
if (formAttTypeValues[value] == "true") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled"); if (formAttTypeValues[value] == "true") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled");
else document.getElementById("AttributeMalware").removeAttribute("disabled"); else document.getElementById("AttributeMalware").removeAttribute("disabled");
} }
} }
function showFormInfo(id) { function showFormInfo(id) {
idDiv = id+'Div'; idDiv = id+'Div';
// LATER use nice animations // LATER use nice animations
//$(idDiv).hide('fast'); //$(idDiv).hide('fast');
// change the content // change the content
var value = $(id).val(); // get the selected value var value = $(id).val(); // get the selected value
$(idDiv).html(formInfoValues[value]); // search in a lookup table $(idDiv).html(formInfoValues[value]); // search in a lookup table
// show it again // show it again
$(idDiv).fadeIn('slow'); $(idDiv).fadeIn('slow');
// do checkbox un/ticked when the document is changed // do checkbox un/ticked when the document is changed
if (formZipTypeValues[value] == "true") { if (formZipTypeValues[value] == "true") {
document.getElementById("AttributeMalware").setAttribute("checked", "checked"); document.getElementById("AttributeMalware").setAttribute("checked", "checked");
if (formAttTypeValues[value] == "false") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled"); if (formAttTypeValues[value] == "false") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled");
else document.getElementById("AttributeMalware").removeAttribute("disabled"); else document.getElementById("AttributeMalware").removeAttribute("disabled");
} else { } else {
document.getElementById("AttributeMalware").removeAttribute("checked"); document.getElementById("AttributeMalware").removeAttribute("checked");
if (formAttTypeValues[value] == "true") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled"); if (formAttTypeValues[value] == "true") document.getElementById("AttributeMalware").setAttribute("disabled", "disabled");
else document.getElementById("AttributeMalware").removeAttribute("disabled"); else document.getElementById("AttributeMalware").removeAttribute("disabled");
} }
} }
// hide the formInfo things // hide the formInfo things
$('#AttributeTypeDiv').hide(); $('#AttributeTypeDiv').hide();
$('#AttributeCategoryDiv').hide(); $('#AttributeCategoryDiv').hide();
$(function(){ $(function(){
// do checkbox un/ticked when the document is ready // do checkbox un/ticked when the document is ready
showFormType("#AttributeCategory"); showFormType("#AttributeCategory");
} }
); );
//hide the formInfo things //hide the formInfo things
$('#AttributeDistributionDiv').hide(); $('#AttributeDistributionDiv').hide();
</script> </script>
<?php echo $this->Js->writeBuffer(); // Write cached scripts <?php echo $this->Js->writeBuffer(); // Write cached scripts