|
5 | 5 | import requests |
6 | 6 | from requests.exceptions import ReadTimeout |
7 | 7 | import traceback |
| 8 | + |
| 9 | +from .apache_utils import make_apache_content |
8 | 10 | def find_ip(attempts=5, proxy=None) -> str: |
9 | 11 | """Finds the public IP address of the current connection.""" |
10 | 12 | url = 'https://checkip.amazonaws.com/' |
@@ -603,40 +605,6 @@ def read_file(path): |
603 | 605 | def read_conf(): |
604 | 606 | return read_file("/etc/apache2/sites-available/000-default.conf") |
605 | 607 |
|
606 | | -import re |
607 | | -def clean_conf(apache_conf, root_path): |
608 | | - apache_conf = re.sub(r'ProxyPass\s+' + re.escape(root_path) + r'\s+.*\n', '', apache_conf) |
609 | | - apache_conf = re.sub(r'ProxyPassReverse\s+' + re.escape(root_path) + r'\s+.*\n', '', apache_conf) |
610 | | - # return apache_conf |
611 | | - return re.sub(r'[ \t]+</VirtualHost>', '</VirtualHost>', apache_conf) |
612 | | - |
613 | | -def collapse_empty_lines(conf: str) -> str: |
614 | | - # Replace multiple consecutive newlines (with optional whitespace) with a single newline |
615 | | - return re.sub(r'\n\s*\n+', '\n\n', conf.strip()) + '\n' |
616 | | - |
617 | | -def sub_at_start(apache_conf, root_path, api_target): |
618 | | - return re.sub( |
619 | | - r'(<VirtualHost\b.*?>)', |
620 | | - f'\\1\n ProxyPass {root_path} {api_target}\n ProxyPassReverse {root_path} {api_target}', |
621 | | - apache_conf, |
622 | | - count=1 |
623 | | - ) |
624 | | - |
625 | | - |
626 | | -def sub_at_end(apache_conf, root_path, api_target): |
627 | | - return re.sub(r'</VirtualHost>', f' ProxyPass {root_path} {api_target}\n ProxyPassReverse {root_path} {api_target}\n</VirtualHost>', apache_conf) |
628 | | - |
629 | | -def make_apache_content(apache_conf, root_path, api_target): |
630 | | - # Remove existing ProxyPass and ProxyPassReverse directives for the root_path |
631 | | - apache_conf = clean_conf(apache_conf, root_path) |
632 | | - |
633 | | - # Add new ProxyPass and ProxyPassReverse directives based on the root_path |
634 | | - if root_path == "/": |
635 | | - return collapse_empty_lines(sub_at_end(apache_conf, root_path, api_target)) |
636 | | - else: |
637 | | - # Add new directives right after the VirtualHost opening tag |
638 | | - return collapse_empty_lines(sub_at_start(apache_conf, root_path, api_target)) |
639 | | - |
640 | 608 | def setup_apache_load_balancer_desktop_app(port, api_base_path): |
641 | 609 | root_path = api_base_path or '/' |
642 | 610 | api_target = f"http://127.0.0.1:{port}{root_path}" |
|
0 commit comments