2014-03-30 22:44:26 +00:00
|
|
|
/*
|
2018-01-04 00:52:49 +00:00
|
|
|
Copyright 2013 The Perkeep Authors
|
2014-03-30 22:44:26 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package importer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2014-05-10 03:28:53 +00:00
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
2014-03-30 22:44:26 +00:00
|
|
|
)
|
|
|
|
|
2014-05-10 03:28:53 +00:00
|
|
|
func (h *Host) execTemplate(w http.ResponseWriter, r *http.Request, data interface{}) {
|
2014-03-30 22:44:26 +00:00
|
|
|
tmplName := strings.TrimPrefix(fmt.Sprintf("%T", data), "importer.")
|
|
|
|
var buf bytes.Buffer
|
2014-05-10 03:28:53 +00:00
|
|
|
err := h.tmpl.ExecuteTemplate(&buf, tmplName, data)
|
2014-03-30 22:44:26 +00:00
|
|
|
if err != nil {
|
|
|
|
http.Error(w, fmt.Sprintf("Error executing template %q: %v", tmplName, err), 500)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Write(buf.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
type importersRootPage struct {
|
|
|
|
Title string
|
|
|
|
Body importersRootBody
|
|
|
|
}
|
|
|
|
|
|
|
|
type importersRootBody struct {
|
2014-04-01 18:47:03 +00:00
|
|
|
Host *Host
|
2014-03-30 22:44:26 +00:00
|
|
|
Importers []*importer
|
|
|
|
}
|
|
|
|
|
|
|
|
type importerPage struct {
|
|
|
|
Title string
|
|
|
|
Body importerBody
|
|
|
|
}
|
|
|
|
|
|
|
|
type importerBody struct {
|
2014-04-01 18:47:03 +00:00
|
|
|
Host *Host
|
2014-03-30 22:44:26 +00:00
|
|
|
Importer *importer
|
|
|
|
SetupHelp template.HTML
|
|
|
|
}
|
|
|
|
|
|
|
|
type acctPage struct {
|
|
|
|
Title string
|
|
|
|
Body acctBody
|
|
|
|
}
|
|
|
|
|
|
|
|
type acctBody struct {
|
|
|
|
Acct *importerAcct
|
|
|
|
AcctType string
|
|
|
|
Running bool
|
|
|
|
LastStatus string
|
|
|
|
StartedAgo time.Duration // or zero if !Running
|
|
|
|
LastAgo time.Duration // non-zero if previous run && !Running
|
|
|
|
LastError string
|
|
|
|
}
|
|
|
|
|
2014-05-10 03:28:53 +00:00
|
|
|
var tmpl = template.Must(template.New("root").Funcs(map[string]interface{}{
|
|
|
|
"bloblink": func(br blob.Ref) string {
|
|
|
|
panic("should be overridden; this one won't be called")
|
|
|
|
},
|
|
|
|
}).Parse(`
|
2014-03-30 22:44:26 +00:00
|
|
|
{{define "pageTop"}}
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>{{.Title}}</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>{{.Title}}</h1>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "pageBottom"}}
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
|
|
|
|
{{define "importersRootPage"}}
|
|
|
|
{{template "pageTop" .}}
|
|
|
|
{{template "importersRootBody" .Body}}
|
|
|
|
{{template "pageBottom"}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "importersRootBody"}}
|
|
|
|
<ul>
|
2014-04-01 18:47:03 +00:00
|
|
|
{{$base := .Host.ImporterBaseURL}}
|
2014-03-30 22:44:26 +00:00
|
|
|
{{range .Importers}}
|
|
|
|
<li><a href="{{$base}}{{.Name}}">{{.Name}}</a></li>
|
|
|
|
{{end}}
|
|
|
|
</ul>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
|
|
|
|
{{define "importerPage"}}
|
|
|
|
{{template "pageTop" .}}
|
|
|
|
{{template "importerBody" .Body}}
|
|
|
|
{{template "pageBottom"}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "importerBody"}}
|
2014-04-01 18:47:03 +00:00
|
|
|
<p>[<a href="{{.Host.ImporterBaseURL}}"><< Back</a>]</p>
|
2014-03-30 22:44:26 +00:00
|
|
|
<ul>
|
2014-05-10 03:28:53 +00:00
|
|
|
<li>Importer configuration permanode: {{.Importer.Node.PermanodeRef | bloblink}}</li>
|
2014-03-30 22:44:26 +00:00
|
|
|
<li>Status: {{.Importer.Status}}</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
{{if .Importer.ShowClientAuthEditForm}}
|
2016-05-17 13:44:26 +00:00
|
|
|
{{if .Importer.InsecureForm}}
|
|
|
|
<h1 style="color:red;">This page is not served securely (no https). Proceed at your own risk.</h1>
|
|
|
|
{{end}}
|
2014-03-30 22:44:26 +00:00
|
|
|
<h1>Client ID & Client Secret</h1>
|
|
|
|
<form method='post'>
|
|
|
|
<input type='hidden' name="mode" value="saveclientidsecret">
|
|
|
|
<table border=0 cellpadding=3>
|
|
|
|
<tr><td align=right>Client ID</td><td><input name="clientID" size=50 value="{{.Importer.ClientID}}"></td></tr>
|
2016-04-24 15:39:15 +00:00
|
|
|
<tr><td align=right>Client Secret</td><td><input name="clientSecret" type=password size=50 value="{{.Importer.ClientSecret}}"></td></tr>
|
2014-03-30 22:44:26 +00:00
|
|
|
<tr><td align=right></td><td><input type='submit' value="Save"></td></tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{.SetupHelp}}
|
|
|
|
|
|
|
|
|
|
|
|
<h1>Accounts</h1>
|
|
|
|
<ul>
|
|
|
|
{{range .Importer.Accounts}}
|
|
|
|
<li><a href="{{.AccountURL}}">{{.AccountLinkText}}</a> {{.AccountLinkSummary}}</li>
|
|
|
|
{{end}}
|
|
|
|
</ul>
|
|
|
|
{{if .Importer.CanAddNewAccount}}
|
|
|
|
<form method='post'>
|
|
|
|
<input type='hidden' name="mode" value="newacct">
|
|
|
|
<input type='submit' value="Add new account">
|
|
|
|
</form>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "acctPage"}}
|
|
|
|
{{template "pageTop" .}}
|
|
|
|
{{template "acctBody" .Body}}
|
|
|
|
{{template "pageBottom"}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "acctBody"}}
|
|
|
|
<p>[<a href="./"><< Back</a>]</p>
|
|
|
|
<ul>
|
|
|
|
<li>Account type: {{.AcctType}}</li>
|
2014-05-10 03:28:53 +00:00
|
|
|
<li>Account metadata permanode: {{.Acct.AccountObject.PermanodeRef | bloblink}}</li>
|
|
|
|
<li>Import root permanode: {{if .Acct.RootObject}}{{.Acct.RootObject.PermanodeRef | bloblink}}{{else}}(none){{end}}</li>
|
2014-03-30 22:44:26 +00:00
|
|
|
<li>Configured: {{.Acct.IsAccountReady}}</li>
|
2014-04-01 18:47:03 +00:00
|
|
|
<li>Summary: {{.Acct.AccountLinkSummary}}</li>
|
2014-05-06 04:23:34 +00:00
|
|
|
<li>Import interval: {{if .Acct.RefreshInterval}}{{.Acct.RefreshInterval}}{{else}}(manual){{end}}</li>
|
2014-03-30 22:44:26 +00:00
|
|
|
<li>Running: {{.Running}}</li>
|
|
|
|
{{if .Running}}
|
|
|
|
<li>Started: {{.StartedAgo}} ago</li>
|
|
|
|
<li>Last status: {{.LastStatus}}</li>
|
|
|
|
{{else}}
|
|
|
|
{{if .LastAgo}}
|
|
|
|
<li>Previous run: {{.LastAgo}} ago{{if .LastError}}: {{.LastError}}{{else}} (success){{end}}</li>
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
{{if .Acct.IsAccountReady}}
|
|
|
|
<form method='post' style='display: inline'>
|
|
|
|
{{if .Running}}
|
|
|
|
<input type='hidden' name='mode' value='stop'>
|
|
|
|
<input type='submit' value='Pause Import'>
|
|
|
|
{{else}}
|
|
|
|
<input type='hidden' name='mode' value='start'>
|
|
|
|
<input type='submit' value='Start Import'>
|
|
|
|
{{end}}
|
|
|
|
</form>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
<form method='post' style='display: inline'>
|
|
|
|
<input type='hidden' name='mode' value='login'>
|
|
|
|
<input type='submit' value='Re-login'>
|
|
|
|
</form>
|
|
|
|
|
2014-05-06 04:23:34 +00:00
|
|
|
<form method='post' style='display: inline'>
|
|
|
|
<input type='hidden' name='mode' value='toggleauto'>
|
|
|
|
<input type='submit' value='Toggle auto'>
|
|
|
|
</form>
|
|
|
|
|
2014-03-30 22:44:26 +00:00
|
|
|
<form method='post' style='display: inline'>
|
|
|
|
<input type='hidden' name='mode' value='delete'>
|
|
|
|
<input type='submit' value='Delete Account' onclick='return confirm("Delete account?")'>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
`))
|