File size: 1,875 Bytes
3909e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
import subprocess

# Function to check Samba status
def check_samba_status():
    try:
        result = subprocess.run(['smbstatus'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        return result.stdout.decode('utf-8')
    except Exception as e:
        return f"Error checking Samba status: {str(e)}"

# Function to interact with LDAP
def query_ldap(query):
    try:
        from ldap3 import Server, Connection, ALL
        server = Server('ldap://localhost')
        conn = Connection(server, user='cn=admin,dc=example,dc=com', password='adminpassword', auto_bind=True)
        conn.search('dc=example,dc=com', query)
        return conn.entries
    except Exception as e:
        return f"Error querying LDAP: {str(e)}"

# Embed Webmin in Gradio UI using iframe
def create_webmin_ui():
    # Webmin will be accessible via port 10000 in the container
    webmin_url = "http://localhost:10000"
    return f'<iframe src="{webmin_url}" width="100%" height="600px"></iframe>'

# Gradio UI Components
with gr.Blocks() as demo:
    with gr.Tab("Samba Status"):
        gr.Markdown("### Samba Service Status")
        samba_output = gr.Textbox(label="Samba Status", interactive=False)
        gr.Button("Check Samba Status").click(check_samba_status, outputs=samba_output)
    
    with gr.Tab("LDAP Query"):
        gr.Markdown("### Query LDAP")
        ldap_query = gr.Textbox(label="LDAP Query", placeholder="Enter LDAP search query...")
        ldap_result = gr.Dataframe(label="LDAP Query Results", interactive=False)
        gr.Button("Execute LDAP Query").click(query_ldap, inputs=ldap_query, outputs=ldap_result)

    with gr.Tab("Webmin Interface"):
        gr.Markdown("### Webmin UI - Manage Samba and Services")
        webmin_ui = gr.HTML(create_webmin_ui())
    
    # Expose the Gradio UI at port 7860
    demo.launch(server_port=7860)