2012-12-11 04:59:23 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
2015-03-18 00:06:06 +02:00
|
|
|
"path"
|
2019-02-10 18:37:45 +02:00
|
|
|
|
2019-05-24 18:08:48 +02:00
|
|
|
"github.com/pusher/oauth2_proxy/pkg/logger"
|
2012-12-11 04:59:23 +03:00
|
|
|
)
|
|
|
|
|
2015-03-18 00:06:06 +02:00
|
|
|
func loadTemplates(dir string) *template.Template {
|
|
|
|
if dir == "" {
|
|
|
|
return getTemplates()
|
|
|
|
}
|
2019-02-10 18:37:45 +02:00
|
|
|
logger.Printf("using custom template directory %q", dir)
|
2015-03-18 00:06:06 +02:00
|
|
|
t, err := template.New("").ParseFiles(path.Join(dir, "sign_in.html"), path.Join(dir, "error.html"))
|
|
|
|
if err != nil {
|
2019-02-10 18:37:45 +02:00
|
|
|
logger.Fatalf("failed parsing template %s", err)
|
2015-03-18 00:06:06 +02:00
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2012-12-11 04:59:23 +03:00
|
|
|
func getTemplates() *template.Template {
|
|
|
|
t, err := template.New("foo").Parse(`{{define "sign_in.html"}}
|
2012-12-26 18:55:41 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en" charset="utf-8">
|
2014-11-09 07:26:52 +02:00
|
|
|
<head>
|
|
|
|
<title>Sign In</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 1.42857143;
|
|
|
|
color: #333;
|
|
|
|
background: #f0f0f0;
|
|
|
|
}
|
|
|
|
.signin {
|
|
|
|
display:block;
|
|
|
|
margin:20px auto;
|
|
|
|
max-width:400px;
|
|
|
|
background: #fff;
|
|
|
|
border:1px solid #ccc;
|
|
|
|
border-radius: 10px;
|
|
|
|
padding: 20px;
|
|
|
|
}
|
|
|
|
.center {
|
|
|
|
text-align:center;
|
|
|
|
}
|
|
|
|
.btn {
|
|
|
|
color: #fff;
|
|
|
|
background-color: #428bca;
|
|
|
|
border: 1px solid #357ebd;
|
|
|
|
-webkit-border-radius: 4;
|
|
|
|
-moz-border-radius: 4;
|
|
|
|
border-radius: 4px;
|
|
|
|
font-size: 14px;
|
|
|
|
padding: 6px 12px;
|
|
|
|
text-decoration: none;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.btn:hover {
|
|
|
|
background-color: #3071a9;
|
|
|
|
border-color: #285e8e;
|
2018-01-23 17:04:41 +02:00
|
|
|
text-decoration: none;
|
2014-11-09 07:26:52 +02:00
|
|
|
}
|
|
|
|
label {
|
|
|
|
display: inline-block;
|
|
|
|
max-width: 100%;
|
|
|
|
margin-bottom: 5px;
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
|
|
|
input {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
height: 34px;
|
|
|
|
padding: 6px 12px;
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 1.42857143;
|
|
|
|
color: #555;
|
|
|
|
background-color: #fff;
|
|
|
|
background-image: none;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
border-radius: 4px;
|
|
|
|
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
|
|
|
|
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
|
|
|
|
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
|
|
|
|
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
|
|
|
|
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
|
|
|
|
margin:0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
}
|
2014-11-10 05:01:50 +02:00
|
|
|
footer {
|
|
|
|
display:block;
|
|
|
|
font-size:10px;
|
|
|
|
color:#aaa;
|
|
|
|
text-align:center;
|
|
|
|
margin-bottom:10px;
|
|
|
|
}
|
|
|
|
footer a {
|
|
|
|
display:inline-block;
|
|
|
|
height:25px;
|
|
|
|
line-height:25px;
|
|
|
|
color:#aaa;
|
|
|
|
text-decoration:underline;
|
|
|
|
}
|
|
|
|
footer a:hover {
|
|
|
|
color:#aaa;
|
|
|
|
}
|
2014-11-09 07:26:52 +02:00
|
|
|
</style>
|
2014-07-22 06:59:13 +03:00
|
|
|
</head>
|
2012-12-26 18:55:41 +03:00
|
|
|
<body>
|
2014-11-09 07:26:52 +02:00
|
|
|
<div class="signin center">
|
2015-05-30 00:47:40 +02:00
|
|
|
<form method="GET" action="{{.ProxyPrefix}}/start">
|
2013-10-22 22:56:29 +03:00
|
|
|
<input type="hidden" name="rd" value="{{.Redirect}}">
|
2014-11-09 07:26:52 +02:00
|
|
|
{{ if .SignInMessage }}
|
|
|
|
<p>{{.SignInMessage}}</p>
|
|
|
|
{{ end}}
|
2017-10-08 06:40:36 +02:00
|
|
|
<button type="submit" class="btn">Sign in with {{.ProviderName}}</button><br/>
|
2012-12-11 04:59:23 +03:00
|
|
|
</form>
|
2014-11-09 07:26:52 +02:00
|
|
|
</div>
|
2014-12-09 22:38:57 +02:00
|
|
|
|
|
|
|
{{ if .CustomLogin }}
|
2014-11-09 07:26:52 +02:00
|
|
|
<div class="signin">
|
2015-05-30 00:47:40 +02:00
|
|
|
<form method="POST" action="{{.ProxyPrefix}}/sign_in">
|
2013-10-22 22:56:29 +03:00
|
|
|
<input type="hidden" name="rd" value="{{.Redirect}}">
|
2014-11-09 07:26:52 +02:00
|
|
|
<label for="username">Username:</label><input type="text" name="username" id="username" size="10"><br/>
|
|
|
|
<label for="password">Password:</label><input type="password" name="password" id="password" size="10"><br/>
|
|
|
|
<button type="submit" class="btn">Sign In</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
2012-12-26 18:55:41 +03:00
|
|
|
{{ end }}
|
2016-01-25 20:43:55 +02:00
|
|
|
<script>
|
|
|
|
if (window.location.hash) {
|
|
|
|
(function() {
|
|
|
|
var inputs = document.getElementsByName('rd');
|
|
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
|
|
inputs[i].value += window.location.hash;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
</script>
|
2014-11-10 05:01:50 +02:00
|
|
|
<footer>
|
2016-06-19 05:53:42 +02:00
|
|
|
{{ if eq .Footer "-" }}
|
|
|
|
{{ else if eq .Footer ""}}
|
2018-11-27 13:45:05 +02:00
|
|
|
Secured with <a href="https://github.com/pusher/oauth2_proxy#oauth2_proxy">OAuth2 Proxy</a> version {{.Version}}
|
2016-06-19 05:53:42 +02:00
|
|
|
{{ else }}
|
|
|
|
{{.Footer}}
|
|
|
|
{{ end }}
|
2014-11-10 05:01:50 +02:00
|
|
|
</footer>
|
2012-12-26 18:55:41 +03:00
|
|
|
</body>
|
|
|
|
</html>
|
2012-12-11 04:59:23 +03:00
|
|
|
{{end}}`)
|
|
|
|
if err != nil {
|
2019-02-10 18:37:45 +02:00
|
|
|
logger.Fatalf("failed parsing template %s", err)
|
2012-12-11 04:59:23 +03:00
|
|
|
}
|
2012-12-17 21:38:33 +03:00
|
|
|
|
2012-12-11 04:59:23 +03:00
|
|
|
t, err = t.Parse(`{{define "error.html"}}
|
2012-12-26 18:55:41 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en" charset="utf-8">
|
2014-11-09 07:26:52 +02:00
|
|
|
<head>
|
|
|
|
<title>{{.Title}}</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
|
|
|
</head>
|
2012-12-11 04:59:23 +03:00
|
|
|
<body>
|
|
|
|
<h2>{{.Title}}</h2>
|
|
|
|
<p>{{.Message}}</p>
|
|
|
|
<hr>
|
2015-05-30 00:47:40 +02:00
|
|
|
<p><a href="{{.ProxyPrefix}}/sign_in">Sign In</a></p>
|
2012-12-11 04:59:23 +03:00
|
|
|
</body>
|
|
|
|
</html>{{end}}`)
|
|
|
|
if err != nil {
|
2019-02-10 18:37:45 +02:00
|
|
|
logger.Fatalf("failed parsing template %s", err)
|
2012-12-11 04:59:23 +03:00
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|