Compare commits

..

220 commits
v0.8 ... master

Author SHA1 Message Date
Seb3thehacker
9a76ff358f
Update README.md (#272) 2022-03-23 16:27:04 -07:00
Andrei Marcu
282c63153d
Update README.md 2021-12-11 13:27:14 -08:00
Andrei Marcu
926d9bf458
Update README.md 2021-03-17 16:38:36 -07:00
ZizzyDizzyMC
2ccd06b9d7
Adding my own actively maintained fork. (#268) 2021-03-17 16:38:13 -07:00
Andrei Marcu
e41270ab91
Update README.md 2021-03-17 15:41:27 -07:00
Andrei Marcu
94f63c2045
Update README.md 2021-01-25 11:29:55 -08:00
Steven Tang
486cc6ff77
Remove entrypoint from sample docker-compose.yml (#252)
Resolves #225

Entrypoint in Dockerfile specifies default bind, filespath, metapath.
Having entrypoint in docker-compose.yml will remove those defaults.
Without the entrypoint line, the command executed is:
`/usr/local/bin/linx-server -bind=0.0.0.0:8080 -filespath=/data/files/ -metapath=/data/meta/ -config /data/linx-server.conf`
2020-11-29 11:09:53 -08:00
Andrei Marcu
91b9885ac6 Update README.md 2020-10-16 16:57:09 -07:00
tuxx
ef99024433
Add LinxShare android client to README.md (#246) 2020-10-16 16:55:11 -07:00
Andrei Marcu
9a5fc11dff Fix GH action (again) 2020-08-14 00:52:25 -07:00
mutantmonkey
456274c1b9
Split and move auth into a separate package (#224)
* Split and move auth into a separate package

This change will make it easier to implement additional authentication
methods, such as OpenID Connect. For now, only the existing "apikeys"
authentication method is supported.

* Use absolute site prefix to prevent redirect loop
2020-08-14 00:42:45 -07:00
mutantmonkey
a2e00d06e0
Clarify how metadata is stored with the S3 backend (#223)
This was suggested in #221.
2020-08-14 00:40:52 -07:00
Andrei Marcu
965d5f6c29 Fix GH action 2020-08-14 00:39:53 -07:00
Andrei Marcu
8ed205181a Add buildx GH action for multi-arch docker images 2020-08-14 00:32:55 -07:00
Infinoid
5eb6f32ff0
Switch to a more comprehensive mimetype detection library (#231) 2020-08-02 22:16:47 -07:00
Andrei Marcu
6ce2bd6b9f Display pages: Add OpenGraph tags for media 2020-05-14 01:12:24 -07:00
Andrei Marcu
e2a65a5b62 README: Clarify docker usage and example 2020-05-14 00:51:19 -07:00
Andrei Marcu
151515f516 Cleanup: Integrate expired files periodic cleanup 2020-05-13 17:38:03 -07:00
mutantmonkey
bc599ae018
Fix typo in readme (#213)
This should say linx-cleanup, not linx-client.
2020-04-16 14:18:21 -07:00
Björn
8edf53c142
Add systemd unit/timer for the cleanup tool (#210)
* add systemd service for the cleanup script

* add systemd timer for the cleanup service
2020-04-13 12:36:03 -07:00
Andrei Marcu
9f7e6b6eea Torrent: Ranged requests so torrents work 2020-03-18 17:26:43 -07:00
Andrei Marcu
3167ab7ff0 README: Update screenshots 2020-03-12 18:34:08 -07:00
Andrei Marcu
2e0319b602 Fix project name in footer 2020-03-12 17:14:50 -07:00
Andrei Marcu
2b21a5bb81 Mobile: Change initial scale for better fit 2020-03-12 17:11:05 -07:00
Andrei Marcu
49d45f52bb Highlight.js: Add license 2020-03-12 16:43:11 -07:00
Andrei Marcu
7212cd6555 Highlight.js: Update and add languages 2020-03-12 16:35:50 -07:00
Andrei Marcu
53e7aa4568 Dockerfile: Update to 1.14 2020-03-12 14:27:25 -07:00
Andrei Marcu
7543c82473 Remote upload: Add direct_url param for redirect 2020-03-12 14:18:12 -07:00
Andrei Marcu
a0c508c422 Travis: Update to 1.14 2020-03-12 13:47:57 -07:00
Andrei Marcu
c61db30f9f Tests: Fix image torrent test 2020-03-12 13:44:28 -07:00
Andrei Marcu
fb0d44f132 Custom pages: Implement adding custom markdown pages to the site navigation 2020-03-12 13:32:35 -07:00
Andrei Marcu
9f6346a373 Basic auth: fix for using different paths 2020-03-12 01:20:56 -07:00
Andrei Marcu
a4c0e0ac37 .gitignore: Add ignore entries 2020-03-11 02:01:38 -07:00
Andrei Marcu
68a80d3698 Go mod: update to 1.14 2020-03-11 02:00:37 -07:00
Thor77
9a8bb1bb7f Add support for go modules 2020-03-11 01:58:36 -07:00
Andrei Marcu
773eb877bd Basic auth: Fix #201 - broken uploads 2020-03-10 22:45:24 -07:00
Andrei Marcu
7ca3331044 Access Key: Fix mobile access 2020-03-07 18:52:29 -08:00
Andrei Marcu
e4468715ac Merge branch 'stek29-accesskey' 2020-03-07 17:53:20 -08:00
Andrei Marcu
e06e9ad6fe Access key: Some cosmetic changes 2020-03-07 17:52:07 -08:00
Andrei Marcu
a4240680c8 Merge branch 'accesskey' of git://github.com/stek29/linx-server into stek29-accesskey 2020-03-06 15:29:41 -08:00
Andrei Marcu
779fc5c425 Readme: Clarify basic auth usage 2020-03-06 15:26:10 -08:00
Paweł Płazieński
597bec430c
Allow Basic authentication in browser (#195) 2020-03-06 15:21:49 -08:00
Andrei Marcu
fabb8f2dd7 S3: Add retro-compatibility for Delete_key 2020-03-06 15:04:32 -08:00
Preben Uhrskov Berg
a86a144485
Remove dash from DeleteKey for 3rd party S3 compatibility (#192) 2020-03-06 14:49:42 -08:00
Viktor Oreshkin
c53b850aef add access_key to api 2020-03-01 04:00:39 +03:00
Viktor Oreshkin
4baaa0a15f add access_key to paste 2020-03-01 03:56:43 +03:00
Viktor Oreshkin
3947197225 wrap access.html in white container 2020-03-01 03:47:28 +03:00
Viktor Oreshkin
5a6e589500 redesign access key input box in uploader 2020-03-01 03:43:53 +03:00
Viktor Oreshkin
4361c44128 fix domain field in setAccessKeyCookies 2020-03-01 03:24:01 +03:00
Viktor Oreshkin
b63274ad01 allow limiting access by passwords (fix #194) 2020-02-17 18:02:47 +03:00
Andrei Marcu
cf0a30f46a
Add URL to demo 2020-01-16 16:26:25 -08:00
Andrei Marcu
1d583bcb48 Fix #189 - Markdown lists don't show numbers/bullets 2019-12-02 18:38:07 -08:00
Andrei Marcu
85be5b078d Add a max-height for videos display 2019-12-02 18:30:15 -08:00
PaulC
0e763cb776 Allow UNIX socket in FastCGI mode (check if bind starts with /) (#190)
Allow UNIX socket in FastCGI mode (check if bind starts with /)
2019-12-02 18:24:11 -08:00
nia
bf090c5119 build.sh: build for netbsd (#181) 2019-06-13 12:50:59 -07:00
mutantmonkey
50c1bdc018 Fix S3 uploads (#178)
My previous change that reworked how metadata generation worked was not
correct for two reasons:

* It passed the original `io.Reader` (with no bytes remaining) to
  `GenerateMetadata`
* It did not seek back to the beginning of the temporary file after
  writing to it, causing any subsequent reads to return EOF.

This change fixes both issues and S3 uploads now work fine. We really
ought to investigate adding test coverage to our S3 backend to avoid
similar recurrences.
2019-06-04 18:35:52 +02:00
mutantmonkey
872340e0dc Fix PutMetadata with S3 backend (#176)
It turns out that the S3 API expects the additional `MetadataDirective:
REPLACE` option in order to update metadata. If this is not provided,
then metadata will simply be copied from the source object, which is not
what we wanted.
2019-05-09 09:13:58 -07:00
mutantmonkey
8098b7e39e Add PutMetadata function to storage backends (#171)
* Add PutMetadata function to storage backends

This function is not currently used, but it will be useful for helper
scripts that need to regenerate metadata on the fly, especially scripts
to migrate between storage backends. In the future, we can also use it
to automatically regenerate metadata if it is found to be missing or
corrupted.

* Add PutMetadata function to storage backend interface and
  implementations
* Rework metadata generation to be more efficient and work better with
  the PutMetadata function
* Add a basic test for metadata generation

* Change PutMetadata to take a Metadata type instead

It's unlikely that this function is useful if it always regenerates the
metadata. Instead, the caller should do that if it needs.
2019-04-09 13:28:18 -07:00
Andrei Marcu
2c0b2b2e79 README reordering 2019-03-14 10:58:17 -07:00
mutantmonkey
770cb20479 Add support for conditional requests (#162)
This change pulls in some code copied from net/http's fs.go so that we
can support If-Match/If-None-Match requests. This will make it easy to
put a caching proxy in front of linx-server instances. Request
validation will still happen as long as the proxy can contact the
origin, so expiration and deletion will still work as expected under
normal circumstances.
2019-01-30 22:52:43 -08:00
mutantmonkey
73f127306c Improve UI a bit (#161)
* Remove right margin from expiration dropdown on index
* Use flexbox for bin/story display
* Move Paste/Save button after expire dropdown, instead of before
2019-01-28 23:00:07 -08:00
mutantmonkey
f46b61399b Fix broken page when file is missing (#160)
With the localfs backend, it's possible for a file to be removed but its
metadata file to remain intact. In this case, viewing the selif URL for
that file would return a broken page with two error pages stacked on top
of each other. This changes fixes that by replacing the output in that
case with a single "Unable to open file." error message.
2019-01-26 16:32:37 -08:00
Andrei Marcu
cde964ffe0 Hide filename input when force random is on 2019-01-26 02:12:49 -08:00
mutantmonkey
8f3108148b Add option to force random filenames (fixes #86) (#159) 2019-01-26 02:04:32 -08:00
Andrei Marcu
a79bc1898a Add binaries/ to .gitignore 2019-01-26 01:00:04 -08:00
mutantmonkey
5037573eab Clean up build.sh and build for linux/arm64 (#158)
* Clean up build.sh and build for linux/arm64
2019-01-26 00:56:35 -08:00
Andrei Marcu
d5aa09a65c
Update screenshots in readme 2019-01-25 01:10:09 -08:00
Andrei Marcu
f6cd7fc6fe Tweak documentation 2019-01-25 00:20:52 -08:00
mutantmonkey
207c19e3df Add -s3-force-path-style flag and config option (#157)
This option forces path-style addressing instead of using a subdomain.
This appears to be needed by Minio.
2019-01-25 00:10:06 -08:00
Andrei Marcu
35c4415f8d Document storage backend usage 2019-01-24 23:39:17 -08:00
mutantmonkey
5d9a93b1e2 Add S3 backend (#156) 2019-01-24 23:33:11 -08:00
Thomas Sänger
0fb5fa1c51 use sha256-simd (#155) 2019-01-24 23:21:49 -08:00
Andrei Marcu
b731e17c1e Cosmetic tweaks & fixes 2019-01-16 02:27:05 -08:00
Simon Alfassa
fd0f3d9e46 Make the web page mobile friendly 2019-01-16 01:09:55 -08:00
mutantmonkey
5340f23f4d Add new multi-stage slim Dockerfile (#154) 2019-01-14 22:41:03 -08:00
Andrei Marcu
9d7f698c70
Add direct_url info to API page 2019-01-14 16:16:15 -08:00
Andrei Marcu
e506304b84 Return direct URL in json responses 2019-01-14 15:28:32 -08:00
Andrei Marcu
1fb92ffce3 Fix bug where using curl with json headers would return the file instead 2019-01-14 15:28:28 -08:00
Andrei Marcu
c746f70c10 Allow changing the "selif" path name 2019-01-14 14:55:27 -08:00
Benjamin Neff
6290f408ff Allow to paste images (#153)
dropzone.js doesn't support pasting itself yet, so adding it externally
and calling `.addFile()` to upload the pasted image.

Fixes #130
2019-01-11 09:09:54 -08:00
mutantmonkey
5f4f16e08b Add file ETag support (fix #138) (#152) 2019-01-08 20:28:01 -08:00
mutantmonkey
10938a3e0b Remove Google URL shortener (fix #146) (#150) 2019-01-08 11:56:32 -08:00
mutantmonkey
bad7d2666e Switch to Referrer-Policy header (#149)
Use of the Content-Security-Policy header to specify a referrer policy
was deprecated in favor of a [new
header](fc55d917be).
This change changes the existing referrer policy directives to use this
header and adds corresponding config options/command line flags.
2019-01-08 11:56:09 -08:00
Andrei Marcu
19a95e36a6 Fix Travis parsing of 1.10 as 1.1 2019-01-08 11:28:10 -08:00
Andrei Marcu
f19247a790 Update Travis to 1.10 and 1.11 2019-01-08 11:18:57 -08:00
Thor77
5d8a0ef605 Serve file directly for curl and wget user agents (#145)
* Serve file directly for curl and wget user agents

Fix #127

* Add test for get with wget user agent

* Add -nodirectagents flag

to disable serving files directly for wget/curl user agents

* Fix TestPutAndGetCLI failing for Go 1.5

It failed because it doesn't include the Content-Type header for every
response.
2018-11-07 10:13:27 -08:00
Andrei Marcu
7c024d9aab
Merge pull request #141 from bruj0/patch-1
Fix files and meta permissions
2018-04-25 21:39:21 -07:00
Rodrigo D. L
b82371250a
Fix files and meta permissions
When running under docker-compose the volume changes the permissions by default to root but its avoided if the directory where it is mounted is created first with the correct owner.
2018-04-21 13:01:25 -03:00
Andrei Marcu
4fa6423a85
Merge pull request #137 from mutantmonkey/issue_136
Fix -nologs on linx-cleanup tool (closes #136)
2018-02-26 12:01:33 -08:00
mutantmonkey
c015b5f1da Fix -nologs on linx-cleanup tool (closes #136) 2018-02-25 14:47:04 -08:00
andreimarcu
e86f19ecb1 Add linx-cleanup to build script 2017-10-10 22:14:53 -07:00
Andrei Marcu
ceea32de6b Merge pull request #124 from mutantmonkey/cleanup_tool
Add linx-cleanup tool
2017-05-04 23:06:26 -07:00
mutantmonkey
a69aa95a87 Add linx-cleanup info to readme 2017-05-04 21:55:15 -07:00
mutantmonkey
32b537a057 Add missing flag.Parse() call 2017-05-03 21:12:41 -07:00
mutantmonkey
c6f62fccdf Drop Mercurial from Dockerfile
We no longer have any Mercurial dependencies, so we don't need to
install it anymore.
2017-05-01 21:49:27 -07:00
mutantmonkey
b7fadd9676 Add linx-cleanup tool
This doesn't completely fix #116, but it makes setting up a cron job to
do cleanup much more pleasant.
2017-05-01 21:27:28 -07:00
Andrei Marcu
d8568e141f Merge pull request #121 from mutantmonkey/remove_mime_extension_map
Remove mime type to extension map from util.go
2017-03-29 21:42:31 -07:00
mutantmonkey
bb7f7a1774 Remove mime type to extension map from util.go
This is no longer used, so it can be removed.
2017-03-25 15:11:21 -07:00
andreimarcu
37f9a0cbbc Change unknown extension from .ext to .file 2017-03-25 08:44:18 -07:00
Andrei Marcu
1c1d3127ab Merge pull request #120 from mutantmonkey/switch_to_filetype
Switch to https://github.com/h2non/filetype
2017-03-25 08:22:28 -07:00
mutantmonkey
e6ac89d6dc Switch to https://github.com/h2non/filetype
This library is much better at detecting MIME types properly than the
existing one. Fixes #117.
2017-03-25 01:08:56 -07:00
Andrei Marcu
e588d78299 Merge pull request #112 from mutantmonkey/issue_111
Fix max expiry when provided expiry is 0
2016-11-02 19:36:59 -07:00
mutantmonkey
647aa2c0f6 Fix max expiry when provided expiry is 0
Previously, we did not properly handle the case where the provided
expiry was zero and the max expiry was configured to be nonzero; add an
additional check to cover this case.

Fixes #111.
2016-11-02 19:31:32 -07:00
Andrei Marcu
0e768cc6f4 Merge pull request #109 from culdev/master
Fix file upload for Internet Explorer
2016-10-23 13:16:08 -07:00
culdev
8f384dc5ce Use value instead of selectedOptions. 2016-10-23 21:07:47 +02:00
Andrei Marcu
e9ae7a794f Merge pull request #105 from Thor77/systemd-service
Add Install-section to systemd-service
2016-10-11 07:56:44 -07:00
Thor77
c75cd5ef9e Add Install-section to systemd-service 2016-10-09 14:59:54 +02:00
andreimarcu
eb036f2819 Fix typo 2016-09-18 22:13:52 -07:00
Andrei Marcu
29d3157a03 Merge pull request #102 from mutantmonkey/maxexpiry
Add option for maximum expiration time (fixes #99)
2016-09-18 22:09:05 -07:00
mutantmonkey
fef43d856e Add option for maximum expiration time (fixes #99) 2016-09-18 22:05:26 -07:00
Andrei Marcu
3321144e74 Merge pull request #101 from mutantmonkey/docker
Add Dockerfile
2016-09-17 20:27:57 -07:00
mutantmonkey
932a470ead add Docker instructions to readme 2016-09-17 20:20:46 -07:00
mutantmonkey
2e5521ce7d Add Dockerfile
This will build the binary directly in the image without a need to have
Go installed locally.
2016-09-17 19:27:39 -07:00
Thor77
4ef3f33821 Add systemd-service (#96) 2016-08-22 11:02:46 -10:00
andreimarcu
81a1513809 Add newline for PUT response 2016-07-22 18:15:44 -07:00
andreimarcu
1e1f28658d Remove spaces in mime mapping and ensure no spaces in filenames 2016-07-22 18:08:59 -07:00
Andrei Marcu
ca11d99678 Merge pull request #93 from mutantmonkey/reduce_open_calls
Remove unnecessary file processing in display.go
2016-07-07 20:06:49 -07:00
mutantmonkey
93d37002dd remove unnecessary file processing in display.go
There is no need to open the file here; nothing is done with the header
after it is read.
2016-07-07 19:34:53 -07:00
andreimarcu
9467be9717 No margin/border without line numbers 2016-06-17 21:22:24 -07:00
andreimarcu
e6db8553b0 Fix line numbers for text 2016-06-16 22:33:32 -07:00
Atrox
027f5cce42 Add ability to short urls for uploaded content (#85)
Add ability to short urls for uploaded content
2016-06-15 08:42:57 -07:00
Andrei Marcu
30d2d63466 Merge pull request #87 from Atrox/sitename
Fix that custom sitename gets ignored
2016-06-15 08:30:42 -07:00
Atrox
aedd7bc589 Fix that custom sitename gets ignored 2016-06-15 14:33:51 +02:00
andreimarcu
f06b06fe76 Add overflow-wrap to lines.css 2016-06-15 01:35:03 -07:00
andreimarcu
0a361a268c Get rid of highlightjs-line-numbers.js 2016-06-15 01:17:25 -07:00
andreimarcu
d6755486b2 Sanitize upload response (Fixes #79) 2016-06-15 00:16:57 -07:00
andreimarcu
e8d2d75c1c Update documentation 2016-06-14 23:38:36 -07:00
andreimarcu
47a1aa6396 Infer sitename from Host if empty 2016-06-14 23:21:39 -07:00
Andrei Marcu
9c6088cfe5 Merge pull request #84 from mutantmonkey/abstract_storage
use abstracted storage for flexibility
2016-06-14 21:10:46 -07:00
mutantmonkey
fcd18eceec use abstracted storage for flexibility
I moved the storage functionality into the StorageBackend interface,
which is currently only implemented by LocalfsBackend.
2016-06-08 20:18:31 -07:00
Andrei Marcu
61eb32a79b Merge pull request #83 from mutantmonkey/csp_frame_ancestors
Use Content-Security-Policy frame-ancestors
2016-06-05 00:29:13 -07:00
Andrei Marcu
2fb58e7da1 Merge pull request #82 from mutantmonkey/infer_siteurl
Infer site URL from host and headers
2016-06-05 00:28:46 -07:00
mutantmonkey
47670af185 Infer site URL from host and headers
We can use the Host property of the request and the X-Forwarded-Proto to
infer the site URL. To reduce complexity, the path is not inferred, and
it is assumed that linx-server is running at /. If this is not the case,
the site URL must be manually configured; this is no different than it
was before.
2016-06-04 18:34:22 -07:00
mutantmonkey
2b5cc07005 Use Content-Security-Policy frame-ancestors
X-Frame-Options has been deprecated by Content Security Policy Level 2.
We will need to provide the option for older browsers for the time
being, but frame-ancestors is preferred on newer ones.
2016-06-04 15:04:32 -07:00
andreimarcu
afa65349cc Fix typos in API template 2016-06-04 00:36:51 -07:00
Andrei Marcu
14ba403145 Merge pull request #81 from mutantmonkey/addheaders
Add ability to set arbitrary headers
2016-06-03 22:59:29 -07:00
mutantmonkey
39bb999db6 Add ability to set arbitrary headers
This is useful if you want to add headers for things like HTTP Strict
Transport Security or HTTP Public Key Pinning.
2016-06-03 22:49:01 -07:00
Andrei Marcu
1f3bc4bfea Merge branch 'mutantmonkey-better_extension_handling' 2016-02-15 14:44:43 -08:00
mutantmonkey
b0d2f2a142 support .tar.gz-style extensions
Some extensions actually consist of multiple parts, like .tar.gz, so we
should handle this properly instead of merging part of the extension
with the bare name. Right now only tar is allowed, but others can be
added easily.

Fixes #74.
2016-02-12 21:27:39 -08:00
Andrei Marcu
bc66bcc069 Merge pull request #73 from mutantmonkey/workaround_chrome_nonsense
workaround chrome nonsense with CSP
2015-12-04 22:34:36 -05:00
mutantmonkey
817ac67632 workaround chrome nonsense with CSP
Apparently the Chromium developers have decided that it was a good idea
for them to use inline styles on the image/PDF viewers in their browser.
I have no idea why they would think this, as it is not, but since this
causes breakage we allow unsafe-inline for styles on files.
2015-12-04 19:28:30 -08:00
andreimarcu
5dcfca5f74 Order matters no. 2 2015-12-04 00:19:33 -05:00
andreimarcu
7c1a4640db Order matters! 2015-12-02 14:58:48 -05:00
andreimarcu
88c00027ea Add line numbers for pastebin. Fixes #70 2015-11-12 11:17:53 -05:00
andreimarcu
10d30df81f Fix out of bounds error 2015-11-12 01:04:05 -05:00
andreimarcu
9cf55ac687 Redirect hotlink instead of 403. Fixes #69 2015-11-12 00:56:22 -05:00
andreimarcu
e6d79eb5cf Temporary fix for text detection 2015-10-30 23:13:43 -04:00
andreimarcu
4856ab0750 Allow for non-/ deployments. Fixes #61 2015-10-30 18:36:47 -04:00
andreimarcu
07aaad2cd8 Match more text mimetypes 2015-10-28 15:55:56 -04:00
andreimarcu
294e8d8be2 Better text detection 2015-10-28 15:21:54 -04:00
andreimarcu
9b1df43ef2 Trim "-" in filenames 2015-10-28 14:31:51 -04:00
andreimarcu
0b37309237 Allow configuration from ini-style file 2015-10-25 14:04:38 -04:00
andreimarcu
c53c909165 Remove unnecessary margin on pastebins 2015-10-21 21:41:27 -04:00
andreimarcu
be08b7f0fd Remove "sandbox" from files CSP to have pdfs work in chrome 2015-10-21 18:20:14 -04:00
andreimarcu
ba9fcd3a7b Document allowing hotlinking 2015-10-18 11:08:47 -04:00
andreimarcu
c8fc62398a Enable randomize in remote uploads 2015-10-18 11:07:39 -04:00
andreimarcu
20456b0b3c Updarte README.md 2015-10-15 20:16:02 -04:00
andreimarcu
39ae89107c Update README.md 2015-10-15 19:51:52 -04:00
andreimarcu
7df3b1328e Update README.md 2015-10-15 19:33:38 -04:00
andreimarcu
50a54bbcfc Add linx-client in API documentation 2015-10-15 17:26:35 -04:00
andreimarcu
0d365409d0 Allow /upload/ for PUT requests without filename 2015-10-15 16:02:46 -04:00
andreimarcu
120909ce46 Template file was missing 2015-10-15 12:26:43 -04:00
andreimarcu
c77f8285d4 Fix/implement .story 2015-10-15 12:24:23 -04:00
andreimarcu
9847beeff5 Cleanup 2015-10-14 22:47:36 -04:00
andreimarcu
3c659601e2 Make it an option for post uploads 2015-10-14 20:40:25 -04:00
andreimarcu
9b724725b3 Blank referrers are allowed 2015-10-14 20:35:43 -04:00
andreimarcu
256ca43d69 Update API documentation with API keys 2015-10-14 16:47:13 -04:00
andreimarcu
b1e82f8d7f Update build.sh to build linx-genkey 2015-10-14 16:31:52 -04:00
andreimarcu
68653372ff Rename auth header to Linx-Api-Key and remove
b64encoding requirement for uploading with keys
2015-10-14 16:18:29 -04:00
andreimarcu
6987edc0d8 Remove non-API navigation links when using auth 2015-10-14 15:20:41 -04:00
andreimarcu
be15ba076d Removed unnecessary duplicate static caching 2015-10-14 14:58:27 -04:00
Andrei Marcu
e1b2896c64 Merge pull request #60 from mutantmonkey/proper_referrer_check
do a proper same-origin check
2015-10-13 23:04:39 -04:00
mutantmonkey
d138755806 do a proper same-origin check
String prefix matching is hacky and provides insufficient checking if it
does not end with a /.
2015-10-13 19:55:32 -07:00
Andrei Marcu
ff1d9f56a1 Merge pull request #59 from mutantmonkey/csp_referrer_fix
fix CSP referrer policy
2015-10-12 10:01:50 -04:00
mutantmonkey
a3723d3665 short-circuit on origin header
If the Origin header is present, we can check it and skip the other
checks.
2015-10-12 01:23:06 -07:00
mutantmonkey
0a1aa869e4 nicer 400 error page 2015-10-12 01:03:02 -07:00
mutantmonkey
a7ae455ac1 strict referrer check improvements
* Always check Origin if it is present, regardless of headers sent
* Whitelist X-Requested-With header
2015-10-12 00:28:04 -07:00
mutantmonkey
61147554a9 update CSP flags in readme 2015-10-12 00:02:22 -07:00
mutantmonkey
cd83f9f0eb fix CSP referrer policy
The policy of "referrer none" was incorrect and was nonfunctional. With
this change, the CSP referrer policy is set to origin, which
will causes only the origin to be sent for requests made from the main
site.

A fix was also needed for referrer checks in two places.
2015-10-11 23:49:15 -07:00
Andrei Marcu
4fee922543 Merge pull request #58 from mutantmonkey/referrer_fixup2
trim trailing / for origin checking
2015-10-11 23:07:45 -04:00
mutantmonkey
39d874374d trim trailing / for origin checking 2015-10-11 20:06:14 -07:00
Andrei Marcu
60239467fd Merge pull request #56 from mutantmonkey/auth
Add support for auth keys (and remote auth keys)
2015-10-11 22:44:30 -04:00
mutantmonkey
613ab24721 show usage for -authfile and -remoteauthfile 2015-10-11 19:38:04 -07:00
mutantmonkey
2cd432b5d3 update readme 2015-10-11 19:33:48 -07:00
mutantmonkey
dd4ac3a7ed add support remote auth keys
These are taken as a parameter to the remote upload page. Note that all
keys will be logged since this is a GET request.
2015-10-11 19:31:13 -07:00
mutantmonkey
3dc4753b7a move reading auth keys into readAuthKeys 2015-10-11 19:30:01 -07:00
andreimarcu
104f648c0f Remove artifact 2015-10-11 21:42:00 -04:00
andreimarcu
ae02f537f7 Add linx-genkey 2015-10-11 21:39:42 -04:00
mutantmonkey
adbc1604dc add some more auth tests
It's going to be difficult to get 100% code coverage, but we can at
least ensure that checkAuth works properly.
2015-10-11 18:37:36 -07:00
mutantmonkey
cc4e2ca0d9 read authfile once only
Read the authfile upon initial server start and store the auth keys in
the auth struct, rather than reading the file for each page load.
2015-10-11 18:36:27 -07:00
mutantmonkey
3c9e260926 improve auth tests and rename auth struct 2015-10-11 17:43:31 -07:00
mutantmonkey
aa7dad3a03 add support for auth keys
Add a middleware that requires authorization for all POST, PUT, and
DELETE requests. This is done using the Authorization header and the
provided auth key is then checked against a file containing scrypted
auth keys. These keys are salted the constant string `linx-server`.
2015-10-11 17:34:53 -07:00
andreimarcu
2b0135697b Add option for using Real-IP 2015-10-11 20:32:28 -04:00
andreimarcu
9ac016c3b5 Document overwriting a file 2015-10-11 20:28:46 -04:00
Andrei Marcu
6c9d517c80 Merge pull request #55 from mutantmonkey/redirect_fix
use 303 redirects instead of 301s
2015-10-10 23:25:57 -04:00
mutantmonkey
52ec9f8e2d use 303 redirects instead of 301s
HTTP status code 301 is for a permanent redirect, which these are not.
Although 302 would work here in most browsers, it would not follow the
HTTP spec, so instead we use 303 which has a clearly and consistently
defined behavior in response to a POST or PUT request.
2015-10-10 20:22:10 -07:00
andreimarcu
354278d488 Real-IP middleware for fastcgi + nginx doc update 2015-10-10 11:22:24 -04:00
andreimarcu
ef13181a23 Adjust the csp_test to use the new mux 2015-10-10 11:17:38 -04:00
Andrei Marcu
d42b2d28ac Merge pull request #53 from mutantmonkey/fixbind
Replace -b and -bind with a single -bind
2015-10-10 11:14:54 -04:00
mutantmonkey
5600dd1ce3 update readme for new -bind flag 2015-10-09 23:16:30 -07:00
mutantmonkey
82edabd036 change -b flag to -bind
This is for consistency with Goji's default flag and is more clear.
2015-10-09 23:06:28 -07:00
mutantmonkey
a09297389b create our own mux instead of using goji default
This is a better way to do things since we were customizing middleware
and everything anyway. It's also necessary in order to avoid pulling in
the default Goji -bind flag: https://github.com/zenazn/goji/issues/47
2015-10-09 23:04:08 -07:00
Andrei Marcu
95d3a62c0c Merge pull request #52 from mutantmonkey/textarea_tab
add tab functionality to pastebin (resolves #48)
2015-10-10 01:25:18 -04:00
mutantmonkey
e0d0e40368 add tab functionality to pastebin (resolves #48)
The tab key now inserts a tab instead of changing the focus.
2015-10-09 22:21:23 -07:00
Andrei Marcu
883768f512 Merge pull request #51 from mutantmonkey/blacklist_fixup
add crossdomain.xml to file blacklist
2015-10-09 18:45:03 -04:00
mutantmonkey
874c23087d add crossdomain.xml to file blacklist 2015-10-09 00:06:23 -07:00
andreimarcu
eeede281a7 Case insensitive fs again 2015-10-08 23:58:57 -04:00
Andrei Marcu
d9723b8350 Merge pull request #49 from mutantmonkey/referrer_check
add strict referrer check for POST uploads
2015-10-08 23:35:19 -04:00
mutantmonkey
6ff181facb add strict referrer check for POST uploads
This should protect against cross-site request forgery without the need
for cookies. It continues to allow requests with Linx-Delete-Key,
Linx-Expiry, or Linx-Randomize headers as these will not be set in the
case of cross-site requests.
2015-10-08 20:27:04 -07:00
andreimarcu
5885ef0832 Case-insensitive filesystems... 2015-10-08 21:50:10 -04:00
andreimarcu
62443e984d API documentation. Fixes #30 2015-10-08 21:48:06 -04:00
andreimarcu
e9132a1193 File overwriting support. Fixes #8 2015-10-08 12:49:29 -04:00
andreimarcu
8ad079ed0a Fix readme 2015-10-08 01:40:03 -04:00
andreimarcu
639d519712 Configurable maximum upload file size. Fixes #35 2015-10-08 01:38:50 -04:00
andreimarcu
040ffa89f7 Adjust margin 2015-10-08 01:18:21 -04:00
andreimarcu
37d3e96e22 Fix no-javascript fallback ugliness of index page. Fixes #37 2015-10-08 00:19:22 -04:00
andreimarcu
ed6ce1d1fa Small cosmetic changes 2015-10-07 23:49:21 -04:00
andreimarcu
a60a7cc9e6 Cache static files + Separate CSS more. Fixes #44 2015-10-07 23:35:48 -04:00
andreimarcu
6e33fe6ac8 Metadata holds mimetype, sha256sum, archiveFiles 2015-10-07 22:45:34 -04:00
andreimarcu
d05f0b645b Display contents of common archives. Fixes #34 2015-10-07 16:45:41 -04:00
81 changed files with 5832 additions and 2249 deletions

60
.github/workflows/buildx.yaml vendored Normal file
View file

@ -0,0 +1,60 @@
name: buildx
on:
push:
tags:
- 'v*'
jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Prepare
id: prepare
run: |
DOCKER_IMAGE=andreimarcu/linx-server
DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386
VERSION=version-${GITHUB_REF#refs/tags/v}
TAGS="--tag ${DOCKER_IMAGE}:${VERSION} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} --file Dockerfile .
-
name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
-
name: Docker Buildx (build)
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
-
name: Docker Login
if: success()
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
-
name: Docker Buildx (push)
if: success()
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}
-
name: Docker Check Manifest
if: always()
run: |
docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
-
name: Clear
if: always()
run: |
rm -f ${HOME}/.docker/config.json

8
.gitignore vendored
View file

@ -20,6 +20,8 @@ _cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
.DS_Store
_testmain.go
*.exe
@ -27,5 +29,11 @@ _testmain.go
*.prof
linx-server
linx-cleanup/linx-cleanup
linx-genkey/linx-genkey
linx-server.conf
files/
meta/
binaries/
custom_pages/
authfile

View file

@ -1,7 +1,7 @@
language: go
go:
- 1.5
- "1.14"
before_script:
- go vet ./...

28
Dockerfile Normal file
View file

@ -0,0 +1,28 @@
FROM golang:1.14-alpine3.11 AS build
COPY . /go/src/github.com/andreimarcu/linx-server
WORKDIR /go/src/github.com/andreimarcu/linx-server
RUN set -ex \
&& apk add --no-cache --virtual .build-deps git \
&& go get -v . \
&& apk del .build-deps
FROM alpine:3.11
COPY --from=build /go/bin/linx-server /usr/local/bin/linx-server
ENV GOPATH /go
ENV SSL_CERT_FILE /etc/ssl/cert.pem
COPY static /go/src/github.com/andreimarcu/linx-server/static/
COPY templates /go/src/github.com/andreimarcu/linx-server/templates/
RUN mkdir -p /data/files && mkdir -p /data/meta && chown -R 65534:65534 /data
VOLUME ["/data/files", "/data/meta"]
EXPOSE 8080
USER nobody
ENTRYPOINT ["/usr/local/bin/linx-server", "-bind=0.0.0.0:8080", "-filespath=/data/files/", "-metapath=/data/meta/"]
CMD ["-sitename=linx", "-allowhotlink"]

192
README.md
View file

@ -1,38 +1,168 @@
# Development on this repository has been frozen.
Linx Server
Feel free to send a pull request if you are maintaining an active fork of this project to add a link to your repository in this readme.
### Active Forks
- ZizzyDizzyMC: [https://github.com/ZizzyDizzyMC/linx-server/](https://github.com/ZizzyDizzyMC/linx-server/)
- Seb3thehacker: [https://github.com/Seb3thehacker/linx-server](https://github.com/Seb3thehacker/linx-server)
---
linx-server
======
[![Build Status](https://travis-ci.org/andreimarcu/linx-server.svg?branch=master)](https://travis-ci.org/andreimarcu/linx-server)
Self-hosted file/media sharing website.
### Clients
**Official**
- CLI: **linx-client** - [Source](https://github.com/andreimarcu/linx-client)
**Unofficial**
- Android: **LinxShare** - [Source](https://github.com/iksteen/LinxShare/) | [Google Play](https://play.google.com/store/apps/details?id=org.thegraveyard.linxshare)
- CLI: **golinx** - [Source](https://github.com/mutantmonkey/golinx)
Soon-to-be opensource replacement of Linx (media-sharing website)
### Features
**Consider it in pre-alpha development stages.**
- Display common filetypes (image, video, audio, markdown, pdf)
- Display syntax-highlighted code with in-place editing
- Documented API with keys for restricting uploads
- Torrent download of files using web seeding
- File expiry, deletion key, file access key, and random filename options
Get release and run
### Screenshots
<img width="730" src="https://user-images.githubusercontent.com/4650950/76579039-03c82680-6488-11ea-8e23-4c927386fbd9.png" />
<img width="180" src="https://user-images.githubusercontent.com/4650950/76578903-771d6880-6487-11ea-8baf-a4a23fef4d26.png" /> <img width="180" src="https://user-images.githubusercontent.com/4650950/76578910-7be21c80-6487-11ea-9a0a-587d59bc5f80.png" /> <img width="180" src="https://user-images.githubusercontent.com/4650950/76578908-7b498600-6487-11ea-8994-ee7b6eb9cdb1.png" /> <img width="180" src="https://user-images.githubusercontent.com/4650950/76578907-7b498600-6487-11ea-8941-8f582bf87fb0.png" />
Getting started
-------------------
1. Grab the latest binary from the [releases](https://github.com/andreimarcu/linx-server/releases)
2. Run ```./linx-server...```
Command-line options
--------------------
- ```-b 127.0.0.1:8080``` -- what to bind to (default is 127.0.0.1:8080)
- ```-sitename myLinx``` -- the site name displayed on top (default is linx)
- ```-siteurl "http://mylinx.example.org/"``` -- the site url (for generating links)
- ```-filespath files/"``` -- Path to store uploads (default is files/)
- ```-metapath meta/``` -- Path to store information about uploads (default is meta/)
- ```-certfile path/to/your.crt``` -- Path to the ssl certificate (required if you want to use the https server)
- ```-keyfile path/to/your.key``` -- Path to the ssl key (required if you want to use the https server)
- ```-contentsecuritypolicy "..."``` -- Content-Security-Policy header for pages (default is "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; referrer none;")
- ```-filecontentsecuritypolicy "..."``` -- Content-Security-Policy header for files (default is "default-src 'none'; img-src 'self'; object-src 'self'; media-src 'self'; sandbox; referrer none;"")
- ```-xframeoptions "..." ``` -- X-Frame-Options header (default is "SAMEORIGIN")
- ```-remoteuploads``` -- (optionally) enable remote uploads (/upload?url=https://...)
- ```-fastcgi``` -- (optionally) serve through fastcgi
- ```-nologs``` -- (optionally) disable request logs in stdout
#### Using Docker
1. Create directories ```files``` and ```meta``` and run ```chown -R 65534:65534 meta && chown -R 65534:65534 files```
2. Create a config file (example provided in repo), we'll refer to it as __linx-server.conf__ in the following examples
Example running
```
docker run -p 8080:8080 -v /path/to/linx-server.conf:/data/linx-server.conf -v /path/to/meta:/data/meta -v /path/to/files:/data/files andreimarcu/linx-server -config /data/linx-server.conf
```
Example with docker-compose
```
version: '2.2'
services:
linx-server:
container_name: linx-server
image: andreimarcu/linx-server
command: -config /data/linx-server.conf
volumes:
- /path/to/files:/data/files
- /path/to/meta:/data/meta
- /path/to/linx-server.conf:/data/linx-server.conf
network_mode: bridge
ports:
- "8080:8080"
restart: unless-stopped
```
Ideally, you would use a reverse proxy such as nginx or caddy to handle TLS certificates.
#### Using a binary release
1. Grab the latest binary from the [releases](https://github.com/andreimarcu/linx-server/releases), then run ```go install```
2. Run ```linx-server -config path/to/linx-server.conf```
Usage
-----
#### Configuration
All configuration options are accepted either as arguments or can be placed in a file as such (see example file linx-server.conf.example in repo):
```ini
bind = 127.0.0.1:8080
sitename = myLinx
maxsize = 4294967296
maxexpiry = 86400
# ... etc
```
...and then run ```linx-server -config path/to/linx-server.conf```
#### Options
|Option|Description
|------|-----------
| ```bind = 127.0.0.1:8080``` | what to bind to (default is 127.0.0.1:8080)
| ```sitename = myLinx``` | the site name displayed on top (default is inferred from Host header)
| ```siteurl = https://mylinx.example.org/``` | the site url (default is inferred from execution context)
| ```selifpath = selif``` | path relative to site base url (the "selif" in mylinx.example.org/selif/image.jpg) where files are accessed directly (default: selif)
| ```maxsize = 4294967296``` | maximum upload file size in bytes (default 4GB)
| ```maxexpiry = 86400``` | maximum expiration time in seconds (default is 0, which is no expiry)
| ```allowhotlink = true``` | Allow file hotlinking
| ```contentsecuritypolicy = "..."``` | Content-Security-Policy header for pages (default is "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self';")
| ```filecontentsecuritypolicy = "..."``` | Content-Security-Policy header for files (default is "default-src 'none'; img-src 'self'; object-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'self';")
| ```refererpolicy = "..."``` | Referrer-Policy header for pages (default is "same-origin")
| ```filereferrerpolicy = "..."``` | Referrer-Policy header for files (default is "same-origin")
| ```xframeoptions = "..." ``` | X-Frame-Options header (default is "SAMEORIGIN")
| ```remoteuploads = true``` | (optionally) enable remote uploads (/upload?url=https://...)
| ```nologs = true``` | (optionally) disable request logs in stdout
| ```force-random-filename = true``` | (optionally) force the use of random filenames
| ```custompagespath = custom_pages/``` | (optionally) specify path to directory containing markdown pages (must end in .md) that will be added to the site navigation (this can be useful for providing contact/support information and so on). For example, custom_pages/My_Page.md will become My Page in the site navigation
#### Cleaning up expired files
When files expire, access is disabled immediately, but the files and metadata
will persist on disk until someone attempts to access them. You can set the following option to run cleanup every few minutes. This can also be done using a separate utility found the linx-cleanup directory.
|Option|Description
|------|-----------
| ```cleanup-every-minutes = 5``` | How often to clean up expired files in minutes (default is 0, which means files will be cleaned up as they are accessed)
#### Require API Keys for uploads
|Option|Description
|------|-----------
| ```authfile = path/to/authfile``` | (optionally) require authorization for upload/delete by providing a newline-separated file of scrypted auth keys
| ```remoteauthfile = path/to/remoteauthfile``` | (optionally) require authorization for remote uploads by providing a newline-separated file of scrypted auth keys
| ```basicauth = true``` | (optionally) allow basic authorization to upload or paste files from browser when `-authfile` is enabled. When uploading, you will be prompted to enter a user and password - leave the user blank and use your auth key as the password
A helper utility ```linx-genkey``` is provided which hashes keys to the format required in the auth files.
#### Storage backends
The following storage backends are available:
|Name|Notes|Options
|----|-----|-------
|LocalFS|Enabled by default, this backend uses the filesystem|```filespath = files/``` -- Path to store uploads (default is files/)<br />```metapath = meta/``` -- Path to store information about uploads (default is meta/)|
|S3|Use with any S3-compatible provider.<br> This implementation will stream files through the linx instance (every download will request and stream the file from the S3 bucket). File metadata will be stored as tags on the object in the bucket.<br><br>For high-traffic environments, one might consider using an external caching layer such as described [in this article](https://blog.sentry.io/2017/03/01/dodging-s3-downtime-with-nginx-and-haproxy.html).|```s3-endpoint = https://...``` -- S3 endpoint<br>```s3-region = us-east-1``` -- S3 region<br>```s3-bucket = mybucket``` -- S3 bucket to use for files and metadata<br>```s3-force-path-style = true``` (optional) -- force path-style addresing (e.g. https://<span></span>s3.amazonaws.com/linx/example.txt)<br><br>Environment variables to provide:<br>```AWS_ACCESS_KEY_ID``` -- the S3 access key<br>```AWS_SECRET_ACCESS_KEY ``` -- the S3 secret key<br>```AWS_SESSION_TOKEN``` (optional) -- the S3 session token|
#### SSL with built-in server
|Option|Description
|------|-----------
| ```certfile = path/to/your.crt``` | Path to the ssl certificate (required if you want to use the https server)
| ```keyfile = path/to/your.key``` | Path to the ssl key (required if you want to use the https server)
#### Use with http proxy
|Option|Description
|------|-----------
| ```realip = true``` | let linx-server know you (nginx, etc) are providing the X-Real-IP and/or X-Forwarded-For headers.
#### Use with fastcgi
|Option|Description
|------|-----------
| ```fastcgi = true``` | serve through fastcgi
Deployment
----------
Linx-server supports being deployed in a subdirectory (ie. example.com/mylinx/) as well as on its own (example.com/).
#### 1. Using fastcgi
@ -52,29 +182,21 @@ server {
}
}
```
And run linx-server with the ```-fastcgi``` option.
And run linx-server with the ```fastcgi = true``` option.
#### 2. Using the built-in https server
Run linx-server with the ```-certfile path/to/cert.file``` and ```-keyfile path/to/key.file``` options.
Run linx-server with the ```certfile = path/to/cert.file``` and ```keyfile = path/to/key.file``` options.
#### 3. Using the built-in http server
Run linx-server normally.
Development
-----------
Any help is welcome, PRs will be reviewed and merged accordingly.
The official IRC channel is #linx on irc.oftc.net
1. ```go get -u github.com/andreimarcu/linx-server ```
2. ```cd $GOPATH/src/github.com/andreimarcu/linx-server ```
3. ```go build && ./linx-server```
TODO
----
Please refer to the [main TODO issue](https://github.com/andreimarcu/linx-server/issues/1)
License
-------
Copyright (C) 2015 Andrei Marcu
@ -94,4 +216,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
Author
-------
Andrei Marcu, http://andreim.net/
Andrei Marcu, https://andreim.net/

147
access.go Normal file
View file

@ -0,0 +1,147 @@
package main
import (
"encoding/json"
"errors"
"log"
"net/http"
"net/url"
"path"
"regexp"
"strings"
"time"
"github.com/andreimarcu/linx-server/backends"
"github.com/flosch/pongo2"
"github.com/zenazn/goji/web"
)
type accessKeySource int
const (
accessKeySourceNone accessKeySource = iota
accessKeySourceCookie
accessKeySourceHeader
accessKeySourceForm
accessKeySourceQuery
)
const accessKeyHeaderName = "Linx-Access-Key"
const accessKeyParamName = "access_key"
var (
errInvalidAccessKey = errors.New("invalid access key")
cliUserAgentRe = regexp.MustCompile("(?i)(lib)?curl|wget")
)
func checkAccessKey(r *http.Request, metadata *backends.Metadata) (accessKeySource, error) {
key := metadata.AccessKey
if key == "" {
return accessKeySourceNone, nil
}
cookieKey, err := r.Cookie(accessKeyHeaderName)
if err == nil {
if cookieKey.Value == key {
return accessKeySourceCookie, nil
}
return accessKeySourceCookie, errInvalidAccessKey
}
headerKey := r.Header.Get(accessKeyHeaderName)
if headerKey == key {
return accessKeySourceHeader, nil
} else if headerKey != "" {
return accessKeySourceHeader, errInvalidAccessKey
}
formKey := r.PostFormValue(accessKeyParamName)
if formKey == key {
return accessKeySourceForm, nil
} else if formKey != "" {
return accessKeySourceForm, errInvalidAccessKey
}
queryKey := r.URL.Query().Get(accessKeyParamName)
if queryKey == key {
return accessKeySourceQuery, nil
} else if formKey != "" {
return accessKeySourceQuery, errInvalidAccessKey
}
return accessKeySourceNone, errInvalidAccessKey
}
func setAccessKeyCookies(w http.ResponseWriter, siteURL, fileName, value string, expires time.Time) {
u, err := url.Parse(siteURL)
if err != nil {
log.Printf("cant parse siteURL (%v): %v", siteURL, err)
return
}
cookie := http.Cookie{
Name: accessKeyHeaderName,
Value: value,
HttpOnly: true,
Domain: u.Hostname(),
Expires: expires,
}
cookie.Path = path.Join(u.Path, fileName)
http.SetCookie(w, &cookie)
cookie.Path = path.Join(u.Path, Config.selifPath, fileName)
http.SetCookie(w, &cookie)
}
func fileAccessHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if !Config.noDirectAgents && cliUserAgentRe.MatchString(r.Header.Get("User-Agent")) && !strings.EqualFold("application/json", r.Header.Get("Accept")) {
fileServeHandler(c, w, r)
return
}
fileName := c.URLParams["name"]
metadata, err := checkFile(fileName)
if err == backends.NotFoundErr {
notFoundHandler(c, w, r)
return
} else if err != nil {
oopsHandler(c, w, r, RespAUTO, "Corrupt metadata.")
return
}
if src, err := checkAccessKey(r, &metadata); err != nil {
// remove invalid cookie
if src == accessKeySourceCookie {
setAccessKeyCookies(w, getSiteURL(r), fileName, "", time.Unix(0, 0))
}
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
dec := json.NewEncoder(w)
_ = dec.Encode(map[string]string{
"error": errInvalidAccessKey.Error(),
})
return
}
_ = renderTemplate(Templates["access.html"], pongo2.Context{
"filename": fileName,
"accesspath": fileName,
}, r, w)
return
}
if metadata.AccessKey != "" {
var expiry time.Time
if Config.accessKeyCookieExpiry != 0 {
expiry = time.Now().Add(time.Duration(Config.accessKeyCookieExpiry) * time.Second)
}
setAccessKeyCookies(w, getSiteURL(r), fileName, metadata.AccessKey, expiry)
}
fileDisplayHandler(c, w, r, fileName, metadata)
}

154
auth/apikeys/apikeys.go Normal file
View file

@ -0,0 +1,154 @@
package apikeys
import (
"bufio"
"encoding/base64"
"fmt"
"log"
"net/http"
"os"
"golang.org/x/crypto/scrypt"
"github.com/zenazn/goji/web"
)
const (
scryptSalt = "linx-server"
scryptN = 16384
scryptr = 8
scryptp = 1
scryptKeyLen = 32
)
type AuthOptions struct {
AuthFile string
UnauthMethods []string
BasicAuth bool
SiteName string
SitePath string
}
type ApiKeysMiddleware struct {
successHandler http.Handler
authKeys []string
o AuthOptions
}
func ReadAuthKeys(authFile string) []string {
var authKeys []string
f, err := os.Open(authFile)
if err != nil {
log.Fatal("Failed to open authfile: ", err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
authKeys = append(authKeys, scanner.Text())
}
err = scanner.Err()
if err != nil {
log.Fatal("Scanner error while reading authfile: ", err)
}
return authKeys
}
func CheckAuth(authKeys []string, key string) (result bool, err error) {
checkKey, err := scrypt.Key([]byte(key), []byte(scryptSalt), scryptN, scryptr, scryptp, scryptKeyLen)
if err != nil {
return
}
encodedKey := base64.StdEncoding.EncodeToString(checkKey)
for _, v := range authKeys {
if encodedKey == v {
result = true
return
}
}
result = false
return
}
func (a ApiKeysMiddleware) getSitePrefix() string {
prefix := a.o.SitePath
if len(prefix) <= 0 || prefix[0] != '/' {
prefix = "/" + prefix
}
return prefix
}
func (a ApiKeysMiddleware) goodAuthorizationHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Location", a.getSitePrefix())
w.WriteHeader(http.StatusFound)
}
func (a ApiKeysMiddleware) badAuthorizationHandler(w http.ResponseWriter, r *http.Request) {
if a.o.BasicAuth {
rs := ""
if a.o.SiteName != "" {
rs = fmt.Sprintf(` realm="%s"`, a.o.SiteName)
}
w.Header().Set("WWW-Authenticate", `Basic`+rs)
}
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
}
func (a ApiKeysMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var successHandler http.Handler
prefix := a.getSitePrefix()
if r.URL.Path == prefix+"auth" {
successHandler = http.HandlerFunc(a.goodAuthorizationHandler)
} else {
successHandler = a.successHandler
}
if sliceContains(a.o.UnauthMethods, r.Method) && r.URL.Path != prefix+"auth" {
// allow unauthenticated methods
successHandler.ServeHTTP(w, r)
return
}
key := r.Header.Get("Linx-Api-Key")
if key == "" && a.o.BasicAuth {
_, password, ok := r.BasicAuth()
if ok {
key = password
}
}
result, err := CheckAuth(a.authKeys, key)
if err != nil || !result {
http.HandlerFunc(a.badAuthorizationHandler).ServeHTTP(w, r)
return
}
successHandler.ServeHTTP(w, r)
}
func NewApiKeysMiddleware(o AuthOptions) func(*web.C, http.Handler) http.Handler {
fn := func(c *web.C, h http.Handler) http.Handler {
return ApiKeysMiddleware{
successHandler: h,
authKeys: ReadAuthKeys(o.AuthFile),
o: o,
}
}
return fn
}
func sliceContains(slice []string, s string) bool {
for _, v := range slice {
if s == v {
return true
}
}
return false
}

View file

@ -0,0 +1,24 @@
package apikeys
import (
"testing"
)
func TestCheckAuth(t *testing.T) {
authKeys := []string{
"vhvZ/PT1jeTbTAJ8JdoxddqFtebSxdVb0vwPlYO+4HM=",
"vFpNprT9wbHgwAubpvRxYCCpA2FQMAK6hFqPvAGrdZo=",
}
if r, err := CheckAuth(authKeys, ""); err != nil && r {
t.Fatal("Authorization passed for empty key")
}
if r, err := CheckAuth(authKeys, "thisisnotvalid"); err != nil && r {
t.Fatal("Authorization passed for invalid key")
}
if r, err := CheckAuth(authKeys, "haPVipRnGJ0QovA9nyqK"); err != nil && !r {
t.Fatal("Authorization failed for valid key")
}
}

205
backends/localfs/localfs.go Normal file
View file

@ -0,0 +1,205 @@
package localfs
import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"time"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/helpers"
)
type LocalfsBackend struct {
metaPath string
filesPath string
}
type MetadataJSON struct {
DeleteKey string `json:"delete_key"`
AccessKey string `json:"access_key,omitempty"`
Sha256sum string `json:"sha256sum"`
Mimetype string `json:"mimetype"`
Size int64 `json:"size"`
Expiry int64 `json:"expiry"`
ArchiveFiles []string `json:"archive_files,omitempty"`
}
func (b LocalfsBackend) Delete(key string) (err error) {
err = os.Remove(path.Join(b.filesPath, key))
if err != nil {
return
}
err = os.Remove(path.Join(b.metaPath, key))
return
}
func (b LocalfsBackend) Exists(key string) (bool, error) {
_, err := os.Stat(path.Join(b.filesPath, key))
return err == nil, err
}
func (b LocalfsBackend) Head(key string) (metadata backends.Metadata, err error) {
f, err := os.Open(path.Join(b.metaPath, key))
if os.IsNotExist(err) {
return metadata, backends.NotFoundErr
} else if err != nil {
return metadata, backends.BadMetadata
}
defer f.Close()
decoder := json.NewDecoder(f)
mjson := MetadataJSON{}
if err := decoder.Decode(&mjson); err != nil {
return metadata, backends.BadMetadata
}
metadata.DeleteKey = mjson.DeleteKey
metadata.AccessKey = mjson.AccessKey
metadata.Mimetype = mjson.Mimetype
metadata.ArchiveFiles = mjson.ArchiveFiles
metadata.Sha256sum = mjson.Sha256sum
metadata.Expiry = time.Unix(mjson.Expiry, 0)
metadata.Size = mjson.Size
return
}
func (b LocalfsBackend) Get(key string) (metadata backends.Metadata, f io.ReadCloser, err error) {
metadata, err = b.Head(key)
if err != nil {
return
}
f, err = os.Open(path.Join(b.filesPath, key))
if err != nil {
return
}
return
}
func (b LocalfsBackend) ServeFile(key string, w http.ResponseWriter, r *http.Request) (err error) {
_, err = b.Head(key)
if err != nil {
return
}
filePath := path.Join(b.filesPath, key)
http.ServeFile(w, r, filePath)
return
}
func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) error {
metaPath := path.Join(b.metaPath, key)
mjson := MetadataJSON{
DeleteKey: metadata.DeleteKey,
AccessKey: metadata.AccessKey,
Mimetype: metadata.Mimetype,
ArchiveFiles: metadata.ArchiveFiles,
Sha256sum: metadata.Sha256sum,
Expiry: metadata.Expiry.Unix(),
Size: metadata.Size,
}
dst, err := os.Create(metaPath)
if err != nil {
return err
}
defer dst.Close()
encoder := json.NewEncoder(dst)
err = encoder.Encode(mjson)
if err != nil {
os.Remove(metaPath)
return err
}
return nil
}
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (m backends.Metadata, err error) {
filePath := path.Join(b.filesPath, key)
dst, err := os.Create(filePath)
if err != nil {
return
}
defer dst.Close()
bytes, err := io.Copy(dst, r)
if bytes == 0 {
os.Remove(filePath)
return m, backends.FileEmptyError
} else if err != nil {
os.Remove(filePath)
return m, err
}
dst.Seek(0, 0)
m, err = helpers.GenerateMetadata(dst)
if err != nil {
os.Remove(filePath)
return
}
dst.Seek(0, 0)
m.Expiry = expiry
m.DeleteKey = deleteKey
m.AccessKey = accessKey
m.ArchiveFiles, _ = helpers.ListArchiveFiles(m.Mimetype, m.Size, dst)
err = b.writeMetadata(key, m)
if err != nil {
os.Remove(filePath)
return
}
return
}
func (b LocalfsBackend) PutMetadata(key string, m backends.Metadata) (err error) {
err = b.writeMetadata(key, m)
if err != nil {
return
}
return
}
func (b LocalfsBackend) Size(key string) (int64, error) {
fileInfo, err := os.Stat(path.Join(b.filesPath, key))
if err != nil {
return 0, err
}
return fileInfo.Size(), nil
}
func (b LocalfsBackend) List() ([]string, error) {
var output []string
files, err := ioutil.ReadDir(b.filesPath)
if err != nil {
return nil, err
}
for _, file := range files {
output = append(output, file.Name())
}
return output, nil
}
func NewLocalfsBackend(metaPath string, filesPath string) LocalfsBackend {
return LocalfsBackend{
metaPath: metaPath,
filesPath: filesPath,
}
}

18
backends/meta.go Normal file
View file

@ -0,0 +1,18 @@
package backends
import (
"errors"
"time"
)
type Metadata struct {
DeleteKey string
AccessKey string
Sha256sum string
Mimetype string
Size int64
Expiry time.Time
ArchiveFiles []string
}
var BadMetadata = errors.New("Corrupted metadata.")

269
backends/s3/s3.go Normal file
View file

@ -0,0 +1,269 @@
package s3
import (
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
"time"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/helpers"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)
type S3Backend struct {
bucket string
svc *s3.S3
}
func (b S3Backend) Delete(key string) error {
_, err := b.svc.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
})
if err != nil {
return err
}
return nil
}
func (b S3Backend) Exists(key string) (bool, error) {
_, err := b.svc.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
})
return err == nil, err
}
func (b S3Backend) Head(key string) (metadata backends.Metadata, err error) {
var result *s3.HeadObjectOutput
result, err = b.svc.HeadObject(&s3.HeadObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() == s3.ErrCodeNoSuchKey || aerr.Code() == "NotFound" {
err = backends.NotFoundErr
}
}
return
}
metadata, err = unmapMetadata(result.Metadata)
return
}
func (b S3Backend) Get(key string) (metadata backends.Metadata, r io.ReadCloser, err error) {
var result *s3.GetObjectOutput
result, err = b.svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() == s3.ErrCodeNoSuchKey || aerr.Code() == "NotFound" {
err = backends.NotFoundErr
}
}
return
}
metadata, err = unmapMetadata(result.Metadata)
r = result.Body
return
}
func (b S3Backend) ServeFile(key string, w http.ResponseWriter, r *http.Request) (err error) {
var result *s3.GetObjectOutput
if r.Header.Get("Range") != "" {
result, err = b.svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
Range: aws.String(r.Header.Get("Range")),
})
w.WriteHeader(206)
w.Header().Set("Content-Range", *result.ContentRange)
w.Header().Set("Content-Length", strconv.FormatInt(*result.ContentLength, 10))
w.Header().Set("Accept-Ranges", "bytes")
} else {
result, err = b.svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
})
}
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() == s3.ErrCodeNoSuchKey || aerr.Code() == "NotFound" {
err = backends.NotFoundErr
}
}
return
}
_, err = io.Copy(w, result.Body)
return
}
func mapMetadata(m backends.Metadata) map[string]*string {
return map[string]*string{
"Expiry": aws.String(strconv.FormatInt(m.Expiry.Unix(), 10)),
"Deletekey": aws.String(m.DeleteKey),
"Size": aws.String(strconv.FormatInt(m.Size, 10)),
"Mimetype": aws.String(m.Mimetype),
"Sha256sum": aws.String(m.Sha256sum),
"AccessKey": aws.String(m.AccessKey),
}
}
func unmapMetadata(input map[string]*string) (m backends.Metadata, err error) {
expiry, err := strconv.ParseInt(aws.StringValue(input["Expiry"]), 10, 64)
if err != nil {
return m, err
}
m.Expiry = time.Unix(expiry, 0)
m.Size, err = strconv.ParseInt(aws.StringValue(input["Size"]), 10, 64)
if err != nil {
return
}
m.DeleteKey = aws.StringValue(input["Deletekey"])
if m.DeleteKey == "" {
m.DeleteKey = aws.StringValue(input["Delete_key"])
}
m.Mimetype = aws.StringValue(input["Mimetype"])
m.Sha256sum = aws.StringValue(input["Sha256sum"])
if key, ok := input["AccessKey"]; ok {
m.AccessKey = aws.StringValue(key)
}
return
}
func (b S3Backend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (m backends.Metadata, err error) {
tmpDst, err := ioutil.TempFile("", "linx-server-upload")
if err != nil {
return m, err
}
defer tmpDst.Close()
defer os.Remove(tmpDst.Name())
bytes, err := io.Copy(tmpDst, r)
if bytes == 0 {
return m, backends.FileEmptyError
} else if err != nil {
return m, err
}
_, err = tmpDst.Seek(0, 0)
if err != nil {
return m, err
}
m, err = helpers.GenerateMetadata(tmpDst)
if err != nil {
return
}
m.Expiry = expiry
m.DeleteKey = deleteKey
m.AccessKey = accessKey
// XXX: we may not be able to write this to AWS easily
//m.ArchiveFiles, _ = helpers.ListArchiveFiles(m.Mimetype, m.Size, tmpDst)
_, err = tmpDst.Seek(0, 0)
if err != nil {
return m, err
}
uploader := s3manager.NewUploaderWithClient(b.svc)
input := &s3manager.UploadInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
Body: tmpDst,
Metadata: mapMetadata(m),
}
_, err = uploader.Upload(input)
if err != nil {
return
}
return
}
func (b S3Backend) PutMetadata(key string, m backends.Metadata) (err error) {
_, err = b.svc.CopyObject(&s3.CopyObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
CopySource: aws.String("/" + b.bucket + "/" + key),
Metadata: mapMetadata(m),
MetadataDirective: aws.String("REPLACE"),
})
if err != nil {
return
}
return
}
func (b S3Backend) Size(key string) (int64, error) {
input := &s3.HeadObjectInput{
Bucket: aws.String(b.bucket),
Key: aws.String(key),
}
result, err := b.svc.HeadObject(input)
if err != nil {
return 0, err
}
return *result.ContentLength, nil
}
func (b S3Backend) List() ([]string, error) {
var output []string
input := &s3.ListObjectsInput{
Bucket: aws.String(b.bucket),
}
results, err := b.svc.ListObjects(input)
if err != nil {
return nil, err
}
for _, object := range results.Contents {
output = append(output, *object.Key)
}
return output, nil
}
func NewS3Backend(bucket string, region string, endpoint string, forcePathStyle bool) S3Backend {
awsConfig := &aws.Config{}
if region != "" {
awsConfig.Region = aws.String(region)
}
if endpoint != "" {
awsConfig.Endpoint = aws.String(endpoint)
}
if forcePathStyle == true {
awsConfig.S3ForcePathStyle = aws.Bool(true)
}
sess := session.Must(session.NewSession(awsConfig))
svc := s3.New(sess)
return S3Backend{bucket: bucket, svc: svc}
}

27
backends/storage.go Normal file
View file

@ -0,0 +1,27 @@
package backends
import (
"errors"
"io"
"net/http"
"time"
)
type StorageBackend interface {
Delete(key string) error
Exists(key string) (bool, error)
Head(key string) (Metadata, error)
Get(key string) (Metadata, io.ReadCloser, error)
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (Metadata, error)
PutMetadata(key string, m Metadata) error
ServeFile(key string, w http.ResponseWriter, r *http.Request) error
Size(key string) (int64, error)
}
type MetaStorageBackend interface {
StorageBackend
List() ([]string, error)
}
var NotFoundErr = errors.New("File not found.")
var FileEmptyError = errors.New("Empty file")

103
build.sh
View file

@ -1,39 +1,76 @@
#!/bin/bash
function build_binary_rice {
name="$1"
for arch in amd64 386; do
GOOS=darwin GOARCH=$arch go build -o "$name"osx-$arch
rice append --exec "$name"osx-$arch
done
for arch in amd64 386; do
GOOS=freebsd GOARCH=$arch go build -o "$name"freebsd-$arch
rice append --exec "$name"freebsd-$arch
done
for arch in arm amd64 386; do
GOOS=netbsd GOARCH=$arch go build -o "$name"netbsd-$arch
rice append --exec "$name"netbsd-$arch
done
for arch in amd64 386; do
GOOS=openbsd GOARCH=$arch go build -o "$name"openbsd-$arch
rice append --exec "$name"openbsd-$arch
done
for arch in arm arm64 amd64 386; do
GOOS=linux GOARCH=$arch go build -o "$name"linux-$arch
rice append --exec "$name"linux-$arch
done
for arch in amd64 386; do
GOOS=windows GOARCH=$arch go build -o "$name"windows-$arch.exe
rice append --exec "$name"windows-$arch.exe
done
}
function build_binary {
name="$1"
for arch in amd64 386; do
GOOS=darwin GOARCH=$arch go build -o "$name"osx-$arch
done
for arch in amd64 386; do
GOOS=freebsd GOARCH=$arch go build -o "$name"freebsd-$arch
done
for arch in arm amd64 386; do
GOOS=netbsd GOARCH=$arch go build -o "$name"netbsd-$arch
done
for arch in amd64 386; do
GOOS=openbsd GOARCH=$arch go build -o "$name"openbsd-$arch
done
for arch in arm arm64 amd64 386; do
GOOS=linux GOARCH=$arch go build -o "$name"linux-$arch
done
for arch in amd64 386; do
GOOS=windows GOARCH=$arch go build -o "$name"windows-$arch.exe
done
}
version="$1"
mkdir -p "binairies/"$filepath"/""$version"
name="binairies/"$filepath"/""$version""/linx-server-v""$version""_"
mkdir -p "binaries/""$version"
GOOS=darwin GOARCH=amd64 go build -o "$name"osx-amd64
rice append --exec "$name"osx-amd64
build_binary_rice "binaries/""$version""/linx-server-v""$version""_"
GOOS=darwin GOARCH=386 go build -o "$name"osx-386
rice append --exec "$name"osx-386
GOOS=freebsd GOARCH=amd64 go build -o "$name"freebsd-amd64
rice append --exec "$name"freebsd-amd64
GOOS=freebsd GOARCH=386 go build -o "$name"freebsd-386
rice append --exec "$name"freebsd-386
GOOS=openbsd GOARCH=amd64 go build -o "$name"openbsd-amd64
rice append --exec "$name"openbsd-amd64
GOOS=openbsd GOARCH=386 go build -o "$name"openbsd-386
rice append --exec "$name"openbsd-386
GOOS=linux GOARCH=arm go build -o "$name"linux-arm
rice append --exec "$name"linux-arm
GOOS=linux GOARCH=amd64 go build -o "$name"linux-amd64
rice append --exec "$name"linux-amd64
GOOS=linux GOARCH=386 go build -o "$name"linux-386
rice append --exec "$name"linux-386
GOOS=windows GOARCH=amd64 go build -o "$name"windows-amd64.exe
rice append --exec "$name"windows-amd64.exe
GOOS=windows GOARCH=386 go build -o "$name"windows-386.exe
rice append --exec "$name"windows-386.exe
cd linx-genkey
build_binary "../binaries/""$version""/linx-genkey-v""$version""_"
cd ..
cd linx-cleanup
build_binary "../binaries/""$version""/linx-cleanup-v""$version""_"
cd ..

42
cleanup/cleanup.go Normal file
View file

@ -0,0 +1,42 @@
package cleanup
import (
"log"
"time"
"github.com/andreimarcu/linx-server/backends/localfs"
"github.com/andreimarcu/linx-server/expiry"
)
func Cleanup(filesDir string, metaDir string, noLogs bool) {
fileBackend := localfs.NewLocalfsBackend(metaDir, filesDir)
files, err := fileBackend.List()
if err != nil {
panic(err)
}
for _, filename := range files {
metadata, err := fileBackend.Head(filename)
if err != nil {
if !noLogs {
log.Printf("Failed to find metadata for %s", filename)
}
}
if expiry.IsTsExpired(metadata.Expiry) {
if !noLogs {
log.Printf("Delete %s", filename)
}
fileBackend.Delete(filename)
}
}
}
func PeriodicCleanup(minutes time.Duration, filesDir string, metaDir string, noLogs bool) {
c := time.Tick(minutes)
for range c {
Cleanup(filesDir, metaDir, noLogs)
}
}

11
csp.go
View file

@ -6,6 +6,7 @@ import (
const (
cspHeader = "Content-Security-Policy"
rpHeader = "Referrer-Policy"
frameOptionsHeader = "X-Frame-Options"
)
@ -15,8 +16,9 @@ type csp struct {
}
type CSPOptions struct {
policy string
frame string
policy string
referrerPolicy string
frame string
}
func (c csp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -25,6 +27,11 @@ func (c csp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Add(cspHeader, c.opts.policy)
}
// only add a Referrer Policy if one is not already set
if existing := w.Header().Get(rpHeader); existing == "" {
w.Header().Add(rpHeader, c.opts.referrerPolicy)
}
w.Header().Set(frameOptionsHeader, c.opts.frame)
c.h.ServeHTTP(w, r)

View file

@ -12,6 +12,7 @@ import (
var testCSPHeaders = map[string]string{
"Content-Security-Policy": "default-src 'none'; style-src 'self';",
"Referrer-Policy": "strict-origin-when-cross-origin",
"X-Frame-Options": "SAMEORIGIN",
}
@ -19,11 +20,14 @@ func TestContentSecurityPolicy(t *testing.T) {
Config.siteURL = "http://linx.example.org/"
Config.filesDir = path.Join(os.TempDir(), generateBarename())
Config.metaDir = Config.filesDir + "_meta"
Config.maxSize = 1024 * 1024 * 1024
Config.noLogs = true
Config.siteName = "linx"
Config.contentSecurityPolicy = "default-src 'none'; style-src 'self';"
Config.xFrameOptions = "SAMEORIGIN"
setup()
Config.selifPath = "selif"
Config.contentSecurityPolicy = testCSPHeaders["Content-Security-Policy"]
Config.referrerPolicy = testCSPHeaders["Referrer-Policy"]
Config.xFrameOptions = testCSPHeaders["X-Frame-Options"]
mux := setup()
w := httptest.NewRecorder()
@ -33,11 +37,12 @@ func TestContentSecurityPolicy(t *testing.T) {
}
goji.Use(ContentSecurityPolicy(CSPOptions{
policy: testCSPHeaders["Content-Security-Policy"],
frame: testCSPHeaders["X-Frame-Options"],
policy: testCSPHeaders["Content-Security-Policy"],
referrerPolicy: testCSPHeaders["Referrer-Policy"],
frame: testCSPHeaders["X-Frame-Options"],
}))
goji.DefaultMux.ServeHTTP(w, req)
mux.ServeHTTP(w, req)
for k, v := range testCSPHeaders {
if w.HeaderMap[k][0] != v {

36
csrf.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"net/http"
"net/url"
)
// Do a strict referrer check, matching against both the Origin header (if
// present) and the Referrer header. If a list of headers is specified, then
// Referrer checking will be skipped if any of those headers are present.
func strictReferrerCheck(r *http.Request, prefix string, whitelistHeaders []string) bool {
p, _ := url.Parse(prefix)
// if there's an Origin header, check it and skip other checks
if origin := r.Header.Get("Origin"); origin != "" {
u, _ := url.Parse(origin)
return sameOrigin(u, p)
}
for _, header := range whitelistHeaders {
if r.Header.Get(header) != "" {
return true
}
}
referrer := r.Header.Get("Referer")
u, _ := url.Parse(referrer)
return sameOrigin(u, p)
}
// Check if two URLs have the same origin
func sameOrigin(u1, u2 *url.URL) bool {
// host also contains the port if one was specified
return (u1.Scheme == u2.Scheme && u1.Host == u2.Host)
}

40
custom_pages.go Normal file
View file

@ -0,0 +1,40 @@
package main
import (
"io/ioutil"
"log"
"path"
"strings"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday"
)
func initializeCustomPages(customPagesDir string) {
files, err := ioutil.ReadDir(customPagesDir)
if err != nil {
log.Fatal("Error reading the custom pages directory: ", err)
}
for _, file := range files {
fileName := file.Name()
if len(fileName) <= 3 {
continue
}
if strings.EqualFold(string(fileName[len(fileName)-3:len(fileName)]), ".md") {
contents, err := ioutil.ReadFile(path.Join(customPagesDir, fileName))
if err != nil {
log.Fatalf("Error reading file %s", fileName)
}
unsafe := blackfriday.MarkdownCommon(contents)
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
fileName := fileName[0 : len(fileName)-3]
customPages[fileName] = string(html)
customPagesNames[fileName] = strings.ReplaceAll(fileName, "_", " ")
}
}
}

View file

@ -3,9 +3,8 @@ package main
import (
"fmt"
"net/http"
"os"
"path"
"github.com/andreimarcu/linx-server/backends"
"github.com/zenazn/goji/web"
)
@ -13,28 +12,20 @@ func deleteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
requestKey := r.Header.Get("Linx-Delete-Key")
filename := c.URLParams["name"]
filePath := path.Join(Config.filesDir, filename)
metaPath := path.Join(Config.metaDir, filename)
// Ensure requested file actually exists
if _, readErr := os.Stat(filePath); os.IsNotExist(readErr) {
// Ensure that file exists and delete key is correct
metadata, err := storageBackend.Head(filename)
if err == backends.NotFoundErr {
notFoundHandler(c, w, r) // 404 - file doesn't exist
return
}
// Ensure delete key is correct
deleteKey, err := metadataGetDeleteKey(filename)
if err != nil {
} else if err != nil {
unauthorizedHandler(c, w, r) // 401 - no metadata available
return
}
if deleteKey == requestKey {
fileDelErr := os.Remove(filePath)
metaDelErr := os.Remove(metaPath)
if (fileDelErr != nil) || (metaDelErr != nil) {
if metadata.DeleteKey == requestKey {
err := storageBackend.Delete(filename)
if err != nil {
oopsHandler(c, w, r, RespPLAIN, "Could not delete")
return
}

View file

@ -4,14 +4,13 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"bitbucket.org/taruti/mimemagic"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/expiry"
"github.com/dustin/go-humanize"
"github.com/flosch/pongo2"
"github.com/microcosm-cc/bluemonday"
@ -21,38 +20,25 @@ import (
const maxDisplayFileSizeBytes = 1024 * 512
func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
fileName := c.URLParams["name"]
filePath := path.Join(Config.filesDir, fileName)
fileInfo, err := os.Stat(filePath)
if !fileExistsAndNotExpired(fileName) {
notFoundHandler(c, w, r)
return
}
expiry, _ := metadataGetExpiry(fileName)
func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request, fileName string, metadata backends.Metadata) {
var expiryHuman string
if expiry != neverExpire {
expiryHuman = humanize.RelTime(time.Now(), expiry, "", "")
if metadata.Expiry != expiry.NeverExpire {
expiryHuman = humanize.RelTime(time.Now(), metadata.Expiry, "", "")
}
sizeHuman := humanize.Bytes(uint64(fileInfo.Size()))
sizeHuman := humanize.Bytes(uint64(metadata.Size))
extra := make(map[string]string)
lines := []string{}
file, _ := os.Open(filePath)
header := make([]byte, 512)
file.Read(header)
file.Close()
mimetype := mimemagic.Match("", header)
extension := strings.TrimPrefix(filepath.Ext(fileName), ".")
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
js, _ := json.Marshal(map[string]string{
"filename": fileName,
"mimetype": mimetype,
"expiry": strconv.FormatInt(expiry.Unix(), 10),
"size": strconv.FormatInt(fileInfo.Size(), 10),
"filename": fileName,
"direct_url": getSiteURL(r) + Config.selifPath + fileName,
"expiry": strconv.FormatInt(metadata.Expiry.Unix(), 10),
"size": strconv.FormatInt(metadata.Size, 10),
"mimetype": metadata.Mimetype,
"sha256sum": metadata.Sha256sum,
})
w.Write(js)
return
@ -60,55 +46,84 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
var tpl *pongo2.Template
if strings.HasPrefix(mimetype, "image/") {
if strings.HasPrefix(metadata.Mimetype, "image/") {
tpl = Templates["display/image.html"]
} else if strings.HasPrefix(mimetype, "video/") {
} else if strings.HasPrefix(metadata.Mimetype, "video/") {
tpl = Templates["display/video.html"]
} else if strings.HasPrefix(mimetype, "audio/") {
} else if strings.HasPrefix(metadata.Mimetype, "audio/") {
tpl = Templates["display/audio.html"]
} else if mimetype == "application/pdf" {
} else if metadata.Mimetype == "application/pdf" {
tpl = Templates["display/pdf.html"]
} else if supportedBinExtension(extension) {
if fileInfo.Size() < maxDisplayFileSizeBytes {
bytes, err := ioutil.ReadFile(filePath)
if err != nil {
tpl = Templates["display/file.html"]
} else {
extra["extension"] = extension
extra["lang_hl"], extra["lang_ace"] = extensionToHlAndAceLangs(extension)
extra["contents"] = string(bytes)
tpl = Templates["display/bin.html"]
}
} else {
tpl = Templates["display/file.html"]
} else if extension == "story" {
metadata, reader, err := storageBackend.Get(fileName)
if err != nil {
oopsHandler(c, w, r, RespHTML, err.Error())
}
if metadata.Size < maxDisplayFileSizeBytes {
bytes, err := ioutil.ReadAll(reader)
if err == nil {
extra["contents"] = string(bytes)
lines = strings.Split(extra["contents"], "\n")
tpl = Templates["display/story.html"]
}
}
} else if extension == "md" {
if fileInfo.Size() < maxDisplayFileSizeBytes {
bytes, err := ioutil.ReadFile(filePath)
if err != nil {
tpl = Templates["display/file.html"]
} else {
metadata, reader, err := storageBackend.Get(fileName)
if err != nil {
oopsHandler(c, w, r, RespHTML, err.Error())
}
if metadata.Size < maxDisplayFileSizeBytes {
bytes, err := ioutil.ReadAll(reader)
if err == nil {
unsafe := blackfriday.MarkdownCommon(bytes)
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
extra["contents"] = string(html)
tpl = Templates["display/md.html"]
}
} else {
tpl = Templates["display/file.html"]
}
} else {
} else if strings.HasPrefix(metadata.Mimetype, "text/") || supportedBinExtension(extension) {
metadata, reader, err := storageBackend.Get(fileName)
if err != nil {
oopsHandler(c, w, r, RespHTML, err.Error())
}
if metadata.Size < maxDisplayFileSizeBytes {
bytes, err := ioutil.ReadAll(reader)
if err == nil {
extra["extension"] = extension
extra["lang_hl"] = extensionToHlLang(extension)
extra["contents"] = string(bytes)
tpl = Templates["display/bin.html"]
}
}
}
// Catch other files
if tpl == nil {
tpl = Templates["display/file.html"]
}
err = tpl.ExecuteWriter(pongo2.Context{
"mime": mimetype,
"filename": fileName,
"size": sizeHuman,
"expiry": expiryHuman,
"extra": extra,
}, w)
err := renderTemplate(tpl, pongo2.Context{
"mime": metadata.Mimetype,
"filename": fileName,
"size": sizeHuman,
"expiry": expiryHuman,
"expirylist": listExpirationTimes(),
"extra": extra,
"forcerandom": Config.forceRandomFilename,
"lines": lines,
"files": metadata.ArchiveFiles,
"siteurl": strings.TrimSuffix(getSiteURL(r), "/"),
}, r, w)
if err != nil {
oopsHandler(c, w, r, RespHTML, "")

View file

@ -2,18 +2,68 @@ package main
import (
"time"
"github.com/andreimarcu/linx-server/expiry"
"github.com/dustin/go-humanize"
)
var neverExpire = time.Unix(0, 0)
var defaultExpiryList = []uint64{
60,
300,
3600,
86400,
604800,
2419200,
31536000,
}
// Determine if a file with expiry set to "ts" has expired yet
func isTsExpired(ts time.Time) bool {
now := time.Now()
return ts != neverExpire && now.After(ts)
type ExpirationTime struct {
Seconds uint64
Human string
}
// Determine if the given filename is expired
func isFileExpired(filename string) bool {
exp, _ := metadataGetExpiry(filename)
return isTsExpired(exp)
func isFileExpired(filename string) (bool, error) {
metadata, err := storageBackend.Head(filename)
if err != nil {
return false, err
}
return expiry.IsTsExpired(metadata.Expiry), nil
}
// Return a list of expiration times and their humanized versions
func listExpirationTimes() []ExpirationTime {
epoch := time.Now()
actualExpiryInList := false
var expiryList []ExpirationTime
for _, expiryEntry := range defaultExpiryList {
if Config.maxExpiry == 0 || expiryEntry <= Config.maxExpiry {
if expiryEntry == Config.maxExpiry {
actualExpiryInList = true
}
duration := time.Duration(expiryEntry) * time.Second
expiryList = append(expiryList, ExpirationTime{
Seconds: expiryEntry,
Human: humanize.RelTime(epoch, epoch.Add(duration), "", ""),
})
}
}
if Config.maxExpiry == 0 {
expiryList = append(expiryList, ExpirationTime{
0,
"never",
})
} else if actualExpiryInList == false {
duration := time.Duration(Config.maxExpiry) * time.Second
expiryList = append(expiryList, ExpirationTime{
Config.maxExpiry,
humanize.RelTime(epoch, epoch.Add(duration), "", ""),
})
}
return expiryList
}

13
expiry/expiry.go Normal file
View file

@ -0,0 +1,13 @@
package expiry
import (
"time"
)
var NeverExpire = time.Unix(0, 0)
// Determine if a file with expiry set to "ts" has expired yet
func IsTsExpired(ts time.Time) bool {
now := time.Now()
return ts != NeverExpire && now.After(ts)
}

View file

@ -1,34 +1,72 @@
package main
import (
"fmt"
"net/http"
"os"
"path"
"net/url"
"strconv"
"strings"
"time"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/expiry"
"github.com/andreimarcu/linx-server/httputil"
"github.com/zenazn/goji/web"
)
func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
fileName := c.URLParams["name"]
filePath := path.Join(Config.filesDir, fileName)
if !fileExistsAndNotExpired(fileName) {
metadata, err := checkFile(fileName)
if err == backends.NotFoundErr {
notFoundHandler(c, w, r)
return
} else if err != nil {
oopsHandler(c, w, r, RespAUTO, "Corrupt metadata.")
return
}
if src, err := checkAccessKey(r, &metadata); err != nil {
// remove invalid cookie
if src == accessKeySourceCookie {
setAccessKeyCookies(w, getSiteURL(r), fileName, "", time.Unix(0, 0))
}
unauthorizedHandler(c, w, r)
return
}
if !Config.allowHotlink {
referer := r.Header.Get("Referer")
if referer != "" && !strings.HasPrefix(referer, Config.siteURL) {
w.WriteHeader(403)
u, _ := url.Parse(referer)
p, _ := url.Parse(getSiteURL(r))
if referer != "" && !sameOrigin(u, p) {
http.Redirect(w, r, Config.sitePath+fileName, 303)
return
}
}
w.Header().Set("Content-Security-Policy", Config.fileContentSecurityPolicy)
w.Header().Set("Referrer-Policy", Config.fileReferrerPolicy)
http.ServeFile(w, r, filePath)
w.Header().Set("Content-Type", metadata.Mimetype)
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))
w.Header().Set("Etag", fmt.Sprintf("\"%s\"", metadata.Sha256sum))
w.Header().Set("Cache-Control", "public, no-cache")
modtime := time.Unix(0, 0)
if done := httputil.CheckPreconditions(w, r, modtime); done == true {
return
}
if r.Method != "HEAD" {
storageBackend.ServeFile(fileName, w, r)
if err != nil {
oopsHandler(c, w, r, RespAUTO, err.Error())
return
}
}
}
func staticHandler(c web.C, w http.ResponseWriter, r *http.Request) {
@ -38,36 +76,34 @@ 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)
return
}
w.Header().Set("Etag", timeStartedStr)
w.Header().Set("Cache-Control", "max-age=86400")
w.Header().Set("Etag", fmt.Sprintf("\"%s\"", timeStartedStr))
w.Header().Set("Cache-Control", "public, max-age=86400")
http.ServeContent(w, r, filePath, timeStarted, file)
return
}
}
func fileExistsAndNotExpired(filename string) bool {
filePath := path.Join(Config.filesDir, filename)
_, err := os.Stat(filePath)
func checkFile(filename string) (metadata backends.Metadata, err error) {
metadata, err = storageBackend.Head(filename)
if err != nil {
return false
return
}
if isFileExpired(filename) {
os.Remove(path.Join(Config.filesDir, filename))
os.Remove(path.Join(Config.metaDir, filename))
return false
if expiry.IsTsExpired(metadata.Expiry) {
storageBackend.Delete(filename)
err = backends.NotFoundErr
return
}
return true
return
}

19
go.mod Normal file
View file

@ -0,0 +1,19 @@
module github.com/andreimarcu/linx-server
go 1.14
require (
github.com/GeertJohan/go.rice v1.0.0
github.com/aws/aws-sdk-go v1.29.19
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/dustin/go-humanize v1.0.0
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4
github.com/gabriel-vasile/mimetype v1.1.1
github.com/microcosm-cc/bluemonday v1.0.2
github.com/minio/sha256-simd v0.1.1
github.com/russross/blackfriday v1.5.1
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
github.com/zeebo/bencode v1.0.0
github.com/zenazn/goji v0.9.0
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
)

76
go.sum Normal file
View file

@ -0,0 +1,76 @@
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/aws/aws-sdk-go v1.29.19 h1:+jifYixffn6kzWygtGWFWQMv0tDGyISZHNwugF9V2sE=
github.com/aws/aws-sdk-go v1.29.19/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 h1:RAV05c0xOkJ3dZGS0JFybxFKZ2WMLabgx3uXnd7rpGs=
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4 h1:GY1+t5Dr9OKADM64SYnQjw/w99HMYvQ0A8/JoUkxVmc=
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
github.com/gabriel-vasile/mimetype v1.1.1 h1:qbN9MPuRf3bstHu9zkI9jDWNfH//9+9kHxr9oRBBBOA=
github.com/gabriel-vasile/mimetype v1.1.1/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 h1:rhqTjzJlm7EbkELJDKMTU7udov+Se0xZkWmugr6zGok=
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
github.com/juju/loggo v0.0.0-20180524022052-584905176618 h1:MK144iBQF9hTSwBW/9eJm034bVoG30IshVm688T2hi8=
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073 h1:WQM1NildKThwdP7qWrNAFGzp4ijNLw8RlgENkaI4MJs=
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.1 h1:B8ZN6pD4PVofmlDCDUdELeYrbsVIDM/bpjW3v3zgcRc=
github.com/russross/blackfriday v1.5.1/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg=
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
github.com/zeebo/bencode v1.0.0 h1:zgop0Wu1nu4IexAZeCZ5qbsjU4O1vMrfCrVgUjbHVuA=
github.com/zeebo/bencode v1.0.0/go.mod h1:Ct7CkrWIQuLWAy9M3atFHYq4kG9Ao/SsY5cdtCXmp9Y=
github.com/zenazn/goji v0.9.0 h1:RSQQAbXGArQ0dIDEq+PI6WqN6if+5KHu6x2Cx/GXLTQ=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

51
headers.go Normal file
View file

@ -0,0 +1,51 @@
package main
import (
"net/http"
"net/url"
"strings"
)
type addheaders struct {
h http.Handler
headers []string
}
func (a addheaders) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for _, header := range a.headers {
headerSplit := strings.SplitN(header, ": ", 2)
w.Header().Add(headerSplit[0], headerSplit[1])
}
a.h.ServeHTTP(w, r)
}
func AddHeaders(headers []string) func(http.Handler) http.Handler {
fn := func(h http.Handler) http.Handler {
return addheaders{h, headers}
}
return fn
}
func getSiteURL(r *http.Request) string {
if Config.siteURL != "" {
return Config.siteURL
} else {
u := &url.URL{}
u.Host = r.Host
if Config.sitePath != "" {
u.Path = Config.sitePath
}
if scheme := r.Header.Get("X-Forwarded-Proto"); scheme != "" {
u.Scheme = scheme
} else if Config.certFile != "" || (r.TLS != nil && r.TLS.HandshakeComplete == true) {
u.Scheme = "https"
} else {
u.Scheme = "http"
}
return u.String()
}
}

70
helpers/archive.go Normal file
View file

@ -0,0 +1,70 @@
package helpers
import (
"archive/tar"
"archive/zip"
"compress/bzip2"
"compress/gzip"
"io"
"sort"
)
type ReadSeekerAt interface {
io.Reader
io.Seeker
io.ReaderAt
}
func ListArchiveFiles(mimetype string, size int64, r ReadSeekerAt) (files []string, err error) {
if mimetype == "application/x-tar" {
tReadr := tar.NewReader(r)
for {
hdr, err := tReadr.Next()
if err == io.EOF || err != nil {
break
}
if hdr.Typeflag == tar.TypeDir || hdr.Typeflag == tar.TypeReg {
files = append(files, hdr.Name)
}
}
sort.Strings(files)
} else if mimetype == "application/x-gzip" {
gzf, err := gzip.NewReader(r)
if err == nil {
tReadr := tar.NewReader(gzf)
for {
hdr, err := tReadr.Next()
if err == io.EOF || err != nil {
break
}
if hdr.Typeflag == tar.TypeDir || hdr.Typeflag == tar.TypeReg {
files = append(files, hdr.Name)
}
}
sort.Strings(files)
}
} else if mimetype == "application/x-bzip" {
bzf := bzip2.NewReader(r)
tReadr := tar.NewReader(bzf)
for {
hdr, err := tReadr.Next()
if err == io.EOF || err != nil {
break
}
if hdr.Typeflag == tar.TypeDir || hdr.Typeflag == tar.TypeReg {
files = append(files, hdr.Name)
}
}
sort.Strings(files)
} else if mimetype == "application/zip" {
zf, err := zip.NewReader(r, size)
if err == nil {
for _, f := range zf.File {
files = append(files, f.Name)
}
}
sort.Strings(files)
}
return
}

74
helpers/helpers.go Normal file
View file

@ -0,0 +1,74 @@
package helpers
import (
"bytes"
"encoding/hex"
"io"
"unicode"
"github.com/andreimarcu/linx-server/backends"
"github.com/gabriel-vasile/mimetype"
"github.com/minio/sha256-simd"
)
func GenerateMetadata(r io.Reader) (m backends.Metadata, err error) {
// Since we don't have the ability to seek within a file, we can use a
// Buffer in combination with a TeeReader to keep a copy of the bytes
// we read when detecting the file type. These bytes are still needed
// to hash the file and determine its size and cannot be discarded.
var buf bytes.Buffer
teeReader := io.TeeReader(r, &buf)
// Get first 512 bytes for mimetype detection
header := make([]byte, 512)
headerlen, err := teeReader.Read(header)
if err != nil {
return
}
// Create a Hash and a MultiReader that includes the Buffer we created
// above along with the original Reader, which will have the rest of
// the file.
hasher := sha256.New()
multiReader := io.MultiReader(&buf, r)
// Copy everything into the Hash, then use the number of bytes written
// as the file size.
var readLen int64
readLen, err = io.Copy(hasher, multiReader)
if err != nil {
return
} else {
m.Size += readLen
}
// Get the hex-encoded string version of the Hash checksum
m.Sha256sum = hex.EncodeToString(hasher.Sum(nil))
// Use the bytes we extracted earlier and attempt to determine the file
// type
kind := mimetype.Detect(header[:headerlen])
m.Mimetype = kind.String()
return
}
func printable(data []byte) bool {
for i, b := range data {
r := rune(b)
// A null terminator that's not at the beginning of the file
if r == 0 && i == 0 {
return false
} else if r == 0 && i < 0 {
continue
}
if r > unicode.MaxASCII {
return false
}
}
return true
}

73
helpers/helpers_test.go Normal file
View file

@ -0,0 +1,73 @@
package helpers
import (
"bytes"
"strings"
"testing"
"unicode/utf16"
)
func TestGenerateMetadata(t *testing.T) {
r := strings.NewReader("This is my test content")
m, err := GenerateMetadata(r)
if err != nil {
t.Fatal(err)
}
expectedSha256sum := "966152d20a77e739716a625373ee15af16e8f4aec631a329a27da41c204b0171"
if m.Sha256sum != expectedSha256sum {
t.Fatalf("Sha256sum was %q instead of expected value of %q", m.Sha256sum, expectedSha256sum)
}
expectedMimetype := "text/plain; charset=utf-8"
if m.Mimetype != expectedMimetype {
t.Fatalf("Mimetype was %q instead of expected value of %q", m.Mimetype, expectedMimetype)
}
expectedSize := int64(23)
if m.Size != expectedSize {
t.Fatalf("Size was %d instead of expected value of %d", m.Size, expectedSize)
}
}
func TestTextCharsets(t *testing.T) {
// verify that different text encodings are detected and passed through
orig := "This is a text string"
utf16 := utf16.Encode([]rune(orig))
utf16LE := make([]byte, len(utf16)*2+2)
utf16BE := make([]byte, len(utf16)*2+2)
utf8 := []byte(orig)
utf16LE[0] = 0xff
utf16LE[1] = 0xfe
utf16BE[0] = 0xfe
utf16BE[1] = 0xff
for i := 0; i < len(utf16); i++ {
lsb := utf16[i] & 0xff
msb := utf16[i] >> 8
utf16LE[i*2+2] = byte(lsb)
utf16LE[i*2+3] = byte(msb)
utf16BE[i*2+2] = byte(msb)
utf16BE[i*2+3] = byte(lsb)
}
testcases := []struct {
data []byte
extension string
mimetype string
}{
{mimetype: "text/plain; charset=utf-8", data: utf8},
{mimetype: "text/plain; charset=utf-16le", data: utf16LE},
{mimetype: "text/plain; charset=utf-16be", data: utf16BE},
}
for i, testcase := range testcases {
r := bytes.NewReader(testcase.data)
m, err := GenerateMetadata(r)
if err != nil {
t.Fatalf("[%d] unexpected error return %v\n", i, err)
}
if m.Mimetype != testcase.mimetype {
t.Errorf("[%d] Expected mimetype '%s', got mimetype '%s'\n", i, testcase.mimetype, m.Mimetype)
}
}
}

27
httputil/LICENSE Normal file
View file

@ -0,0 +1,27 @@
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

218
httputil/conditional.go Normal file
View file

@ -0,0 +1,218 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// HTTP file system request handler
package httputil
import (
"net/http"
"net/textproto"
"strings"
"time"
)
// scanETag determines if a syntactically valid ETag is present at s. If so,
// the ETag and remaining text after consuming ETag is returned. Otherwise,
// it returns "", "".
func scanETag(s string) (etag string, remain string) {
s = textproto.TrimString(s)
start := 0
if strings.HasPrefix(s, "W/") {
start = 2
}
if len(s[start:]) < 2 || s[start] != '"' {
return "", ""
}
// ETag is either W/"text" or "text".
// See RFC 7232 2.3.
for i := start + 1; i < len(s); i++ {
c := s[i]
switch {
// Character values allowed in ETags.
case c == 0x21 || c >= 0x23 && c <= 0x7E || c >= 0x80:
case c == '"':
return s[:i+1], s[i+1:]
default:
return "", ""
}
}
return "", ""
}
// etagStrongMatch reports whether a and b match using strong ETag comparison.
// Assumes a and b are valid ETags.
func etagStrongMatch(a, b string) bool {
return a == b && a != "" && a[0] == '"'
}
// etagWeakMatch reports whether a and b match using weak ETag comparison.
// Assumes a and b are valid ETags.
func etagWeakMatch(a, b string) bool {
return strings.TrimPrefix(a, "W/") == strings.TrimPrefix(b, "W/")
}
// condResult is the result of an HTTP request precondition check.
// See https://tools.ietf.org/html/rfc7232 section 3.
type condResult int
const (
condNone condResult = iota
condTrue
condFalse
)
func checkIfMatch(w http.ResponseWriter, r *http.Request) condResult {
im := r.Header.Get("If-Match")
if im == "" {
return condNone
}
for {
im = textproto.TrimString(im)
if len(im) == 0 {
break
}
if im[0] == ',' {
im = im[1:]
continue
}
if im[0] == '*' {
return condTrue
}
etag, remain := scanETag(im)
if etag == "" {
break
}
if etagStrongMatch(etag, w.Header().Get("Etag")) {
return condTrue
}
im = remain
}
return condFalse
}
func checkIfUnmodifiedSince(r *http.Request, modtime time.Time) condResult {
ius := r.Header.Get("If-Unmodified-Since")
if ius == "" || isZeroTime(modtime) {
return condNone
}
if t, err := http.ParseTime(ius); err == nil {
// The Date-Modified header truncates sub-second precision, so
// use mtime < t+1s instead of mtime <= t to check for unmodified.
if modtime.Before(t.Add(1 * time.Second)) {
return condTrue
}
return condFalse
}
return condNone
}
func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) condResult {
inm := r.Header.Get("If-None-Match")
if inm == "" {
return condNone
}
buf := inm
for {
buf = textproto.TrimString(buf)
if len(buf) == 0 {
break
}
if buf[0] == ',' {
buf = buf[1:]
}
if buf[0] == '*' {
return condFalse
}
etag, remain := scanETag(buf)
if etag == "" {
break
}
if etagWeakMatch(etag, w.Header().Get("Etag")) {
return condFalse
}
buf = remain
}
return condTrue
}
func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult {
if r.Method != "GET" && r.Method != "HEAD" {
return condNone
}
ims := r.Header.Get("If-Modified-Since")
if ims == "" || isZeroTime(modtime) {
return condNone
}
t, err := http.ParseTime(ims)
if err != nil {
return condNone
}
// The Date-Modified header truncates sub-second precision, so
// use mtime < t+1s instead of mtime <= t to check for unmodified.
if modtime.Before(t.Add(1 * time.Second)) {
return condFalse
}
return condTrue
}
var unixEpochTime = time.Unix(0, 0)
// isZeroTime reports whether t is obviously unspecified (either zero or Unix()=0).
func isZeroTime(t time.Time) bool {
return t.IsZero() || t.Equal(unixEpochTime)
}
func setLastModified(w http.ResponseWriter, modtime time.Time) {
if !isZeroTime(modtime) {
w.Header().Set("Last-Modified", modtime.UTC().Format(http.TimeFormat))
}
}
func writeNotModified(w http.ResponseWriter) {
// RFC 7232 section 4.1:
// a sender SHOULD NOT generate representation metadata other than the
// above listed fields unless said metadata exists for the purpose of
// guiding cache updates (e.g., Last-Modified might be useful if the
// response does not have an ETag field).
h := w.Header()
delete(h, "Content-Type")
delete(h, "Content-Length")
if h.Get("Etag") != "" {
delete(h, "Last-Modified")
}
w.WriteHeader(http.StatusNotModified)
}
// CheckPreconditions evaluates request preconditions and reports whether a precondition
// resulted in sending StatusNotModified or StatusPreconditionFailed.
func CheckPreconditions(w http.ResponseWriter, r *http.Request, modtime time.Time) (done bool) {
// This function carefully follows RFC 7232 section 6.
ch := checkIfMatch(w, r)
if ch == condNone {
ch = checkIfUnmodifiedSince(r, modtime)
}
if ch == condFalse {
w.WriteHeader(http.StatusPreconditionFailed)
return true
}
switch checkIfNoneMatch(w, r) {
case condFalse:
if r.Method == "GET" || r.Method == "HEAD" {
writeNotModified(w)
return true
} else {
w.WriteHeader(http.StatusPreconditionFailed)
return true
}
case condNone:
if checkIfModifiedSince(r, modtime) == condFalse {
writeNotModified(w)
return true
}
}
return false
}

19
linx-cleanup/README.md Normal file
View file

@ -0,0 +1,19 @@
linx-cleanup
-------------------------
When files expire, access is disabled immediately, but the files and metadata
will persist on disk until someone attempts to access them.
If you'd like to automatically clean up files that have expired, you can use the included `linx-cleanup` utility. To run it automatically, use a cronjob or similar type
of scheduled task.
You should be careful to ensure that only one instance of `linx-cleanup` runs at
a time to avoid unexpected behavior. It does not implement any type of locking.
|Option|Description
|------|-----------
| ```-filespath files/``` | Path to stored uploads (default is files/)
| ```-nologs``` | (optionally) disable deletion logs in stdout
| ```-metapath meta/``` | Path to stored information about uploads (default is meta/)

View file

@ -0,0 +1,23 @@
package main
import (
"flag"
"github.com/andreimarcu/linx-server/cleanup"
)
func main() {
var filesDir string
var metaDir string
var noLogs bool
flag.StringVar(&filesDir, "filespath", "files/",
"path to files directory")
flag.StringVar(&metaDir, "metapath", "meta/",
"path to metadata directory")
flag.BoolVar(&noLogs, "nologs", false,
"don't log deleted files")
flag.Parse()
cleanup.Cleanup(filesDir, metaDir, noLogs)
}

View file

@ -0,0 +1,12 @@
[Unit]
Description=Self-hosted file/code/media sharing (expired files cleanup)
After=network.target
[Service]
User=linx
Group=linx
ExecStart=/usr/bin/linx-cleanup
WorkingDirectory=/srv/linx/
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,8 @@
[Unit]
Description=Run linx-cleanup every hour
[Timer]
OnUnitActiveSec=1h
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,32 @@
package main
import (
"bufio"
"encoding/base64"
"fmt"
"os"
"golang.org/x/crypto/scrypt"
)
const (
scryptSalt = "linx-server"
scryptN = 16384
scryptr = 8
scryptp = 1
scryptKeyLen = 32
)
func main() {
fmt.Printf("Enter key to hash: ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
checkKey, err := scrypt.Key([]byte(scanner.Text()), []byte(scryptSalt), scryptN, scryptr, scryptp, scryptKeyLen)
if err != nil {
return
}
fmt.Println(base64.StdEncoding.EncodeToString(checkKey))
}

12
linx-server.conf.example Normal file
View file

@ -0,0 +1,12 @@
bind = 127.0.0.1:8080
sitename = myLinx
siteurl = https://mylinx.example.org/
selifpath = s
maxsize = 4294967296
maxexpiry = 86400
allowhotlink = true
remoteuploads = true
nologs = true
force-random-filename = false
cleanup-every-minutes = 5

11
linx-server.service Normal file
View file

@ -0,0 +1,11 @@
[Unit]
Description=Self-hosted file/code/media sharing website
After=network.target
[Service]
User=linx
Group=linx
ExecStart=/usr/bin/linx-server
[Install]
WantedBy=multi-user.target

84
meta.go
View file

@ -1,84 +0,0 @@
package main
import (
"bufio"
"errors"
"fmt"
"os"
"path"
"strconv"
"time"
)
// Write metadata from Upload struct to file
func metadataWrite(filename string, upload *Upload) error {
// Write metadata, overwriting if necessary
file, err := os.Create(path.Join(Config.metaDir, upload.Filename))
if err != nil {
return err
}
defer file.Close()
w := bufio.NewWriter(file)
fmt.Fprintln(w, upload.Expiry.Unix())
fmt.Fprintln(w, upload.DeleteKey)
return w.Flush()
}
// Return list of strings from a filename's metadata source
func metadataRead(filename string) ([]string, error) {
file, err := os.Open(path.Join(Config.metaDir, filename))
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}
func metadataGetExpiry(filename string) (expiry time.Time, err error) {
metadata, err := metadataRead(filename)
// XXX in this case it's up to the caller to determine proper behavior
// for a nonexistant metadata file or broken file
if err != nil {
return
}
if len(metadata) < 1 {
err = errors.New("ERR: Metadata file does not contain expiry")
return
}
expirySecs, err := strconv.ParseInt(metadata[0], 10, 64)
expiry = time.Unix(expirySecs, 0)
return
}
func metadataGetDeleteKey(filename string) (string, error) {
metadata, err := metadataRead(filename)
if len(metadata) < 2 {
err := errors.New("ERR: Metadata file does not contain deletion key")
return "", err
}
if err != nil {
return "", err
} else {
return metadata[1], err
}
}

View file

@ -20,22 +20,54 @@ const (
)
func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := Templates["index.html"].ExecuteWriter(pongo2.Context{}, w)
err := renderTemplate(Templates["index.html"], pongo2.Context{
"maxsize": Config.maxSize,
"expirylist": listExpirationTimes(),
"forcerandom": Config.forceRandomFilename,
}, r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := Templates["paste.html"].ExecuteWriter(pongo2.Context{}, w)
err := renderTemplate(Templates["paste.html"], pongo2.Context{
"expirylist": listExpirationTimes(),
"forcerandom": Config.forceRandomFilename,
}, r, w)
if err != nil {
oopsHandler(c, w, r, RespHTML, "")
}
}
func apiDocHandler(c web.C, w http.ResponseWriter, r *http.Request) {
err := renderTemplate(Templates["API.html"], pongo2.Context{
"siteurl": getSiteURL(r),
"forcerandom": Config.forceRandomFilename,
}, r, w)
if err != nil {
oopsHandler(c, w, r, RespHTML, "")
}
}
func makeCustomPageHandler(fileName string) func(c web.C, w http.ResponseWriter, r *http.Request) {
return func(c web.C, w http.ResponseWriter, r *http.Request) {
err := renderTemplate(Templates["custom_page.html"], pongo2.Context{
"siteurl": getSiteURL(r),
"forcerandom": Config.forceRandomFilename,
"contents": customPages[fileName],
"filename": fileName,
"pagename": customPagesNames[fileName],
}, r, w)
if err != nil {
oopsHandler(c, w, r, RespHTML, "")
}
}
}
func notFoundHandler(c web.C, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
err := Templates["404.html"].ExecuteWriter(pongo2.Context{}, w)
err := renderTemplate(Templates["404.html"], pongo2.Context{}, r, w)
if err != nil {
oopsHandler(c, w, r, RespHTML, "")
}
@ -48,14 +80,12 @@ func oopsHandler(c web.C, w http.ResponseWriter, r *http.Request, rt RespType, m
if rt == RespHTML {
w.WriteHeader(500)
Templates["oops.html"].ExecuteWriter(pongo2.Context{"msg": msg}, w)
renderTemplate(Templates["oops.html"], pongo2.Context{"msg": msg}, r, w)
return
} else if rt == RespPLAIN {
w.WriteHeader(500)
fmt.Fprintf(w, "%s", msg)
return
} else if rt == RespJSON {
js, _ := json.Marshal(map[string]string{
"error": msg,
@ -65,7 +95,6 @@ func oopsHandler(c web.C, w http.ResponseWriter, r *http.Request, rt RespType, m
w.WriteHeader(500)
w.Write(js)
return
} else if rt == RespAUTO {
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
oopsHandler(c, w, r, RespJSON, msg)
@ -75,9 +104,39 @@ func oopsHandler(c web.C, w http.ResponseWriter, r *http.Request, rt RespType, m
}
}
func badRequestHandler(c web.C, w http.ResponseWriter, r *http.Request, rt RespType, msg string) {
if rt == RespHTML {
w.WriteHeader(http.StatusBadRequest)
err := renderTemplate(Templates["400.html"], pongo2.Context{"msg": msg}, r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
} else if rt == RespPLAIN {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "%s", msg)
return
} else if rt == RespJSON {
js, _ := json.Marshal(map[string]string{
"error": msg,
})
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusBadRequest)
w.Write(js)
return
} else if rt == RespAUTO {
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
badRequestHandler(c, w, r, RespJSON, msg)
} else {
badRequestHandler(c, w, r, RespHTML, msg)
}
}
}
func unauthorizedHandler(c web.C, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(401)
err := Templates["401.html"].ExecuteWriter(pongo2.Context{}, w)
err := renderTemplate(Templates["401.html"], pongo2.Context{}, r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

276
server.go
View file

@ -6,33 +6,74 @@ import (
"net"
"net/http"
"net/http/fcgi"
"net/url"
"os"
"os/signal"
"regexp"
"strconv"
"strings"
"syscall"
"time"
"github.com/GeertJohan/go.rice"
rice "github.com/GeertJohan/go.rice"
"github.com/andreimarcu/linx-server/auth/apikeys"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/backends/localfs"
"github.com/andreimarcu/linx-server/backends/s3"
"github.com/andreimarcu/linx-server/cleanup"
"github.com/flosch/pongo2"
"github.com/zenazn/goji"
"github.com/vharitonsky/iniflags"
"github.com/zenazn/goji/graceful"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware"
)
type headerList []string
func (h *headerList) String() string {
return strings.Join(*h, ",")
}
func (h *headerList) Set(value string) error {
*h = append(*h, value)
return nil
}
var Config struct {
bind string
filesDir string
metaDir string
siteName string
siteURL string
sitePath string
selifPath string
certFile string
keyFile string
contentSecurityPolicy string
fileContentSecurityPolicy string
referrerPolicy string
fileReferrerPolicy string
xFrameOptions string
maxSize int64
maxExpiry uint64
realIp bool
noLogs bool
allowHotlink bool
fastcgi bool
remoteUploads bool
basicAuth bool
authFile string
remoteAuthFile string
addHeaders headerList
noDirectAgents bool
s3Endpoint string
s3Region string
s3Bucket string
s3ForcePathStyle bool
forceRandomFilename bool
accessKeyCookieExpiry uint64
customPagesDir string
cleanupEveryMinutes uint64
}
var Templates = make(map[string]*pongo2.Template)
@ -40,15 +81,43 @@ var TemplateSet *pongo2.TemplateSet
var staticBox *rice.Box
var timeStarted time.Time
var timeStartedStr string
var remoteAuthKeys []string
var metaStorageBackend backends.MetaStorageBackend
var storageBackend backends.StorageBackend
var customPages = make(map[string]string)
var customPagesNames = make(map[string]string)
func setup() {
goji.Use(ContentSecurityPolicy(CSPOptions{
policy: Config.contentSecurityPolicy,
frame: Config.xFrameOptions,
func setup() *web.Mux {
mux := web.New()
// middleware
mux.Use(middleware.RequestID)
if Config.realIp {
mux.Use(middleware.RealIP)
}
if !Config.noLogs {
mux.Use(middleware.Logger)
}
mux.Use(middleware.Recoverer)
mux.Use(middleware.AutomaticOptions)
mux.Use(ContentSecurityPolicy(CSPOptions{
policy: Config.contentSecurityPolicy,
referrerPolicy: Config.referrerPolicy,
frame: Config.xFrameOptions,
}))
mux.Use(AddHeaders(Config.addHeaders))
if Config.noLogs {
goji.Abandon(middleware.Logger)
if Config.authFile != "" {
mux.Use(apikeys.NewApiKeysMiddleware(apikeys.AuthOptions{
AuthFile: Config.authFile,
UnauthMethods: []string{"GET", "HEAD", "OPTIONS", "TRACE"},
BasicAuth: Config.basicAuth,
SiteName: Config.siteName,
SitePath: Config.sitePath,
}))
}
// make directories if needed
@ -62,9 +131,35 @@ func setup() {
log.Fatal("Could not create metadata directory:", err)
}
// ensure siteURL ends wth '/'
if lastChar := Config.siteURL[len(Config.siteURL)-1:]; lastChar != "/" {
Config.siteURL = Config.siteURL + "/"
if Config.siteURL != "" {
// ensure siteURL ends wth '/'
if lastChar := Config.siteURL[len(Config.siteURL)-1:]; lastChar != "/" {
Config.siteURL = Config.siteURL + "/"
}
parsedUrl, err := url.Parse(Config.siteURL)
if err != nil {
log.Fatal("Could not parse siteurl:", err)
}
Config.sitePath = parsedUrl.Path
} else {
Config.sitePath = "/"
}
Config.selifPath = strings.TrimLeft(Config.selifPath, "/")
if lastChar := Config.selifPath[len(Config.selifPath)-1:]; lastChar != "/" {
Config.selifPath = Config.selifPath + "/"
}
if Config.s3Bucket != "" {
storageBackend = s3.NewS3Backend(Config.s3Bucket, Config.s3Region, Config.s3Endpoint, Config.s3ForcePathStyle)
} else {
storageBackend = localfs.NewLocalfsBackend(Config.metaDir, Config.filesDir)
if Config.cleanupEveryMinutes > 0 {
go cleanup.PeriodicCleanup(time.Duration(Config.cleanupEveryMinutes)*time.Minute, Config.filesDir, Config.metaDir, Config.noLogs)
}
}
// Template setup
@ -73,7 +168,6 @@ func setup() {
log.Fatal("Error: could not load templates", err)
}
TemplateSet := pongo2.NewSet("templates", p2l)
TemplateSet.Globals["sitename"] = Config.siteName
err = populateTemplatesMap(TemplateSet, Templates)
if err != nil {
log.Fatal("Error: could not load templates", err)
@ -84,88 +178,174 @@ func setup() {
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 + Config.selifPath + `(?P<name>[a-z0-9-\.]+)$`)
selifIndexRe := regexp.MustCompile("^" + Config.sitePath + Config.selifPath + `$`)
torrentRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)/torrent$`)
goji.Get("/", indexHandler)
goji.Get("/paste/", pasteHandler)
goji.Get("/paste", http.RedirectHandler("/paste/", 301))
if Config.authFile == "" || Config.basicAuth {
mux.Get(Config.sitePath, indexHandler)
mux.Get(Config.sitePath+"paste/", pasteHandler)
} else {
mux.Get(Config.sitePath, http.RedirectHandler(Config.sitePath+"API", 303))
mux.Get(Config.sitePath+"paste/", http.RedirectHandler(Config.sitePath+"API/", 303))
}
mux.Get(Config.sitePath+"paste", http.RedirectHandler(Config.sitePath+"paste/", 301))
mux.Get(Config.sitePath+"API/", apiDocHandler)
mux.Get(Config.sitePath+"API", http.RedirectHandler(Config.sitePath+"API/", 301))
if Config.remoteUploads {
goji.Get("/upload", uploadRemote)
goji.Get("/upload/", uploadRemote)
mux.Get(Config.sitePath+"upload", uploadRemote)
mux.Get(Config.sitePath+"upload/", uploadRemote)
if Config.remoteAuthFile != "" {
remoteAuthKeys = apikeys.ReadAuthKeys(Config.remoteAuthFile)
}
}
goji.Post("/upload", uploadPostHandler)
goji.Post("/upload/", uploadPostHandler)
goji.Put("/upload", uploadPutHandler)
goji.Put("/upload/:name", uploadPutHandler)
goji.Delete("/:name", deleteHandler)
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)
goji.Get("/static/*", staticHandler)
goji.Get("/favicon.ico", staticHandler)
goji.Get("/robots.txt", staticHandler)
goji.Get(nameRe, fileDisplayHandler)
goji.Get(selifRe, fileServeHandler)
goji.Get(selifIndexRe, unauthorizedHandler)
goji.Get(torrentRe, fileTorrentHandler)
goji.NotFound(notFoundHandler)
mux.Delete(Config.sitePath+":name", deleteHandler)
mux.Get(Config.sitePath+"static/*", staticHandler)
mux.Get(Config.sitePath+"favicon.ico", staticHandler)
mux.Get(Config.sitePath+"robots.txt", staticHandler)
mux.Get(nameRe, fileAccessHandler)
mux.Post(nameRe, fileAccessHandler)
mux.Get(selifRe, fileServeHandler)
mux.Get(selifIndexRe, unauthorizedHandler)
mux.Get(torrentRe, fileTorrentHandler)
if Config.customPagesDir != "" {
initializeCustomPages(Config.customPagesDir)
for fileName := range customPagesNames {
mux.Get(Config.sitePath+fileName, makeCustomPageHandler(fileName))
mux.Get(Config.sitePath+fileName+"/", makeCustomPageHandler(fileName))
}
}
mux.NotFound(notFoundHandler)
return mux
}
func main() {
flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
flag.StringVar(&Config.bind, "bind", "127.0.0.1:8080",
"host to bind to (default: 127.0.0.1:8080)")
flag.StringVar(&Config.filesDir, "filespath", "files/",
"path to files directory")
flag.StringVar(&Config.metaDir, "metapath", "meta/",
"path to metadata directory")
flag.BoolVar(&Config.basicAuth, "basicauth", false,
"allow logging by basic auth password")
flag.BoolVar(&Config.noLogs, "nologs", false,
"remove stdout output for each request")
flag.BoolVar(&Config.allowHotlink, "allowhotlink", false,
"Allow hotlinking of files")
flag.StringVar(&Config.siteName, "sitename", "linx",
flag.StringVar(&Config.siteName, "sitename", "",
"name of the site")
flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
flag.StringVar(&Config.siteURL, "siteurl", "",
"site base url (including trailing slash)")
flag.StringVar(&Config.selifPath, "selifpath", "selif",
"path relative to site base url where files are accessed directly")
flag.Int64Var(&Config.maxSize, "maxsize", 4*1024*1024*1024,
"maximum upload file size in bytes (default 4GB)")
flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0,
"maximum expiration time in seconds (default is 0, which is no expiry)")
flag.StringVar(&Config.certFile, "certfile", "",
"path to ssl certificate (for https)")
flag.StringVar(&Config.keyFile, "keyfile", "",
"path to ssl key (for https)")
flag.BoolVar(&Config.realIp, "realip", false,
"use X-Real-IP/X-Forwarded-For headers as original host")
flag.BoolVar(&Config.fastcgi, "fastcgi", false,
"serve through fastcgi")
flag.BoolVar(&Config.remoteUploads, "remoteuploads", false,
"enable remote uploads")
flag.StringVar(&Config.authFile, "authfile", "",
"path to a file containing newline-separated scrypted auth keys")
flag.StringVar(&Config.remoteAuthFile, "remoteauthfile", "",
"path to a file containing newline-separated scrypted auth keys for remote uploads")
flag.StringVar(&Config.contentSecurityPolicy, "contentsecuritypolicy",
"default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; referrer none;",
"default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self';",
"value of default Content-Security-Policy header")
flag.StringVar(&Config.fileContentSecurityPolicy, "filecontentsecuritypolicy",
"default-src 'none'; img-src 'self'; object-src 'self'; media-src 'self'; sandbox; referrer none;",
"default-src 'none'; img-src 'self'; object-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'self';",
"value of Content-Security-Policy header for file access")
flag.StringVar(&Config.referrerPolicy, "referrerpolicy",
"same-origin",
"value of default Referrer-Policy header")
flag.StringVar(&Config.fileReferrerPolicy, "filereferrerpolicy",
"same-origin",
"value of Referrer-Policy header for file access")
flag.StringVar(&Config.xFrameOptions, "xframeoptions", "SAMEORIGIN",
"value of X-Frame-Options header")
flag.Parse()
flag.Var(&Config.addHeaders, "addheader",
"Add an arbitrary header to the response. This option can be used multiple times.")
flag.BoolVar(&Config.noDirectAgents, "nodirectagents", false,
"disable serving files directly for wget/curl user agents")
flag.StringVar(&Config.s3Endpoint, "s3-endpoint", "",
"S3 endpoint")
flag.StringVar(&Config.s3Region, "s3-region", "",
"S3 region")
flag.StringVar(&Config.s3Bucket, "s3-bucket", "",
"S3 bucket to use for files and metadata")
flag.BoolVar(&Config.s3ForcePathStyle, "s3-force-path-style", false,
"Force path-style addressing for S3 (e.g. https://s3.amazonaws.com/linx/example.txt)")
flag.BoolVar(&Config.forceRandomFilename, "force-random-filename", false,
"Force all uploads to use a random filename")
flag.Uint64Var(&Config.accessKeyCookieExpiry, "access-cookie-expiry", 0, "Expiration time for access key cookies in seconds (set 0 to use session cookies)")
flag.StringVar(&Config.customPagesDir, "custompagespath", "",
"path to directory containing .md files to render as custom pages")
flag.Uint64Var(&Config.cleanupEveryMinutes, "cleanup-every-minutes", 0,
"How often to clean up expired files in minutes (default is 0, which means files will be cleaned up as they are accessed)")
setup()
iniflags.Parse()
mux := setup()
if Config.fastcgi {
listener, err := net.Listen("tcp", Config.bind)
var listener net.Listener
var err error
if Config.bind[0] == '/' {
// UNIX path
listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: Config.bind, Net: "unix"})
cleanup := func() {
log.Print("Removing FastCGI socket")
os.Remove(Config.bind)
}
defer cleanup()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
log.Print("Signal: ", sig)
cleanup()
os.Exit(0)
}()
} else {
listener, err = net.Listen("tcp", Config.bind)
}
if err != nil {
log.Fatal("Could not bind: ", err)
}
log.Printf("Serving over fastcgi, bound on %s, using siteurl %s", Config.bind, Config.siteURL)
fcgi.Serve(listener, goji.DefaultMux)
log.Printf("Serving over fastcgi, bound on %s", Config.bind)
fcgi.Serve(listener, mux)
} else if Config.certFile != "" {
log.Printf("Serving over https, bound on %s, using siteurl %s", Config.bind, Config.siteURL)
err := graceful.ListenAndServeTLS(Config.bind, Config.certFile, Config.keyFile, goji.DefaultMux)
log.Printf("Serving over https, bound on %s", Config.bind)
err := graceful.ListenAndServeTLS(Config.bind, Config.certFile, Config.keyFile, mux)
if err != nil {
log.Fatal(err)
}
} else {
log.Printf("Serving over http, bound on %s, using siteurl %s", Config.bind, Config.siteURL)
err := graceful.ListenAndServe(Config.bind, goji.DefaultMux)
log.Printf("Serving over http, bound on %s", Config.bind)
err := graceful.ListenAndServe(Config.bind, mux)
if err != nil {
log.Fatal(err)
}

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,55 @@
#dropzone { width: 400px;
#dzone {
display: none;
}
.fallback {
background-color: #FAFBFC;
padding-top: 40px;
padding-bottom: 20px;
text-align: center;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
}
#fileinput {
margin-top: 20px;
}
#submitbtn {
margin-top: 30px;
background-color: #FFF;
border: 2px solid #556A7F;
width: 90px;
height: 30px;
}
#submitbtn:hover {
background-color: #556A7F;
color: white;
border: 2px solid #FAFBFC;
}
#dropzone {
width: 400px;
margin-left: auto;
margin-right: auto;
}
#choices {
padding-bottom: 20px;
@media(max-width: 450px) {
#dropzone {
width: auto;
}
}
#uploads {
margin-top: 20px;
}
div.dz-default {
border: 2px dashed #C9C9C9;
border-radius: 5px;
color: #C9C9C9;
font: 14px "helvetica neue",helvetica,arial,sans-serif;
background-color: #FAFBFC;

View file

@ -8,7 +8,8 @@
font-size: 12px;
line-height: 1.6;
word-wrap: break-word;
width: 680px;
width: 80vw;
max-width: 680px;
padding: 10px;
}
@ -43,6 +44,10 @@
overflow: auto;
}
.markdown-body li {
list-style: unset;
}
.markdown-body code,
.markdown-body kbd,
.markdown-body pre {

View file

@ -0,0 +1,29 @@
.linenumbers {
border-left: 1px solid #ccc;
margin-left: 36px;
position: relative;
}
.linenumbers code {
counter-reset: linenumbers;
}
.linenumbers code div:before {
content: counter(linenumbers);
counter-increment: linenumbers;
left: -36px;
width: 28px;
position: absolute;
text-align: right;
padding-right: 5px;
color: #999;
overflow-wrap: normal;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

View file

@ -1,13 +0,0 @@
.hljs {
display: block;
background: #f0e0d6;
color: #800000;
padding: 0.5em;
font-family: arial,helvetica,sans-serif;
font-size: 13px;
}
.hljs-comment {
color: #789922;
}

View file

@ -2,89 +2,71 @@
/* Tomorrow Comment */
.hljs-comment,
.hljs-title {
.hljs-quote {
color: #8e908c;
}
/* Tomorrow Red */
.hljs-variable,
.hljs-attribute,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.ruby .hljs-constant,
.xml .hljs-tag .hljs-title,
.xml .hljs-pi,
.xml .hljs-doctype,
.html .hljs-doctype,
.css .hljs-id,
.css .hljs-class,
.css .hljs-pseudo {
.hljs-deletion {
color: #c82829;
}
/* Tomorrow Orange */
.hljs-number,
.hljs-preprocessor,
.hljs-pragma,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-constant {
.hljs-meta,
.hljs-link {
color: #f5871f;
}
/* Tomorrow Yellow */
.ruby .hljs-class .hljs-title,
.css .hljs-rules .hljs-attribute {
.hljs-attribute {
color: #eab700;
}
/* Tomorrow Green */
.hljs-string,
.hljs-value,
.hljs-inheritance,
.hljs-header,
.ruby .hljs-symbol,
.xml .hljs-cdata {
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
color: #718c00;
}
/* Tomorrow Aqua */
.css .hljs-hexcolor {
color: #3e999f;
}
/* Tomorrow Blue */
.hljs-function,
.python .hljs-decorator,
.python .hljs-title,
.ruby .hljs-function .hljs-title,
.ruby .hljs-title .hljs-keyword,
.perl .hljs-sub,
.javascript .hljs-title,
.coffeescript .hljs-title {
.hljs-title,
.hljs-section {
color: #4271ae;
}
/* Tomorrow Purple */
.hljs-keyword,
.javascript .hljs-function {
.hljs-selector-tag {
color: #8959a8;
}
.hljs {
display: block;
overflow-x: auto;
background: white;
color: #4d4d4c;
padding: 0.5em;
}
.coffeescript .javascript,
.javascript .xml,
.tex .hljs-formula,
.xml .javascript,
.xml .vbscript,
.xml .css,
.xml .hljs-cdata {
opacity: 0.5;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}

648
static/css/hint.css Normal file
View file

@ -0,0 +1,648 @@
/*! Hint.css - v2.3.1 - 2016-06-05
* http://kushagragour.in/lab/hint/
* Copyright (c) 2016 Kushagra Gour; Licensed */
/*-------------------------------------* HINT.css - A CSS tooltip library
\*-------------------------------------*/
/**
* HINT.css is a tooltip library made in pure CSS.
*
* Source: https://github.com/chinchang/hint.css
* Demo: http://kushagragour.in/lab/hint/
*
* Release under The MIT License
*
*/
/**
* source: hint-core.scss
*
* Defines the basic styling for the tooltip.
* Each tooltip is made of 2 parts:
* 1) body (:after)
* 2) arrow (:before)
*
* Classes added:
* 1) hint
*/
[class*="hint--"] {
position: relative;
display: inline-block;
/**
* tooltip arrow
*/
/**
* tooltip body
*/ }
[class*="hint--"]:before, [class*="hint--"]:after {
position: absolute;
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
visibility: hidden;
opacity: 0;
z-index: 1000000;
pointer-events: none;
-webkit-transition: 0.3s ease;
-moz-transition: 0.3s ease;
transition: 0.3s ease;
-webkit-transition-delay: 0ms;
-moz-transition-delay: 0ms;
transition-delay: 0ms; }
[class*="hint--"]:hover:before, [class*="hint--"]:hover:after {
visibility: visible;
opacity: 1; }
[class*="hint--"]:hover:before, [class*="hint--"]:hover:after {
-webkit-transition-delay: 100ms;
-moz-transition-delay: 100ms;
transition-delay: 100ms; }
[class*="hint--"]:before {
content: '';
position: absolute;
background: transparent;
border: 6px solid transparent;
z-index: 1000001; }
[class*="hint--"]:after {
background: #383838;
color: white;
padding: 8px 10px;
font-size: 12px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 12px;
white-space: nowrap; }
[class*="hint--"][aria-label]:after {
content: attr(aria-label); }
[class*="hint--"][data-hint]:after {
content: attr(data-hint); }
[aria-label='']:before, [aria-label='']:after,
[data-hint='']:before,
[data-hint='']:after {
display: none !important; }
/**
* source: hint-position.scss
*
* Defines the positoning logic for the tooltips.
*
* Classes added:
* 1) hint--top
* 2) hint--bottom
* 3) hint--left
* 4) hint--right
*/
/**
* set default color for tooltip arrows
*/
.hint--top-left:before {
border-top-color: #383838; }
.hint--top-right:before {
border-top-color: #383838; }
.hint--top:before {
border-top-color: #383838; }
.hint--bottom-left:before {
border-bottom-color: #383838; }
.hint--bottom-right:before {
border-bottom-color: #383838; }
.hint--bottom:before {
border-bottom-color: #383838; }
.hint--left:before {
border-left-color: #383838; }
.hint--right:before {
border-right-color: #383838; }
/**
* top tooltip
*/
.hint--top:before {
margin-bottom: -11px; }
.hint--top:before, .hint--top:after {
bottom: 100%;
left: 50%; }
.hint--top:before {
left: calc(50% - 6px); }
.hint--top:after {
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
transform: translateX(-50%); }
.hint--top:hover:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--top:hover:after {
-webkit-transform: translateX(-50%) translateY(-8px);
-moz-transform: translateX(-50%) translateY(-8px);
transform: translateX(-50%) translateY(-8px); }
/**
* bottom tooltip
*/
.hint--bottom:before {
margin-top: -11px; }
.hint--bottom:before, .hint--bottom:after {
top: 100%;
left: 50%; }
.hint--bottom:before {
left: calc(50% - 6px); }
.hint--bottom:after {
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
transform: translateX(-50%); }
.hint--bottom:hover:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--bottom:hover:after {
-webkit-transform: translateX(-50%) translateY(8px);
-moz-transform: translateX(-50%) translateY(8px);
transform: translateX(-50%) translateY(8px); }
/**
* right tooltip
*/
.hint--right:before {
margin-left: -11px;
margin-bottom: -6px; }
.hint--right:after {
margin-bottom: -14px; }
.hint--right:before, .hint--right:after {
left: 100%;
bottom: 50%; }
.hint--right:hover:before {
-webkit-transform: translateX(8px);
-moz-transform: translateX(8px);
transform: translateX(8px); }
.hint--right:hover:after {
-webkit-transform: translateX(8px);
-moz-transform: translateX(8px);
transform: translateX(8px); }
/**
* left tooltip
*/
.hint--left:before {
margin-right: -11px;
margin-bottom: -6px; }
.hint--left:after {
margin-bottom: -14px; }
.hint--left:before, .hint--left:after {
right: 100%;
bottom: 50%; }
.hint--left:hover:before {
-webkit-transform: translateX(-8px);
-moz-transform: translateX(-8px);
transform: translateX(-8px); }
.hint--left:hover:after {
-webkit-transform: translateX(-8px);
-moz-transform: translateX(-8px);
transform: translateX(-8px); }
/**
* top-left tooltip
*/
.hint--top-left:before {
margin-bottom: -11px; }
.hint--top-left:before, .hint--top-left:after {
bottom: 100%;
left: 50%; }
.hint--top-left:before {
left: calc(50% - 6px); }
.hint--top-left:after {
-webkit-transform: translateX(-100%);
-moz-transform: translateX(-100%);
transform: translateX(-100%); }
.hint--top-left:after {
margin-left: 12px; }
.hint--top-left:hover:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--top-left:hover:after {
-webkit-transform: translateX(-100%) translateY(-8px);
-moz-transform: translateX(-100%) translateY(-8px);
transform: translateX(-100%) translateY(-8px); }
/**
* top-right tooltip
*/
.hint--top-right:before {
margin-bottom: -11px; }
.hint--top-right:before, .hint--top-right:after {
bottom: 100%;
left: 50%; }
.hint--top-right:before {
left: calc(50% - 6px); }
.hint--top-right:after {
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
transform: translateX(0); }
.hint--top-right:after {
margin-left: -12px; }
.hint--top-right:hover:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--top-right:hover:after {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
/**
* bottom-left tooltip
*/
.hint--bottom-left:before {
margin-top: -11px; }
.hint--bottom-left:before, .hint--bottom-left:after {
top: 100%;
left: 50%; }
.hint--bottom-left:before {
left: calc(50% - 6px); }
.hint--bottom-left:after {
-webkit-transform: translateX(-100%);
-moz-transform: translateX(-100%);
transform: translateX(-100%); }
.hint--bottom-left:after {
margin-left: 12px; }
.hint--bottom-left:hover:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--bottom-left:hover:after {
-webkit-transform: translateX(-100%) translateY(8px);
-moz-transform: translateX(-100%) translateY(8px);
transform: translateX(-100%) translateY(8px); }
/**
* bottom-right tooltip
*/
.hint--bottom-right:before {
margin-top: -11px; }
.hint--bottom-right:before, .hint--bottom-right:after {
top: 100%;
left: 50%; }
.hint--bottom-right:before {
left: calc(50% - 6px); }
.hint--bottom-right:after {
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
transform: translateX(0); }
.hint--bottom-right:after {
margin-left: -12px; }
.hint--bottom-right:hover:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--bottom-right:hover:after {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
/**
* source: hint-sizes.scss
*
* Defines width restricted tooltips that can span
* across multiple lines.
*
* Classes added:
* 1) hint--small
* 2) hint--medium
* 3) hint--large
*
*/
.hint--small:after,
.hint--medium:after,
.hint--large:after {
white-space: normal;
line-height: 1.4em; }
.hint--small:after {
width: 80px; }
.hint--medium:after {
width: 150px; }
.hint--large:after {
width: 300px; }
/**
* source: hint-theme.scss
*
* Defines basic theme for tooltips.
*
*/
[class*="hint--"] {
/**
* tooltip body
*/ }
[class*="hint--"]:after {
text-shadow: 0 -1px 0px black;
box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3); }
/**
* source: hint-color-types.scss
*
* Contains tooltips of various types based on color differences.
*
* Classes added:
* 1) hint--error
* 2) hint--warning
* 3) hint--info
* 4) hint--success
*
*/
/**
* Error
*/
.hint--error:after {
background-color: #b34e4d;
text-shadow: 0 -1px 0px #592726; }
.hint--error.hint--top-left:before {
border-top-color: #b34e4d; }
.hint--error.hint--top-right:before {
border-top-color: #b34e4d; }
.hint--error.hint--top:before {
border-top-color: #b34e4d; }
.hint--error.hint--bottom-left:before {
border-bottom-color: #b34e4d; }
.hint--error.hint--bottom-right:before {
border-bottom-color: #b34e4d; }
.hint--error.hint--bottom:before {
border-bottom-color: #b34e4d; }
.hint--error.hint--left:before {
border-left-color: #b34e4d; }
.hint--error.hint--right:before {
border-right-color: #b34e4d; }
/**
* Warning
*/
.hint--warning:after {
background-color: #c09854;
text-shadow: 0 -1px 0px #6c5328; }
.hint--warning.hint--top-left:before {
border-top-color: #c09854; }
.hint--warning.hint--top-right:before {
border-top-color: #c09854; }
.hint--warning.hint--top:before {
border-top-color: #c09854; }
.hint--warning.hint--bottom-left:before {
border-bottom-color: #c09854; }
.hint--warning.hint--bottom-right:before {
border-bottom-color: #c09854; }
.hint--warning.hint--bottom:before {
border-bottom-color: #c09854; }
.hint--warning.hint--left:before {
border-left-color: #c09854; }
.hint--warning.hint--right:before {
border-right-color: #c09854; }
/**
* Info
*/
.hint--info:after {
background-color: #3986ac;
text-shadow: 0 -1px 0px #1a3c4d; }
.hint--info.hint--top-left:before {
border-top-color: #3986ac; }
.hint--info.hint--top-right:before {
border-top-color: #3986ac; }
.hint--info.hint--top:before {
border-top-color: #3986ac; }
.hint--info.hint--bottom-left:before {
border-bottom-color: #3986ac; }
.hint--info.hint--bottom-right:before {
border-bottom-color: #3986ac; }
.hint--info.hint--bottom:before {
border-bottom-color: #3986ac; }
.hint--info.hint--left:before {
border-left-color: #3986ac; }
.hint--info.hint--right:before {
border-right-color: #3986ac; }
/**
* Success
*/
.hint--success:after {
background-color: #458746;
text-shadow: 0 -1px 0px #1a321a; }
.hint--success.hint--top-left:before {
border-top-color: #458746; }
.hint--success.hint--top-right:before {
border-top-color: #458746; }
.hint--success.hint--top:before {
border-top-color: #458746; }
.hint--success.hint--bottom-left:before {
border-bottom-color: #458746; }
.hint--success.hint--bottom-right:before {
border-bottom-color: #458746; }
.hint--success.hint--bottom:before {
border-bottom-color: #458746; }
.hint--success.hint--left:before {
border-left-color: #458746; }
.hint--success.hint--right:before {
border-right-color: #458746; }
/**
* source: hint-always.scss
*
* Defines a persisted tooltip which shows always.
*
* Classes added:
* 1) hint--always
*
*/
.hint--always:after, .hint--always:before {
opacity: 1;
visibility: visible; }
.hint--always.hint--top:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--always.hint--top:after {
-webkit-transform: translateX(-50%) translateY(-8px);
-moz-transform: translateX(-50%) translateY(-8px);
transform: translateX(-50%) translateY(-8px); }
.hint--always.hint--top-left:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--always.hint--top-left:after {
-webkit-transform: translateX(-100%) translateY(-8px);
-moz-transform: translateX(-100%) translateY(-8px);
transform: translateX(-100%) translateY(-8px); }
.hint--always.hint--top-right:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--always.hint--top-right:after {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--always.hint--bottom:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--always.hint--bottom:after {
-webkit-transform: translateX(-50%) translateY(8px);
-moz-transform: translateX(-50%) translateY(8px);
transform: translateX(-50%) translateY(8px); }
.hint--always.hint--bottom-left:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--always.hint--bottom-left:after {
-webkit-transform: translateX(-100%) translateY(8px);
-moz-transform: translateX(-100%) translateY(8px);
transform: translateX(-100%) translateY(8px); }
.hint--always.hint--bottom-right:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--always.hint--bottom-right:after {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--always.hint--left:before {
-webkit-transform: translateX(-8px);
-moz-transform: translateX(-8px);
transform: translateX(-8px); }
.hint--always.hint--left:after {
-webkit-transform: translateX(-8px);
-moz-transform: translateX(-8px);
transform: translateX(-8px); }
.hint--always.hint--right:before {
-webkit-transform: translateX(8px);
-moz-transform: translateX(8px);
transform: translateX(8px); }
.hint--always.hint--right:after {
-webkit-transform: translateX(8px);
-moz-transform: translateX(8px);
transform: translateX(8px); }
/**
* source: hint-rounded.scss
*
* Defines rounded corner tooltips.
*
* Classes added:
* 1) hint--rounded
*
*/
.hint--rounded:after {
border-radius: 4px; }
/**
* source: hint-effects.scss
*
* Defines various transition effects for the tooltips.
*
* Classes added:
* 1) hint--no-animate
* 2) hint--bounce
*
*/
.hint--no-animate:before, .hint--no-animate:after {
-webkit-transition-duration: 0ms;
-moz-transition-duration: 0ms;
transition-duration: 0ms; }
.hint--bounce:before, .hint--bounce:after {
-webkit-transition: opacity 0.3s ease, visibility 0.3s ease, -webkit-transform 0.3s cubic-bezier(0.71, 1.7, 0.77, 1.24);
-moz-transition: opacity 0.3s ease, visibility 0.3s ease, -moz-transform 0.3s cubic-bezier(0.71, 1.7, 0.77, 1.24);
transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s cubic-bezier(0.71, 1.7, 0.77, 1.24); }

View file

@ -1,56 +1,56 @@
body {
background-color: #E8ECF0;
color: #556A7F;
background-color: #E8ECF0;
color: #556A7F;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
#container_container {
display: table;
table-layout: fixed;
margin-left: auto;
margin-right: auto;
display: table;
table-layout: fixed;
margin-left: auto;
margin-right: auto;
}
#container {
display: table-cell;
min-width: 200px;
display: table-cell;
min-width: 200px;
}
#header a {
text-decoration: none;
color: #556A7F;
text-decoration: none;
color: #556A7F;
}
#navigation {
margin-top: 4px;
margin-top: 4px;
}
#navigation a {
text-decoration: none;
border-bottom: 1px dotted #556A7F;
color: #556A7F;
text-decoration: none;
border-bottom: 1px dotted #556A7F;
color: #556A7F;
}
#navigation a:hover {
background-color: #C7D1EB;
background-color: #C7D1EB;
}
#main {
background-color: white;
background-color: white;
padding: 6px 5px 8px 5px;
padding: 6px 5px 8px 5px;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
text-align: center;
text-align: center;
}
#main a {
color: #556A7F;
color: #556A7F;
}
#normal-content {
@ -59,10 +59,7 @@ body {
#normal-code {
margin-top: 0;
}
.ninfo {
margin-bottom: 5px;
margin-bottom: 0;
}
.dinfo {
@ -70,19 +67,24 @@ body {
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
margin-bottom: 15px;
}
#info {
text-align: left;
background-color: white;
padding: 5px 5px 5px 5px;
padding: 5px;
}
#info #filename,
#editform #filename {
width: 232px;
.info-flex {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
}
.info-actions {
margin-left: 15px;
font-size: 13px;
text-align: right;
}
#info #extension,
@ -90,15 +92,6 @@ body {
width: 40px;
}
#info .float-left {
margin-top: 2px;
margin-right: 20px;
}
#info .right {
font-size: 13px;
}
#info a {
text-decoration: none;
color: #556A7F;
@ -109,89 +102,97 @@ body {
background-color: #E8ECF0;
}
#info input[type=text] {
border: 0;
color: #556A7F;
#info input[type=checkbox] {
margin: 0;
vertical-align: bottom;
}
#footer {
color: gray;
text-align: right;
margin-top: 30px;
margin-bottom: 10px;
font-size: 11px;
color: gray;
text-align: right;
margin-top: 30px;
margin-bottom: 10px;
font-size: 11px;
}
#footer a {
color: gray;
text-decoration: none;
color: gray;
text-decoration: none;
}
.normal {
text-align: left;
font-size: 13px;
text-align: left;
font-size: 13px;
}
.normal a {
text-decoration: none;
border-bottom: 1px dotted gray;
text-decoration: none;
border-bottom: 1px dotted gray;
}
.normal a:hover {
color: black;
background-color: #E8ECF0;
color: black;
background-color: #E8ECF0;
}
.normal ul {
padding-left: 15px;
padding-left: 15px;
}
.normal li {
margin-bottom: 3px;
list-style: none;
margin-bottom: 3px;
list-style: none;
}
.normal li a {
font-weight: bold;
font-weight: bold;
}
.fixed {
width: 800px;
width: 80vw;
max-width: 800px;
}
.paste {
width: 70vw;
max-width: 700px;
}
.needs-border {
border-top: 1px solid rgb(214, 214, 214);
border-top: 1px solid rgb(214, 214, 214);
}
.left {
text-align: left;
text-align: left;
}
.float-left {
float: left;
float: left;
}
.pad-left {
padding-left: 10px;
}
.pad-right {
padding-right: 10px;
padding-right: 10px;
}
.text-right {
text-align: right;
text-align: right;
}
.center {
text-align: center;
text-align: center;
}
.float-right, .right {
float: right;
float: right;
}
.clear {
clear: both;
clear: both;
}
#upload_header {
@ -245,19 +246,42 @@ body {
}
#choices {
float: left;
width: 100%;
text-align: left;
vertical-align: bottom;
margin-top: 5px;
font-size:13px;
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
margin-top: 5px;
font-size: 13px;
}
#expiry {
float: right;
padding-top: 1px;
}
#randomize {
vertical-align: bottom;
margin: 0;
}
#access_key {
min-width: 100%;
line-height: 1.3em;
}
#access_key input, span {
vertical-align: middle;
}
#access_key_checkbox {
margin: 0;
}
#access_key_input {
padding: 0;
display: none;
}
.oopscontent {
width: 400px;
}
@ -267,19 +291,49 @@ body {
border: 0;
}
.error-404 img {
max-width: 90vw;
}
.padme {
padding-left: 5px;
padding-right: 5px;
}
.editor {
width: 705px;
height: 450px;
border-color: #cccccc;
font-family: monospace;
resize: none;
overflow: auto;
width: 100%;
height: 450px;
border: 1px solid #eaeaea;
font-family: monospace;
resize: none;
overflow: auto;
border-radius: 2px;
padding: 2px;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
#info input[type=text] {
border: 1px solid #eaeaea;
color: #556A7F;
padding: 2px 4px;
font-family: Arial, Helvetica, sans-serif;
}
.storygreen {
color: #789922;
}
.storyred {
color: #800000;
}
/* Content display {{{ */
.display-audio,
.display-file {
width: 500px;
width: 100%;
}
.display-image {
@ -294,6 +348,7 @@ body {
.display-video {
width: 800px;
max-height: 70vh;
}
.scrollable {
@ -301,470 +356,23 @@ body {
}
.storycontent {
background-color: #f0e0d6;
background-color: #f0e0d6 !important;
}
#editform,
#editform .editor {
display: none;
width: 100%
}
#codeb {
white-space: pre-wrap;
}
#editor {
#inplace-editor {
display: none;
width: 794px;
width: 100%;
height: 800px;
font-size: 13px;
}
/* }}} */
/* cat.js */
.qq-uploader { position:relative; width: 100%;}
.qq-upload-button {
width: 400px;
padding-top: 60px;
height: 75px;
margin-left:auto;
margin-right:auto;
border: 2px dashed #C9C9C9;
color:#C9C9C9;
font: 14px "helvetica neue", helvetica, arial, sans-serif;
background-color: #FAFBFC;
}
.qq-upload-button-hover {
background:#EFF4F8;
}
.qq-upload-button-focus {outline:1px dotted black;}
.qq-upload-button-depr {
background-color: #8C9CBF;
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #8C9CBF), color-stop(50%, #546A9E), color-stop(50%, #36518F), color-stop(100%, #3D5691));
background-image: -webkit-linear-gradient(top, #8C9CBF 0%, #546A9E 50%, #36518F 50%, #3D5691 100%);
background-image: -moz-linear-gradient(top, #8C9CBF 0%, #546A9E 50%, #36518F 50%, #3D5691 100%);
background-image: -ms-linear-gradient(top, #8C9CBF 0%, #546A9E 50%, #36518F 50%, #3D5691 100%);
background-image: -o-linear-gradient(top, #8C9CBF 0%, #546A9E 50%, #36518F 50%, #3D5691 100%);
background-image: linear-gradient(top, #8C9CBF 0%, #546A9E 50%, #36518F 50%, #3D5691 100%);
border: 1px solid #172D6E;
border-bottom: 1px solid #0E1D45;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: inset 0 1px 0 0 #b1b9cb;
-moz-box-shadow: inset 0 1px 0 0 #b1b9cb;
box-shadow: inset 0 1px 0 0 #b1b9cb;
color: white;
font: bold 14px "helvetica neue", helvetica, arial, sans-serif;
padding: 7px 0 8px 0;
text-decoration: none;
text-align: center;
text-shadow: 0 -1px 1px #000F4D;
width: 140px;
}
.qq-upload-button2 {
display:block; /* or inline-block */
margin-left:auto;
margin-right:auto;
width: 105px; padding: 7px 0; text-align:center;
background: hsl(212, 77%, 26%); border-bottom:1px solid #ddd;color:#fff;
}
.qq-upload-drop-area {
position:absolute; top:0; left:0; width:100%; height:100%; min-height: 50px; z-index:2;
background:#2c89f0; text-align:center;
border: 2px dashed #C9C9C9;
color:white;
}
.qq-upload-drop-area span {
display:block; position:absolute; top: 50%; width:100%; margin-top:-8px; font-size:16px;
}
.qq-upload-drop-area-active {background:#093E7C;}
#toggleme{
display:none;
}
.qq-upload-list {
margin: 15px 3px 10px 3px;
font-size: 12px;
}
.qq-upload-list li {
display: block;
background-color:#E8ECF0;
padding: 8px 5px 8px 5px;
margin: 5px 0 0 0;
border: 1px solid #C9C9C9;
font-size:13px;
text-align: left;
list-style: none;
line-height: normal;
}
.qq-upload-list li a:hover {
}
.qq-upload-list li a {
}
.qq-upload-file, .qq-upload-spinner, .qq-upload-size, .qq-upload-cancel, .qq-upload-failed-text {
margin-right: 7px;
}
.qq-upload-file {}
.qq-upload-spinner {display:inline-block; width:15px; height:15px; vertical-align:text-bottom;}
.qq-upload-size,.qq-upload-cancel {font-size:11px;}
.qq-upload-failed-text {display:none;}
.qq-upload-fail .qq-upload-failed-text {display:inline;}
/*
Uploadify v2.1.4
Release Date: November 8, 2010
Copyright (c) 2010 Ronnie Garcia, Travis Nickels
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
.uploadifyQueueItem {
background-color: #F5F5F5;
border: 2px solid #E5E5E5;
font: 11px Verdana, Geneva, sans-serif;
margin-top: 5px;
padding: 10px;
width: 350px;
}
.uploadifyError {
background-color: #FDE5DD !important;
border: 2px solid #FBCBBC !important;
}
.uploadifyQueueItem .cancel {
float: right;
}
.uploadifyQueue .completed {
background-color: #E5E5E5;
}
.uploadifyProgress {
background-color: #E5E5E5;
margin-top: 10px;
width: 100%;
}
.uploadifyProgressBar {
background-color: #0099FF;
height: 3px;
width: 1px;
}
/*! Hint.css - v1.3.1 - 2013-11-23
* http://kushagragour.in/lab/hint/
* Copyright (c) 2013 Kushagra Gour; Licensed MIT */
/*-------------------------------------*\
HINT.css - A CSS tooltip library
\*-------------------------------------*/
/**
* HINT.css is a tooltip library made in pure CSS.
*
* Source: https://github.com/chinchang/hint.css
* Demo: http://kushagragour.in/lab/hint/
*
* Release under The MIT License
*
*/
/**
* source: hint-core.scss
*
* Defines the basic styling for the tooltip.
* Each tooltip is made of 2 parts:
* 1) body (:after)
* 2) arrow (:before)
*
* Classes added:
* 1) hint
*/
.hint, [data-hint] {
position: relative;
display: inline-block;
/**
* tooltip arrow
*/
/**
* tooltip body
*/ }
.hint:before, .hint:after, [data-hint]:before, [data-hint]:after {
position: absolute;
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
visibility: hidden;
opacity: 0;
z-index: 1000000;
pointer-events: none;
-webkit-transition: 0.3s ease;
-moz-transition: 0.3s ease;
transition: 0.3s ease; }
.hint:hover:before, .hint:hover:after, .hint:focus:before, .hint:focus:after, [data-hint]:hover:before, [data-hint]:hover:after, [data-hint]:focus:before, [data-hint]:focus:after {
visibility: visible;
opacity: 1; }
.hint:before, [data-hint]:before {
content: '';
position: absolute;
background: transparent;
border: 6px solid transparent;
z-index: 1000001; }
.hint:after, [data-hint]:after {
content: attr(data-hint);
background: #556A7F;
color: white;
text-shadow: 0 -1px 0px black;
padding: 8px 10px;
font-size: 12px;
line-height: 12px;
white-space: nowrap;
box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3); }
/**
* source: hint-position.scss
*
* Defines the positoning logic for the tooltips.
*
* Classes added:
* 1) hint--top
* 2) hint--bottom
* 3) hint--left
* 4) hint--right
*/
/**
* set default color for tooltip arrows
*/
.hint--top:before {
border-top-color: #556A7F; }
.hint--bottom:before {
border-bottom-color: #556A7F; }
.hint--left:before {
border-left-color: #556A7F; }
.hint--right:before {
border-right-color: #556A7F; }
/**
* top tooltip
*/
.hint--top:before {
margin-bottom: -12px; }
.hint--top:after {
margin-left: -18px; }
.hint--top:before, .hint--top:after {
bottom: 100%;
left: 50%; }
.hint--top:hover:after, .hint--top:hover:before, .hint--top:focus:after, .hint--top:focus:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
/**
* bottom tooltip
*/
.hint--bottom:before {
margin-top: -12px; }
.hint--bottom:after {
margin-left: -18px; }
.hint--bottom:before, .hint--bottom:after {
top: 100%;
left: 50%; }
.hint--bottom:hover:after, .hint--bottom:hover:before, .hint--bottom:focus:after, .hint--bottom:focus:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
/**
* right tooltip
*/
.hint--right:before {
margin-left: -12px;
margin-bottom: -6px; }
.hint--right:after {
margin-bottom: -14px; }
.hint--right:before, .hint--right:after {
left: 100%;
bottom: 50%; }
.hint--right:hover:after, .hint--right:hover:before, .hint--right:focus:after, .hint--right:focus:before {
-webkit-transform: translateX(8px);
-moz-transform: translateX(8px);
transform: translateX(8px); }
/**
* left tooltip
*/
.hint--left:before {
margin-right: -12px;
margin-bottom: -6px; }
.hint--left:after {
margin-bottom: -14px; }
.hint--left:before, .hint--left:after {
right: 100%;
bottom: 50%; }
.hint--left:hover:after, .hint--left:hover:before, .hint--left:focus:after, .hint--left:focus:before {
-webkit-transform: translateX(-8px);
-moz-transform: translateX(-8px);
transform: translateX(-8px); }
/**
* source: hint-color-types.scss
*
* Contains tooltips of various types based on color differences.
*
* Classes added:
* 1) hint--error
* 2) hint--warning
* 3) hint--info
* 4) hint--success
*
*/
/**
* Error
*/
.hint--error:after {
background-color: #b34e4d;
text-shadow: 0 -1px 0px #592726; }
.hint--error.hint--top:before {
border-top-color: #b34e4d; }
.hint--error.hint--bottom:before {
border-bottom-color: #b34e4d; }
.hint--error.hint--left:before {
border-left-color: #b34e4d; }
.hint--error.hint--right:before {
border-right-color: #b34e4d; }
/**
* Warning
*/
.hint--warning:after {
background-color: #c09854;
text-shadow: 0 -1px 0px #6c5328; }
.hint--warning.hint--top:before {
border-top-color: #c09854; }
.hint--warning.hint--bottom:before {
border-bottom-color: #c09854; }
.hint--warning.hint--left:before {
border-left-color: #c09854; }
.hint--warning.hint--right:before {
border-right-color: #c09854; }
/**
* Info
*/
.hint--info:after {
background-color: #3986ac;
text-shadow: 0 -1px 0px #193b4d; }
.hint--info.hint--top:before {
border-top-color: #3986ac; }
.hint--info.hint--bottom:before {
border-bottom-color: #3986ac; }
.hint--info.hint--left:before {
border-left-color: #3986ac; }
.hint--info.hint--right:before {
border-right-color: #3986ac; }
/**
* Success
*/
.hint--success:after {
background-color: #458746;
text-shadow: 0 -1px 0px #1a321a; }
.hint--success.hint--top:before {
border-top-color: #458746; }
.hint--success.hint--bottom:before {
border-bottom-color: #458746; }
.hint--success.hint--left:before {
border-left-color: #458746; }
.hint--success.hint--right:before {
border-right-color: #458746; }
/**
* source: hint-always.scss
*
* Defines a persisted tooltip which shows always.
*
* Classes added:
* 1) hint--always
*
*/
.hint--always:after, .hint--always:before {
opacity: 1;
visibility: visible; }
.hint--always.hint--top:after, .hint--always.hint--top:before {
-webkit-transform: translateY(-8px);
-moz-transform: translateY(-8px);
transform: translateY(-8px); }
.hint--always.hint--bottom:after, .hint--always.hint--bottom:before {
-webkit-transform: translateY(8px);
-moz-transform: translateY(8px);
transform: translateY(8px); }
.hint--always.hint--left:after, .hint--always.hint--left:before {
-webkit-transform: translateX(-8px);
-moz-transform: translateX(-8px);
transform: translateX(-8px); }
.hint--always.hint--right:after, .hint--always.hint--right:before {
-webkit-transform: translateX(8px);
-moz-transform: translateX(8px);
transform: translateX(8px); }
/**
* source: hint-rounded.scss
*
* Defines rounded corner tooltips.
*
* Classes added:
* 1) hint--rounded
*
*/
.hint--rounded:after {
border-radius: 4px; }
/**
* source: hint-effects.scss
*
* Defines various transition effects for the tooltips.
*
* Classes added:
* 1) hint--bounce
*
*/
.hint--bounce:before, .hint--bounce:after {
-webkit-transition: opacity 0.3s ease, visibility 0.3s ease, -webkit-transform 0.3s cubic-bezier(0.71, 1.7, 0.77, 1.24);
-moz-transition: opacity 0.3s ease, visibility 0.3s ease, -moz-transform 0.3s cubic-bezier(0.71, 1.7, 0.77, 1.24);
transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s cubic-bezier(0.71, 1.7, 0.77, 1.24); }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View file

@ -1,59 +1,58 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
var navlist = document.getElementById("info").getElementsByClassName("right")[0];
init();
function init() {
var editA = document.createElement('a');
editA.setAttribute("href", "#");
editA.addEventListener('click', function(ev) {
edit(ev);
return false;
});
editA.innerHTML = "edit";
var separator = document.createTextNode(" | ");
navlist.insertBefore(editA, navlist.firstChild);
navlist.insertBefore(separator, navlist.children[1]);
document.getElementById('save').addEventListener('click', paste);
document.getElementById('wordwrap').addEventListener('click', wrap);
}
function edit(ev) {
navlist.remove();
document.getElementById("filename").remove();
document.getElementById("editform").style.display = "block";
var normalcontent = document.getElementById("normal-content");
normalcontent.removeChild(document.getElementById("normal-code"));
var editordiv = document.getElementById("editor");
editordiv.style.display = "block";
}
function paste(ev) {
var editordiv = document.getElementById("editor");
document.getElementById("newcontent").value = editordiv.value;
document.forms["reply"].submit();
}
function wrap(ev) {
if (document.getElementById("wordwrap").checked) {
document.getElementById("codeb").style.wordWrap = "break-word";
document.getElementById("codeb").style.whiteSpace = "pre-wrap";
}
else {
document.getElementById("codeb").style.wordWrap = "normal";
document.getElementById("codeb").style.whiteSpace = "pre";
}
}
// @license-end
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
var navlist = document.getElementById("info").getElementsByClassName("info-actions")[0];
init();
function init() {
var editA = document.createElement('a');
editA.setAttribute("href", "#");
editA.addEventListener('click', function(ev) {
edit(ev);
return false;
});
editA.innerHTML = "edit";
var separator = document.createTextNode(" | ");
navlist.insertBefore(editA, navlist.firstChild);
navlist.insertBefore(separator, navlist.children[1]);
document.getElementById('save').addEventListener('click', paste);
document.getElementById('wordwrap').addEventListener('click', wrap);
}
function edit(ev) {
ev.preventDefault();
navlist.remove();
document.getElementById("filename").remove();
document.getElementById("editform").style.display = "block";
var normalcontent = document.getElementById("normal-content");
normalcontent.removeChild(document.getElementById("normal-code"));
var editordiv = document.getElementById("inplace-editor");
editordiv.style.display = "block";
editordiv.addEventListener('keydown', handleTab);
}
function paste(ev) {
var editordiv = document.getElementById("inplace-editor");
document.getElementById("newcontent").value = editordiv.value;
document.forms["reply"].submit();
}
function wrap(ev) {
if (document.getElementById("wordwrap").checked) {
document.getElementById("codeb").style.wordWrap = "break-word";
document.getElementById("codeb").style.whiteSpace = "pre-wrap";
}
else {
document.getElementById("codeb").style.wordWrap = "normal";
document.getElementById("codeb").style.whiteSpace = "pre";
}
}
// @license-end

View file

@ -3,4 +3,16 @@
hljs.tabReplace = ' ';
hljs.initHighlightingOnLoad();
var codeb = document.getElementById("codeb");
var lines = codeb.innerHTML.split("\n");
codeb.innerHTML = "";
for (var i = 0; i < lines.length; i++) {
var div = document.createElement("div");
div.innerHTML = lines[i] + "\n";
codeb.appendChild(div);
};
var ncode = document.getElementById("normal-code");
ncode.className = "linenumbers";
// @license-end

740
static/js/clipboard.js Normal file
View file

@ -0,0 +1,740 @@
/*!
* clipboard.js v1.5.10
* https://zenorocha.github.io/clipboard.js
*
* Licensed MIT © Zeno Rocha
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var matches = require('matches-selector')
module.exports = function (element, selector, checkYoSelf) {
var parent = checkYoSelf ? element : element.parentNode
while (parent && parent !== document) {
if (matches(parent, selector)) return parent;
parent = parent.parentNode
}
}
},{"matches-selector":5}],2:[function(require,module,exports){
var closest = require('closest');
/**
* Delegates event to a selector.
*
* @param {Element} element
* @param {String} selector
* @param {String} type
* @param {Function} callback
* @param {Boolean} useCapture
* @return {Object}
*/
function delegate(element, selector, type, callback, useCapture) {
var listenerFn = listener.apply(this, arguments);
element.addEventListener(type, listenerFn, useCapture);
return {
destroy: function() {
element.removeEventListener(type, listenerFn, useCapture);
}
}
}
/**
* Finds closest match and invokes callback.
*
* @param {Element} element
* @param {String} selector
* @param {String} type
* @param {Function} callback
* @return {Function}
*/
function listener(element, selector, type, callback) {
return function(e) {
e.delegateTarget = closest(e.target, selector, true);
if (e.delegateTarget) {
callback.call(element, e);
}
}
}
module.exports = delegate;
},{"closest":1}],3:[function(require,module,exports){
/**
* Check if argument is a HTML element.
*
* @param {Object} value
* @return {Boolean}
*/
exports.node = function(value) {
return value !== undefined
&& value instanceof HTMLElement
&& value.nodeType === 1;
};
/**
* Check if argument is a list of HTML elements.
*
* @param {Object} value
* @return {Boolean}
*/
exports.nodeList = function(value) {
var type = Object.prototype.toString.call(value);
return value !== undefined
&& (type === '[object NodeList]' || type === '[object HTMLCollection]')
&& ('length' in value)
&& (value.length === 0 || exports.node(value[0]));
};
/**
* Check if argument is a string.
*
* @param {Object} value
* @return {Boolean}
*/
exports.string = function(value) {
return typeof value === 'string'
|| value instanceof String;
};
/**
* Check if argument is a function.
*
* @param {Object} value
* @return {Boolean}
*/
exports.fn = function(value) {
var type = Object.prototype.toString.call(value);
return type === '[object Function]';
};
},{}],4:[function(require,module,exports){
var is = require('./is');
var delegate = require('delegate');
/**
* Validates all params and calls the right
* listener function based on its target type.
*
* @param {String|HTMLElement|HTMLCollection|NodeList} target
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listen(target, type, callback) {
if (!target && !type && !callback) {
throw new Error('Missing required arguments');
}
if (!is.string(type)) {
throw new TypeError('Second argument must be a String');
}
if (!is.fn(callback)) {
throw new TypeError('Third argument must be a Function');
}
if (is.node(target)) {
return listenNode(target, type, callback);
}
else if (is.nodeList(target)) {
return listenNodeList(target, type, callback);
}
else if (is.string(target)) {
return listenSelector(target, type, callback);
}
else {
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
}
}
/**
* Adds an event listener to a HTML element
* and returns a remove listener function.
*
* @param {HTMLElement} node
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listenNode(node, type, callback) {
node.addEventListener(type, callback);
return {
destroy: function() {
node.removeEventListener(type, callback);
}
}
}
/**
* Add an event listener to a list of HTML elements
* and returns a remove listener function.
*
* @param {NodeList|HTMLCollection} nodeList
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listenNodeList(nodeList, type, callback) {
Array.prototype.forEach.call(nodeList, function(node) {
node.addEventListener(type, callback);
});
return {
destroy: function() {
Array.prototype.forEach.call(nodeList, function(node) {
node.removeEventListener(type, callback);
});
}
}
}
/**
* Add an event listener to a selector
* and returns a remove listener function.
*
* @param {String} selector
* @param {String} type
* @param {Function} callback
* @return {Object}
*/
function listenSelector(selector, type, callback) {
return delegate(document.body, selector, type, callback);
}
module.exports = listen;
},{"./is":3,"delegate":2}],5:[function(require,module,exports){
/**
* Element prototype.
*/
var proto = Element.prototype;
/**
* Vendor function.
*/
var vendor = proto.matchesSelector
|| proto.webkitMatchesSelector
|| proto.mozMatchesSelector
|| proto.msMatchesSelector
|| proto.oMatchesSelector;
/**
* Expose `match()`.
*/
module.exports = match;
/**
* Match `el` to `selector`.
*
* @param {Element} el
* @param {String} selector
* @return {Boolean}
* @api public
*/
function match(el, selector) {
if (vendor) return vendor.call(el, selector);
var nodes = el.parentNode.querySelectorAll(selector);
for (var i = 0; i < nodes.length; ++i) {
if (nodes[i] == el) return true;
}
return false;
}
},{}],6:[function(require,module,exports){
function select(element) {
var selectedText;
if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
element.focus();
element.setSelectionRange(0, element.value.length);
selectedText = element.value;
}
else {
if (element.hasAttribute('contenteditable')) {
element.focus();
}
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
selectedText = selection.toString();
}
return selectedText;
}
module.exports = select;
},{}],7:[function(require,module,exports){
function E () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx
});
return this;
},
once: function (name, callback, ctx) {
var self = this;
function listener () {
self.off(name, listener);
callback.apply(ctx, arguments);
};
listener._ = callback
return this.on(name, listener, ctx);
},
emit: function (name) {
var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
off: function (name, callback) {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
(liveEvents.length)
? e[name] = liveEvents
: delete e[name];
return this;
}
};
module.exports = E;
},{}],8:[function(require,module,exports){
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', 'select'], factory);
} else if (typeof exports !== "undefined") {
factory(module, require('select'));
} else {
var mod = {
exports: {}
};
factory(mod, global.select);
global.clipboardAction = mod.exports;
}
})(this, function (module, _select) {
'use strict';
var _select2 = _interopRequireDefault(_select);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var ClipboardAction = function () {
/**
* @param {Object} options
*/
function ClipboardAction(options) {
_classCallCheck(this, ClipboardAction);
this.resolveOptions(options);
this.initSelection();
}
/**
* Defines base properties passed from constructor.
* @param {Object} options
*/
ClipboardAction.prototype.resolveOptions = function resolveOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = options.action;
this.emitter = options.emitter;
this.target = options.target;
this.text = options.text;
this.trigger = options.trigger;
this.selectedText = '';
};
ClipboardAction.prototype.initSelection = function initSelection() {
if (this.text) {
this.selectFake();
} else if (this.target) {
this.selectTarget();
}
};
ClipboardAction.prototype.selectFake = function selectFake() {
var _this = this;
var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
this.removeFake();
this.fakeHandler = document.body.addEventListener('click', function () {
return _this.removeFake();
});
this.fakeElem = document.createElement('textarea');
// Prevent zooming on iOS
this.fakeElem.style.fontSize = '12pt';
// Reset box model
this.fakeElem.style.border = '0';
this.fakeElem.style.padding = '0';
this.fakeElem.style.margin = '0';
// Move element out of screen horizontally
this.fakeElem.style.position = 'fixed';
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
// Move element to the same position vertically
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
this.fakeElem.setAttribute('readonly', '');
this.fakeElem.value = this.text;
document.body.appendChild(this.fakeElem);
this.selectedText = (0, _select2.default)(this.fakeElem);
this.copyText();
};
ClipboardAction.prototype.removeFake = function removeFake() {
if (this.fakeHandler) {
document.body.removeEventListener('click');
this.fakeHandler = null;
}
if (this.fakeElem) {
document.body.removeChild(this.fakeElem);
this.fakeElem = null;
}
};
ClipboardAction.prototype.selectTarget = function selectTarget() {
this.selectedText = (0, _select2.default)(this.target);
this.copyText();
};
ClipboardAction.prototype.copyText = function copyText() {
var succeeded = undefined;
try {
succeeded = document.execCommand(this.action);
} catch (err) {
succeeded = false;
}
this.handleResult(succeeded);
};
ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
if (succeeded) {
this.emitter.emit('success', {
action: this.action,
text: this.selectedText,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
} else {
this.emitter.emit('error', {
action: this.action,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
}
};
ClipboardAction.prototype.clearSelection = function clearSelection() {
if (this.target) {
this.target.blur();
}
window.getSelection().removeAllRanges();
};
ClipboardAction.prototype.destroy = function destroy() {
this.removeFake();
};
_createClass(ClipboardAction, [{
key: 'action',
set: function set() {
var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
this._action = action;
if (this._action !== 'copy' && this._action !== 'cut') {
throw new Error('Invalid "action" value, use either "copy" or "cut"');
}
},
get: function get() {
return this._action;
}
}, {
key: 'target',
set: function set(target) {
if (target !== undefined) {
if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
if (this.action === 'copy' && target.hasAttribute('disabled')) {
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
}
if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
}
this._target = target;
} else {
throw new Error('Invalid "target" value, use a valid Element');
}
}
},
get: function get() {
return this._target;
}
}]);
return ClipboardAction;
}();
module.exports = ClipboardAction;
});
},{"select":6}],9:[function(require,module,exports){
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
} else if (typeof exports !== "undefined") {
factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
} else {
var mod = {
exports: {}
};
factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
global.clipboard = mod.exports;
}
})(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
'use strict';
var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
var _goodListener2 = _interopRequireDefault(_goodListener);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}
var Clipboard = function (_Emitter) {
_inherits(Clipboard, _Emitter);
/**
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
* @param {Object} options
*/
function Clipboard(trigger, options) {
_classCallCheck(this, Clipboard);
var _this = _possibleConstructorReturn(this, _Emitter.call(this));
_this.resolveOptions(options);
_this.listenClick(trigger);
return _this;
}
/**
* Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor.
* @param {Object} options
*/
Clipboard.prototype.resolveOptions = function resolveOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
};
Clipboard.prototype.listenClick = function listenClick(trigger) {
var _this2 = this;
this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
return _this2.onClick(e);
});
};
Clipboard.prototype.onClick = function onClick(e) {
var trigger = e.delegateTarget || e.currentTarget;
if (this.clipboardAction) {
this.clipboardAction = null;
}
this.clipboardAction = new _clipboardAction2.default({
action: this.action(trigger),
target: this.target(trigger),
text: this.text(trigger),
trigger: trigger,
emitter: this
});
};
Clipboard.prototype.defaultAction = function defaultAction(trigger) {
return getAttributeValue('action', trigger);
};
Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
var selector = getAttributeValue('target', trigger);
if (selector) {
return document.querySelector(selector);
}
};
Clipboard.prototype.defaultText = function defaultText(trigger) {
return getAttributeValue('text', trigger);
};
Clipboard.prototype.destroy = function destroy() {
this.listener.destroy();
if (this.clipboardAction) {
this.clipboardAction.destroy();
this.clipboardAction = null;
}
};
return Clipboard;
}(_tinyEmitter2.default);
/**
* Helper function to retrieve attribute value.
* @param {String} suffix
* @param {Element} element
*/
function getAttributeValue(suffix, element) {
var attribute = 'data-clipboard-' + suffix;
if (!element.hasAttribute(attribute)) {
return;
}
return element.getAttribute(attribute);
}
module.exports = Clipboard;
});
},{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9)
});

File diff suppressed because one or more lines are too long

3
static/js/paste.js Normal file
View file

@ -0,0 +1,3 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
document.getElementById('content').addEventListener('keydown', handleTab);
// @license-end

View file

@ -1,49 +1,71 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
Dropzone.options.dropzone = {
init: function() {
},
addedfile: function(file) {
var upload = document.createElement("div");
upload.className = "upload";
init: function () {
var dzone = document.getElementById("dzone");
dzone.style.display = "block";
},
addedfile: function (file) {
if (!this.options.autoProcessQueue) {
var dropzone = this;
var xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.readyState !== XMLHttpRequest.DONE) {
return;
}
if (xhr.status < 400) {
dropzone.processQueue()
dropzone.options.autoProcessQueue = true;
} else {
dropzone.cancelUpload(file)
}
};
xhr.open("HEAD", "auth", true);
xhr.send()
}
var upload = document.createElement("div");
upload.className = "upload";
var fileLabel = document.createElement("span");
fileLabel.innerHTML = file.name;
file.fileLabel = fileLabel;
upload.appendChild(fileLabel);
var fileLabel = document.createElement("span");
fileLabel.innerHTML = file.name;
file.fileLabel = fileLabel;
upload.appendChild(fileLabel);
var fileActions = document.createElement("div");
fileActions.className = "right";
file.fileActions = fileActions;
upload.appendChild(fileActions);
var fileActions = document.createElement("div");
fileActions.className = "right";
file.fileActions = fileActions;
upload.appendChild(fileActions);
var cancelAction = document.createElement("span");
cancelAction.className = "cancel";
cancelAction.innerHTML = "Cancel";
cancelAction.addEventListener('click', function(ev) {
this.removeFile(file);
}.bind(this));
file.cancelActionElement = cancelAction;
fileActions.appendChild(cancelAction);
var cancelAction = document.createElement("span");
cancelAction.className = "cancel";
cancelAction.innerHTML = "Cancel";
cancelAction.addEventListener('click', function (ev) {
this.removeFile(file);
}.bind(this));
file.cancelActionElement = cancelAction;
fileActions.appendChild(cancelAction);
var progress = document.createElement("span");
file.progressElement = progress;
fileActions.appendChild(progress);
var progress = document.createElement("span");
file.progressElement = progress;
fileActions.appendChild(progress);
file.uploadElement = upload;
file.uploadElement = upload;
document.getElementById("uploads").appendChild(upload);
},
uploadprogress: function(file, p, bytesSent) {
p = parseInt(p);
file.progressElement.innerHTML = p + "%";
file.uploadElement.setAttribute("style", 'background-image: -webkit-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -moz-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -ms-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -o-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%)');
},
sending: function(file, xhr, formData) {
formData.append("randomize", document.getElementById("randomize").checked);
formData.append("expires", document.getElementById("expires").selectedOptions[0].value);
},
success: function(file, resp) {
document.getElementById("uploads").appendChild(upload);
},
uploadprogress: function (file, p, bytesSent) {
p = parseInt(p);
file.progressElement.innerHTML = p + "%";
file.uploadElement.setAttribute("style", 'background-image: -webkit-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -moz-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -ms-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: -o-linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%); background-image: linear-gradient(left, #F2F4F7 ' + p + '%, #E2E2E2 ' + p + '%)');
},
sending: function (file, xhr, formData) {
var randomize = document.getElementById("randomize");
if (randomize != null) {
formData.append("randomize", randomize.checked);
}
formData.append("expires", document.getElementById("expires").value);
},
success: function (file, resp) {
file.fileActions.removeChild(file.progressElement);
var fileLabelLink = document.createElement("a");
@ -57,43 +79,76 @@ Dropzone.options.dropzone = {
var deleteAction = document.createElement("span");
deleteAction.innerHTML = "Delete";
deleteAction.className = "cancel";
deleteAction.addEventListener('click', function(ev) {
xhr = new XMLHttpRequest();
xhr.open("DELETE", resp.url, true);
xhr.setRequestHeader("Linx-Delete-Key", resp.delete_key);
xhr.onreadystatechange = function(file) {
if (xhr.readyState == 4 && xhr.status === 200) {
var text = document.createTextNode("Deleted ");
file.fileLabel.insertBefore(text, file.fileLabelLink);
file.fileLabel.className = "deleted";
file.fileActions.removeChild(file.cancelActionElement);
}
}.bind(this, file);
xhr.send();
});
file.fileActions.removeChild(file.cancelActionElement);
file.cancelActionElement = deleteAction;
file.fileActions.appendChild(deleteAction);
},
error: function(file, resp, xhrO) {
deleteAction.addEventListener('click', function (ev) {
xhr = new XMLHttpRequest();
xhr.open("DELETE", resp.url, true);
xhr.setRequestHeader("Linx-Delete-Key", resp.delete_key);
xhr.onreadystatechange = function (file) {
if (xhr.readyState == 4 && xhr.status === 200) {
var text = document.createTextNode("Deleted ");
file.fileLabel.insertBefore(text, file.fileLabelLink);
file.fileLabel.className = "deleted";
file.fileActions.removeChild(file.cancelActionElement);
}
}.bind(this, file);
xhr.send();
});
file.fileActions.removeChild(file.cancelActionElement);
file.cancelActionElement = deleteAction;
file.fileActions.appendChild(deleteAction);
},
canceled: function (file) {
this.options.error(file);
},
error: function (file, resp, xhrO) {
file.fileActions.removeChild(file.cancelActionElement);
file.fileActions.removeChild(file.progressElement);
if (file.status === "canceled") {
file.fileLabel.innerHTML = file.name + ": Canceled ";
}
else {
file.fileLabel.innerHTML = file.name + ": " + resp.error;
}
file.fileLabel.className = "error";
},
if (file.status === "canceled") {
file.fileLabel.innerHTML = file.name + ": Canceled ";
}
else {
if (resp.error) {
file.fileLabel.innerHTML = file.name + ": " + resp.error;
}
else if (resp.includes("<html")) {
file.fileLabel.innerHTML = file.name + ": Server Error";
}
else {
file.fileLabel.innerHTML = file.name + ": " + resp;
}
}
file.fileLabel.className = "error";
},
maxFilesize: 4096,
previewsContainer: "#uploads",
parallelUploads: 5,
headers: {"Accept": "application/json"},
dictDefaultMessage: "Click or Drop file(s)",
dictFallbackMessage: ""
autoProcessQueue: document.getElementById("dropzone").getAttribute("data-auth") !== "basic",
maxFilesize: Math.round(parseInt(document.getElementById("dropzone").getAttribute("data-maxsize"), 10) / 1024 / 1024),
previewsContainer: "#uploads",
parallelUploads: 5,
headers: { "Accept": "application/json" },
dictDefaultMessage: "Click or Drop file(s) or Paste image",
dictFallbackMessage: ""
};
document.onpaste = function (event) {
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) {
var item = items[index];
if (item.kind === "file") {
Dropzone.forElement("#dropzone").addFile(item.getAsFile());
}
}
};
document.getElementById("access_key_checkbox").onchange = function (event) {
if (event.target.checked) {
document.getElementById("access_key_input").style.display = "inline-block";
document.getElementById("access_key_text").style.display = "none";
} else {
document.getElementById("access_key_input").value = "";
document.getElementById("access_key_input").style.display = "none";
document.getElementById("access_key_text").style.display = "inline-block";
}
};
// @end-license

18
static/js/util.js Normal file
View file

@ -0,0 +1,18 @@
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
function handleTab(ev) {
// change tab key behavior to insert tab instead of change focus
if(ev.keyCode == 9) {
ev.preventDefault();
var val = this.value;
var start = this.selectionStart;
var end = this.selectionEnd;
this.value = val.substring(0, start) + '\t' + val.substring(end);
this.selectionStart = start + 1;
this.selectionEnd = end + 1;
}
}
// @license-end

View file

@ -3,10 +3,12 @@ package main
import (
"bytes"
"io"
"net/http"
"path"
"path/filepath"
"strings"
"github.com/GeertJohan/go.rice"
rice "github.com/GeertJohan/go.rice"
"github.com/flosch/pongo2"
)
@ -44,15 +46,20 @@ func populateTemplatesMap(tSet *pongo2.TemplateSet, tMap map[string]*pongo2.Temp
templates := []string{
"index.html",
"paste.html",
"404.html",
"API.html",
"400.html",
"401.html",
"404.html",
"oops.html",
"access.html",
"custom_page.html",
"display/audio.html",
"display/image.html",
"display/video.html",
"display/pdf.html",
"display/bin.html",
"display/story.html",
"display/md.html",
"display/file.html",
}
@ -68,3 +75,28 @@ func populateTemplatesMap(tSet *pongo2.TemplateSet, tMap map[string]*pongo2.Temp
return nil
}
func renderTemplate(tpl *pongo2.Template, context pongo2.Context, r *http.Request, writer io.Writer) error {
if Config.siteName == "" {
parts := strings.Split(r.Host, ":")
context["sitename"] = parts[0]
} else {
context["sitename"] = Config.siteName
}
context["sitepath"] = Config.sitePath
context["selifpath"] = Config.selifPath
context["custom_pages_names"] = customPagesNames
var a string
if Config.authFile == "" {
a = "none"
} else if Config.basicAuth {
a = "basic"
} else {
a = "header"
}
context["auth"] = a
return tpl.ExecuteWriter(context, writer)
}

7
templates/400.html Normal file
View file

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block content %}
<div id="main">
400 Bad Request
</div>
{% endblock %}

View file

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% block content %}
401 Unauthorized
<div id="main">
401 Unauthorized
</div>
{% endblock %}

View file

@ -1,5 +1,9 @@
{% extends "base.html" %}
{% block title %}{{sitename}} - 404 Not Found{% endblock %}
{% block content %}
<a href="/"><img src='/static/images/404.jpg'></a>
{% endblock %}
<div class="error-404">
<a href="{{ sitepath }}"><img src='{{ sitepath }}static/images/404.jpg'></a>
</div>
{% endblock %}

154
templates/API.html Normal file
View file

@ -0,0 +1,154 @@
{% extends "base.html" %}
{% block title %}{{sitename}} - API{% endblock %}
{% block head %}
<link href="{{ sitepath }}static/css/github-markdown.css" rel="stylesheet" type="text/css">
{% endblock %}
{% block content %}
<div id="main">
<div id='inner_content'>
<div class="normal markdown-body">
<h2>API</h2>
<h3>Client</h3>
<p>To simplify uploading and deleting files, you can use <a target="_blank"
href="https://github.com/andreimarcu/linx-client">linx-client</a>, which uses this API.</p>
{% if auth != "none" %}
<h3>Keys</h3>
<p>This instance uses API Keys, therefore you will need to provide a key for uploading and deleting
files.<br /> To do so, add the <code>Linx-Api-Key</code> header with your key.</p>
{% endif %}
<h3>Uploading a file</h3>
<p>To upload a file, make a PUT request to <code>{{ siteurl }}upload/</code> and you will get the url of
your upload back.</p>
<p><strong>Optional headers with the request</strong></p>
{% if not forcerandom %}
<p>Randomize the filename<br />
<code>Linx-Randomize: yes</code></p>
{% endif %}
<p>Specify a custom deletion key<br />
<code>Linx-Delete-Key: mysecret</code></p>
<p>Protect file with password<br />
<code>Linx-Access-Key: mysecret</code></p>
<p>Specify an expiration time (in seconds)<br />
<code>Linx-Expiry: 60</code></p>
<p>Get a json response<br />
<code>Accept: application/json</code></p>
<p>The json response will then contain:</p>
<blockquote>
<p>“url”: the publicly available upload url<br />
“direct_url”: the url to access the file directly<br />
“filename”: the (optionally generated) filename<br />
“delete_key”: the (optionally generated) deletion key,<br />
“access_key”: the (optionally supplied) access key,<br />
“expiry”: the unix timestamp at which the file will expire (0 if never)<br />
“size”: the size in bytes of the file<br />
“mimetype”: the guessed mimetype of the file<br />
“sha256sum”: the sha256sum of the file,</p>
</blockquote>
<p><strong>Examples</strong></p>
<p>Uploading myphoto.jpg</p>
{% if auth != "none" %}
<pre><code>$ curl -H &#34;Linx-Api-Key: mysecretkey&#34; -T myphoto.jpg {{ siteurl }}upload/
{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}7z4h4ut.jpg{% endif %}</code></pre>
{% else %}
<pre><code>$ curl -T myphoto.jpg {{ siteurl }}upload/
{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}wtq7pan.jpg{% endif %}</code></pre>
{% endif %}
<p>Uploading myphoto.jpg with an expiry of 20 minutes</p>
{% if auth != "none" %}
<pre><code>$ curl -H &#34;Linx-Api-Key: mysecretkey&#34; -H &#34;Linx-Expiry: 1200&#34; -T myphoto.jpg {{ siteurl }}upload/
{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}jm295snf.jpg{% endif %}</code></pre>
{% else %}
<pre><code>$ curl -H &#34;Linx-Expiry: 1200&#34; -T myphoto.jpg {{ siteurl }}upload/
{{ siteurl }}{% if not forcerandom %}myphoto.jpg{% else %}1doym9u2.jpg{% endif %}</code></pre>
{% endif %}
<p>Uploading myphoto.jpg with a random filename and getting a json response:</p>
{% if auth != "none" %}
<pre><code>$ curl -H &#34;Linx-Api-Key: mysecretkey&#34; -H &#34;Accept: application/json&#34;{% if not forcerandom %} -H &#34;Linx-Randomize: yes&#34;{% endif %} -T myphoto.jpg {{ siteurl }}upload/
{&#34;delete_key&#34;:&#34;...&#34;,&#34;expiry&#34;:&#34;0&#34;,&#34;filename&#34;:&#34;f34h4iu.jpg&#34;,&#34;mimetype&#34;:&#34;image/jpeg&#34;,
&#34;sha256sum&#34;:&#34;...&#34;,&#34;size&#34;:&#34;...&#34;,&#34;url&#34;:&#34;{{ siteurl }}f34h4iu.jpg&#34;}</code></pre>
{% else %}
<pre><code>$ curl -H &#34;Accept: application/json&#34;{% if not forcerandom %} -H &#34;Linx-Randomize: yes&#34;{% endif %} -T myphoto.jpg {{ siteurl }}upload/
{&#34;delete_key&#34;:&#34;...&#34;,&#34;expiry&#34;:&#34;0&#34;,&#34;filename&#34;:&#34;f34h4iu.jpg&#34;,&#34;mimetype&#34;:&#34;image/jpeg&#34;,
&#34;sha256sum&#34;:&#34;...&#34;,&#34;size&#34;:&#34;...&#34;,&#34;url&#34;:&#34;{{ siteurl }}f34h4iu.jpg&#34;}</code></pre>
{% endif %}
<h3>Overwriting a file</h3>
<p>To overwrite a file you uploaded, simply provide the <code>Linx-Delete-Key</code> header with the
original file's deletion key.</p>
<p><strong>Example</p></strong>
<p>To overwrite myphoto.jpg</p>
{% if auth != "none" %}
<pre><code>$ curl -H &#34;Linx-Api-Key: mysecretkey&#34; -H &#34;Linx-Delete-Key: mysecret&#34; -T myphoto.jpg {{ siteurl }}upload/
{{ siteurl }}myphoto.jpg</code></pre>
{% else %}
<pre><code>$ curl -H &#34;Linx-Delete-Key: mysecret&#34; -T myphoto.jpg {{ siteurl }}upload/
{{ siteurl }}myphoto.jpg</code></pre>
{% endif %}
<h3>Deleting a file</h3>
<p>To delete a file you uploaded, make a DELETE request to <code>{{ siteurl }}yourfile.ext</code> with the
delete key set as the <code>Linx-Delete-Key</code> header.</p>
<p><strong>Example</strong></p>
<p>To delete myphoto.jpg</p>
{% if auth != "none" %}
<pre><code>$ curl -H &#34;Linx-Api-Key: mysecretkey&#34; -H &#34;Linx-Delete-Key: mysecret&#34; -X DELETE {{ siteurl }}myphoto.jpg
DELETED</code></pre>
{% else %}
<pre><code>$ curl -H &#34;Linx-Delete-Key: mysecret&#34; -X DELETE {{ siteurl }}myphoto.jpg
DELETED</code></pre>
{% endif %}
<h3>Information about a file</h3>
<p>To retrieve information about a file, make a GET request the public url with
<code>Accept: application/json</code> headers and you will receive a json response containing:</p>
<blockquote>
<p>“url”: the publicly available upload url<br />
“direct_url”: the url to access the file directly<br />
“filename”: the (optionally generated) filename<br />
“expiry”: the unix timestamp at which the file will expire (0 if never)<br />
“size”: the size in bytes of the file<br />
“mimetype”: the guessed mimetype of the file<br />
“sha256sum”: the sha256sum of the file,</p>
</blockquote>
<p><strong>Example</strong></p>
<pre><code>$ curl -H &#34;Accept: application/json&#34; {{ siteurl }}myphoto.jpg
{&#34;expiry&#34;:&#34;0&#34;,&#34;filename&#34;:&#34;myphoto.jpg&#34;,&#34;mimetype&#34;:&#34;image/jpeg&#34;,&#34;sha256sum&#34;:&#34;...&#34;,&#34;size&#34;:&#34;...&#34;}</code></pre>
</div>
</div>
</div>
{% endblock %}

14
templates/access.html Normal file
View file

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block title %}{{sitename}} - Password protected file{% endblock %}
{% block content %}
<div id="main" class="oopscontent">
<form action="{{ unlockpath }}" method="POST" enctype="multipart/form-data">
{{ filename }} is protected with a password: <br /><br />
<input name="access_key" type="password" />
<input id="submitbtn" type="submit" value="Unlock">
<br /><br />
</form>
</div>
{% endblock %}

View file

@ -1,10 +1,13 @@
<!DOCTYPE html>
<html>
<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'>
<meta name='viewport' content='width=device-width, initial-scale=0.8'>
<link href='{{ sitepath }}static/css/linx.css?v=1' media='screen, projection' rel='stylesheet' type='text/css'>
<link href='{{ sitepath }}static/css/hint.css' rel='stylesheet' type='text/css'>
<link href='{{ sitepath }}static/images/favicon.gif' rel='icon' type='image/gif'>
{% block head %}{% endblock %}
</head>
@ -13,19 +16,26 @@
<div id="container">
<div id="header">
<div id="navigation" class="right">
<a href="/">Upload</a> |
<a href="/paste/">Paste</a>
{% if auth != "header" %}
<a href="{{ sitepath }}">Upload</a> |
<a href="{{ sitepath }}paste/">Paste</a> |
{% endif %}
<a href="{{ sitepath }}API/">API</a>
{% for custom_file_name, custom_page_name in custom_pages_names sorted %}
| <a href="{{ sitepath }}{{ custom_file_name }}/">{{ custom_page_name }}</a>
{% endfor %}
</div>
<h2><a href="/" title="{{ sitename }}">{{ sitename }}</a></h2>
<h2><a href="{{ sitepath }}" title="{{ sitename }}">{{ sitename }}</a></h2>
</div>
{% block content %}{% endblock %}
<div id="footer">
<a href="https://github.com/andreimarcu/linx-server">linx</a>
<a href="https://github.com/andreimarcu/linx-server">linx-server</a>
</div>
</div>
</div>
</body>
</html>
</html>

View file

@ -0,0 +1,19 @@
{% extends "base.html" %}
{% block title %}{{sitename}} - {{ pagename }}{% endblock %}
{% block head %}
<link href="{{ sitepath }}static/css/github-markdown.css" rel="stylesheet" type="text/css">
{% endblock %}
{% block content %}
<div id="main">
<div id='inner_content'>
<div class="normal markdown-body">
<h2>{{ pagename }}</h2>
{{ contents|safe }}
</div>
</div>
</div>
{% endblock %}

View file

@ -1,9 +1,12 @@
{% extends "base.html" %}
{% block head %}
<meta property="og:audio" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
{% endblock %}
{% block main %}
<audio class="display-audio" controls preload='auto'>
<source src='/selif/{{ filename }}'>
<a href='/selif/{{ filename }}'>Download it instead</a>
<source src='{{ sitepath }}{{ selifpath }}{{ filename }}'>
<a href='{{ sitepath }}{{ selifpath }}{{ filename }}'>Download it instead</a>
</audio>
{% endblock %}
{% endblock %}

View file

@ -1,35 +1,36 @@
{% extends "../base.html" %}
{% block title %}{{ filename }}{% endblock %}
{% block title %}{{sitename}} - {{ filename }}{% endblock %}
{% block bodymore %}{% endblock %}
{% block content %}
<div id="info" class="dinfo">
<div class="float-left" id="filename">
{{ filename }}
</div>
<div class="right">
{% if expiry %}
<span>file expires in {{ expiry }}</span> |
{% endif %}
{% block infomore %}{% endblock %}
<span>{{ size }}</span> |
<a href="{{ filename }}/torrent" download>torrent</a> |
<a href="/selif/{{ filename }}" download>get</a>
</div>
{% block infoleft %}{% endblock %}
<div class="clear"></div>
<div id="info" class="dinfo info-flex">
<div id="filename">
{{ filename }}
</div>
<div id="main" {% block mainmore %}{% endblock %}>
<div id='inner_content' {% block innercontentmore %}{% endblock %} >
{% block main %}{% endblock %}
</div>
<div class="info-actions">
{% if expiry %}
<span>file expires in {{ expiry }}</span> |
{% endif %}
{% block infomore %}{% endblock %}
<span>{{ size }}</span> |
<a href="{{ filename }}/torrent" download>torrent</a> |
<a href="{{ sitepath }}{{ selifpath }}{{ filename }}" download>get</a>
</div>
{% endblock %}
{% block infoleft %}{% endblock %}
</div>
<div id="main" {% block mainmore %}{% endblock %}>
<div id='inner_content' {% block innercontentmore %}{% endblock %}>
{% block main %}{% endblock %}
</div>
</div>
<script src="{{ sitepath }}static/js/clipboard.js"></script>
{% endblock %}

View file

@ -1,56 +1,52 @@
{% extends "base.html" %}
{% block head %}
{% if extra.extension == "story" %}
<link href="/static/css/highlight/story.css" rel="stylesheet" type="text/css">
{% else %}
<link href="/static/css/highlight/tomorrow.css" rel="stylesheet" type="text/css">
{% endif %}
{% endblock %}
<link href="{{ sitepath }}static/css/highlight/tomorrow.css" rel="stylesheet" type="text/css">
{% if extra.lang_hl != "text" %}
<link href="{{ sitepath }}static/css/highlight/lines.css" rel="stylesheet" type="text/css">
{% endif %}
{% endblock %}
{% block innercontentmore %} class="scrollable"{% endblock %}
{% block mainmore %} {% if extra.extension == "story" %} class="storycontent"{% endif %} {% endblock %}
{% block infoleft %}
<div id="editform">
<form id="reply" action='/upload' method='post' >
<div class="right">
<select id="expiry" name="expires">
<option disabled=disabled>Expires:</option>
<option value="0">never</option>
<option value="60">a minute</option>
<option value="300">5 minutes</option>
<option value="3600">an hour</option>
<option value="86400">a day</option>
<option value="604800">a week</option>
<option value="2419200">a month</option>
<option value="29030400">a year</option>
</select>
<button id="save">save</button>
<form id="reply" action='{{ sitepath }}upload' method='post'>
<div class="info-flex">
<div>
{% if not forcerandom %}<input class="codebox" name='filename' id="filename" type='text' value="" placeholder="filename">{% endif %}.<input id="extension" class="codebox" name='extension' type='text' value="{{ extra.extension }}" placeholder="txt">
</div>
<div class="info-actions">
<select id="expiry" name="expires">
<option disabled>Expires:</option>
{% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}"{% if forloop.Last %} selected{% endif %}>{{ expiry.Human }}</option>
{% endfor %}
</select>
<button type="submit" id="save">Save</button>
</div>
</div>
<input class="codebox" name='filename' id="filename" type='text' value="" placeholder="filename (empty for random filename)">.<input id="extension" class="codebox" name='extension' type='text' value="{{ extra.extension }}" placeholder="txt">
<textarea name='content' id="newcontent" class="editor"></textarea>
</form>
</div>
{% endblock %}
{%block infomore %}
{% block infomore %}
<label>wrap <input id="wordwrap" type="checkbox" checked></label> |
{% endblock %}
{% block main %}
<div id="normal-content" class="normal {% if extra.lang_hl != "story" %}fixed{% endif %}">
<div id="normal-content" class="normal fixed">
<pre id="normal-code"><code id="codeb" class="{{ extra.lang_hl }}">{{ extra.contents }}</code></pre>
<textarea id="editor" class="editor">{{ extra.contents }}</textarea>
<textarea id="inplace-editor" class="editor">{{ extra.contents }}</textarea>
</div>
{% 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/bin.js"></script>
<script src="{{ sitepath }}static/js/util.js"></script>
<script src="{{ sitepath }}static/js/bin.js?v=1"></script>
{% endblock %}

View file

@ -2,6 +2,15 @@
{% 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 }}{{ selifpath }}{{ filename }}">{{ filename }}</a>, <a href="{{ sitepath }}{{ selifpath }}{{ filename }}">click here</a> to download.</p>
{% if files|length > 0 %}
<p>Contents of the archive:</p>
<ul>
{% for file in files %}
<li>{{ file }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endblock %}

View file

@ -1,7 +1,11 @@
{% extends "base.html" %}
{% block main %}
<a href="/selif/{{ filename }}">
<img class="display-image" src="/selif/{{ filename }}" />
</a>
{% block head %}
<meta property="og:image" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
{% endblock %}
{% block main %}
<a href="{{ sitepath }}{{ selifpath }}{{ filename }}">
<img class="display-image" src="{{ sitepath }}{{ selifpath }}{{ filename }}" />
</a>
{% endblock %}

View file

@ -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 %}

View file

@ -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 }}{{ selifpath }}{{ 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 }}{{ selifpath }}{{ filename }}">click here to download the PDF file.</a></p>
</object>
{% endblock %}

View file

@ -0,0 +1,46 @@
{% extends "base.html" %}
{% block head %}
<link href="{{ sitepath }}static/css/story.css" rel="stylesheet" type="text/css">
{% endblock %}
{% block innercontentmore %} class="scrollable"{% endblock %}
{% block mainmore %} class="storycontent" {% endblock %}
{% block infoleft %}
<div id="editform">
<form id="reply" action='{{ sitepath }}upload' method='post'>
<div class="info-flex">
<div>
{% if not forcerandom %}<input class="codebox" name='filename' id="filename" type='text' value="" placeholder="filename">{% endif %}.<input id="extension" class="codebox" name='extension' type='text' value="story" placeholder="txt">
</div>
<div class="info-actions">
<select id="expiry" name="expires">
<option disabled>Expires:</option>
{% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}"{% if forloop.Last %} selected{% endif %}>{{ expiry.Human }}</option>
{% endfor %}
</select>
<button type="submit" id="save">Save</button>
</div>
</div>
<textarea name='content' id="newcontent" class="editor"></textarea>
</form>
</div>
{% endblock %}
{%block infomore %}
<label>wrap <input id="wordwrap" type="checkbox" checked></label> |
{% endblock %}
{% block main %}
<div id="normal-content" class="normal">
<pre id="normal-code"><code id="codeb" class="story">{% for line in lines %}{% if line|make_list|first == ">" %}<span class="storygreen">{{ line }}</span>{% else %}<span class="storyred">{{ line }}</span>{% endif %}{% endfor %}</code></pre>
<textarea id="inplace-editor" class="editor">{{ extra.contents }}</textarea>
</div>
<script src="{{ sitepath }}static/js/util.js"></script>
<script src="{{ sitepath }}static/js/bin.js?v=1"></script>
{% endblock %}

View file

@ -1,8 +1,12 @@
{% extends "base.html" %}
{% block head %}
<meta property="og:video" content="{{ siteurl }}{{ sitepath }}{{ selifpath }}{{ filename }}" />
{% endblock %}
{% block main %}
<video class="display-video" controls autoplay>
<source src="/selif/{{ filename }}"/>
<a href='/selif/{{ filename }}'>Download it instead</a>
<source src="{{ sitepath }}{{ selifpath }}{{ filename }}" />
<a href='{{ sitepath }}{{ selifpath }}{{ filename }}'>Download it instead</a>
</video>
{% endblock %}
{% endblock %}

View file

@ -1,37 +1,49 @@
{% 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 %}
{% block content %}
<div id="fileupload">
<form action="/upload" class="dropzone" id="dropzone" method="POST" enctype="multipart/form-data">
<form action="{{ sitepath }}upload" class="dropzone" id="dropzone" method="POST" enctype="multipart/form-data"
data-maxsize="{{ maxsize }}" data-auth="{{ auth }}">
<div class="fallback">
<input name="file" type="file" /><br />
<input type="submit" value="Upload">
<input id="fileinput" name="file" type="file" /><br />
<input id="submitbtn" type="submit" value="Upload">
</div>
<div id="dzone" class="dz-default dz-message">
<span>Click or Drop file(s)</span>
<span>Click or Drop file(s) or Paste image</span>
</div>
<div id="choices">
<span class="hint--top hint--bounce"
data-hint="Replace the filename with random characters. The file extension is retained">
<label><input {% if forcerandom %} disabled {% endif %} name="randomize" id="randomize" type="checkbox"
checked /> Randomize filename</label>
</span>
<div id="expiry">
<label>File expiry:
<select name="expires" id="expires">
<option value="0">never</option>
<option value="60">a minute</option>
<option value="300">5 minutes</option>
<option value="3600">an hour</option>
<option value="86400">a day</option>
<option value="604800">a week</option>
<option value="2419200">a month</option>
<option value="29030400">a year</option>
</select>
<label>File expiry:
<select name="expires" id="expires">
{% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}" {% if forloop.Last %} selected{% endif %}>
{{ expiry.Human }}</option>
{% endfor %}
</select>
</label>
</div>
<label><input name="randomize" id="randomize" type="checkbox" checked /> Randomize filename</label>
<div id="access_key">
<span class="hint--top hint--bounce"
data-hint="Require password to access (this does not encrypt the file but only limits access)">
<label>
<input type="checkbox" id="access_key_checkbox" />
<span id="access_key_text">Require access password</span>
</label>
<input id="access_key_input" name="access_key" type="text" placeholder="Access password" />
</span>
</div>
</div>
<div class="clear"></div>
</form>
@ -39,6 +51,6 @@
<div class="clear"></div>
</div>
<script src="/static/js/dropzone.js"></script>
<script src="/static/js/upload.js"></script>
{% endblock %}
<script src="{{ sitepath }}static/js/dropzone.js"></script>
<script src="{{ sitepath }}static/js/upload.js"></script>
{% endblock %}

View file

@ -1,40 +1,40 @@
{% extends "base.html" %}
{% block title %}{{sitename}} - Paste{% endblock %}
{% block content %}
<form id="reply" action='/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>
<div class="right">
<select id="expiry" name="expires">
<option disabled=disabled>Expires:</option>
<option value="0">never</option>
<option value="60">a minute</option>
<option value="300">5 minutes</option>
<option value="3600">an hour</option>
<option value="86400">a day</option>
<option value="604800">a week</option>
<option value="2419200">a month</option>
<option value="29030400">a year</option>
</select>
<input type="submit" value="Paste">
<form id="reply" action='{{ sitepath }}upload' method='post'>
<div id="main" class="paste">
<div id="info" class="info-flex">
<div>
{% if not forcerandom %}<span class="hint--top hint--bounce"
data-hint="Leave empty for random filename"><input class="codebox" name='filename' id="filename"
type='text' value="" placeholder="filename" /></span>{% endif %}.<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>
</div>
<div>
<span class="hint--top hint--bounce" data-hint="Require password to access (leave empty to disable)">
<input class="codebox" name="access_key" type="text" placeholder="password" />
</span>
<select id="expiry" name="expires">
<option disabled>Expires:</option>
{% for expiry in expirylist %}
<option value="{{ expiry.Seconds }}" {% if forloop.Last %} selected{% endif %}>{{ expiry.Human }}
</option>
{% endfor %}
</select>
<button type="submit">Paste</button>
</div>
</div>
<div id="inner_content">
<textarea name='content' id="content" class="editor"></textarea>
<div id="inner_content" class="padme">
<textarea name='content' id="content" class="editor"></textarea>
</div>
</div>
</form>
</div>
</form>
{% endblock %}
<script src="{{ sitepath }}static/js/util.js"></script>
<script src="{{ sitepath }}static/js/paste.js"></script>
{% endblock %}

View file

@ -2,73 +2,44 @@ package main
import (
"bytes"
"crypto/sha1"
"fmt"
"io"
"net/http"
"os"
"path"
"time"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/expiry"
"github.com/andreimarcu/linx-server/torrent"
"github.com/zeebo/bencode"
"github.com/zenazn/goji/web"
)
const (
TORRENT_PIECE_LENGTH = 262144
)
func createTorrent(fileName string, f io.Reader, r *http.Request) ([]byte, error) {
url := getSiteURL(r) + Config.selifPath + fileName
chunk := make([]byte, torrent.TORRENT_PIECE_LENGTH)
type TorrentInfo struct {
PieceLength int `bencode:"piece length"`
Pieces string `bencode:"pieces"`
Name string `bencode:"name"`
Length int `bencode:"length"`
}
type Torrent struct {
Encoding string `bencode:"encoding"`
Info TorrentInfo `bencode:"info"`
UrlList []string `bencode:"url-list"`
}
func hashPiece(piece []byte) []byte {
h := sha1.New()
h.Write(piece)
return h.Sum(nil)
}
func createTorrent(fileName string, filePath string) ([]byte, error) {
chunk := make([]byte, TORRENT_PIECE_LENGTH)
torrent := Torrent{
t := torrent.Torrent{
Encoding: "UTF-8",
Info: TorrentInfo{
PieceLength: TORRENT_PIECE_LENGTH,
Info: torrent.TorrentInfo{
PieceLength: torrent.TORRENT_PIECE_LENGTH,
Name: fileName,
},
UrlList: []string{fmt.Sprintf("%sselif/%s", Config.siteURL, fileName)},
}
f, err := os.Open(filePath)
if err != nil {
return []byte{}, err
UrlList: []string{url},
}
for {
n, err := f.Read(chunk)
n, err := io.ReadFull(f, chunk)
if err == io.EOF {
break
} else if err != nil {
} else if err != nil && err != io.ErrUnexpectedEOF {
return []byte{}, err
}
torrent.Info.Length += n
torrent.Info.Pieces += string(hashPiece(chunk[:n]))
t.Info.Length += n
t.Info.Pieces += string(torrent.HashPiece(chunk[:n]))
}
f.Close()
data, err := bencode.EncodeBytes(&torrent)
data, err := bencode.EncodeBytes(&t)
if err != nil {
return []byte{}, err
}
@ -78,14 +49,27 @@ func createTorrent(fileName string, filePath string) ([]byte, error) {
func fileTorrentHandler(c web.C, w http.ResponseWriter, r *http.Request) {
fileName := c.URLParams["name"]
filePath := path.Join(Config.filesDir, fileName)
if !fileExistsAndNotExpired(fileName) {
metadata, f, err := storageBackend.Get(fileName)
if err == backends.NotFoundErr {
notFoundHandler(c, w, r)
return
} else if err == backends.BadMetadata {
oopsHandler(c, w, r, RespAUTO, "Corrupt metadata.")
return
} else if err != nil {
oopsHandler(c, w, r, RespAUTO, err.Error())
return
}
defer f.Close()
if expiry.IsTsExpired(metadata.Expiry) {
storageBackend.Delete(fileName)
notFoundHandler(c, w, r)
return
}
encoded, err := createTorrent(fileName, filePath)
encoded, err := createTorrent(fileName, f, r)
if err != nil {
oopsHandler(c, w, r, RespHTML, "Could not create torrent.")
return

28
torrent/torrent.go Normal file
View file

@ -0,0 +1,28 @@
package torrent
import (
"crypto/sha1"
)
const (
TORRENT_PIECE_LENGTH = 262144
)
type TorrentInfo struct {
PieceLength int `bencode:"piece length"`
Pieces string `bencode:"pieces"`
Name string `bencode:"name"`
Length int `bencode:"length"`
}
type Torrent struct {
Encoding string `bencode:"encoding"`
Info TorrentInfo `bencode:"info"`
UrlList []string `bencode:"url-list"`
}
func HashPiece(piece []byte) []byte {
h := sha1.New()
h.Write(piece)
return h.Sum(nil)
}

View file

@ -2,16 +2,24 @@ package main
import (
"fmt"
"os"
"testing"
"github.com/andreimarcu/linx-server/torrent"
"github.com/zeebo/bencode"
)
func TestCreateTorrent(t *testing.T) {
fileName := "server.go"
var decoded Torrent
var decoded torrent.Torrent
encoded, err := createTorrent(fileName, fileName)
f, err := os.Open("server.go")
if err != nil {
t.Fatal(err)
}
defer f.Close()
encoded, err := createTorrent(fileName, f, nil)
if err != nil {
t.Fatal(err)
}
@ -38,23 +46,29 @@ func TestCreateTorrent(t *testing.T) {
t.Fatal("Length was less than or equal to 0, expected more")
}
tracker := fmt.Sprintf("%sselif/%s", Config.siteURL, fileName)
tracker := fmt.Sprintf("%s%s%s", Config.siteURL, Config.selifPath, fileName)
if decoded.UrlList[0] != tracker {
t.Fatalf("First entry in URL list was %s, expected %s", decoded.UrlList[0], tracker)
}
}
func TestCreateTorrentWithImage(t *testing.T) {
var decoded Torrent
var decoded torrent.Torrent
encoded, err := createTorrent("test.jpg", "static/images/404.jpg")
f, err := os.Open("static/images/404.jpg")
if err != nil {
t.Fatal(err)
}
defer f.Close()
encoded, err := createTorrent("test.jpg", f, nil)
if err != nil {
t.Fatal(err)
}
bencode.DecodeBytes(encoded, &decoded)
if decoded.Info.Pieces != "r\x01\x80j\x99\x84\n\xd3dZ;1NX\xec;\x9d$+f" {
if decoded.Info.Pieces != "\xd6\xff\xbf'^)\x85?\xb4.\xb0\xc1|\xa3\x83\xeeX\xf9\xfd\xd7" {
t.Fatal("Torrent pieces did not match expected pieces for image")
}
}

284
upload.go
View file

@ -8,7 +8,6 @@ import (
"io"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
@ -16,37 +15,47 @@ import (
"strings"
"time"
"bitbucket.org/taruti/mimemagic"
"github.com/andreimarcu/linx-server/auth/apikeys"
"github.com/andreimarcu/linx-server/backends"
"github.com/andreimarcu/linx-server/expiry"
"github.com/dchest/uniuri"
"github.com/gabriel-vasile/mimetype"
"github.com/zenazn/goji/web"
)
var FileTooLargeError = errors.New("File too large.")
var fileBlacklist = map[string]bool{
"favicon.ico": true,
"index.htm": true,
"index.html": true,
"index.php": true,
"robots.txt": true,
"favicon.ico": true,
"index.htm": true,
"index.html": true,
"index.php": true,
"robots.txt": true,
"crossdomain.xml": true,
}
// Describes metadata directly from the user request
type UploadRequest struct {
src io.Reader
size int64
filename string
expiry time.Duration // Seconds until expiry, 0 = never
deleteKey string // Empty string if not defined
randomBarename bool
deletionKey string // Empty string if not defined
accessKey string // Empty string if not defined
}
// Metadata associated with a file as it would actually be stored
type Upload struct {
Filename string // Final filename on disk
Size int64
Expiry time.Time // Unix timestamp of expiry, 0=never
DeleteKey string // Deletion key, one generated if not provided
Filename string // Final filename on disk
Metadata backends.Metadata
}
func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if !strictReferrerCheck(r, getSiteURL(r), []string{"Linx-Delete-Key", "Linx-Expiry", "Linx-Randomize", "X-Requested-With"}) {
badRequestHandler(c, w, r, RespAUTO, "")
return
}
upReq := UploadRequest{}
uploadHeaderProcess(r, &upReq)
@ -60,48 +69,58 @@ func uploadPostHandler(c web.C, w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
r.ParseForm()
if r.Form.Get("randomize") == "true" {
upReq.randomBarename = true
}
upReq.expiry = parseExpiry(r.Form.Get("expires"))
upReq.src = file
upReq.size = headers.Size
upReq.filename = headers.Filename
} else {
if r.FormValue("content") == "" {
oopsHandler(c, w, r, RespHTML, "Empty file")
if r.PostFormValue("content") == "" {
badRequestHandler(c, w, r, RespAUTO, "Empty file")
return
}
extension := r.FormValue("extension")
extension := r.PostFormValue("extension")
if extension == "" {
extension = "txt"
}
upReq.src = strings.NewReader(r.FormValue("content"))
upReq.expiry = parseExpiry(r.FormValue("expires"))
upReq.filename = r.FormValue("filename") + "." + extension
content := r.PostFormValue("content")
upReq.src = strings.NewReader(content)
upReq.size = int64(len(content))
upReq.filename = r.PostFormValue("filename") + "." + extension
}
upReq.expiry = parseExpiry(r.PostFormValue("expires"))
upReq.accessKey = r.PostFormValue(accessKeyParamName)
if r.PostFormValue("randomize") == "true" {
upReq.randomBarename = true
}
upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
if err != nil {
if err == FileTooLargeError || err == backends.FileEmptyError {
badRequestHandler(c, w, r, RespJSON, err.Error())
return
} else if err != nil {
oopsHandler(c, w, r, RespJSON, "Could not upload file: "+err.Error())
return
}
js := generateJSONresponse(upload)
js := generateJSONresponse(upload, r)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Write(js)
} else {
if err != nil {
if err == FileTooLargeError || err == backends.FileEmptyError {
badRequestHandler(c, w, r, RespHTML, err.Error())
return
} else if err != nil {
oopsHandler(c, w, r, RespHTML, "Could not upload file: "+err.Error())
return
}
http.Redirect(w, r, "/"+upload.Filename, 301)
http.Redirect(w, r, Config.sitePath+upload.Filename, 303)
}
}
func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
@ -110,37 +129,66 @@ func uploadPutHandler(c web.C, w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
upReq.filename = c.URLParams["name"]
upReq.src = r.Body
upReq.src = http.MaxBytesReader(w, r.Body, Config.maxSize)
upload, err := processUpload(upReq)
if strings.EqualFold("application/json", r.Header.Get("Accept")) {
if err != nil {
if err == FileTooLargeError || err == backends.FileEmptyError {
badRequestHandler(c, w, r, RespJSON, err.Error())
return
} else if err != nil {
oopsHandler(c, w, r, RespJSON, "Could not upload file: "+err.Error())
return
}
js := generateJSONresponse(upload)
js := generateJSONresponse(upload, r)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Write(js)
} else {
if err != nil {
if err == FileTooLargeError || err == backends.FileEmptyError {
badRequestHandler(c, w, r, RespPLAIN, err.Error())
return
} else if err != nil {
oopsHandler(c, w, r, RespPLAIN, "Could not upload file: "+err.Error())
return
}
fmt.Fprintf(w, Config.siteURL+upload.Filename)
fmt.Fprintf(w, "%s\n", getSiteURL(r)+upload.Filename)
}
}
func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
if Config.remoteAuthFile != "" {
key := r.FormValue("key")
if key == "" && Config.basicAuth {
_, password, ok := r.BasicAuth()
if ok {
key = password
}
}
result, err := apikeys.CheckAuth(remoteAuthKeys, key)
if err != nil || !result {
if Config.basicAuth {
rs := ""
if Config.siteName != "" {
rs = fmt.Sprintf(` realm="%s"`, Config.siteName)
}
w.Header().Set("WWW-Authenticate", `Basic`+rs)
}
unauthorizedHandler(c, w, r)
return
}
}
if r.FormValue("url") == "" {
http.Redirect(w, r, "/", 301)
http.Redirect(w, r, Config.sitePath, 303)
return
}
upReq := UploadRequest{}
grabUrl, _ := url.Parse(r.FormValue("url"))
directURL := r.FormValue("direct_url") == "yes"
resp, err := http.Get(grabUrl.String())
if err != nil {
@ -149,8 +197,10 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
}
upReq.filename = filepath.Base(grabUrl.Path)
upReq.src = resp.Body
upReq.deletionKey = r.FormValue("deletekey")
upReq.src = http.MaxBytesReader(w, resp.Body, Config.maxSize)
upReq.deleteKey = r.FormValue("deletekey")
upReq.accessKey = r.FormValue(accessKeyParamName)
upReq.randomBarename = r.FormValue("randomize") == "yes"
upReq.expiry = parseExpiry(r.FormValue("expiry"))
upload, err := processUpload(upReq)
@ -161,7 +211,7 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
return
}
js := generateJSONresponse(upload)
js := generateJSONresponse(upload, r)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.Write(js)
} else {
@ -170,7 +220,11 @@ func uploadRemote(c web.C, w http.ResponseWriter, r *http.Request) {
return
}
http.Redirect(w, r, "/"+upload.Filename, 301)
if directURL {
http.Redirect(w, r, Config.sitePath+Config.selifPath+upload.Filename, 303)
} else {
http.Redirect(w, r, Config.sitePath+upload.Filename, 303)
}
}
}
@ -179,20 +233,27 @@ func uploadHeaderProcess(r *http.Request, upReq *UploadRequest) {
upReq.randomBarename = true
}
upReq.deletionKey = r.Header.Get("Linx-Delete-Key")
upReq.deleteKey = r.Header.Get("Linx-Delete-Key")
upReq.accessKey = r.Header.Get(accessKeyHeaderName)
// Get seconds until expiry. Non-integer responses never expire.
expStr := r.Header.Get("Linx-Expiry")
upReq.expiry = parseExpiry(expStr)
}
func processUpload(upReq UploadRequest) (upload Upload, err error) {
// Determine the appropriate filename, then write to disk
barename, extension := barePlusExt(upReq.filename)
if upReq.size > Config.maxSize {
return upload, FileTooLargeError
}
// Determine the appropriate filename
barename, extension := barePlusExt(upReq.filename)
randomize := false
// Randomize the "barename" (filename without extension) if needed
if upReq.randomBarename || len(barename) == 0 {
barename = generateBarename()
randomize = true
}
var header []byte
@ -201,79 +262,83 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
header = make([]byte, 512)
n, _ := upReq.src.Read(header)
if n == 0 {
return upload, errors.New("Empty file")
return upload, backends.FileEmptyError
}
header = header[:n]
// Determine the type of file from header
mimetype := mimemagic.Match("", header)
// If the mime type is in our map, use that
// otherwise just use "ext"
if val, exists := mimeToExtension[mimetype]; exists {
extension = val
kind := mimetype.Detect(header)
if len(kind.Extension()) < 2 {
extension = "file"
} else {
extension = "ext"
extension = kind.Extension()[1:] // remove leading "."
}
}
upload.Filename = strings.Join([]string{barename, extension}, ".")
upload.Filename = strings.Replace(upload.Filename, " ", "", -1)
_, err = os.Stat(path.Join(Config.filesDir, upload.Filename))
fileexists, _ := storageBackend.Exists(upload.Filename)
// Check if the delete key matches, in which case overwrite
if fileexists {
metad, merr := storageBackend.Head(upload.Filename)
if merr == nil {
if upReq.deleteKey == metad.DeleteKey {
fileexists = false
} else if Config.forceRandomFilename == true {
// the file exists
// the delete key doesn't match
// force random filenames is enabled
randomize = true
}
}
} else if Config.forceRandomFilename == true {
// the file doesn't exist
// force random filenames is enabled
randomize = true
// set fileexists to true to generate a new barename
fileexists = true
}
fileexists := err == nil
for fileexists {
counter, err := strconv.Atoi(string(barename[len(barename)-1]))
if err != nil {
barename = barename + "1"
if randomize {
barename = generateBarename()
} else {
barename = barename[:len(barename)-1] + strconv.Itoa(counter+1)
counter, err := strconv.Atoi(string(barename[len(barename)-1]))
if err != nil {
barename = barename + "1"
} else {
barename = barename[:len(barename)-1] + strconv.Itoa(counter+1)
}
}
upload.Filename = strings.Join([]string{barename, extension}, ".")
_, err = os.Stat(path.Join(Config.filesDir, upload.Filename))
fileexists = err == nil
fileexists, err = storageBackend.Exists(upload.Filename)
}
if fileBlacklist[strings.ToLower(upload.Filename)] {
return upload, errors.New("Prohibited filename")
}
dst, err := os.Create(path.Join(Config.filesDir, upload.Filename))
if err != nil {
return
}
defer dst.Close()
// Get the rest of the metadata needed for storage
var fileExpiry time.Time
if upReq.expiry == 0 {
upload.Expiry = neverExpire
fileExpiry = expiry.NeverExpire
} else {
upload.Expiry = time.Now().Add(upReq.expiry)
fileExpiry = time.Now().Add(upReq.expiry)
}
// If no delete key specified, pick a random one.
if upReq.deletionKey == "" {
upload.DeleteKey = uniuri.NewLen(30)
} else {
upload.DeleteKey = upReq.deletionKey
if upReq.deleteKey == "" {
upReq.deleteKey = uniuri.NewLen(30)
}
metadataWrite(upload.Filename, &upload)
bytes, err := io.Copy(dst, io.MultiReader(bytes.NewReader(header), upReq.src))
if bytes == 0 {
os.Remove(path.Join(Config.filesDir, upload.Filename))
os.Remove(path.Join(Config.metaDir, upload.Filename))
return upload, errors.New("Empty file")
} else if err != nil {
os.Remove(path.Join(Config.filesDir, upload.Filename))
os.Remove(path.Join(Config.metaDir, upload.Filename))
return
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey)
if err != nil {
return upload, err
}
upload.Size = bytes
return
}
@ -281,43 +346,68 @@ func generateBarename() string {
return uniuri.NewLenChars(8, []byte("abcdefghijklmnopqrstuvwxyz0123456789"))
}
func generateJSONresponse(upload Upload) []byte {
func generateJSONresponse(upload Upload, r *http.Request) []byte {
js, _ := json.Marshal(map[string]string{
"url": Config.siteURL + upload.Filename,
"url": getSiteURL(r) + upload.Filename,
"direct_url": getSiteURL(r) + Config.selifPath + upload.Filename,
"filename": upload.Filename,
"delete_key": upload.DeleteKey,
"expiry": strconv.FormatInt(upload.Expiry.Unix(), 10),
"size": strconv.FormatInt(upload.Size, 10),
"delete_key": upload.Metadata.DeleteKey,
"access_key": upload.Metadata.AccessKey,
"expiry": strconv.FormatInt(upload.Metadata.Expiry.Unix(), 10),
"size": strconv.FormatInt(upload.Metadata.Size, 10),
"mimetype": upload.Metadata.Mimetype,
"sha256sum": upload.Metadata.Sha256sum,
})
return js
}
var barePlusRe = regexp.MustCompile(`[^A-Za-z0-9\-]`)
var bareRe = regexp.MustCompile(`[^A-Za-z0-9\-]`)
var extRe = regexp.MustCompile(`[^A-Za-z0-9\-\.]`)
var compressedExts = map[string]bool{
".bz2": true,
".gz": true,
".xz": true,
}
var archiveExts = map[string]bool{
".tar": true,
}
func barePlusExt(filename string) (barename, extension string) {
filename = strings.TrimSpace(filename)
filename = strings.ToLower(filename)
extension = path.Ext(filename)
barename = filename[:len(filename)-len(extension)]
if compressedExts[extension] {
ext2 := path.Ext(barename)
if archiveExts[ext2] {
barename = barename[:len(barename)-len(ext2)]
extension = ext2 + extension
}
}
extension = barePlusRe.ReplaceAllString(extension, "")
barename = barePlusRe.ReplaceAllString(barename, "")
extension = extRe.ReplaceAllString(extension, "")
barename = bareRe.ReplaceAllString(barename, "")
extension = strings.Trim(extension, "-.")
barename = strings.Trim(barename, "-")
return
}
func parseExpiry(expStr string) time.Duration {
if expStr == "" {
return 0
return time.Duration(Config.maxExpiry) * time.Second
} else {
expiry, err := strconv.ParseInt(expStr, 10, 64)
fileExpiry, err := strconv.ParseUint(expStr, 10, 64)
if err != nil {
return 0
return time.Duration(Config.maxExpiry) * time.Second
} else {
return time.Duration(expiry) * time.Second
if Config.maxExpiry > 0 && (fileExpiry > Config.maxExpiry || fileExpiry == 0) {
fileExpiry = Config.maxExpiry
}
return time.Duration(fileExpiry) * time.Second
}
}
}

914
util.go
View file

@ -1,15 +1,10 @@
package main
func extensionToHlAndAceLangs(extension string) (hlExt, aceExt string) {
func extensionToHlLang(extension string) (hlExt string) {
hlExt, exists := extensionToHl[extension]
if !exists {
hlExt = "text"
}
aceExt, exists = extensionToAce[extension]
if !exists {
aceExt = "text"
}
return
}
@ -18,854 +13,63 @@ func supportedBinExtension(extension string) bool {
return exists
}
var mimeToExtension = map[string]string{
"application/andrew-inset": "ez",
"application/applixware": "aw",
"application/atom+xml": "atom",
"application/atomcat+xml": "atomcat",
"application/atomsvc+xml": "atomsvc",
"application/ccxml+xml": "ccxml",
"application/cdmi-capability": "cdmia",
"application/cdmi-container": "cdmic",
"application/cdmi-domain": "cdmid",
"application/cdmi-object": "cdmio",
"application/cdmi-queue": "cdmiq",
"application/cu-seeme": "cu",
"application/davmount+xml": "davmount",
"application/docbook+xml": "dbk",
"application/dssc+der": "dssc",
"application/dssc+xml": "xdssc",
"application/ecmascript": "ecma",
"application/emma+xml": "emma",
"application/epub+zip": "epub",
"application/exi": "exi",
"application/font-tdpfr": "pfr",
"application/gml+xml": "gml",
"application/gpx+xml": "gpx",
"application/gxf": "gxf",
"application/hyperstudio": "stk",
"application/inkml+xml": "ink inkml",
"application/ipfix": "ipfix",
"application/java-archive": "jar",
"application/java-serialized-object": "ser",
"application/java-vm": "class",
"application/javascript": "js",
"application/json": "json",
"application/jsonml+json": "jsonml",
"application/lost+xml": "lostxml",
"application/mac-binhex40": "hqx",
"application/mac-compactpro": "cpt",
"application/mads+xml": "mads",
"application/marc": "mrc",
"application/marcxml+xml": "mrcx",
"application/mathematica": "ma",
"application/mathml+xml": "mathml",
"application/mbox": "mbox",
"application/mediaservercontrol+xml": "mscml",
"application/metalink+xml": "metalink",
"application/metalink4+xml": "meta4",
"application/mets+xml": "mets",
"application/mods+xml": "mods",
"application/mp21": "mp21",
"application/mp4": "mp4s",
"application/msword": "doc",
"application/mxf": "mxf",
"application/octet-stream": "bin",
"application/oda": "oda",
"application/oebps-package+xml": "opf",
"application/ogg": "ogx",
"application/omdoc+xml": "omdoc",
"application/onenote": "onetoc",
"application/oxps": "oxps",
"application/patch-ops-error+xml": "xer",
"application/pdf": "pdf",
"application/pgp-encrypted": "pgp",
"application/pgp-signature": "asc",
"application/pics-rules": "prf",
"application/pkcs10": "p10",
"application/pkcs7-mime": "p7m",
"application/pkcs7-signature": "p7s",
"application/pkcs8": "p8",
"application/pkix-attr-cert": "ac",
"application/pkix-cert": "cer",
"application/pkix-crl": "crl",
"application/pkix-pkipath": "pkipath",
"application/pkixcmp": "pki",
"application/pls+xml": "pls",
"application/postscript": "ps",
"application/prs.cww": "cww",
"application/pskc+xml": "pskcxml",
"application/rdf+xml": "rdf",
"application/reginfo+xml": "rif",
"application/relax-ng-compact-syntax": "rnc",
"application/resource-lists+xml": "rl",
"application/resource-lists-diff+xml": "rld",
"application/rls-services+xml": "rs",
"application/rpki-ghostbusters": "gbr",
"application/rpki-manifest": "mft",
"application/rpki-roa": "roa",
"application/rsd+xml": "rsd",
"application/rss+xml": "rss",
"application/rtf": "rtf",
"application/sbml+xml": "sbml",
"application/scvp-cv-request": "scq",
"application/scvp-cv-response": "scs",
"application/scvp-vp-request": "spq",
"application/scvp-vp-response": "spp",
"application/sdp": "sdp",
"application/set-payment-initiation": "setpay",
"application/set-registration-initiation": "setreg",
"application/shf+xml": "shf",
"application/smil+xml": "smil",
"application/sparql-query": "rq",
"application/sparql-results+xml": "srx",
"application/srgs": "gram",
"application/srgs+xml": "grxml",
"application/sru+xml": "sru",
"application/ssdl+xml": "ssdl",
"application/ssml+xml": "ssml",
"application/tei+xml": "tei",
"application/thraud+xml": "tfi",
"application/timestamped-data": "tsd",
"application/vnd.3gpp.pic-bw-large": "plb",
"application/vnd.3gpp.pic-bw-small": "psb",
"application/vnd.3gpp.pic-bw-var": "pvb",
"application/vnd.3gpp2.tcap": "tcap",
"application/vnd.3m.post-it-notes": "pwn",
"application/vnd.accpac.simply.aso": "aso",
"application/vnd.accpac.simply.imp": "imp",
"application/vnd.acucobol": "acu",
"application/vnd.acucorp": "atc acutc",
"application/vnd.adobe.air-application-installer-package+zip": "air",
"application/vnd.adobe.formscentral.fcdt": "fcdt",
"application/vnd.adobe.fxp": "fxp",
"application/vnd.adobe.xdp+xml": "xdp",
"application/vnd.adobe.xfdf": "xfdf",
"application/vnd.ahead.space": "ahead",
"application/vnd.airzip.filesecure.azf": "azf",
"application/vnd.airzip.filesecure.azs": "azs",
"application/vnd.amazon.ebook": "azw",
"application/vnd.americandynamics.acc": "acc",
"application/vnd.amiga.ami": "ami",
"application/vnd.android.package-archive": "apk",
"application/vnd.anser-web-certificate-issue-initiation": "cii",
"application/vnd.anser-web-funds-transfer-initiation": "fti",
"application/vnd.antix.game-component": "atx",
"application/vnd.apple.installer+xml": "mpkg",
"application/vnd.apple.mpegurl": "m3u8",
"application/vnd.aristanetworks.swi": "swi",
"application/vnd.astraea-software.iota": "iota",
"application/vnd.audiograph": "aep",
"application/vnd.blueice.multipass": "mpm",
"application/vnd.bmi": "bmi",
"application/vnd.businessobjects": "rep",
"application/vnd.chemdraw+xml": "cdxml",
"application/vnd.chipnuts.karaoke-mmd": "mmd",
"application/vnd.cinderella": "cdy",
"application/vnd.claymore": "cla",
"application/vnd.cloanto.rp9": "rp9",
"application/vnd.clonk.c4group": "c4g",
"application/vnd.cluetrust.cartomobile-config": "c11amc",
"application/vnd.cluetrust.cartomobile-config-pkg": "c11amz",
"application/vnd.commonspace": "csp",
"application/vnd.contact.cmsg": "cdbcmsg",
"application/vnd.cosmocaller": "cmc",
"application/vnd.crick.clicker": "clkx",
"application/vnd.crick.clicker.keyboard": "clkk",
"application/vnd.crick.clicker.palette": "clkp",
"application/vnd.crick.clicker.template": "clkt",
"application/vnd.crick.clicker.wordbank": "clkw",
"application/vnd.criticaltools.wbs+xml": "wbs",
"application/vnd.ctc-posml": "pml",
"application/vnd.cups-ppd": "ppd",
"application/vnd.curl.car": "car",
"application/vnd.curl.pcurl": "pcurl",
"application/vnd.dart": "dart",
"application/vnd.data-vision.rdz": "rdz",
"application/vnd.dece.data": "uvf",
"application/vnd.dece.ttml+xml": "uvt",
"application/vnd.dece.unspecified": "uvx",
"application/vnd.dece.zip": "uvz",
"application/vnd.denovo.fcselayout-link": "fe_launch",
"application/vnd.dna": "dna",
"application/vnd.dolby.mlp": "mlp",
"application/vnd.dpgraph": "dpg",
"application/vnd.dreamfactory": "dfac",
"application/vnd.ds-keypoint": "kpxx",
"application/vnd.dvb.ait": "ait",
"application/vnd.dvb.service": "svc",
"application/vnd.dynageo": "geo",
"application/vnd.ecowin.chart": "mag",
"application/vnd.enliven": "nml",
"application/vnd.epson.esf": "esf",
"application/vnd.epson.msf": "msf",
"application/vnd.epson.quickanime": "qam",
"application/vnd.epson.salt": "slt",
"application/vnd.epson.ssf": "ssf",
"application/vnd.eszigno3+xml": "es3",
"application/vnd.ezpix-album": "ez2",
"application/vnd.ezpix-package": "ez3",
"application/vnd.fdf": "fdf",
"application/vnd.fdsn.mseed": "mseed",
"application/vnd.fdsn.seed": "seed",
"application/vnd.flographit": "gph",
"application/vnd.fluxtime.clip": "ftc",
"application/vnd.framemaker": "fm",
"application/vnd.frogans.fnc": "fnc",
"application/vnd.frogans.ltf": "ltf",
"application/vnd.fsc.weblaunch": "fsc",
"application/vnd.fujitsu.oasys": "oas",
"application/vnd.fujitsu.oasys2": "oa2",
"application/vnd.fujitsu.oasys3": "oa3",
"application/vnd.fujitsu.oasysgp": "fg5",
"application/vnd.fujitsu.oasysprs": "bh2",
"application/vnd.fujixerox.ddd": "ddd",
"application/vnd.fujixerox.docuworks": "xdw",
"application/vnd.fujixerox.docuworks.binder": "xbd",
"application/vnd.fuzzysheet": "fzs",
"application/vnd.genomatix.tuxedo": "txd",
"application/vnd.geogebra.file": "ggb",
"application/vnd.geogebra.tool": "ggt",
"application/vnd.geometry-explorer": "gex gre",
"application/vnd.geonext": "gxt",
"application/vnd.geoplan": "g2w",
"application/vnd.geospace": "g3w",
"application/vnd.gmx": "gmx",
"application/vnd.google-earth.kml+xml": "kml",
"application/vnd.google-earth.kmz": "kmz",
"application/vnd.grafeq": "gqf gqs",
"application/vnd.groove-account": "gac",
"application/vnd.groove-help": "ghf",
"application/vnd.groove-identity-message": "gim",
"application/vnd.groove-injector": "grv",
"application/vnd.groove-tool-message": "gtm",
"application/vnd.groove-tool-template": "tpl",
"application/vnd.groove-vcard": "vcg",
"application/vnd.hal+xml": "hal",
"application/vnd.handheld-entertainment+xml": "zmm",
"application/vnd.hbci": "hbci",
"application/vnd.hhe.lesson-player": "les",
"application/vnd.hp-hpgl": "hpgl",
"application/vnd.hp-hpid": "hpid",
"application/vnd.hp-hps": "hps",
"application/vnd.hp-jlyt": "jlt",
"application/vnd.hp-pcl": "pcl",
"application/vnd.hp-pclxl": "pclxl",
"application/vnd.hydrostatix.sof-data": "sfd-hdstx",
"application/vnd.ibm.minipay": "mpy",
"application/vnd.ibm.modcap": "afp",
"application/vnd.ibm.rights-management": "irm",
"application/vnd.ibm.secure-container": "sc",
"application/vnd.iccprofile": "icc icm",
"application/vnd.igloader": "igl",
"application/vnd.immervision-ivp": "ivp",
"application/vnd.immervision-ivu": "ivu",
"application/vnd.insors.igm": "igm",
"application/vnd.intercon.formnet": "xpw",
"application/vnd.intergeo": "i2g",
"application/vnd.intu.qbo": "qbo",
"application/vnd.intu.qfx": "qfx",
"application/vnd.ipunplugged.rcprofile": "rcprofile",
"application/vnd.irepository.package+xml": "irp",
"application/vnd.is-xpr": "xpr",
"application/vnd.isac.fcs": "fcs",
"application/vnd.jam": "jam",
"application/vnd.jcp.javame.midlet-rms": "rms",
"application/vnd.jisp": "jisp",
"application/vnd.joost.joda-archive": "joda",
"application/vnd.kahootz": "ktz",
"application/vnd.kde.karbon": "karbon",
"application/vnd.kde.kchart": "chrt",
"application/vnd.kde.kformula": "kfo",
"application/vnd.kde.kivio": "flw",
"application/vnd.kde.kontour": "kon",
"application/vnd.kde.kpresenter": "kpr",
"application/vnd.kde.kspread": "ksp",
"application/vnd.kde.kword": "kwd",
"application/vnd.kenameaapp": "htke",
"application/vnd.kidspiration": "kia",
"application/vnd.kinar": "kne knp",
"application/vnd.koan": "skp",
"application/vnd.kodak-descriptor": "sse",
"application/vnd.las.las+xml": "lasxml",
"application/vnd.llamagraphics.life-balance.desktop": "lbd",
"application/vnd.llamagraphics.life-balance.exchange+xml": "lbe",
"application/vnd.lotus-1-2-3": "123",
"application/vnd.lotus-approach": "apr",
"application/vnd.lotus-freelance": "pre",
"application/vnd.lotus-notes": "nsf",
"application/vnd.lotus-organizer": "org",
"application/vnd.lotus-screencam": "scm",
"application/vnd.lotus-wordpro": "lwp",
"application/vnd.macports.portpkg": "portpkg",
"application/vnd.mcd": "mcd",
"application/vnd.medcalcdata": "mc1",
"application/vnd.mediastation.cdkey": "cdkey",
"application/vnd.mfer": "mwf",
"application/vnd.mfmp": "mfm",
"application/vnd.micrografx.flo": "flo",
"application/vnd.micrografx.igx": "igx",
"application/vnd.mif": "mif",
"application/vnd.mobius.daf": "daf",
"application/vnd.mobius.dis": "dis",
"application/vnd.mobius.mbk": "mbk",
"application/vnd.mobius.mqy": "mqy",
"application/vnd.mobius.msl": "msl",
"application/vnd.mobius.plc": "plc",
"application/vnd.mobius.txf": "txf",
"application/vnd.mophun.application": "mpn",
"application/vnd.mophun.certificate": "mpc",
"application/vnd.mozilla.xul+xml": "xul",
"application/vnd.ms-artgalry": "cil",
"application/vnd.ms-cab-compressed": "cab",
"application/vnd.ms-excel": "xls",
"application/vnd.ms-excel.addin.macroenabled.12": "xlam",
"application/vnd.ms-excel.sheet.binary.macroenabled.12": "xlsb",
"application/vnd.ms-excel.sheet.macroenabled.12": "xlsm",
"application/vnd.ms-excel.template.macroenabled.12": "xltm",
"application/vnd.ms-fontobject": "eot",
"application/vnd.ms-htmlhelp": "chm",
"application/vnd.ms-ims": "ims",
"application/vnd.ms-lrm": "lrm",
"application/vnd.ms-officetheme": "thmx",
"application/vnd.ms-pki.seccat": "cat",
"application/vnd.ms-pki.stl": "stl",
"application/vnd.ms-powerpoint": "ppt pps pot",
"application/vnd.ms-powerpoint.addin.macroenabled.12": "ppam",
"application/vnd.ms-powerpoint.presentation.macroenabled.12": "pptm",
"application/vnd.ms-powerpoint.slide.macroenabled.12": "sldm",
"application/vnd.ms-powerpoint.slideshow.macroenabled.12": "ppsm",
"application/vnd.ms-powerpoint.template.macroenabled.12": "potm",
"application/vnd.ms-project": "mpp mpt",
"application/vnd.ms-word.document.macroenabled.12": "docm",
"application/vnd.ms-word.template.macroenabled.12": "dotm",
"application/vnd.ms-works": "wps",
"application/vnd.ms-wpl": "wpl",
"application/vnd.ms-xpsdocument": "xps",
"application/vnd.mseq": "mseq",
"application/vnd.musician": "mus",
"application/vnd.muvee.style": "msty",
"application/vnd.mynfc": "taglet",
"application/vnd.neurolanguage.nlu": "nlu",
"application/vnd.nitf": "ntf nitf",
"application/vnd.noblenet-directory": "nnd",
"application/vnd.noblenet-sealer": "nns",
"application/vnd.noblenet-web": "nnw",
"application/vnd.nokia.n-gage.data": "ngdat",
"application/vnd.nokia.n-gage.symbian.install": "n-gage",
"application/vnd.nokia.radio-preset": "rpst",
"application/vnd.nokia.radio-presets": "rpss",
"application/vnd.novadigm.edm": "edm",
"application/vnd.novadigm.edx": "edx",
"application/vnd.novadigm.ext": "ext",
"application/vnd.oasis.opendocument.chart": "odc",
"application/vnd.oasis.opendocument.chart-template": "otc",
"application/vnd.oasis.opendocument.database": "odb",
"application/vnd.oasis.opendocument.formula": "odf",
"application/vnd.oasis.opendocument.formula-template": "odft",
"application/vnd.oasis.opendocument.graphics": "odg",
"application/vnd.oasis.opendocument.graphics-template": "otg",
"application/vnd.oasis.opendocument.image": "odi",
"application/vnd.oasis.opendocument.image-template": "oti",
"application/vnd.oasis.opendocument.presentation": "odp",
"application/vnd.oasis.opendocument.presentation-template": "otp",
"application/vnd.oasis.opendocument.spreadsheet": "ods",
"application/vnd.oasis.opendocument.spreadsheet-template": "ots",
"application/vnd.oasis.opendocument.text": "odt",
"application/vnd.oasis.opendocument.text-master": "odm",
"application/vnd.oasis.opendocument.text-template": "ott",
"application/vnd.oasis.opendocument.text-web": "oth",
"application/vnd.olpc-sugar": "xo",
"application/vnd.oma.dd2+xml": "dd2",
"application/vnd.openofficeorg.extension": "oxt",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
"application/vnd.openxmlformats-officedocument.presentationml.slide": "sldx",
"application/vnd.openxmlformats-officedocument.presentationml.slideshow": "ppsx",
"application/vnd.openxmlformats-officedocument.presentationml.template": "potx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.template": "xltx",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
"application/vnd.openxmlformats-officedocument.wordprocessingml.template": "dotx",
"application/vnd.osgeo.mapguide.package": "mgp",
"application/vnd.osgi.dp": "dp",
"application/vnd.osgi.subsystem": "esa",
"application/vnd.palm": "pdb pqa oprc",
"application/vnd.pawaafile": "paw",
"application/vnd.pg.format": "str",
"application/vnd.pg.osasli": "ei6",
"application/vnd.picsel": "efif",
"application/vnd.pmi.widget": "wg",
"application/vnd.pocketlearn": "plf",
"application/vnd.powerbuilder6": "pbd",
"application/vnd.previewsystems.box": "box",
"application/vnd.proteus.magazine": "mgz",
"application/vnd.publishare-delta-tree": "qps",
"application/vnd.pvi.ptid1": "ptid",
"application/vnd.quark.quarkxpress": "qxd",
"application/vnd.realvnc.bed": "bed",
"application/vnd.recordare.musicxml": "mxl",
"application/vnd.recordare.musicxml+xml": "musicxml",
"application/vnd.rig.cryptonote": "cryptonote",
"application/vnd.rim.cod": "cod",
"application/vnd.rn-realmedia": "rm",
"application/vnd.rn-realmedia-vbr": "rmvb",
"application/vnd.route66.link66+xml": "link66",
"application/vnd.sailingtracker.track": "st",
"application/vnd.seemail": "see",
"application/vnd.sema": "sema",
"application/vnd.semd": "semd",
"application/vnd.semf": "semf",
"application/vnd.shana.informed.formdata": "ifm",
"application/vnd.shana.informed.formtemplate": "itp",
"application/vnd.shana.informed.interchange": "iif",
"application/vnd.shana.informed.package": "ipk",
"application/vnd.simtech-mindmapper": "twd",
"application/vnd.smaf": "mmf",
"application/vnd.smart.teacher": "teacher",
"application/vnd.solent.sdkm+xml": "sdkm",
"application/vnd.spotfire.dxp": "dxp",
"application/vnd.spotfire.sfs": "sfs",
"application/vnd.stardivision.calc": "sdc",
"application/vnd.stardivision.draw": "sda",
"application/vnd.stardivision.impress": "sdd",
"application/vnd.stardivision.math": "smf",
"application/vnd.stardivision.writer": "sdw",
"application/vnd.stardivision.writer-global": "sgl",
"application/vnd.stepmania.package": "smzip",
"application/vnd.stepmania.stepchart": "sm",
"application/vnd.sun.xml.calc": "sxc",
"application/vnd.sun.xml.calc.template": "stc",
"application/vnd.sun.xml.draw": "sxd",
"application/vnd.sun.xml.draw.template": "std",
"application/vnd.sun.xml.impress": "sxi",
"application/vnd.sun.xml.impress.template": "sti",
"application/vnd.sun.xml.math": "sxm",
"application/vnd.sun.xml.writer": "sxw",
"application/vnd.sun.xml.writer.global": "sxg",
"application/vnd.sun.xml.writer.template": "stw",
"application/vnd.sus-calendar": "sus",
"application/vnd.svd": "svd",
"application/vnd.symbian.install": "sis",
"application/vnd.syncml+xml": "xsm",
"application/vnd.syncml.dm+wbxml": "bdm",
"application/vnd.syncml.dm+xml": "xdm",
"application/vnd.tao.intent-module-archive": "tao",
"application/vnd.tcpdump.pcap": "pcap",
"application/vnd.tmobile-livetv": "tmo",
"application/vnd.trid.tpt": "tpt",
"application/vnd.triscape.mxs": "mxs",
"application/vnd.trueapp": "tra",
"application/vnd.ufdl": "ufdl",
"application/vnd.uiq.theme": "utz",
"application/vnd.umajin": "umj",
"application/vnd.unity": "unityweb",
"application/vnd.uoml+xml": "uoml",
"application/vnd.vcx": "vcx",
"application/vnd.visio": "vsd",
"application/vnd.visionary": "vis",
"application/vnd.vsf": "vsf",
"application/vnd.wap.wbxml": "wbxml",
"application/vnd.wap.wmlc": "wmlc",
"application/vnd.wap.wmlscriptc": "wmlsc",
"application/vnd.webturbo": "wtb",
"application/vnd.wolfram.player": "nbp",
"application/vnd.wordperfect": "wpd",
"application/vnd.wqd": "wqd",
"application/vnd.wt.stf": "stf",
"application/vnd.xara": "xar",
"application/vnd.xfdl": "xfdl",
"application/vnd.yamaha.hv-dic": "hvd",
"application/vnd.yamaha.hv-script": "hvs",
"application/vnd.yamaha.hv-voice": "hvp",
"application/vnd.yamaha.openscoreformat": "osf",
"application/vnd.yamaha.openscoreformat.osfpvg+xml": "osfpvg",
"application/vnd.yamaha.smaf-audio": "saf",
"application/vnd.yamaha.smaf-phrase": "spf",
"application/vnd.yellowriver-custom-menu": "cmp",
"application/vnd.zul": "zir",
"application/vnd.zzazz.deck+xml": "zaz",
"application/voicexml+xml": "vxml",
"application/widget": "wgt",
"application/winhlp": "hlp",
"application/wsdl+xml": "wsdl",
"application/wspolicy+xml": "wspolicy",
"application/x-7z-compressed": "7z",
"application/x-abiword": "abw",
"application/x-ace-compressed": "ace",
"application/x-apple-diskimage": "dmg",
"application/x-authorware-bin": "aab",
"application/x-authorware-map": "aam",
"application/x-authorware-seg": "aas",
"application/x-bcpio": "bcpio",
"application/x-bittorrent": "torrent",
"application/x-blorb": "blb",
"application/x-bzip": "bz",
"application/x-bzip2": "bz2",
"application/x-cbr": "cbr",
"application/x-cdlink": "vcd",
"application/x-cfs-compressed": "cfs",
"application/x-chat": "chat",
"application/x-chess-pgn": "pgn",
"application/x-conference": "nsc",
"application/x-cpio": "cpio",
"application/x-csh": "csh",
"application/x-debian-package": "deb",
"application/x-dgc-compressed": "dgc",
"application/x-director": "dir",
"application/x-doom": "wad",
"application/x-dtbncx+xml": "ncx",
"application/x-dtbook+xml": "dtb",
"application/x-dtbresource+xml": "res",
"application/x-dvi": "dvi",
"application/x-envoy": "evy",
"application/x-eva": "eva",
"application/x-font-bdf": "bdf",
"application/x-font-ghostscript": "gsf",
"application/x-font-linux-psf": "psf",
"application/x-font-otf": "otf",
"application/x-font-pcf": "pcf",
"application/x-font-snf": "snf",
"application/x-font-ttf": "ttf",
"application/x-font-type1": "pfa",
"application/x-font-woff": "woff",
"application/x-freearc": "arc",
"application/x-futuresplash": "spl",
"application/x-gca-compressed": "gca",
"application/x-glulx": "ulx",
"application/x-gnumeric": "gnumeric",
"application/x-gramps-xml": "gramps",
"application/x-gtar": "gtar",
"application/x-hdf": "hdf",
"application/x-install-instructions": "install",
"application/x-iso9660-image": "iso",
"application/x-java-jnlp-file": "jnlp",
"application/x-latex": "latex",
"application/x-lzh-compressed": "lzh",
"application/x-mie": "mie",
"application/x-mobipocket-ebook": "prc",
"application/x-ms-application": "application",
"application/x-ms-shortcut": "lnk",
"application/x-ms-wmd": "wmd",
"application/x-ms-wmz": "wmz",
"application/x-ms-xbap": "xbap",
"application/x-msaccess": "mdb",
"application/x-msbinder": "obd",
"application/x-mscardfile": "crd",
"application/x-msclip": "clp",
"application/x-msdownload": "exe",
"application/x-msmediaview": "mvb",
"application/x-msmetafile": "wmf",
"application/x-msmoney": "mny",
"application/x-mspublisher": "pub",
"application/x-msschedule": "scd",
"application/x-msterminal": "trm",
"application/x-mswrite": "wri",
"application/x-netcdf": "nc",
"application/x-nzb": "nzb",
"application/x-pkcs12": "p12",
"application/x-pkcs7-certificates": "p7b",
"application/x-pkcs7-certreqresp": "p7r",
"application/x-rar-compressed": "rar",
"application/x-research-info-systems": "ris",
"application/x-sh": "sh",
"application/x-shar": "shar",
"application/x-shockwave-flash": "swf",
"application/x-silverlight-app": "xap",
"application/x-sql": "sql",
"application/x-stuffit": "sit",
"application/x-stuffitx": "sitx",
"application/x-subrip": "srt",
"application/x-sv4cpio": "sv4cpio",
"application/x-sv4crc": "sv4crc",
"application/x-t3vm-image": "t3",
"application/x-tads": "gam",
"application/x-tar": "tar",
"application/x-tcl": "tcl",
"application/x-tex": "tex",
"application/x-tex-tfm": "tfm",
"application/x-texinfo": "texinfo",
"application/x-tgif": "obj",
"application/x-ustar": "ustar",
"application/x-wais-source": "src",
"application/x-x509-ca-cert": "der",
"application/x-xfig": "fig",
"application/x-xliff+xml": "xlf",
"application/x-xpinstall": "xpi",
"application/x-xz": "xz",
"application/x-zmachine": "z1",
"application/xaml+xml": "xaml",
"application/xcap-diff+xml": "xdf",
"application/xenc+xml": "xenc",
"application/xhtml+xml": "xhtml",
"application/xml": "xml",
"application/xml-dtd": "dtd",
"application/xop+xml": "xop",
"application/xproc+xml": "xpl",
"application/xslt+xml": "xslt",
"application/xspf+xml": "xspf",
"application/xv+xml": "mxml",
"application/yang": "yang",
"application/yin+xml": "yin",
"application/zip": "zip",
"audio/adpcm": "adp",
"audio/basic": "au",
"audio/midi": "mid",
"audio/mp4": "mp4a",
"audio/mpeg": "mpga",
"audio/ogg": "oga",
"audio/s3m": "s3m",
"audio/silk": "sil",
"audio/vnd.dece.audio": "uva",
"audio/vnd.digital-winds": "eol",
"audio/vnd.dra": "dra",
"audio/vnd.dts": "dts",
"audio/vnd.dts.hd": "dtshd",
"audio/vnd.lucent.voice": "lvp",
"audio/vnd.ms-playready.media.pya": "pya",
"audio/vnd.nuera.ecelp4800": "ecelp4800",
"audio/vnd.nuera.ecelp7470": "ecelp7470",
"audio/vnd.nuera.ecelp9600": "ecelp9600",
"audio/vnd.rip": "rip",
"audio/webm": "weba",
"audio/x-aac": "aac",
"audio/x-aiff": "aif",
"audio/x-caf": "caf",
"audio/x-flac": "flac",
"audio/x-matroska": "mka",
"audio/x-mpegurl": "m3u",
"audio/x-ms-wax": "wax",
"audio/x-ms-wma": "wma",
"audio/x-pn-realaudio": "ram",
"audio/x-pn-realaudio-plugin": "rmp",
"audio/x-wav": "wav",
"audio/xm": "xm",
"chemical/x-cdx": "cdx",
"chemical/x-cif": "cif",
"chemical/x-cmdf": "cmdf",
"chemical/x-cml": "cml",
"chemical/x-csml": "csml",
"chemical/x-xyz": "xyz",
"image/bmp": "bmp",
"image/cgm": "cgm",
"image/g3fax": "g3",
"image/gif": "gif",
"image/ief": "ief",
"image/jpeg": "jpg",
"image/ktx": "ktx",
"image/png": "png",
"image/prs.btif": "btif",
"image/sgi": "sgi",
"image/svg+xml": "svg svgz",
"image/tiff": "tiff tif",
"image/vnd.adobe.photoshop": "psd",
"image/vnd.dece.graphic": "uvi",
"image/vnd.dvb.subtitle": "sub",
"image/vnd.djvu": "djvu",
"image/vnd.dwg": "dwg",
"image/vnd.dxf": "dxf",
"image/vnd.fastbidsheet": "fbs",
"image/vnd.fpx": "fpx",
"image/vnd.fst": "fst",
"image/vnd.fujixerox.edmics-mmr": "mmr",
"image/vnd.fujixerox.edmics-rlc": "rlc",
"image/vnd.ms-modi": "mdi",
"image/vnd.ms-photo": "wdp",
"image/vnd.net-fpx": "npx",
"image/vnd.wap.wbmp": "wbmp",
"image/vnd.xiff": "xif",
"image/webp": "webp",
"image/x-3ds": "3ds",
"image/x-cmu-raster": "ras",
"image/x-cmx": "cmx",
"image/x-freehand": "fh",
"image/x-icon": "ico",
"image/x-mrsid-image": "sid",
"image/x-pcx": "pcx",
"image/x-pict": "pic",
"image/x-portable-anymap": "pnm",
"image/x-portable-bitmap": "pbm",
"image/x-portable-graymap": "pgm",
"image/x-portable-pixmap": "ppm",
"image/x-rgb": "rgb",
"image/x-tga": "tga",
"image/x-xbitmap": "xbm",
"image/x-xpixmap": "xpm",
"image/x-xwindowdump": "xwd",
"message/rfc822": "eml mime",
"model/iges": "igs",
"model/mesh": "mesh",
"model/vnd.collada+xml": "dae",
"model/vnd.dwf": "dwf",
"model/vnd.gdl": "gdl",
"model/vnd.gtw": "gtw",
"model/vnd.mts": "mts",
"model/vnd.vtu": "vtu",
"model/vrml": "wrl vrml",
"model/x3d+binary": "x3db",
"model/x3d+vrml": "x3dv",
"model/x3d+xml": "x3d",
"text/cache-manifest": "appcache",
"text/calendar": "ics ifb",
"text/css": "css",
"text/csv": "csv",
"text/html": "html",
"text/n3": "n3",
"text/plain": "txt",
"text/prs.lines.tag": "dsc",
"text/richtext": "rtx",
"text/sgml": "sgml sgm",
"text/tab-separated-values": "tsv",
"text/troff": "t",
"text/turtle": "ttl",
"text/uri-list": "uri",
"text/vcard": "vcard",
"text/vnd.curl": "curl",
"text/vnd.curl.dcurl": "dcurl",
"text/vnd.curl.scurl": "scurl",
"text/vnd.curl.mcurl": "mcurl",
"text/vnd.dvb.subtitle": "sub",
"text/vnd.fly": "fly",
"text/vnd.fmi.flexstor": "flx",
"text/vnd.graphviz": "gv",
"text/vnd.in3d.3dml": "3dml",
"text/vnd.in3d.spot": "spot",
"text/vnd.sun.j2me.app-descriptor": "jad",
"text/vnd.wap.wml": "wml",
"text/vnd.wap.wmlscript": "wmls",
"text/x-asm": "s asm",
"text/x-c": "c",
"text/x-fortran": "f",
"text/x-java-source": "java",
"text/x-opml": "opml",
"text/x-pascal": "p pas",
"text/x-nfo": "nfo",
"text/x-shellscript": "sh",
"text/x-setext": "etx",
"text/x-sfv": "sfv",
"text/x-tex": "tex",
"text/x-uuencode": "uu",
"text/x-vcalendar": "vcs",
"text/x-vcard": "vcf",
"video/3gpp": "3gp",
"video/3gpp2": "3g2",
"video/h261": "h261",
"video/h263": "h263",
"video/h264": "h264",
"video/jpeg": "jpgv",
"video/jpm": "jpm",
"video/mj2": "mj2",
"video/mp4": "mp4",
"video/mpeg": "mpeg",
"video/ogg": "ogv",
"video/quicktime": "qt",
"video/vnd.dece.hd": "uvh",
"video/vnd.dece.mobile": "uvm",
"video/vnd.dece.pd": "uvp",
"video/vnd.dece.sd": "uvs",
"video/vnd.dece.video": "uvv",
"video/vnd.dvb.file": "dvb",
"video/vnd.fvt": "fvt",
"video/vnd.mpegurl": "m4u",
"video/vnd.ms-playready.media.pyv": "pyv",
"video/vnd.uvvu.mp4": "uvvu",
"video/vnd.vivo": "viv",
"video/webm": "webm",
"video/x-f4v": "f4v",
"video/x-fli": "fli",
"video/x-flv": "flv",
"video/x-m4v": "m4v",
"video/x-matroska": "mkv",
"video/x-mng": "mng",
"video/x-ms-asf": "asf",
"video/x-ms-vob": "vob",
"video/x-ms-wm": "wm",
"video/x-ms-wmv": "wmv",
"video/x-ms-wmx": "wmx",
"video/x-ms-wvx": "wvx",
"video/x-msvideo": "avi",
"video/x-sgi-movie": "movie",
"video/x-smv": "smv",
"x-conference/x-cooltalk": "ice",
}
var extensionToAce = map[string]string{
"c": "c_cpp",
"h": "c_cpp",
"cpp": "c_cpp",
"clj": "clojure",
"coffee": "coffee",
"cfc": "coldfusion",
"cs": "csharp",
"sh": "sh",
"bash": "sh",
"css": "css",
"go": "golang",
"diff": "diff",
"html": "html",
"xml": "xml",
"ini": "ini",
"java": "java",
"js": "javascript",
"json": "json",
"jsp": "jsp",
"tex": "latex",
"lisp": "lisp",
"less": "less",
"lua": "lua",
"md": "markdown",
"ocaml": "ocaml",
"tcl": "tcl",
"yaml": "yaml",
"php": "php",
"pl": "perl",
"py": "python",
"rb": "ruby",
"sql": "sql",
"apache": "apache",
"cmake": "cmake",
"bat": "dos",
"scala": "scala",
"txt": "text",
}
var extensionToHl = map[string]string{
"c": "cpp",
"h": "cpp",
"cpp": "c_cpp",
"clj": "clojure",
"coffee": "coffee",
"cfc": "coldfusion",
"cs": "csharp",
"sh": "sh",
"bash": "sh",
"css": "css",
"go": "go",
"diff": "diff",
"html": "html",
"htm": "html",
"ini": "ini",
"java": "java",
"js": "javascript",
"json": "json",
"jsp": "jsp",
"tex": "latex",
"lisp": "lisp",
"less": "less",
"lua": "lua",
"ocaml": "ocaml",
"tcl": "tcl",
"nginx": "nginx",
"xml": "xml",
"yaml": "yaml",
"php": "php",
"pl": "perl",
"py": "python",
"rb": "ruby",
"sql": "sql",
"apache": "apache",
"cmake": "cmake",
"bat": "dos",
"scala": "scala",
"story": "story",
"txt": "text",
"ahk": "autohotkey",
"apache": "apache",
"applescript": "applescript",
"bas": "basic",
"bash": "sh",
"bat": "dos",
"c": "cpp",
"cfc": "coldfusion",
"clj": "clojure",
"cmake": "cmake",
"coffee": "coffee",
"cpp": "c_cpp",
"cs": "csharp",
"css": "css",
"d": "d",
"dart": "dart",
"diff": "diff",
"dockerfile": "dockerfile",
"elm": "elm",
"erl": "erlang",
"for": "fortran",
"go": "go",
"h": "cpp",
"htm": "html",
"html": "html",
"ini": "ini",
"java": "java",
"js": "javascript",
"json": "json",
"jsp": "jsp",
"kt": "kotlin",
"less": "less",
"lisp": "lisp",
"lua": "lua",
"m": "objectivec",
"nginx": "nginx",
"ocaml": "ocaml",
"php": "php",
"pl": "perl",
"proto": "protobuf",
"ps": "powershell",
"py": "python",
"rb": "ruby",
"rs": "rust",
"scala": "scala",
"scm": "scheme",
"scpt": "applescript",
"scss": "scss",
"sh": "sh",
"sql": "sql",
"tcl": "tcl",
"tex": "latex",
"toml": "ini",
"ts": "typescript",
"txt": "text",
"xml": "xml",
"yaml": "yaml",
"yml": "yaml",
}