Allow for non-/ deployments. Fixes #61
This commit is contained in:
parent
07aaad2cd8
commit
4856ab0750
@ -69,8 +69,11 @@ remoteuploads = true
|
||||
|
||||
A helper utility ```linx-genkey``` is provided which hashes keys to the format required in the auth files.
|
||||
|
||||
|
||||
Deployment
|
||||
----------
|
||||
Linx-server supports being deployed in a subdirectory (ie. example.com/mylinx/) as well as on its own (example.com/).
|
||||
|
||||
|
||||
#### 1. Using fastcgi
|
||||
|
||||
@ -98,6 +101,7 @@ Run linx-server with the ```-certfile path/to/cert.file``` and ```-keyfile path/
|
||||
#### 3. Using the built-in http server
|
||||
Run linx-server normally.
|
||||
|
||||
|
||||
Development
|
||||
-----------
|
||||
Any help is welcome, PRs will be reviewed and merged accordingly.
|
||||
|
@ -45,10 +45,10 @@ func staticHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
} else {
|
||||
if path == "/favicon.ico" {
|
||||
path = "/static/images/favicon.gif"
|
||||
path = Config.sitePath + "/static/images/favicon.gif"
|
||||
}
|
||||
|
||||
filePath := strings.TrimPrefix(path, "/static/")
|
||||
filePath := strings.TrimPrefix(path, Config.sitePath+"static/")
|
||||
file, err := staticBox.Open(filePath)
|
||||
if err != nil {
|
||||
notFoundHandler(c, w, r)
|
||||
|
54
server.go
54
server.go
@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/fcgi"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@ -25,6 +26,7 @@ var Config struct {
|
||||
metaDir string
|
||||
siteName string
|
||||
siteURL string
|
||||
sitePath string
|
||||
certFile string
|
||||
keyFile string
|
||||
contentSecurityPolicy string
|
||||
@ -91,6 +93,13 @@ func setup() *web.Mux {
|
||||
Config.siteURL = Config.siteURL + "/"
|
||||
}
|
||||
|
||||
parsedUrl, err := url.Parse(Config.siteURL)
|
||||
if err != nil {
|
||||
log.Fatal("Could not parse siteurl:", err)
|
||||
}
|
||||
|
||||
Config.sitePath = parsedUrl.Path
|
||||
|
||||
// Template setup
|
||||
p2l, err := NewPongo2TemplatesLoader()
|
||||
if err != nil {
|
||||
@ -99,6 +108,7 @@ func setup() *web.Mux {
|
||||
TemplateSet := pongo2.NewSet("templates", p2l)
|
||||
TemplateSet.Globals["sitename"] = Config.siteName
|
||||
TemplateSet.Globals["siteurl"] = Config.siteURL
|
||||
TemplateSet.Globals["sitepath"] = Config.sitePath
|
||||
TemplateSet.Globals["using_auth"] = Config.authFile != ""
|
||||
err = populateTemplatesMap(TemplateSet, Templates)
|
||||
if err != nil {
|
||||
@ -110,43 +120,43 @@ func setup() *web.Mux {
|
||||
timeStartedStr = strconv.FormatInt(timeStarted.Unix(), 10)
|
||||
|
||||
// Routing setup
|
||||
nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
|
||||
selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
|
||||
selifIndexRe := regexp.MustCompile(`^/selif/$`)
|
||||
torrentRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)/torrent$`)
|
||||
nameRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)$`)
|
||||
selifRe := regexp.MustCompile("^" + Config.sitePath + `selif/(?P<name>[a-z0-9-\.]+)$`)
|
||||
selifIndexRe := regexp.MustCompile("^" + Config.sitePath + `selif/$`)
|
||||
torrentRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)/torrent$`)
|
||||
|
||||
if Config.authFile == "" {
|
||||
mux.Get("/", indexHandler)
|
||||
mux.Get("/paste/", pasteHandler)
|
||||
mux.Get(Config.sitePath, indexHandler)
|
||||
mux.Get(Config.sitePath+"paste/", pasteHandler)
|
||||
} else {
|
||||
mux.Get("/", http.RedirectHandler("/API", 303))
|
||||
mux.Get("/paste/", http.RedirectHandler("/API/", 303))
|
||||
mux.Get(Config.sitePath, http.RedirectHandler(Config.sitePath+"API", 303))
|
||||
mux.Get(Config.sitePath+"paste/", http.RedirectHandler(Config.sitePath+"API/", 303))
|
||||
}
|
||||
mux.Get("/paste", http.RedirectHandler("/paste/", 301))
|
||||
mux.Get(Config.sitePath+"paste", http.RedirectHandler(Config.sitePath+"paste/", 301))
|
||||
|
||||
mux.Get("/API/", apiDocHandler)
|
||||
mux.Get("/API", http.RedirectHandler("/API/", 301))
|
||||
mux.Get(Config.sitePath+"API/", apiDocHandler)
|
||||
mux.Get(Config.sitePath+"API", http.RedirectHandler(Config.sitePath+"API/", 301))
|
||||
|
||||
if Config.remoteUploads {
|
||||
mux.Get("/upload", uploadRemote)
|
||||
mux.Get("/upload/", uploadRemote)
|
||||
mux.Get(Config.sitePath+"upload", uploadRemote)
|
||||
mux.Get(Config.sitePath+"upload/", uploadRemote)
|
||||
|
||||
if Config.remoteAuthFile != "" {
|
||||
remoteAuthKeys = readAuthKeys(Config.remoteAuthFile)
|
||||
}
|
||||
}
|
||||
|
||||
mux.Post("/upload", uploadPostHandler)
|
||||
mux.Post("/upload/", uploadPostHandler)
|
||||
mux.Put("/upload", uploadPutHandler)
|
||||
mux.Put("/upload/", uploadPutHandler)
|
||||
mux.Put("/upload/:name", uploadPutHandler)
|
||||
mux.Post(Config.sitePath+"upload", uploadPostHandler)
|
||||
mux.Post(Config.sitePath+"upload/", uploadPostHandler)
|
||||
mux.Put(Config.sitePath+"upload", uploadPutHandler)
|
||||
mux.Put(Config.sitePath+"upload/", uploadPutHandler)
|
||||
mux.Put(Config.sitePath+"upload/:name", uploadPutHandler)
|
||||
|
||||
mux.Delete("/:name", deleteHandler)
|
||||
mux.Delete(Config.sitePath+":name", deleteHandler)
|
||||
|
||||
mux.Get("/static/*", staticHandler)
|
||||
mux.Get("/favicon.ico", staticHandler)
|
||||
mux.Get("/robots.txt", staticHandler)
|
||||
mux.Get(Config.sitePath+"static/*", staticHandler)
|
||||
mux.Get(Config.sitePath+"favicon.ico", staticHandler)
|
||||
mux.Get(Config.sitePath+"robots.txt", staticHandler)
|
||||
mux.Get(nameRe, fileDisplayHandler)
|
||||
mux.Get(selifRe, fileServeHandler)
|
||||
mux.Get(selifIndexRe, unauthorizedHandler)
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<a href="/"><img src='/static/images/404.jpg'></a>
|
||||
<a href="{{ sitepath }}"><img src='{{ sitepath }}static/images/404.jpg'></a>
|
||||
{% endblock %}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href="/static/css/github-markdown.css" rel="stylesheet" type="text/css">
|
||||
<link href="{{ sitepath }}static/css/github-markdown.css" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -3,8 +3,8 @@
|
||||
<head>
|
||||
<title>{% block title %}{{ sitename }}{% endblock %}</title>
|
||||
<meta charset='utf-8' content='text/html' http-equiv='content-type'>
|
||||
<link href='/static/css/linx.css' media='screen, projection' rel='stylesheet' type='text/css'>
|
||||
<link href='/static/images/favicon.gif' rel='icon' type='image/gif'>
|
||||
<link href='{{ sitepath }}static/css/linx.css' media='screen, projection' rel='stylesheet' type='text/css'>
|
||||
<link href='{{ sitepath }}static/images/favicon.gif' rel='icon' type='image/gif'>
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
|
||||
@ -14,12 +14,12 @@
|
||||
<div id="header">
|
||||
<div id="navigation" class="right">
|
||||
{% if !using_auth %}
|
||||
<a href="/">Upload</a> |
|
||||
<a href="/paste/">Paste</a> |
|
||||
<a href="{{ sitepath }}">Upload</a> |
|
||||
<a href="{{ sitepath }}paste/">Paste</a> |
|
||||
{% endif %}
|
||||
<a href="/API/">API</a>
|
||||
<a href="{{ sitepath }}API/">API</a>
|
||||
</div>
|
||||
<h2><a href="/" title="{{ sitename }}">{{ sitename }}</a></h2>
|
||||
<h2><a href="{{ sitepath }}" title="{{ sitename }}">{{ sitename }}</a></h2>
|
||||
</div>
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
{% block main %}
|
||||
<audio class="display-audio" controls preload='auto'>
|
||||
<source src='/selif/{{ filename }}'>
|
||||
<a href='/selif/{{ filename }}'>Download it instead</a>
|
||||
<source src='{{ sitepath }}selif/{{ filename }}'>
|
||||
<a href='{{ sitepath }}selif/{{ filename }}'>Download it instead</a>
|
||||
</audio>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
{% block infomore %}{% endblock %}
|
||||
<span>{{ size }}</span> |
|
||||
<a href="{{ filename }}/torrent" download>torrent</a> |
|
||||
<a href="/selif/{{ filename }}" download>get</a>
|
||||
<a href="{{ sitepath }}selif/{{ filename }}" download>get</a>
|
||||
</div>
|
||||
|
||||
{% block infoleft %}{% endblock %}
|
||||
|
@ -1,14 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href="/static/css/highlight/tomorrow.css" rel="stylesheet" type="text/css">
|
||||
<link href="{{ sitepath }}static/css/highlight/tomorrow.css" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block innercontentmore %} class="scrollable"{% endblock %}
|
||||
|
||||
{% block infoleft %}
|
||||
<div id="editform">
|
||||
<form id="reply" action='/upload' method='post' >
|
||||
<form id="reply" action='{{ sitepath }}upload' method='post' >
|
||||
<div class="right">
|
||||
<select id="expiry" name="expires">
|
||||
<option disabled=disabled>Expires:</option>
|
||||
@ -43,10 +43,10 @@
|
||||
|
||||
|
||||
{% if extra.lang_hl != "text" %}
|
||||
<script src="/static/js/highlight/highlight.pack.js"></script>
|
||||
<script src="/static/js/bin_hljs.js"></script>
|
||||
<script src="{{ sitepath }}static/js/highlight/highlight.pack.js"></script>
|
||||
<script src="{{ sitepath }}static/js/bin_hljs.js"></script>
|
||||
{% endif %}
|
||||
|
||||
<script src="/static/js/util.js"></script>
|
||||
<script src="/static/js/bin.js"></script>
|
||||
<script src="{{ sitepath }}static/js/util.js"></script>
|
||||
<script src="{{ sitepath }}static/js/bin.js"></script>
|
||||
{% endblock %}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block main %}
|
||||
<div class="normal display-file">
|
||||
<p class="center">You are requesting <a href="/selif/{{ filename }}">{{ filename }}</a>, <a href="/selif/{{ filename }}">click here</a> to download.</p>
|
||||
<p class="center">You are requesting <a href="{{ sitepath }}selif/{{ filename }}">{{ filename }}</a>, <a href="{{ sitepath }}selif/{{ filename }}">click here</a> to download.</p>
|
||||
|
||||
{% if files|length > 0 %}
|
||||
<p>Contents of the archive:</p>
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main %}
|
||||
<a href="/selif/{{ filename }}">
|
||||
<img class="display-image" src="/selif/{{ filename }}" />
|
||||
<a href="{{ sitepath }}selif/{{ filename }}">
|
||||
<img class="display-image" src="{{ sitepath }}selif/{{ filename }}" />
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href="/static/css/github-markdown.css" rel="stylesheet" type="text/css">
|
||||
<link href="{{ sitepath }}static/css/github-markdown.css" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
@ -1,10 +1,10 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main %}
|
||||
<object class="display-pdf" data="/selif/{{ filename }}" type="application/pdf">
|
||||
<object class="display-pdf" data="{{ sitepath }}selif/{{ filename }}" type="application/pdf">
|
||||
|
||||
<p>It appears your Web browser is not configured to display PDF files.
|
||||
No worries, just <a href="/selif/{{ filename }}">click here to download the PDF file.</a></p>
|
||||
No worries, just <a href="{{ sitepath }}selif/{{ filename }}">click here to download the PDF file.</a></p>
|
||||
|
||||
</object>
|
||||
{% endblock %}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href="/static/css/story.css" rel="stylesheet" type="text/css">
|
||||
<link href="{{ sitepath }}static/css/story.css" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block innercontentmore %} class="scrollable"{% endblock %}
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
{% block infoleft %}
|
||||
<div id="editform">
|
||||
<form id="reply" action='/upload' method='post' >
|
||||
<form id="reply" action='{{ sitepath }}upload' method='post' >
|
||||
<div class="right">
|
||||
<select id="expiry" name="expires">
|
||||
<option disabled=disabled>Expires:</option>
|
||||
@ -43,6 +43,6 @@
|
||||
</div>
|
||||
|
||||
|
||||
<script src="/static/js/util.js"></script>
|
||||
<script src="/static/js/bin.js"></script>
|
||||
<script src="{{ sitepath }}static/js/util.js"></script>
|
||||
<script src="{{ sitepath }}static/js/bin.js"></script>
|
||||
{% endblock %}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block main %}
|
||||
<video class="display-video" controls autoplay>
|
||||
<source src="/selif/{{ filename }}"/>
|
||||
<a href='/selif/{{ filename }}'>Download it instead</a>
|
||||
<source src="{{ sitepath }}selif/{{ filename }}"/>
|
||||
<a href='{{ sitepath }}selif/{{ filename }}'>Download it instead</a>
|
||||
</video>
|
||||
{% endblock %}
|
||||
|
@ -1,12 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href='/static/css/dropzone.css' media='screen, projection' rel='stylesheet' type='text/css'>
|
||||
<link href='{{ sitepath }}static/css/dropzone.css' media='screen, projection' rel='stylesheet' type='text/css'>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="fileupload">
|
||||
<form action="/upload" class="dropzone" id="dropzone" method="POST" enctype="multipart/form-data" data-maxsize="{{ maxsize }}">
|
||||
<form action="{{ sitepath }}upload" class="dropzone" id="dropzone" method="POST" enctype="multipart/form-data" data-maxsize="{{ maxsize }}">
|
||||
<div class="fallback">
|
||||
<input id="fileinput" name="file" type="file" /><br />
|
||||
<input id="submitbtn" type="submit" value="Upload">
|
||||
@ -39,6 +39,6 @@
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/dropzone.js"></script>
|
||||
<script src="/static/js/upload.js"></script>
|
||||
<script src="{{ sitepath }}static/js/dropzone.js"></script>
|
||||
<script src="{{ sitepath }}static/js/upload.js"></script>
|
||||
{% endblock %}
|
||||
|
@ -1,11 +1,11 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link href="/static/css/hint.css" rel="stylesheet" type="text/css">
|
||||
<link href="{{ sitepath }}static/css/hint.css" rel="stylesheet" type="text/css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form id="reply" action='/upload' method='post'>
|
||||
<form id="reply" action='{{ sitepath }}upload' method='post'>
|
||||
<div id="main">
|
||||
<div id="info" class="ninfo">
|
||||
<input class="codebox" name='filename' id="filename" type='text' value="" placeholder="filename (empty for random filename)" />.<span class="hint--top hint--bounce" data-hint="Enable syntax highlighting by adding the extension"><input id="extension" class="codebox" name='extension' type='text' value="" placeholder="txt" /></span>
|
||||
@ -34,6 +34,6 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/static/js/util.js"></script>
|
||||
<script src="/static/js/paste.js"></script>
|
||||
<script src="{{ sitepath }}static/js/util.js"></script>
|
||||
<script src="{{ sitepath }}static/js/paste.js"></script>
|
||||
{% endblock %}
|
||||
|
@ -103,7 +103,7 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/"+upload.Filename, 303)
|
||||
http.Redirect(w, r, Config.sitePath+upload.Filename, 303)
|
||||
}
|
||||
|
||||
}
|
||||
@ -147,7 +147,7 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if r.FormValue("url") == "" {
|
||||
http.Redirect(w, r, "/", 303)
|
||||
http.Redirect(w, r, Config.sitePath, 303)
|
||||
return
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/"+upload.Filename, 303)
|
||||
http.Redirect(w, r, Config.sitePath+upload.Filename, 303)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user