| 119 | |
| 120 | |
| 121 | def configure_network(cfg: dict) -> dict: |
| 122 | print() |
| 123 | print(bold("Network settings") + dim(" (press enter to accept defaults)")) |
| 124 | cfg["lan_sharing"] = prompt_yes_no( |
| 125 | "Enable LAN sharing?", |
| 126 | default=bool(cfg.get("lan_sharing", False)), |
| 127 | ) |
| 128 | |
| 129 | default_host = str(cfg.get("listen_host", "127.0.0.1")) |
| 130 | if cfg["lan_sharing"] and default_host == "127.0.0.1": |
| 131 | default_host = "0.0.0.0" |
| 132 | cfg["listen_host"] = prompt("Listen host", default=default_host) |
| 133 | |
| 134 | port = prompt( |
| 135 | "HTTP proxy port", |
| 136 | default=str(cfg.get("http_port", cfg.get("listen_port", 8085))), |
| 137 | ) |
| 138 | try: |
| 139 | cfg["http_port"] = int(port) |
| 140 | except ValueError: |
| 141 | cfg["http_port"] = 8085 |
| 142 | |
| 143 | # SOCKS5 is always enabled at runtime; only port is configurable. |
| 144 | sport = prompt("SOCKS5 port", default=str(cfg.get("socks5_port", 1080))) |
| 145 | try: |
| 146 | cfg["socks5_port"] = int(sport) |
| 147 | except ValueError: |
| 148 | cfg["socks5_port"] = 1080 |
| 149 | return cfg |
| 150 | |
| 151 | |
| 152 | def write_config(cfg: dict) -> None: |