Skip to content

Commit 965e81c

Browse files
committed
Initial commit
1 parent bd88a3b commit 965e81c

File tree

12 files changed

+713
-1
lines changed

12 files changed

+713
-1
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git
2+
.gitignore
3+
.github
4+
.gitattributes
5+
READMETEMPLATE.md
6+
README.md

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear on external disk
35+
.Spotlight-V100
36+
.Trashes
37+
38+
# Directories potentially created on remote AFP share
39+
.AppleDB
40+
.AppleDesktop
41+
Network Trash Folder
42+
Temporary Items
43+
.apdisk

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM lsiobase/alpine.python:3.7
2+
3+
# set version label
4+
ARG BUILD_DATE
5+
ARG VERSION
6+
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
7+
LABEL maintainer="aptalca"
8+
9+
# install packages
10+
RUN \
11+
apk add --no-cache --virtual=build-dependencies \
12+
build-base \
13+
openldap-dev \
14+
python2-dev \
15+
python3-dev && \
16+
pip install --no-cache-dir \
17+
cryptography \
18+
python-ldap && \
19+
echo "**** remove build dependencies ****" && \
20+
apk del --purge \
21+
build-dependencies && \
22+
rm -rf \
23+
/tmp/*
24+
25+
# copy local files
26+
COPY root/ /
27+
28+
# ports and volumes
29+
EXPOSE 8888 9000

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# docker-ldap-auth
1+
[linuxserverurl]: https://linuxserver.io
2+
[forumurl]: https://forum.linuxserver.io
3+
[ircurl]: https://www.linuxserver.io/irc/
4+
[podcasturl]: https://www.linuxserver.io/podcast/
5+
6+
[![linuxserver.io](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/linuxserver_medium.png)][linuxserverurl]
7+
8+
## This is a Container in active development by the [LinuxServer.io][linuxserverurl] team and is not recommended for use by the general public.
9+
10+
If you want to comment\contribute on this container , are looking for support on any of our other work , or are curious about us in general, check out the following.
11+
12+
* [forum.linuxserver.io][forumurl]
13+
* [IRC][ircurl] on freenode at `#linuxserver.io`
14+
* [Podcast][podcasturl] covers everything to do with getting the most from your Linux Server plus a focus on all things Docker and containerisation!
15+

READMETEMPLATE.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
[linuxserverurl]: https://linuxserver.io
2+
[forumurl]: https://forum.linuxserver.io
3+
[ircurl]: https://www.linuxserver.io/irc/
4+
[appurl]: www.example.com
5+
[dockerfileurl]: https://github.com/linuxserver/docker-<container-name>/blob/master/Dockerfile
6+
[hub]: https://hub.docker.com/r/<image-name>/
7+
8+
9+
10+
[![linuxserver.io](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/linuxserver_medium.png?v=4&s=4000)][linuxserverurl]
11+
12+
13+
## Contact information:-
14+
15+
| Type | Address/Details |
16+
| :---: | --- |
17+
| Discord | [Discord](https://discord.gg/YWrKVTn) |
18+
| IRC | freenode at `#linuxserver.io` more information at:- [IRC][ircurl]
19+
| Forum | [Linuserver.io forum][forumurl] |
20+
21+
&nbsp;
22+
&nbsp;
23+
24+
The [LinuxServer.io][linuxserverurl] team brings you another image release featuring :-
25+
26+
+ regular and timely application updates
27+
+ easy user mappings
28+
+ custom base image with s6 overlay
29+
+ weekly base OS updates with common layers across the entire LinuxServer.io ecosystem to minimise space usage, down time and bandwidth
30+
+ security updates
31+
32+
# <image-name>
33+
34+
[![Dockerfile-link](https://raw.githubusercontent.com/linuxserver/docker-templates/master/linuxserver.io/img/Dockerfile-Link-green.png)][dockerfileurl]
35+
36+
Provide a short, concise description of the application. No more than two SHORT paragraphs. Link to sources where possible and include an image illustrating your point if necessary. Point users to the original applications website, as that's the best place to get support - not here.
37+
38+
`IMPORTANT, replace all instances of <image-name> with the correct dockerhub repo (ie linuxserver/plex) and <container-name> information (ie, plex) and make sure to update the block at the top of this file containing app specific urls, dockerhub url and dockerfile url etc.`
39+
40+
&nbsp;
41+
42+
## Usage
43+
44+
```
45+
docker create \
46+
--name=<container-name> \
47+
-v <path to data>:/config \
48+
-e PGID=<gid> -e PUID=<uid> \
49+
-p 1234:1234 \
50+
<image-name>
51+
```
52+
53+
&nbsp;
54+
55+
## Parameters
56+
57+
The parameters are split into two halves, separated by a colon, the left hand side representing the host and the right the container side.
58+
For example with a port -p external:internal - what this shows is the port mapping from internal to external of the container.
59+
So -p 8080:80 would expose port 80 from inside the container to be accessible from the host's IP on port 8080
60+
http://192.168.x.x:8080 would show you what's running INSIDE the container on port 80.
61+
62+
63+
64+
| Parameter | Function |
65+
| :---: | --- |
66+
| `-p 1234` | the port(s) |
67+
| `-v /config` | explain what lives here |
68+
| `-e PGID` | for GroupID, see below for explanation |
69+
| `-e PUID` | for UserID, see below for explanation |
70+
71+
&nbsp;
72+
73+
## User / Group Identifiers
74+
75+
Sometimes when using volumes (`-v` flags) permissions issues can arise between the host OS and the container, we avoid this issue by allowing you to specify the user `PUID` and group `PGID`.
76+
77+
Ensure any volume directories on the host are owned by the same user you specify and it will "just work" &trade;.
78+
79+
In this instance `PUID=1001` and `PGID=1001`, to find yours use `id user` as below:
80+
81+
```
82+
$ id <dockeruser>
83+
uid=1001(dockeruser) gid=1001(dockergroup) groups=1001(dockergroup)
84+
```
85+
86+
&nbsp;
87+
88+
## Setting up the application
89+
90+
Insert a basic user guide here to get a n00b up and running with the software inside the container. DELETE ME
91+
92+
93+
&nbsp;
94+
95+
## Container access and information.
96+
97+
| Function | Command |
98+
| :--- | :--- |
99+
| Shell access (live container) | `docker exec -it <container-name> /bin/bash` |
100+
| Realtime container logs | `docker logs -f <container-name>` |
101+
| Container version | `docker inspect -f '{{ index .Config.Labels "build_version" }}' <container-name>` |
102+
| Image version | `docker inspect -f '{{ index .Config.Labels "build_version" }}' <image-name>` |
103+
| Dockerfile | [Dockerfile][dockerfileurl] |
104+
105+
&nbsp;
106+
107+
## Changelog
108+
109+
| Date | Changes |
110+
| :---: | --- |
111+
| dd.MM.yy | Initial Release. |

root/app/fernet-key.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
''''which python2 >/dev/null && exec python2 "$0" "$@" # '''
3+
''''which python >/dev/null && exec python "$0" "$@" # '''
4+
5+
from cryptography.fernet import Fernet
6+
7+
key = Fernet.generate_key()
8+
print key

root/app/ldap-backend-app.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/sh
2+
''''which python2 >/dev/null && exec python2 "$0" "$@" # '''
3+
''''which python >/dev/null && exec python "$0" "$@" # '''
4+
5+
# Copyright (C) 2014-2015 Nginx, Inc.
6+
# Copyright (C) 2018 LinuxServer.io
7+
8+
# Example of an application working on port 9000
9+
# To interact with nginx-ldap-auth-daemon this application
10+
# 1) accepts GET requests on /login and responds with a login form
11+
# 2) accepts POST requests on /login, sets a cookie, and responds with redirect
12+
13+
import sys, os, signal, base64, Cookie, cgi, urlparse
14+
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
15+
from cryptography.fernet import Fernet
16+
17+
Listen = ('localhost', 9000)
18+
19+
import threading
20+
from SocketServer import ThreadingMixIn
21+
class AuthHTTPServer(ThreadingMixIn, HTTPServer):
22+
pass
23+
24+
class AppHandler(BaseHTTPRequestHandler):
25+
26+
def do_GET(self):
27+
28+
url = urlparse.urlparse(self.path)
29+
30+
if url.path.startswith("/login"):
31+
return self.auth_form()
32+
33+
self.send_response(200)
34+
self.end_headers()
35+
self.wfile.write('Hello, world! Requested URL: ' + self.path + '\n')
36+
37+
38+
# send login form html
39+
def auth_form(self, target = None):
40+
41+
# try to get target location from header
42+
if target == None:
43+
target = self.headers.get('X-Target')
44+
45+
# form cannot be generated if target is unknown
46+
if target == None:
47+
self.log_error('target url is not passed')
48+
self.send_response(500)
49+
return
50+
51+
html="""
52+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
53+
<html>
54+
<head>
55+
<meta http-equiv=Content-Type content="text/html;charset=UTF-8">
56+
<title>Log In</title>
57+
<style type="text/css" rel="stylesheet">
58+
body { background-color: #f1f1f1; font-family: sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif; }
59+
.log-in { width: 400px; height: 500px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; background-color: #fff; border-radius: 3px; overflow: hidden; -webkit-box-shadow: 0px 0px 2px 0px rgba(222,222,222,1); -moz-box-shadow: 0px 0px 2px 0px rgba(222,222,222,1); box-shadow: 0px 0px 2px 0px rgba(222,222,222,1); }
60+
.log-in > div { position: relative; }
61+
.log-in .content { margin-top: 50px; padding: 20px; text-align: center; }
62+
h1, h2 { text-align: center; }
63+
h1 { margin-top: 20px; margin-bottom: 20px; letter-spacing: -0.05rem; color: #565656; font-size: 1.6rem; }
64+
form { margin-top: 50px; }
65+
input[type="text"], input[type="password"] { width: 80%; padding: 10px; border-top: 0; border-left: 0; border-right: 0; outline: none; }
66+
input[type="text"]:focus, input[type="password"]:focus { border-bottom: 2px solid #666; }
67+
button { width: 80%; padding: 10px; background-color: #3468e2; border: none; color: #fff; cursor: pointer; margin-top: 50px; }
68+
button:hover { background-color: #5581e8; }
69+
</style>
70+
</head>
71+
<body>
72+
<div class="log-in">
73+
<div class="content">
74+
<h1>Log in to your account</h1>
75+
<form action="/login" method="post">
76+
<p>
77+
<input type="text" name="username" placeholder="Username" aria-label="Username" />
78+
</p>
79+
<p>
80+
<input type="password" name="password" placeholder="Password" aria-label="Password" />
81+
</p>
82+
<!-- <p>
83+
<input type="text" name="token" placeholder="2FA Token" aria-label="2FA Token" />
84+
</p> -->
85+
<input type="hidden" name="target" value="/">
86+
<button type="submit" class="submit btn btn-primary">Log In</button>
87+
</form>
88+
</div>
89+
</div>
90+
</body>
91+
</html>"""
92+
93+
self.send_response(200)
94+
self.end_headers()
95+
self.wfile.write(html.replace('TARGET', target))
96+
97+
98+
# processes posted form and sets the cookie with login/password
99+
def do_POST(self):
100+
101+
# prepare arguments for cgi module to read posted form
102+
env = {'REQUEST_METHOD':'POST',
103+
'CONTENT_TYPE': self.headers['Content-Type'],}
104+
105+
# read the form contents
106+
form = cgi.FieldStorage(fp = self.rfile, headers = self.headers,
107+
environ = env)
108+
109+
# extract required fields
110+
user = form.getvalue('username')
111+
passwd = form.getvalue('password')
112+
target = form.getvalue('target')
113+
114+
if user != None and passwd != None and target != None:
115+
116+
# form is filled, set the cookie and redirect to target
117+
# so that auth daemon will be able to use information from cookie
118+
119+
self.send_response(302)
120+
121+
cipher_suite = Fernet('REPLACEWITHFERNETKEY')
122+
enc = cipher_suite.encrypt(user + ':' + passwd)
123+
self.send_header('Set-Cookie', 'nginxauth=' + enc + '; httponly')
124+
125+
self.send_header('Location', target)
126+
self.end_headers()
127+
128+
return
129+
130+
self.log_error('some form fields are not provided')
131+
self.auth_form(target)
132+
133+
134+
def log_message(self, format, *args):
135+
if len(self.client_address) > 0:
136+
addr = BaseHTTPRequestHandler.address_string(self)
137+
else:
138+
addr = "-"
139+
140+
sys.stdout.write("%s - - [%s] %s\n" % (addr,
141+
self.log_date_time_string(), format % args))
142+
143+
def log_error(self, format, *args):
144+
self.log_message(format, *args)
145+
146+
147+
def exit_handler(signal, frame):
148+
sys.exit(0)
149+
150+
if __name__ == '__main__':
151+
server = AuthHTTPServer(Listen, AppHandler)
152+
signal.signal(signal.SIGINT, exit_handler)
153+
server.serve_forever()

0 commit comments

Comments
 (0)