Skip to content

Commit

Permalink
simple ldap auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberb committed Oct 30, 2023
1 parent 464fbcd commit 2d8efc7
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 127 deletions.
243 changes: 123 additions & 120 deletions modules/cmd_args.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def check_versions():

expected_torch_version = "2.0.0"
expected_xformers_version = "0.0.20"
expected_gradio_version = "3.41.2"
expected_gradio_version = "3.43.2"

if version.parse(torch.__version__) < version.parse(expected_torch_version):
print_error_explanation(f"""
Expand Down
12 changes: 12 additions & 0 deletions modules/initialize_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ def validate_tls_options():
startup_timer.record("TLS")


def webui_auth_ldap(username, password):
from modules.shared_cmd_options import cmd_opts
import ldap
conn = ldap.initialize(cmd_opts.ldap_uri)
try:
conn.simple_bind_s(cmd_opts.ldap_bind_dn.replace('{username}', username), password)
return True
except Exception:
conn.unbind()
return False


def get_gradio_auth_creds():
"""
Convert the gradio_auth and gradio_auth_path commandline arguments into
Expand Down
2 changes: 1 addition & 1 deletion modules/shared_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}))

options_templates.update(options_section(('saving-paths', "Paths for saving"), {
"outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to three directories below", component_args=hide_dirs),
"outdir_samples": OptionInfo(cmd_opts.outdir_samples, "Output directory for images; if empty, defaults to three directories below", component_args=hide_dirs),
"outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs),
"outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs),
"outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs),
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ clean-fid
einops
fastapi>=0.90.1
gfpgan
gradio==3.41.2
gradio==3.43.2
inflection
jsonmerge
kornia
Expand All @@ -32,3 +32,4 @@ torch
torchdiffeq
torchsde
transformers==4.30.2
python-ldap==3.2.0
2 changes: 1 addition & 1 deletion requirements_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ clean-fid==0.1.35
einops==0.4.1
fastapi==0.94.0
gfpgan==1.3.8
gradio==3.41.2
gradio==3.43.2
httpcore==0.15
inflection==0.5.1
jsonmerge==1.8.0
Expand Down
12 changes: 9 additions & 3 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def api_only():
)


def webui_auth():
from modules.shared_cmd_options import cmd_opts
if cmd_opts.ldap_uri:
return initialize_util.webui_auth_ldap
else:
return list(initialize_util.get_gradio_auth_creds()) or None


def webui():
from modules.shared_cmd_options import cmd_opts

Expand All @@ -67,8 +75,6 @@ def webui():
if not cmd_opts.no_gradio_queue:
shared.demo.queue(64)

gradio_auth_creds = list(initialize_util.get_gradio_auth_creds()) or None

auto_launch_browser = False
if os.getenv('SD_WEBUI_RESTARTING') != '1':
if shared.opts.auto_launch_browser == "Remote" or cmd_opts.autolaunch:
Expand All @@ -84,7 +90,7 @@ def webui():
ssl_certfile=cmd_opts.tls_certfile,
ssl_verify=cmd_opts.disable_tls_verify,
debug=cmd_opts.gradio_debug,
auth=gradio_auth_creds,
auth=webui_auth(),
inbrowser=auto_launch_browser,
prevent_thread_lock=True,
allowed_paths=cmd_opts.gradio_allowed_path,
Expand Down

0 comments on commit 2d8efc7

Please sign in to comment.