UUID support for syncing

pull/61/head
Christophe Vandeplas 2012-03-20 13:40:58 +01:00
parent 2c7f01f61e
commit 495cc1a6c2
12 changed files with 68 additions and 19 deletions

View File

@ -83,7 +83,8 @@ class EventsController extends AppController {
// force check userid and orgname to be from yourself // force check userid and orgname to be from yourself
$this->request->data['Event']['user_id'] = $this->Auth->user('id'); $this->request->data['Event']['user_id'] = $this->Auth->user('id');
$this->request->data['Event']['org'] = $this->Auth->user('org'); $this->request->data['Event']['org'] = $this->Auth->user('org');
$this->Event->create(); $this->request->data['Event']['uuid'] = String::uuid();
$this->Event->create();
if ($this->Event->save($this->request->data)) { if ($this->Event->save($this->request->data)) {
$this->Session->setFlash(__('The event has been saved')); $this->Session->setFlash(__('The event has been saved'));
$this->redirect(array('action' => 'view', $this->Event->getId())); $this->redirect(array('action' => 'view', $this->Event->getId()));
@ -126,7 +127,7 @@ class EventsController extends AppController {
$this->request->data['Event']['alerted'] = 0; $this->request->data['Event']['alerted'] = 0;
// say what fields are to be updated // say what fields are to be updated
$fieldList=array('user_id', 'org', 'date', 'risk', 'info', 'alerted'); $fieldList=array('user_id', 'org', 'date', 'risk', 'info', 'alerted', 'private');
if ($this->Event->save($this->request->data, true, $fieldList)) { if ($this->Event->save($this->request->data, true, $fieldList)) {
$this->Session->setFlash(__('The event has been saved')); $this->Session->setFlash(__('The event has been saved'));
$this->redirect(array('action' => 'view', $id)); $this->redirect(array('action' => 'view', $id));

View File

@ -61,7 +61,7 @@ class SignaturesController extends AppController {
$this->Signature->create(); $this->Signature->create();
$this->request->data['Signature']['value'] = $signature; // set the value as the content of the single line $this->request->data['Signature']['value'] = $signature; // set the value as the content of the single line
$this->request->data['Signature']['uuid'] = String::uuid();
if ($this->Signature->save($this->request->data)) { if ($this->Signature->save($this->request->data)) {
$successes .= " ".($key+1); $successes .= " ".($key+1);
} else { } else {
@ -89,6 +89,8 @@ class SignaturesController extends AppController {
// //
// create the signature // create the signature
$this->Signature->create(); $this->Signature->create();
$this->request->data['Signature']['uuid'] = String::uuid();
if ($this->Signature->save($this->request->data)) { if ($this->Signature->save($this->request->data)) {
// inform the user and redirect // inform the user and redirect
$this->Session->setFlash(__('The signature has been saved')); $this->Session->setFlash(__('The signature has been saved'));
@ -128,7 +130,7 @@ class SignaturesController extends AppController {
if ($this->Signature->save($this->request->data)) { if ($this->Signature->save($this->request->data)) {
$this->Session->setFlash(__('The signature has been saved')); $this->Session->setFlash(__('The signature has been saved'));
$this->redirect(array('action' => 'index')); $this->redirect($this->referer());
} else { } else {
$this->Session->setFlash(__('The signature could not be saved. Please, try again.')); $this->Session->setFlash(__('The signature could not be saved. Please, try again.'));
} }
@ -136,6 +138,11 @@ class SignaturesController extends AppController {
$this->request->data = $this->Signature->read(null, $id); $this->request->data = $this->Signature->read(null, $id);
} }
// combobox for types
$types = $this->Signature->validate['type']['rule'][1];
$types = $this->_arrayToValuesIndexArray($types);
$this->set('types',compact('types'));
} }
/** /**

View File

@ -271,7 +271,7 @@ class UsersController extends AppController {
// What org posted what type of signature // What org posted what type of signature
// LATER beautify types_histogram // LATER beautify types_histogram http://dev.sencha.com/deploy/ext-4.0.0/examples/charts/StackedBar.html
$this->loadModel('Signature'); $this->loadModel('Signature');
$fields = array('Event.org', 'Signature.type', 'count(Signature.type) as `num_types`'); $fields = array('Event.org', 'Signature.type', 'count(Signature.type) as `num_types`');
$params = array('recursive' => 0, $params = array('recursive' => 0,

View File

@ -87,6 +87,16 @@ class Event extends AppModel {
//'on' => 'create', // Limit validation to 'create' or 'update' operations //'on' => 'create', // Limit validation to 'create' or 'update' operations
), ),
), ),
'private' => array(
'boolean' => array(
'rule' => array('boolean'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
); );
//The Associations below have been created with all possible keys, those that are not needed can be removed //The Associations below have been created with all possible keys, those that are not needed can be removed

View File

@ -92,6 +92,26 @@ class Signature extends AppModel {
//'on' => 'create', // Limit validation to 'create' or 'update' operations //'on' => 'create', // Limit validation to 'create' or 'update' operations
), ),
), ),
'revision' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'private' => array(
'boolean' => array(
'rule' => array('boolean'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
); );
//The Associations below have been created with all possible keys, those that are not needed can be removed //The Associations below have been created with all possible keys, those that are not needed can be removed
@ -111,6 +131,16 @@ class Signature extends AppModel {
) )
); );
function beforeSave() {
// increment the revision number
if (empty($this->data['Signature']['revision'])) $this->data['Signature']['revision'] = 0;
$this->data['Signature']['revision'] = 1 + $this->data['Signature']['revision'] ;
// always return true after a beforeSave()
return true;
}
function validateSignatureValue ($fields) { function validateSignatureValue ($fields) {
$value = $fields['value']; $value = $fields['value'];
$event_id = $this->data['Signature']['event_id']; $event_id = $this->data['Signature']['event_id'];

View File

@ -6,7 +6,7 @@
echo $this->Form->input('date'); echo $this->Form->input('date');
echo $this->Form->input('risk'); echo $this->Form->input('risk');
echo $this->Form->input('info'); echo $this->Form->input('info');
?> ?>
</fieldset> </fieldset>
<?php echo $this->Form->end(__('Submit', true));?> <?php echo $this->Form->end(__('Submit', true));?>

View File

@ -13,9 +13,7 @@
</tr> </tr>
<?php <?php
foreach ($events as $event): foreach ($events as $event):
// FIXME reactivate the onclick without breaking the delete form submit
?> ?>
<!-- <tr onclick="document.location ='<?php echo $this->Html->url(array('action' => 'view', $event['Event']['id']), true) ;?>';" > -->
<tr> <tr>
<td onclick="document.location ='<?php echo $this->Html->url(array('action' => 'view', $event['Event']['id']), true) ;?>';"> <td onclick="document.location ='<?php echo $this->Html->url(array('action' => 'view', $event['Event']['id']), true) ;?>';">
<?php echo $this->Html->link($event['Event']['id'], array('controller' => 'events', 'action' => 'view', $event['Event']['id'])); ?> <?php echo $this->Html->link($event['Event']['id'], array('controller' => 'events', 'action' => 'view', $event['Event']['id'])); ?>
@ -64,6 +62,5 @@
<div class="actions"> <div class="actions">
<ul> <ul>
<?php echo $this->element('actions_menu'); ?> <?php echo $this->element('actions_menu'); ?>
</ul> </ul>
</div> </div>

View File

@ -40,6 +40,11 @@
<?php echo $event['Event']['risk']; ?> <?php echo $event['Event']['risk']; ?>
&nbsp; &nbsp;
</dd> </dd>
<!-- dt>UUID</dt>
<dd>
<?php echo $event['Event']['uuid']; ?>
&nbsp;
</dd -->
<dt>Info</dt> <dt>Info</dt>
<dd> <dd>
<?php echo nl2br(Sanitize::html($event['Event']['info'])); ?> <?php echo nl2br(Sanitize::html($event['Event']['info'])); ?>

View File

@ -16,14 +16,13 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
$cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework');
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<?php echo $this->Html->charset(); ?> <?php echo $this->Html->charset(); ?>
<title> <title>
<?php echo $cakeDescription ?>: CyDefSIG:
<?php echo $title_for_layout; ?> <?php echo $title_for_layout; ?>
</title> </title>
<?php <?php

View File

@ -4,21 +4,18 @@
<legend><?php echo __('Edit Signature'); ?></legend> <legend><?php echo __('Edit Signature'); ?></legend>
<?php <?php
echo $this->Form->input('id'); echo $this->Form->input('id');
echo $this->Form->input('event_id');
echo $this->Form->input('type'); echo $this->Form->input('type');
echo $this->Form->input('value'); echo $this->Form->input('value');
echo $this->Form->input('to_ids'); echo $this->Form->input('to_ids');
echo $this->Form->input('uuid');
?> ?>
</fieldset> </fieldset>
<?php echo $this->Form->end(__('Submit'));?> <?php echo $this->Form->end(__('Submit'));?>
</div> </div>
<div class="actions"> <div class="actions">
<ul> <ul>
<li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('Signature.id')), null, __('Are you sure you want to delete # %s?', $this->Form->value('Signature.id'))); ?></li>
<li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('Signature.id')), null, __('Are you sure you want to delete # %s?', $this->Form->value('Signature.id'))); ?></li> <li>&nbsp;</li>
<li><?php echo $this->Html->link(__('List Signatures'), array('action' => 'index'));?></li> <?php echo $this->element('actions_menu'); ?>
<li><?php echo $this->Html->link(__('List Events'), array('controller' => 'events', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Event'), array('controller' => 'events', 'action' => 'add')); ?> </li>
</ul> </ul>
</div> </div>

View File

@ -46,3 +46,6 @@
</ul> </ul>
</div> </div>
<div class="users index">
</div>

View File

@ -4,7 +4,7 @@
<p><b>Backend rewrite + security</b><br/> <p><b>Backend rewrite + security</b><br/>
Complete rewrite of the backend code to migrate to CakePHP 2.x (from CakePHP 1.3). <br/> Complete rewrite of the backend code to migrate to CakePHP 2.x (from CakePHP 1.3). <br/>
During this rewrite the code was cleaned up, CSRF protection should now be present on all the important actions.<br/> During this rewrite the code was cleaned up, CSRF protection should now be present on all the important actions.<br/>
Password strength validation, anti-bruteforce has been implemented.<br/> Password strength validation has been implemented.<br/>
Some intermittent bugs might have slipped in during the (manual) conversion. Please contact me <a href="mailto:user1088@qet.be">user1088@qet.be</a> to report any issues. Some intermittent bugs might have slipped in during the (manual) conversion. Please contact me <a href="mailto:user1088@qet.be">user1088@qet.be</a> to report any issues.
</p> </p>
<p><b>Terms and News</b><br/> <p><b>Terms and News</b><br/>