new: added defaults from/to local storage

This commit is contained in:
Simone Margaritelli
2024-04-06 10:19:07 -04:00
parent 07d219ba79
commit bf524cae2a
5 changed files with 567 additions and 470 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<title>Arc</title>
@@ -56,6 +57,7 @@
<script type="text/javascript" src="/js/notify.js"></script>
<script type="text/javascript" src="/js/app.js"></script>
</head>
<body id="ngscope" ng-app="PM" ng-controller="PMController">
<div class="main-container container-fluid">
@@ -74,7 +76,8 @@
<!-- if user is logged instead -->
<span ng-if="arc.IsLogged()" ng-switch on="arc.HasStore()">
<div class="notifications badge badge-pill badge-warning" ng-if="status.events.length" ng-include src="'/views/notifications.html'">
<div class="notifications badge badge-pill badge-warning" ng-if="status.events.length" ng-include
src="'/views/notifications.html'">
</div>
<!-- no store selected, show available stores -->
@@ -82,12 +85,17 @@
<ul id="stores_list" class="list-group stores-list">
<li class="list-group-item">
<div class="row">
<div class="col-6">
<div class="col-4">
<center class="action-button" ng-click="doLogout()">
<i class="fa fa-sign-out" aria-hidden="true"></i>
</center>
</div>
<div class="col-6" style="border-left: 1px solid #eee">
<div class="col-4">
<center class="action-button" ng-click="onSettings()">
<i class="fa fa-cog" aria-hidden="true"></i>
</center>
</div>
<div class="col-4" style="border-left: 1px solid #eee">
<center class="action-button" ng-click="onNewStore()">
<i class="fa fa-file" aria-hidden="true"></i>
</center>
@@ -107,6 +115,8 @@
<span ng-include src="'/views/store_list_item.html'"></span>
</li>
</ul>
<div ng-include src="'/views/modals/settings.html'"></div>
</div>
<!-- store selected, load records from it -->
@@ -127,13 +137,8 @@
</script>
</div>
<div class="col-6 input-group">
<input
type="text"
id="search_filter"
class="search-filter form-control border"
ng-model="search"
ng-change="updateFilter()"
placeholder="Search ..."/>
<input type="text" id="search_filter" class="search-filter form-control border" ng-model="search"
ng-change="updateFilter()" placeholder="Search ..." />
</div>
</div>
<!-- will show session expire time when approaching 5 minutes left -->
@@ -166,12 +171,8 @@
</small>
</li>
<li
ng-repeat="r in arc.records | orderBy:['pinned','updated_at']:true"
class="list-group-item"
id="secret_list_item_{{ r.id }}"
ng-if="filterSecret(r)"
ng-click="onShowSecret(r.id)"
<li ng-repeat="r in arc.records | orderBy:['pinned','updated_at']:true" class="list-group-item"
id="secret_list_item_{{ r.id }}" ng-if="filterSecret(r)" ng-click="onShowSecret(r.id)"
ng-class="{'expired': isExpired(r), 'expiring': isExpiring(r), 'pinned': isPinned(r) }">
<span ng-include src="'/views/secret_list_item.html?v=17'"></span>
</li>
@@ -209,4 +210,5 @@
</footer>
</body>
</html>

View File

@@ -368,6 +368,24 @@ app.controller('PMController', ['$scope', function (scope) {
}
};
scope.onSettings = function () {
$('#arc_default_login').val(window.localStorage['arc_default_login']);
$('#arc_default_username').val(window.localStorage['arc_default_username']);
$('#arc_default_full_name').val(window.localStorage['arc_default_full_name']);
$('#settings_modal').modal().on('hidden.bs.modal', function () {
document.title = 'Settings';
scope.setRoute("/settings");
});
};
scope.doSaveSettings = function () {
window.localStorage['arc_default_login'] = $('#arc_default_login').val();
window.localStorage['arc_default_username'] = $('#arc_default_username').val();
window.localStorage['arc_default_full_name'] = $('#arc_default_full_name').val();
$('#settings_modal').modal('hide');
};
scope.onNewStore = function () {
var store_title = $.trim(prompt("Please enter the store title:"));
if (store_title) {
@@ -641,7 +659,8 @@ app.controller('PMController', ['$scope', function (scope) {
});
};
scope.onNewSecret = function() {null
scope.onNewSecret = function () {
null
scope.showSecretModal(true, { title: "Put a title ..." });
};

View File

@@ -23,37 +23,47 @@ var REGISTERED_TYPES = [
];
var REGISTERED_TEMPLATES = [
{ name: "Web Login", fields:[
{
name: "Web Login", fields: [
new URLEntry("URL", "https://"),
new InputEntry( "Login", "" ),
new InputEntry("Login", "<default_login>"),
new PasswordEntry("Password", "")
]},
{ name: "Email Account", fields:[
]
},
{
name: "Email Account", fields: [
new InputEntry("Provider", ""),
new InputEntry("SMTP Server", ""),
new PasswordEntry("SMTP Password", ""),
new InputEntry("IMAP Server", ""),
new PasswordEntry("IMAP Password", "")
]},
{ name: "SSH / FTP Account", fields:[
]
},
{
name: "SSH / FTP Account", fields: [
new URLEntry("Hostname", ""),
new InputEntry( "Username", "" ),
new InputEntry("Username", "<default_username>"),
new PasswordEntry("Password", "")
]},
{ name: "Credit Card", fields:[
]
},
{
name: "Credit Card", fields: [
new InputEntry("Bank Name", ""),
new InputEntry( "Owner Name", "" ),
new InputEntry("Owner Name", "<default_full_name>"),
new InputEntry("Card Number", ""),
new InputEntry("Valid Until", ""),
new PasswordEntry("CVV", "")
]},
{ name: "Simple List", fields:[
]
},
{
name: "Simple List", fields: [
new CheckboxEntry("Option A", ""),
new CheckboxEntry("Option B", ""),
new CheckboxEntry("Option C", ""),
new CheckboxEntry("Option D", ""),
new CheckboxEntry("Option E", ""),
]}
]
}
];
/*
@@ -125,7 +135,20 @@ function TypeClone(e) {
var clone = $.extend(true, {}, e);
clone.id += '_' + g_EntryCounter++;
if (clone.value.indexOf('<default') == 0) {
var def_value_name = 'arc_' + clone.value.replaceAll('<', '').replaceAll('>', '');
// lookup default value from local storage
if (window.localStorage.hasOwnProperty(def_value_name)) {
clone.value = window.localStorage[def_value_name];
} else {
// no default value has been defined yet for this, fallback to empty clone
clone.value = '';
}
} else {
// create an empty clone
clone.value = "";
}
return clone;
}

View File

@@ -0,0 +1,53 @@
<div class="modal modal-full" id="settings_modal" role="dialog" aria-hidden="true" tabindex="-1">
<div class="modal-dialog modal-dialog-full" role="document">
<div class="modal-content modal-content-full">
<div class="modal-body modal-body-full" id="settings_body">
<form id="settings_form">
<div class="form-group">
<h1>Defaults</h1>
<div style="clear:both"></div>
<small class="form-text text-muted" id="cleartext-warning">
You can optionally define default values to be used in secret templates.
</small>
<br />
<div class="form-group">
<h5 class="editable label label-default entry-title label-0">Login</h5>
<div style="clear:both"></div>
<div class="input-group mif">
<input class="form-control" data-entry-type="0" type="text" name="arc_default_login"
id="arc_default_login" value="">
</div>
</div>
<div class="form-group">
<h5 class="editable label label-default entry-title label-0">Username</h5>
<div style="clear:both"></div>
<div class="input-group mif">
<input class="form-control" data-entry-type="0" type="text" name="arc_default_username"
id="arc_default_username" value="">
</div>
</div>
<div class="form-group">
<h5 class="editable label label-default entry-title label-0">Full Name</h5>
<div style="clear:both"></div>
<div class="input-group mif">
<input class="form-control" data-entry-type="0" type="text" name="arc_default_full_name"
id="arc_default_full_name" value="">
</div>
</div>
<br />
<button type="submit" class="btn btn-secondary float-right" ng-click="doSaveSettings()"
id="saveSettingsButton">Save</button>
</div>
</form>
</div>
</div> <!-- content -->
</div> <!-- dialog -->
</div>