Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
Fixed #12
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Mar 31, 2019
1 parent 8751e44 commit 87f4bfc
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 24 deletions.
2 changes: 2 additions & 0 deletions system/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@
<div class="toolbar">
<input type="text" id="newnotename" placeholder="Notizname">
<button id="newnote">Neu</button>
<span class="ui-icon ui-icon-color-333 ui-icon-unlocked encrypt-note" title="Notiz wird nicht verschlüsselt."></span>
<span class="ui-icon ui-icon-color-333 ui-icon-locked encrypt-note disable" title="Notiz wird verschlüsselt."></span>
<button id="notesarchive">Notizarchiv</button>
</div>

Expand Down
55 changes: 55 additions & 0 deletions system/load/devjs/cla_enc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Diese Klasse dient Notizen zu ver- und entschluesseln.
*/
class NotesEncrypter{

/**
* >> Konstruktor <<
* lädt Daten aus dem localStorage sofern verfügbar.
*/
constructor(){
if( localStorage.getItem("notes_encrypt_data") !== null ){
this.data = JSON.parse( localStorage.getItem("notes_encrypt_data") );
}
else{
this.data = {
password : "",
status : false
};
}
}

setNotesPassword( password ){
this.data.password = sjcl.codec.hex.fromBits( sjcl.hash.sha256.hash( password + "bu79ubwqrzbIgbuwiw" ) );
this.data.status = true;
this.saveLocalStorage();
}

requestForPassword(){
if(!this.data.status){
errorMessage( "Es ist kein Passwort zum Verschlüsseln von Notizen angegeben.", 20 );
}
}

encryptNote(text){
if(!this.data.status){
return text;
}
return JSON.stringify( sjcl.encrypt(this.data.password, text ) );
}

decryptNote(text){
if(!this.data.status){
return text;
}
return sjcl.decrypt(this.data.password, JSON.parse( text ) );
}

/**
* >> PRIVATE <<
* Die internen Daten im localStorage ablegen.
*/
saveLocalStorage(){
localStorage.setItem("notes_encrypt_data", JSON.stringify( this.data ) );
}
}
11 changes: 10 additions & 1 deletion system/load/devjs/fun_authCodeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function authCodeManager(){
+'<input class="newPassword" type="password" id="newPasswordB" placeholder="Neues Passwort"> <span class="newPasswordIndikator" id="newPasswordBIndikator">Bitte geben Sie das Passwort ein!</span><br />'
+'<button id="newPasswordSet">Ändern</button>'
+'<div id="newPasswordDone" class="disable"></div>';

html += '<h3>Passwort zur Verschlüsselung von Notizen</h3>'
+'<input class="noteEncPassw" type="password" id="noteEncPassw" placeholder="Passwort" value="'+ (systemEncrypter.data.status ? '*******' : '') +'"> <span>Bitte geben Sie ein Passwort zur Verschlüsselung der Notizen ein!</span><br />'
+'<button id="noteEncPasswSet" disabled>Ändern</button>';
dialogSetContent( html );

//Passwort Button aus
Expand Down Expand Up @@ -130,6 +132,13 @@ function authCodeManager(){
$( "button#newPasswordSet" ).prop('disabled', true);
}
});
$( "input.noteEncPassw" ).on( 'keyup', function (){
$( "button#noteEncPasswSet" ).prop('disabled', $( "input.noteEncPassw" ).val().length < 4);
});
$("button#noteEncPasswSet").click( function(){
systemEncrypter.setNotesPassword( $( "input.noteEncPassw" ).val() );
$( "button#noteEncPasswSet" ).prop('disabled', true);
});

//Löschen von Authcodes
$( "button.deleteAuthLink" ).click( function () {
Expand Down
27 changes: 20 additions & 7 deletions system/load/devjs/fun_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function list(){
//Eine bestimmte Notiz zuletzt geöffnet, dann zu dieser zurückkehren
if( localStorage.getItem( "note_maker_reopen" ) != null && localStorage.getItem( "note_maker_reopen" ) != 'none' ){
var lastopend = JSON.parse( localStorage.getItem( "note_maker_reopen" ) );
maker( lastopend.noteid, lastopend.name );
maker( lastopend.noteid, lastopend.name, void 0, void 0, lastopend.enc );
}


Expand Down Expand Up @@ -79,7 +79,9 @@ function list(){
// alle durchgehen
$.each( notes, function(k,v){
//anfügen
table += '<li class="noteslist_notesnames box'+ ( v.starred ? ' starrednote' : '') +'" noteid="' + v.noteid + '"><span class="notesnames">'+ v.name +'</span> <span class="noteseditbuttons">'
table += '<li class="noteslist_notesnames box'+ ( v.starred ? ' starrednote' : '') +'" noteid="' + v.noteid + '" enc="'+ ( v.enc ? 'true' : 'false' ) +'"><span class="notesnames">' + v.name
+ ( v.enc ? '<span class="ui-icon ui-icon-color-333 ui-icon-locked" title="Verschlüsselte Notiz."></span>' : '' )
+ '</span> <span class="noteseditbuttons">'
+ '<button art="star" title="Notiz als wichtig markieren">&starf;</button>'
+ '<button art="up" title="Nach oben" '+ (k != 0 ? '' : 'disabled="disabled"' ) +'>&uarr;</button>'
+ '<button art="down" title="Nach unten" '+ ( notes.length - 1 != k ? '' : 'disabled="disabled"' ) +'>&darr;</button>'
Expand Down Expand Up @@ -136,9 +138,16 @@ function list(){
$( "div.noteslist div.listpart div.list ul li span.notesnames" ).off('click').click(function(){
var noteid = $( this ).parent().attr( "noteid" );
var name = $( this ).text();
var enc = $( this ).parent().attr( "enc" ) === 'true';
//Notiz zeigen
console.log( 'Oeffne: "'+ name + '" ("' + noteid + '")' );
maker( noteid, name );
if(enc){
systemEncrypter.requestForPassword();
if( !systemEncrypter.data.status ){
return;
}
}
maker( noteid, name, void 0, void 0, enc );
});

if( systemOfflineMode ){
Expand Down Expand Up @@ -168,9 +177,13 @@ function list(){
);
});
}



$("div.noteslist div.toolbar span.encrypt-note").off('click').click(function(){
$("div.noteslist div.toolbar span.encrypt-note").toggleClass( 'disable' );
if( !$("div.noteslist div.toolbar span.encrypt-note.ui-icon-locked").hasClass( 'disable' ) ){
systemEncrypter.requestForPassword();
}
});
$("div.noteslist div.toolbar span.encrypt-note").tooltip();
}

//Neue Notiz
Expand All @@ -179,7 +192,7 @@ function list(){
$( "div.noteslist div.listpart div.loading" ).removeClass( "disable" );

ajax_request( "list",
{"userid" : userinformation.id, "name" : name },
{"userid" : userinformation.id, "name" : name, "enc" : !$("div.noteslist div.toolbar span.encrypt-note.ui-icon-locked").hasClass( 'disable' ) },
function ( data ) {
$( "div.noteslist div.listpart div.loading" ).addClass( "disable" );
if( data.status === 'okay' ){
Expand Down
47 changes: 36 additions & 11 deletions system/load/devjs/fun_maker.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
var cm_editor;

//Notesmaker
function maker(noteid, notename, sharecont, savecallback) {
function maker(noteid, notename, sharecont, savecallback, encrypted) {
//sharecont enthält Freigabeinhalt, wenn Freigabe geladen werden soll
//savecallback ist Funktion um veränderungen des Shares zu speichern
//encrypted gibt an, eine verschluesselte Dateie zu oeffnen

if( typeof encrypted === "undefined" || encrypted !== true ){
encrypted = false;
}
if(encrypted){
$("button#publishnote").prop('disabled', true);
}

// Erstelle zwei Variablen, die Zustand darstellen
if (typeof sharecont === "undefined") {
var share = false;
var shareeditable = false;

//diese Notiz als geöffnete speichern
localStorage.setItem("note_maker_reopen", JSON.stringify({ noteid: noteid, name: notename }));
localStorage.setItem("note_maker_reopen", JSON.stringify({ noteid: noteid, name: notename, enc: encrypted }));
}
else {
if (typeof savecallback === "function") {
Expand Down Expand Up @@ -114,11 +122,23 @@ function maker(noteid, notename, sharecont, savecallback) {
//neue Notiz (dann Server noch leer)
if (!data.data.empty) {

var cont = data.data.content;
if( encrypted ){
try {
cont = systemEncrypter.decryptNote( data.data.content );
} catch (error) {
localStorage.setItem("note_maker_reopen", 'none');
removeCodeMirrorListeners();
list();
setTimeout( () => { errorMessage('Kann Notiz nicht entschlüsseln!', 10); }, 200 );
}
}

//Daten übernehmen
notedata = {
"name": data.data.name,
"id": data.data.id,
"content": data.data.content,
"content": cont,
"lastserverchanged": data.data.geandert
};

Expand All @@ -141,12 +161,13 @@ function maker(noteid, notename, sharecont, savecallback) {
}

function removeCodeMirrorListeners(){
//die EventListener weg machen
// Parser
cm_editor.off("change", here_parser_reparse);
// Speicherung
cm_editor.off("change", here_codemi_save);

if( typeof cm_editor === "object" ){
//die EventListener weg machen
// Parser
cm_editor.off("change", here_parser_reparse);
// Speicherung
cm_editor.off("change", here_codemi_save);
}
//keine Notiz mehr geöffnet
newerNoteOnServerFound = function (){};
}
Expand Down Expand Up @@ -466,8 +487,12 @@ function maker(noteid, notename, sharecont, savecallback) {
}
else{
$("div.noteview div.loading").removeClass("disable");
var cont = cm_editor.getValue();
if(encrypted){
cont = systemEncrypter.encryptNote(cont);
}
ajax_request("view",
{ "userid": userinformation.id, "noteid": noteid, "note": { "name": $("input#notename").val(), "cont": cm_editor.getValue() } },
{ "userid": userinformation.id, "noteid": noteid, "note": { "name": $("input#notename").val(), "cont": cont } },
function (data) {
$("div.noteview div.loading").addClass("disable");
if (
Expand Down Expand Up @@ -679,7 +704,7 @@ function maker(noteid, notename, sharecont, savecallback) {
//Dialog Inhalt bauen
var html = '<table><tr><th>Änderungen</th><th>Zeitpunkt</th></tr>';
$.each(data.data, function (k, v) {
html += '<tr><td>' + v.diff + '</td>';
html += '<tr><td>' + ( encrypted ? 'Kein Diff. bei verschlüsselten Notizen!' : v.diff ) + '</td>';
html += '<td>' + v.time + '<button key="' + k + '" class="takeInputFromHistory">Zurückkehren</button></td></tr>'
});
html += '</table>';
Expand Down
3 changes: 3 additions & 0 deletions system/load/devjs/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ var errorMessageTimeOut = null;
var systemOfflineMode = false;
var systemOfflineManager = new OfflineManager();

//Notizen verschluesseln
var systemEncrypter = new NotesEncrypter();

//REST oder Session API?
var systemRESTAPI = false;

Expand Down
4 changes: 4 additions & 0 deletions system/load/notes.dev.css
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ div#freigabeManagerDialog tr {
font-family: Ubuntu, sans-serif;
font-size: 1em;
}

.ui-icon-color-333{
background-image: url(js-libs/images/ui-icons_333_256x240.png);
}
2 changes: 2 additions & 0 deletions system/load/notes.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
BUILD-NOTE:
> $(function(){loginsys();if(isOpenedAsApp){displayAsApp();}});
>> devjs/cla_offlinemanager.js
>> devjs/cla_enc.js
>> devjs/globals.js
>> devjs/fun_loginsys.js
>> devjs/fun_list.js
Expand Down Expand Up @@ -65,6 +66,7 @@ var requireFiles = function () {

requireFiles([
domain + "/load/devjs/cla_offlinemanager.js",
domain + "/load/devjs/cla_enc.js",
domain + "/load/devjs/globals.js",
domain + "/load/devjs/fun_loginsys.js",
domain + "/load/devjs/fun_list.js",
Expand Down
2 changes: 1 addition & 1 deletion system/load/notes.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion system/load/notes.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions system/php/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
}
}
//Neu
elseif( check_params( POST, array( 'userid' => 'strAZaz09', 'name' => 'strALL') ) ){
elseif( check_params( POST, array( 'userid' => 'strAZaz09', 'name' => 'strALL', '*enc' => 'strAZaz09' ) ) ){
//Userid
// => Konvention nur kleine Buchstaben!
$userid = preg_replace( '/[^a-z]/', '', $_POST['userid'] );
Expand Down Expand Up @@ -219,7 +219,8 @@
$notesfile->setValue( [null], array(
'name' => $_POST['name'],
'noteid' => $newid,
'position' => $pos + 1
'position' => $pos + 1,
'enc' => !empty($_POST['enc']) && $_POST['enc'] === 'true'
));

//Okay Ausgabe
Expand Down
2 changes: 1 addition & 1 deletion system/php/systemInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract class SystemInit{

//Sytemversion
// [ Hauptversionsnummer, Unternummer, Patch, Zusatz (Alpha, Beta, Final) ] => [1, 23, 5, 'B'] -> 1.23.5 Beta
const SYSTEMVERSION = [ 1, 1, 2, 'Final' ];
const SYSTEMVERSION = [ 1, 1, 3, 'Beta' ];

/*
Auslesen der Konfiguration
Expand Down

0 comments on commit 87f4bfc

Please sign in to comment.