Dear Gitlab users, due to maintenance reasons, Gitlab will not be available on Thursday 30.09.2021 from 5:00 pm to approximately 5:30 pm.

Commit 1839781b authored by Andreas Wagner's avatar Andreas Wagner
Browse files

Fix webform mode.

parent 9422bd21
......@@ -5,6 +5,7 @@ import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
......@@ -34,14 +35,17 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
router.LoadHTMLGlob("templates/*")
// Routes - one for the html/webapp, one group per API version...
metadataConf, _ := json.MarshalIndent(conf.Metadata, "", "\t")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", nil)
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"metadataConf": string(metadataConf),
})
// page := c.DefaultQuery("p", "index")
// c.String(http.StatusOK, "Service homepage with page "+page+".")
})
router.GET("/index.html", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"metadataConf": conf.Metadata,
"metadataConf": string(metadataConf),
})
})
......@@ -112,12 +116,12 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
signature = c.Query("signature")
}
result := ValidMAC(streamToByte(r), []byte(signature), []byte(conf.Secret))
result := ValidMAC(streamToByte(r), []byte("sha1="+signature), []byte(conf.Secret))
if !result {
if conf.Verbose {
mac := hmac.New(sha1.New, []byte(conf.Secret))
mac.Write(streamToByte(r))
expectedMAC := []byte("sha1=" + hex.EncodeToString(mac.Sum(nil)))
expectedMAC := hex.EncodeToString(mac.Sum(nil))
log.Warnf("File upload request with invalid HMAC signature received, ignoring. Sign.: %s, Message hash: %s", signature, expectedMAC)
} else {
log.Warnf("File upload request with invalid HMAC signature received, ignoring")
......
......@@ -105,12 +105,14 @@
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label" for="writeDOIparentPath">Parent path:</label>
<div class="col-sm-10"><input class="form-control" type="text" id="writeDOIparentPath" name="writeDOIparentPath" disabled value=""/></div>
<div class="col-sm-10">
<input class="form-control" type="text" id="writeDOIparentPath" name="writeDOIparentPath" value="/TEI/teiHeader/fileDesc/publicationStmt/idno" disabled />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label" for="writeDOIposition">Position:</label>
<div class="col-sm-10">
<select class="form-control" id="writeDOIposition" name="writeDOIposition" disabled>
<select class="form-control" id="writeDOIposition" name="writeDOIposition" value="firstChild" disabled>
<option value="firstChild">firstChild</option>
<option value="lastChild">lastChild</option>
</select>
......@@ -118,12 +120,12 @@
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label" for="writeDOIelementType">Element type:</label>
<div class="col-sm-10"><input class="form-control" type="text" id="writeDOIelementType" name="writeDOIelementType" disabled value=""/>
<div class="col-sm-10"><input class="form-control" type="text" id="writeDOIelementType" name="writeDOIelementType" value="idno" disabled />
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label" for="writeDOIattributeName">Attribute name:</label>
<div class="col-sm-10"><input class="form-control" type="text" id="writeDOIattributeName" name="writeDOIattributeName" disabled value=""/>
<div class="col-sm-10"><input class="form-control" type="text" id="writeDOIattributeName" name="writeDOIattributeName" value="" disabled />
</div>
</div>
<!--
......@@ -159,7 +161,7 @@
<div class="form-group row">
<label class="col-sm-2 col-form-label" for="doPublish">Publish zenodo deposit:</label>
<div class="col-sm-10">
<input type="checkbox" id="doPublish" name="doPublish"/>
<input type="checkbox" id="doPublish" name="doPublish" value="True"/>
</div>
</div>
</div>
......@@ -168,13 +170,17 @@
<input class="btn btn-primary" type="submit" value="Send"/>
</div>
</div>
<div class="card card-body">
<p>
<a data-toggle="collapse" href="#collapseConf" aria-expanded="false" aria-controls="collapseExample">Here</a>
is the server's current metadata field configuration. <em>Note: this is a dump of an internal struct, don't copy as-is to your config.json!</em>
</p>
<div class="collapse card card-body" id="collapseConf">
<pre>{{ .metadataConf }}</pre>
</div>
</div>
</form>
<div class="comment">
Here is the current metadata field configuration:
<pre>
{{ .metadataConf }}
</pre>
</div>
</div>
<div class="pb-2 mt-4 mb-2" id="direct-post">
<h3>Direct POST requests</h3>
......@@ -243,9 +249,18 @@
function getFileSignature() {
var file = document.getElementById('file').files[0];
var sig = CryptoJS.HmacSHA1(file, document.getElementById('secret').value);
console.log("File signature: " + sig);
document.getElementById('signature').value = sig;
if (file) {
read = new FileReader();
read.readAsText(file);
read.onloadend = function(){
var fcontent = read.result;
var sig = CryptoJS.HmacSHA1(fcontent, document.getElementById('secret').value);
console.log("File ready. " + fcontent.length.toLocaleString() + " bytes. Signature: " + sig);
document.getElementById('signature').value = sig;
}
}
}
function togglePassphraseViz() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment