Add the restoration function to the HTML UI.

+ Add a new restore UI box. When a user delegates successfully for a
  restoration, the current restoration state is returned.
+ Add the persistence state to the summary output.
+ Rename "ordernum" to "slot": this is a longstanding complaint about
  the UI, and I fixed it while I was mucking about with this PR.
This commit is contained in:
Kyle Isom
2016-08-12 10:19:10 -07:00
parent 5a8e70047a
commit 39e11fa81d
3 changed files with 138 additions and 7 deletions

View File

@@ -156,6 +156,7 @@ type ResponseData struct {
type SummaryData struct {
Status string
State string
Live map[string]keycache.ActiveUser
All map[string]passvault.Summary
}
@@ -185,7 +186,8 @@ func jsonStatusError(err error) ([]byte, error) {
return json.Marshal(ResponseData{Status: err.Error()})
}
func jsonSummary() ([]byte, error) {
return json.Marshal(SummaryData{Status: "ok", Live: crypt.LiveSummary(), All: records.GetSummary()})
state := crypt.Status()
return json.Marshal(SummaryData{Status: "ok", State: state.State, Live: crypt.LiveSummary(), All: records.GetSummary()})
}
func jsonResponse(resp []byte) ([]byte, error) {
return json.Marshal(ResponseData{Status: "ok", Response: resp})
@@ -300,6 +302,7 @@ func Create(jsonIn []byte) ([]byte, error) {
// Summary processes a summary request.
func Summary(jsonIn []byte) ([]byte, error) {
log.Println(string(jsonIn))
var s SummaryRequest
var err error

View File

@@ -29,6 +29,7 @@ const (
<li><a href="#delegate">Delegate</a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#admin">Admin</a></li>
<li><a href="#restore">Restore</a></li>
<li><a href="#encrypt">Encrypt</a></li>
<li><a href="#decrypt">Decrypt</a></li>
<li><a href="#owners">Owners</a></li>
@@ -109,6 +110,8 @@ const (
</form>
<div class="hide summary-results">
<h4>Delegation Persistence</h4>
<p class="summary-state"></p>
<h4>Current Delegations</h4>
<ul class="list-group summary-user-delegations"></ul>
@@ -237,6 +240,37 @@ const (
</form>
</div>
</section>
<section class="row">
<div id="restore" class="col-md-6">
<h3>Restore</h3>
<form id="user-restore" class="ro-user-restore" role="form" action="/restore" method="post">
<div class="feedback restore-feedback"></div>
<div class="form-group row">
<div class="col-md-6">
<label for="restore-user">User name</label>
<input type="text" name="Name" class="form-control" id="restore-user" placeholder="User name" required />
</div>
<div class="col-md-6">
<label for="restore-user-pass">Password</label>
<input type="password" name="Password" class="form-control" id="restore-user-pass" placeholder="Password" required />
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<label for="restore-user-time">Delegation Time <small>(e.g., 2h34m)</small></label>
<input type="text" name="Time" class="form-control" id="restore-user-time" placeholder="1h" required />
</div>
<div class="col-md-6">
<label for="restore-uses">Uses</label>
<input type="number" name="Uses" class="form-control" id="restore-uses" placeholder="5" required />
</div>
</div>
<button type="submit" class="btn btn-primary">Restore</button>
</form>
</div>
</section>
<hr />
<section class="row">
<div id="encrypt" class="col-md-6">
@@ -481,7 +515,7 @@ const (
</div>
<div class="form-group row">
<div class="col-md-6">
<label for="orderlink-ordernum">Order Number</label>
<label for="orderlink-ordernum">Slot Name</label>
<input type="text" name="ordernum" class="form-control" id="orderlink-ordernum" placeholder="d34db33f..."/>
</div>
<div class="col-md-6">
@@ -582,7 +616,9 @@ const (
$.each(data.Live, buildLiveItem);
$.each(data.All, buildAllItem);
$('.summary-state').replaceWith(
'<p>Persistence is '+data.State+'.</a>'
);
$('.summary-results').removeClass('hide');
}
})
@@ -666,6 +702,31 @@ const (
});
});
// Restore
$('body').on('submit', '#user-restore', function(evt){
evt.preventDefault();
var $form = $(evt.currentTarget),
data = serialize($form);
// Force 'uses' to an integer.
data.Uses = parseInt(data.Uses, 10);
submit( $form, {
data : data,
success : function(d){
console.log(d.Response);
response = JSON.parse(window.atob(d.Response));
console.log(response);
$form.find('.feedback')
.append(makeAlert({
type: 'success',
message: 'Delegating '+htmlspecialchars(data.Name)+
'; persistence is currently '+response.Status
}));
}
});
});
// Encrypt data
$('body').on('submit', '#encrypt', function(evt){
evt.preventDefault();
@@ -855,6 +916,9 @@ const (
case "ordernum":
setValue = $("#delegate-slot");
break;
case "slot":
setValue = $("#delegate-slot");
break;
default:
break;
}
@@ -870,7 +934,7 @@ const (
var labels = decodeURIComponent(document.getElementById("orderlink-labels").value);
var uses = decodeURIComponent(document.getElementById("orderlink-uses").value);
var link = "https://" + document.location.host + "?delegator="+ delegator + "&delegatee="+ delegatee + "&label=" + labels + "&ordernum=" + orderNum + "&uses=" + uses + "&duration="+ duration;
var link = "https://" + document.location.host + "?delegator="+ delegator + "&delegatee="+ delegatee + "&label=" + labels + "&slot=" + orderNum + "&uses=" + uses + "&duration="+ duration;
$('.orderlink-feedback').empty().append(makeAlert({ type: 'success', message: '<p>'+htmlspecialchars(link)+'</p>' }) );
}
function htmlspecialchars(s) {

View File

@@ -24,6 +24,7 @@
<li><a href="#delegate">Delegate</a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#admin">Admin</a></li>
<li><a href="#restore">Restore</a></li>
<li><a href="#encrypt">Encrypt</a></li>
<li><a href="#decrypt">Decrypt</a></li>
<li><a href="#owners">Owners</a></li>
@@ -104,6 +105,8 @@
</form>
<div class="hide summary-results">
<h4>Delegation Persistence</h4>
<p class="summary-state"></p>
<h4>Current Delegations</h4>
<ul class="list-group summary-user-delegations"></ul>
@@ -232,6 +235,37 @@
</form>
</div>
</section>
<section class="row">
<div id="restore" class="col-md-6">
<h3>Restore</h3>
<form id="user-restore" class="ro-user-restore" role="form" action="/restore" method="post">
<div class="feedback restore-feedback"></div>
<div class="form-group row">
<div class="col-md-6">
<label for="restore-user">User name</label>
<input type="text" name="Name" class="form-control" id="restore-user" placeholder="User name" required />
</div>
<div class="col-md-6">
<label for="restore-user-pass">Password</label>
<input type="password" name="Password" class="form-control" id="restore-user-pass" placeholder="Password" required />
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<label for="restore-user-time">Delegation Time <small>(e.g., 2h34m)</small></label>
<input type="text" name="Time" class="form-control" id="restore-user-time" placeholder="1h" required />
</div>
<div class="col-md-6">
<label for="restore-uses">Uses</label>
<input type="number" name="Uses" class="form-control" id="restore-uses" placeholder="5" required />
</div>
</div>
<button type="submit" class="btn btn-primary">Restore</button>
</form>
</div>
</section>
<hr />
<section class="row">
<div id="encrypt" class="col-md-6">
@@ -476,7 +510,7 @@
</div>
<div class="form-group row">
<div class="col-md-6">
<label for="orderlink-ordernum">Order Number</label>
<label for="orderlink-ordernum">Slot Name</label>
<input type="text" name="ordernum" class="form-control" id="orderlink-ordernum" placeholder="d34db33f..."/>
</div>
<div class="col-md-6">
@@ -577,7 +611,9 @@
$.each(data.Live, buildLiveItem);
$.each(data.All, buildAllItem);
$('.summary-state').replaceWith(
'<p>Persistence is '+data.State+'.</a>'
);
$('.summary-results').removeClass('hide');
}
})
@@ -661,6 +697,31 @@
});
});
// Restore
$('body').on('submit', '#user-restore', function(evt){
evt.preventDefault();
var $form = $(evt.currentTarget),
data = serialize($form);
// Force 'uses' to an integer.
data.Uses = parseInt(data.Uses, 10);
submit( $form, {
data : data,
success : function(d){
console.log(d.Response);
response = JSON.parse(window.atob(d.Response));
console.log(response);
$form.find('.feedback')
.append(makeAlert({
type: 'success',
message: 'Delegating '+htmlspecialchars(data.Name)+
'; persistence is currently '+response.Status
}));
}
});
});
// Encrypt data
$('body').on('submit', '#encrypt', function(evt){
evt.preventDefault();
@@ -850,6 +911,9 @@
case "ordernum":
setValue = $("#delegate-slot");
break;
case "slot":
setValue = $("#delegate-slot");
break;
default:
break;
}
@@ -865,7 +929,7 @@
var labels = decodeURIComponent(document.getElementById("orderlink-labels").value);
var uses = decodeURIComponent(document.getElementById("orderlink-uses").value);
var link = "https://" + document.location.host + "?delegator="+ delegator + "&delegatee="+ delegatee + "&label=" + labels + "&ordernum=" + orderNum + "&uses=" + uses + "&duration="+ duration;
var link = "https://" + document.location.host + "?delegator="+ delegator + "&delegatee="+ delegatee + "&label=" + labels + "&slot=" + orderNum + "&uses=" + uses + "&duration="+ duration;
$('.orderlink-feedback').empty().append(makeAlert({ type: 'success', message: '<p>'+htmlspecialchars(link)+'</p>' }) );
}
function htmlspecialchars(s) {