| import gradio as gr |
| import subprocess |
|
|
| |
| 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)}" |
|
|
| |
| 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)}" |
|
|
| |
| def create_webmin_ui(): |
| |
| webmin_url = "http://localhost:10000" |
| return f'<iframe src="{webmin_url}" width="100%" height="600px"></iframe>' |
|
|
| |
| 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()) |
| |
| |
| demo.launch(server_port=7860) |
|
|