Implement sending commands to all severs

This commit is contained in:
Subnet_Masked 2024-02-04 16:24:51 -05:00
parent b53442c482
commit 81df9ef443
Signed by: Subnet_Masked
GPG key ID: E1BB06A2490954E9

View file

@ -41,9 +41,9 @@ def list_servers(mode=int(1)):
def create_server(isfirstrun=False): def create_server(isfirstrun=False):
global servers global servers
if(isfirstrun): if(isfirstrun):
print('!! Looks like you do not have any servers yet - Let\'s add one.\n') print('\n!! Looks like you do not have any servers yet - Let\'s add one.\n')
print('=== Add Server ===') print('\n=== Add Server ===')
srv_name = input('Name: ') srv_name = input('Name: ')
srv_addr = input('Address: ') srv_addr = input('Address: ')
srv_port = input('Port: ') srv_port = input('Port: ')
@ -62,7 +62,7 @@ def create_server(isfirstrun=False):
def pop_server(): def pop_server():
global servers global servers
print('=== Remove Server ===\nPick a server to delete') print('\n=== Remove Server ===\nPick a server to delete')
list_servers(2) list_servers(2)
delete = int(input('?: ')) delete = int(input('?: '))
@ -74,13 +74,13 @@ def pop_server():
def send_commands(): def send_commands():
proceed=True proceed=True
print('=== Send commands ===') print('\n=== Send commands ===')
choice = int(input('Single Server (1) or All (2)?: ')) choice = int(input('Single Server (1) or All (2)?: '))
if(choice==1): if(choice==1):
list_servers(2) list_servers(2)
server = int(input('Server?: ')) server = int(input('Server?: '))
while(proceed): while(proceed):
command = input('Input command: ') command = input('Input command (None to exit): ')
if(command!=""): if(command!=""):
with Client(servers[server]['address'], int(servers[server]['port']), passwd=servers[server]['password']) as client: with Client(servers[server]['address'], int(servers[server]['port']), passwd=servers[server]['password']) as client:
response = client.run(command) response = client.run(command)
@ -91,7 +91,18 @@ def send_commands():
print('No command was entered. Exiting.\n') print('No command was entered. Exiting.\n')
initial_choice() initial_choice()
elif(choice==2): elif(choice==2):
print('Would do every server') while(proceed):
command = input('Input command (None to exit): ')
for x in servers:
if(command!=""):
with Client(x['address'], int(x['port']), passwd=x['password']) as client:
response = client.run(command)
print(x['name']+': '+response)
else:
proceed = False
print('No command was entered. Exiting.\n')
initial_choice()
def initial_choice(): def initial_choice():
choose_func = input('=== Choose Function ===\n1. Add servers\n2. Remove servers\n3. List servers\n4. Send commands\n5. Exit\n?: ') choose_func = input('=== Choose Function ===\n1. Add servers\n2. Remove servers\n3. List servers\n4. Send commands\n5. Exit\n?: ')