| 253 | |
| 254 | |
| 255 | def do_command(params, command_line): |
| 256 | # Block control characters to prevent newline-injection at the shell boundary. |
| 257 | if isinstance(command_line, str) and any(ch in command_line for ch in _DISALLOWED_COMMAND_CHARS): |
| 258 | logging.error('Invalid command: control characters are not allowed in command input.') |
| 259 | return |
| 260 | |
| 261 | def is_msp(params_local): |
| 262 | if params_local.enterprise: |
| 263 | if 'licenses' in params_local.enterprise: |
| 264 | msp_license = next((x for x in params_local.enterprise['licenses'] if x['lic_status'].startswith('msp')), |
| 265 | None) |
| 266 | if msp_license: |
| 267 | return True |
| 268 | return False |
| 269 | |
| 270 | if command_line.lower() == 'h' or command_line.lower() == 'history': |
| 271 | display.formatted_history(stack) |
| 272 | return |
| 273 | |
| 274 | if command_line.lower().startswith('server'): |
| 275 | _, sp, server = command_line.partition(' ') |
| 276 | server = server.strip() if server else '' |
| 277 | |
| 278 | # Handle help flag |
| 279 | if server in ('-h', '--help'): |
| 280 | print('Usage: server [REGION]') |
| 281 | print() |
| 282 | print('Set or display the current Keeper region.') |
| 283 | print() |
| 284 | print('Valid regions:') |
| 285 | print(f' Production: US, EU, AU, CA, JP, GOV') |
| 286 | print(f' Dev: US_DEV, EU_DEV, AU_DEV, CA_DEV, JP_DEV, GOV_DEV') |
| 287 | print(f' QA: US_QA, EU_QA, AU_QA, CA_QA, JP_QA, GOV_QA') |
| 288 | return |
| 289 | |
| 290 | if server: |
| 291 | if not params.session_token: |
| 292 | # Look up server in KEEPER_SERVERS (case insensitive) |
| 293 | server_upper = server.upper() |
| 294 | if server_upper in KEEPER_SERVERS: |
| 295 | params.server = KEEPER_SERVERS[server_upper] |
| 296 | logging.info('Keeper region is set to %s', server_upper) |
| 297 | else: |
| 298 | # Check if it matches a valid hostname directly |
| 299 | server_lower = server.lower() |
| 300 | if server_lower in KEEPER_SERVERS.values(): |
| 301 | params.server = server_lower |
| 302 | logging.info('Keeper server is set to %s', params.server) |
| 303 | else: |
| 304 | logging.error('Invalid region: %s', server) |
| 305 | print(f'Valid regions: {", ".join(sorted(KEEPER_SERVERS.keys()))}') |
| 306 | else: |
| 307 | logging.warning('Cannot change Keeper region while logged in') |
| 308 | else: |
| 309 | print(params.server) |
| 310 | return |
| 311 | |
| 312 | if command_line.startswith('ksm'): |