summaryrefslogtreecommitdiff
path: root/backend
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2012-02-11 23:48:42 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2012-02-11 23:48:42 (UTC)
commita0661c3b02aa26d6b08ff13dc321e09478868159 (patch) (unidiff)
tree87bd0af25a0732adb9d14a34d25f9d5479fdf5ee /backend
parent96d01919d3ff42c3fdd7f6186a0500caccd3c140 (diff)
parent7804333809bf725e32a08c531a06acd7d668e190 (diff)
downloadclipperz-a0661c3b02aa26d6b08ff13dc321e09478868159.zip
clipperz-a0661c3b02aa26d6b08ff13dc321e09478868159.tar.gz
clipperz-a0661c3b02aa26d6b08ff13dc321e09478868159.tar.bz2
Merge pull request #25 from gcsolaroli/master
Initial integration of /beta and /gamma with a single backend
Diffstat (limited to 'backend') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/properties/php.properties.json7
-rw-r--r--backend/php/src/configuration.php6
-rw-r--r--backend/php/src/index.php189
-rw-r--r--backend/python/properties/python.properties.json8
4 files changed, 193 insertions, 17 deletions
diff --git a/backend/php/properties/php.properties.json b/backend/php/properties/php.properties.json
index 32d5084..8ce703a 100644
--- a/backend/php/properties/php.properties.json
+++ b/backend/php/properties/php.properties.json
@@ -1,4 +1,9 @@
1{ 1{
2 "request.path": "../index.php", 2 "request.path": "index.php",
3 "should.pay.toll": "false" 3 "should.pay.toll": "false"
4
5 "development.settings": {
6 "url": "http://localhost/php/clipperz"
7 }
8
4} \ No newline at end of file 9} \ No newline at end of file
diff --git a/backend/php/src/configuration.php b/backend/php/src/configuration.php
index 291e3a1..85f680e 100644
--- a/backend/php/src/configuration.php
+++ b/backend/php/src/configuration.php
@@ -17,8 +17,8 @@ $configuration['db_encoding'] = 0;
17// edit the information below to match your database settings 17// edit the information below to match your database settings
18 18
19 $configuration['db'] = 'clipperz'; //database name 19 $configuration['db'] = 'clipperz'; //database name
20 $configuration['host'] = 'localhost'; //database host 20 $configuration['host'] = 'localhost'; //database host
21 $configuration['user'] = 'root'; //database user 21 $configuration['user'] = 'clipperz'; //database user
22 $configuration['pass'] = 'pass'; //database password 22 $configuration['pass'] = 'clipperz'; //database password
23 $configuration['port'] = '3306'; //database port 23 $configuration['port'] = '3306'; //database port
24 24
diff --git a/backend/php/src/index.php b/backend/php/src/index.php
index 214ac01..da7c60c 100644
--- a/backend/php/src/index.php
+++ b/backend/php/src/index.php
@@ -141,5 +141,7 @@ function updateUserData($parameters, &$user) {
141 $user->statistics =$parameters["statistics"]; 141 $user->statistics =$parameters["statistics"];
142 $user->version =$parameters["version"]; 142 $user->version =$parameters["version"];
143 $user->lock = $parameters["lock"]; 143 if (array_key_exists("lock", $parameters)) {
144 $user->lock = $parameters["lock"];
145 }
144} 146}
145 147
@@ -154,5 +156,7 @@ function updateRecordData($parameters, &$record, &$recordVersion) {
154 $recordVersion->data = $recordVersionData ["data"]; 156 $recordVersion->data = $recordVersionData ["data"];
155 $recordVersion->version = $recordVersionData ["version"]; 157 $recordVersion->version = $recordVersionData ["version"];
156 $recordVersion->previous_version_id =$recordVersionData ["previousVersion"]; 158 if (array_key_exists("previousVersion", $recordVersionData)) {
159 $recordVersion->previous_version_id =$recordVersionData ["previousVersion"];
160 }
157 $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"]; 161 $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"];
158} 162}
@@ -366,4 +370,5 @@ error_log("oneTimePassword");
366 case "message": 370 case "message":
367error_log("message"); 371error_log("message");
372//error_log("message: ".json_encode($parameters));
368 if ($parameters["srpSharedSecret"] == $_SESSION["K"]) { 373 if ($parameters["srpSharedSecret"] == $_SESSION["K"]) {
369 $message = $parameters["message"]; 374 $message = $parameters["message"];
@@ -448,4 +453,86 @@ error_log("message");
448 453
449 //============================================================= 454 //=============================================================
455 } else if ($message == "saveChanges") {
456
457//{
458// "message":"saveChanges",
459// "srpSharedSecret":"edc78508907c942173818f7247fa64869ba80672a7aa8d27b8fa6bfe524fb9c8",
460// "parameters":{
461// "records":{
462// "updated":[
463// {
464// "currentRecordVersion":{
465// "previousVersionKey":"####",
466// "reference":"08c8eb7ec528fbf987bbfb84fe2e960cf9ae937b19fbb5f05d8d90a7039fac6a",
467// "data":"WYQ16AjodjsmyZDXa4MKxOju0F…beD/zXlbVb0Zj0ZI/N55bZ",
468// "version":"0.3"
469// },
470// "record":{
471// "reference":"83de5304f60a808e48a815c6203d7d3f24874d3f40faba420bbc60b376fcc356",
472// "data":"B6uBuBE Aly0knvgrUppodDTGZQC…guizL9QvHCWyM bQQBGBVvHZ6LfA==",
473// "version":"0.3"
474// }
475// }
476// ],
477// "deleted":[
478//
479// ]
480// },
481// "user":{
482// "header":"{\"rec…sion\":\"0.1\"}",
483// "statistics":"e6iXVEM4i8ZatPZFCCads/9F",
484// "version":"0.3"
485// }
486// }
487//}
488 $user = new user();
489 $user = $user->Get($_SESSION["userId"]);
490 updateUserData($parameters["parameters"]["user"], $user);
491
492 $recordToUpdateParameterList = $parameters["parameters"]["records"]["updated"];
493 $c = count($recordToUpdateParameterList);
494 for ($i=0; $i<$c; $i++) {
495 $recordList = $user->GetRecordList(array(array("reference", "=", $recordToUpdateParameterList [$i]["record"]["reference"])));
496 if (count($recordList) == 0) {
497 $currentRecord = new record();
498 $currentVersion = new recordversion();
499 $isNewRecord = true;
500 } else {
501 $currentRecord = $recordList[0];
502 $currentRecordVersions = $currentRecord->GetRecordversionList();
503 $currentVersion = $currentRecordVersions[0];
504 $isNewRecord = false;
505 }
506
507 updateRecordData($recordToUpdateParameterList[$i], $currentRecord, $currentVersion);
508
509 if ($isNewRecord == true) {
510 $currentRecord->SaveNew();
511 $currentVersion->SaveNew();
512
513 $currentRecord->AddRecordversion($currentVersion);
514 $user->AddRecord($currentRecord);
515 }
516
517 $currentRecord->Save();
518 $currentVersion->Save();
519 }
520
521 $user->Save();
522
523 $recordToDeleteReferenceList = $parameters["parameters"]["records"]["deleted"];
524 $recordList = array();
525 $c = count($recordToDeleteReferenceList);
526 for ($i=0; $i<$c; $i++) {
527 array_push($recordList, array("reference", "=", $recordToDeleteReferenceList[$i]));
528 }
529
530 $record = new record();
531 $record->DeleteList($recordList, true);
532
533 $result["lock"] = $user->lock;
534 $result["result"] = "done";
535
536 //=============================================================
450 } else if ($message == "getRecordDetail") { 537 } else if ($message == "getRecordDetail") {
451//{ 538//{
@@ -475,4 +562,71 @@ error_log("message");
475 // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4=" 562 // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4="
476 //} 563 //}
564
565
566 // #Actual result (causing error in /gamma)
567 //{
568 // "result" : {
569 // "currentVersion" : {
570 // "reference" : "cb05177f96a832062c6b936d24323cb74a64e2ef1d97ee026cd1003755af7495",
571 // "data" : "RAnoHmikp7RmiZ2WVyEMW+Ia",
572 // "header" : "",
573 // "version" : "0.3",
574 // "creationDate" : "0000-00-00 00:00:00",
575 // "updateDate" : "2011-10-09 19:49:11",
576 // "accessDate" : "2011-10-09 19:49:11"
577 // },
578 // "reference" : "b07e2afa2ba782b9f379649b36ded6de0452b43c27e6b887c7ce4f2a93f44346",
579 // "data" : "NtK1nkLUabbJQx5uO8ept...ZJ5dkJYYkyh3VQ==",
580 // "version" : "0.3",
581 // "creationDate" : "2011-10-09 19:49:11",
582 // "updateDate" : "Tue, 30 Nov 1999 00:00:00 +0000",
583 // "accessDate" : "0000-00-00 00:00:00",
584 // "oldestUsedEncryptedVersion" : "---"
585 // }
586 //}
587
588
589 // #Response from the online /gamma version
590 //{
591 // "result" : {
592 // "versions" : {
593 // "e2c193f017ad4f6babf51de59f7550a40596afc0c27373b6a360e426b5bc06de" : {
594 // "reference" : "e2c193f017ad4f6babf51de59f7550a40596afc0c27373b6a360e426b5bc06de",
595 // "data" : "s\/3ClggH4uCcf+BkIMqQ...+W0PVt\/MJ3t7s1g0g",
596 // "creationDate" : "Mon, 10 October 2011 14:42:42 UTC",
597 // "header" : "####",
598 // "updateDate" : "Mon, 10 October 2011 14:42:42 UTC",
599 // "previousVersion" : "a96a6d8b9ac73fcdf874d8a8534ffb2d43da8f5222e96a4a29bd2ae437619463",
600 // "version" : "0.3",
601 // "accessDate" : "Mon, 10 October 2011 14:42:42 UTC",
602 // "previousVersionKey" : "####"
603 // },
604 // [...]
605 // "a96a6d8b9ac73fcdf874d8a8534ffb2d43da8f5222e96a4a29bd2ae437619463" : {
606 // "reference" : "a96a6d8b9ac73fcdf874d8a8534ffb2d43da8f5222e96a4a29bd2ae437619463",
607 // "accessDate" : "Mon, 10 October 2011 14:41:17 UTC",
608 // "creationDate" : "Mon, 27 October 2008 08:16:14 UTC",
609 // "version" : "0.3",
610 // "data" : "m3yhZu81UAjCY6U2Kn...IUCb9suV0fldGOg=",
611 // "updateDate" : "Mon, 27 October 2008 08:16:14 UTC",
612 // "header" : "####"
613 // }
614 // },
615 // "oldestUsedEncryptedVersion" : "0.2",
616 // "reference" : "36ec1a41118813ced3553534fa2607d781cba687768db305beed368a8e06e113",
617 // "data" : "frlUkTbaOWD9j2ROat...ruWioCK0Mss27oHjPg==",
618 // "creationDate" : "Wed, 14 March 2007 17:39:35 UTC",
619 // "version" : "0.3",
620 // "accessDate" : "Mon, 10 October 2011 14:45:12 UTC",
621 // "currentVersion" : "e2c193f017ad4f6babf51de59f7550a40596afc0c27373b6a360e426b5bc06de",
622 // "updatedDate" : "Mon, 10 October 2011 14:45:12 UTC"
623 // },
624 // "toll" : {
625 // "requestType" : "MESSAGE",
626 // "targetValue" : "a516c942a3792cc620775a41f8870a6c7b51796d9a94da978a75da6a52eb1e10",
627 // "cost" : 2
628 // }
629 // }
630
477 $record = new record(); 631 $record = new record();
478 632
@@ -481,13 +635,19 @@ error_log("message");
481 $currentRecordVersions = $currentRecord->GetRecordversionList(); 635 $currentRecordVersions = $currentRecord->GetRecordversionList();
482 $currentVersion = $currentRecordVersions[0]; 636 $currentVersion = $currentRecordVersions[0];
483 637
484 $result["currentVersion"] = array(); 638 $result["versions"] = array();
485 $result["currentVersion"]["reference"] =$currentVersion->reference; 639 // foreach ($currentRecordVersions as $currentVersion) {
486 $result["currentVersion"]["data"] = $currentVersion->data; 640 $result["versions"][$currentVersion->reference] = array();
487 $result["currentVersion"]["header"] = $currentVersion->header; 641 $result["versions"][$currentVersion->reference]["reference"]= $currentVersion->reference;
488 $result["currentVersion"]["version"] = $currentVersion->version; 642 $result["versions"][$currentVersion->reference]["data"] = $currentVersion->data;
489 $result["currentVersion"]["creationDate"] =$currentVersion->creation_date; 643 $result["versions"][$currentVersion->reference]["header"] = $currentVersion->header;
490 $result["currentVersion"]["updateDate"] =$currentVersion->update_date; 644 $result["versions"][$currentVersion->reference]["version"] = $currentVersion->version;
491 $result["currentVersion"]["accessDate"] =$currentVersion->access_date; 645 $result["versions"][$currentVersion->reference]["creationDate"]= $currentVersion->creation_date;
646 $result["versions"][$currentVersion->reference]["updateDate"]= $currentVersion->update_date;
647 $result["versions"][$currentVersion->reference]["accessDate"]= $currentVersion->access_date;
648
649 // }
650 $result["currentVersion"] = $currentVersion->reference;
651 // $result["currentVersion"] = $currentRecord->currentVersion; //????
492 652
493 $result["reference"] = $currentRecord->reference; 653 $result["reference"] = $currentRecord->reference;
@@ -750,6 +910,9 @@ error_log("default");
750 910
751 session_write_close(); 911 session_write_close();
912
913 $finalResult = Array();
914 $finalResult["result"] = $result;
752 915
753 echo(json_encode($result)); 916 echo(json_encode($finalResult));
754error_log("result: ".json_encode($result)); 917error_log("result: ".json_encode($finalResult));
755?> 918?>
diff --git a/backend/python/properties/python.properties.json b/backend/python/properties/python.properties.json
index e69de29..128c98e 100644
--- a/backend/python/properties/python.properties.json
+++ b/backend/python/properties/python.properties.json
@@ -0,0 +1,8 @@
1{
2 "request.path": "clipperz.py",
3 "should.pay.toll": "false"
4
5 "development.settings": {
6 "url": "http://localhost/python/clipperz"
7 }
8} \ No newline at end of file