Upload 3 files
Browse files- Dockerfile +49 -0
- gradio_app.py +47 -0
- start.sh +10 -0
Dockerfile
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Alpine as the base image
|
| 2 |
+
FROM python:3.10-alpine
|
| 3 |
+
|
| 4 |
+
# Install system dependencies and libraries required for Samba, LDAP, Webmin, and Gradio
|
| 5 |
+
RUN apk update && apk add --no-cache \
|
| 6 |
+
bash \
|
| 7 |
+
samba \
|
| 8 |
+
libsasl \
|
| 9 |
+
libldap \
|
| 10 |
+
libressl-dev \
|
| 11 |
+
build-base \
|
| 12 |
+
python3-dev \
|
| 13 |
+
libffi-dev \
|
| 14 |
+
gcc \
|
| 15 |
+
musl-dev \
|
| 16 |
+
ldap-dev \
|
| 17 |
+
smbclient \
|
| 18 |
+
&& pip install --no-cache-dir \
|
| 19 |
+
gradio \
|
| 20 |
+
ldap3 \
|
| 21 |
+
smbprotocol \
|
| 22 |
+
&& apk clean
|
| 23 |
+
|
| 24 |
+
# Install Webmin (manually as it isn't available in Alpine's package manager)
|
| 25 |
+
RUN apk add --no-cache wget && \
|
| 26 |
+
wget https://github.com/webmin/webmin/releases/download/1.979/webmin-1.979.tar.gz && \
|
| 27 |
+
tar -xvzf webmin-1.979.tar.gz && \
|
| 28 |
+
cd webmin-1.979 && \
|
| 29 |
+
./setup.sh /usr/local/webmin && \
|
| 30 |
+
rm -rf /webmin-1.979 /webmin-1.979.tar.gz
|
| 31 |
+
|
| 32 |
+
# Create the directory for the app
|
| 33 |
+
WORKDIR /app
|
| 34 |
+
|
| 35 |
+
# Copy the Gradio app code into the container
|
| 36 |
+
COPY gradio_app.py /app/gradio_app.py
|
| 37 |
+
|
| 38 |
+
# Expose required ports: Webmin (10000), Gradio (7860), and Samba (445)
|
| 39 |
+
EXPOSE 7860 10000 445
|
| 40 |
+
|
| 41 |
+
# Provision Samba Domain (optional)
|
| 42 |
+
RUN samba-domain-provision
|
| 43 |
+
|
| 44 |
+
# Add a script to manage Samba, Webmin, and Gradio
|
| 45 |
+
COPY start.sh /start.sh
|
| 46 |
+
RUN chmod +x /start.sh
|
| 47 |
+
|
| 48 |
+
# Start Samba, Webmin, and Gradio
|
| 49 |
+
CMD ["/start.sh"]
|
gradio_app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
# Function to check Samba status
|
| 5 |
+
def check_samba_status():
|
| 6 |
+
try:
|
| 7 |
+
result = subprocess.run(['smbstatus'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 8 |
+
return result.stdout.decode('utf-8')
|
| 9 |
+
except Exception as e:
|
| 10 |
+
return f"Error checking Samba status: {str(e)}"
|
| 11 |
+
|
| 12 |
+
# Function to interact with LDAP
|
| 13 |
+
def query_ldap(query):
|
| 14 |
+
try:
|
| 15 |
+
from ldap3 import Server, Connection, ALL
|
| 16 |
+
server = Server('ldap://localhost')
|
| 17 |
+
conn = Connection(server, user='cn=admin,dc=example,dc=com', password='adminpassword', auto_bind=True)
|
| 18 |
+
conn.search('dc=example,dc=com', query)
|
| 19 |
+
return conn.entries
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"Error querying LDAP: {str(e)}"
|
| 22 |
+
|
| 23 |
+
# Embed Webmin in Gradio UI using iframe
|
| 24 |
+
def create_webmin_ui():
|
| 25 |
+
# Webmin will be accessible via port 10000 in the container
|
| 26 |
+
webmin_url = "http://localhost:10000"
|
| 27 |
+
return f'<iframe src="{webmin_url}" width="100%" height="600px"></iframe>'
|
| 28 |
+
|
| 29 |
+
# Gradio UI Components
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
with gr.Tab("Samba Status"):
|
| 32 |
+
gr.Markdown("### Samba Service Status")
|
| 33 |
+
samba_output = gr.Textbox(label="Samba Status", interactive=False)
|
| 34 |
+
gr.Button("Check Samba Status").click(check_samba_status, outputs=samba_output)
|
| 35 |
+
|
| 36 |
+
with gr.Tab("LDAP Query"):
|
| 37 |
+
gr.Markdown("### Query LDAP")
|
| 38 |
+
ldap_query = gr.Textbox(label="LDAP Query", placeholder="Enter LDAP search query...")
|
| 39 |
+
ldap_result = gr.Dataframe(label="LDAP Query Results", interactive=False)
|
| 40 |
+
gr.Button("Execute LDAP Query").click(query_ldap, inputs=ldap_query, outputs=ldap_result)
|
| 41 |
+
|
| 42 |
+
with gr.Tab("Webmin Interface"):
|
| 43 |
+
gr.Markdown("### Webmin UI - Manage Samba and Services")
|
| 44 |
+
webmin_ui = gr.HTML(create_webmin_ui())
|
| 45 |
+
|
| 46 |
+
# Expose the Gradio UI at port 7860
|
| 47 |
+
demo.launch(server_port=7860)
|
start.sh
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
# Start Samba in the foreground
|
| 4 |
+
samba -F &
|
| 5 |
+
|
| 6 |
+
# Start Webmin in the background (assuming it's installed at /usr/local/webmin)
|
| 7 |
+
perl /usr/local/webmin/miniserv.pl &
|
| 8 |
+
|
| 9 |
+
# Run the Gradio app
|
| 10 |
+
python3 /app/gradio_app.py
|