Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from __future__ import unicode_literals
- from prompt_toolkit import prompt
- from prompt_toolkit.history import InMemoryHistory
- from urllib.request import urlopen
- import bs4 as BeautifulSoup
- import webbrowser
- import paramiko
- import getpass
- def main(main_1=None, cpe_1=None, dsl_1=None):
- history = InMemoryHistory()
- #login = input('Login as: ')
- #passd = getpass.getpass(prompt='Password for ' + login + ': ')
- while True:
- text = prompt("# ", history=history)
- while text == '':
- text = prompt("# ", history=history)
- if text == 'en 1':
- try:
- if main_1 is None:
- main1 = urlopen('file:///C:/Users/gperru/Desktop/main1.jsp').read()
- print('loading main')
- msoup1 = BeautifulSoup.BeautifulSoup(main1, 'lxml')
- lmain1 = msoup1.get_text().split('\n')
- id_se1 = lmain1[lmain1.index('/bds/id_service_administratif') +1]
- nom_u1 = lmain1[lmain1.index('/bds/contrat/site_coord/nom_usuel') +1]
- siren1 = lmain1[lmain1.index('/bds/contrat/siren') +1]
- nom_p1 = lmain1[lmain1.index('/facturation/gestionnaire_flotte/nom_prenom') + 1]
- telep1 = lmain1[lmain1.index('/facturation/gestionnaire_flotte/telephone') + 1]
- cdp_n1 = lmain1[lmain1.index('/bds/Cdp_Nom') +1]
- cdp_t1 = lmain1[lmain1.index('/bds/Cdp_Tel') +1]
- cdp_e1 = lmain1[lmain1.index('/bds/Cdp_Email') +1]
- inter1 = lmain1[lmain1.index('/intervention/installateur/@value') +1]
- except:
- print('main file not found')
- return main()
- try:
- if cpe_1 is None:
- cpe1 = urlopen('file:///C:/Users/gperru/Desktop/cpe1.jsp').read()
- print('loading cpe')
- csoup1 = BeautifulSoup.BeautifulSoup(cpe1, 'lxml')
- lcpe1 = csoup1.get_text().split('\n')
- id_co1 = lcpe1[lcpe1.index('/bds/id_commande') +1]
- id_pa1 = lcpe1[lcpe1.index('/bds/cpe/config/id_package') +1]
- ip_lo1 = lcpe1[lcpe1.index('/bds/confip/ip_loopback_ce') +1]
- data21 = lcpe1[lcpe1.index('/temp/data224') +1]
- adres1 = lcpe1[lcpe1.index('/bds/config/priseip/vlan1/adresse_lan1') +1]
- except:
- print('cpe file not found')
- return main()
- try:
- if dsl_1 is None:
- dsl1 = urlopen('file:///C:/Users/gperru/Desktop/dsl1.jsp').read()
- print('loading dsl')
- dsoup1 = BeautifulSoup.BeautifulSoup(dsl1, 'lxml')
- ldsl1 = dsoup1.get_text().split('\n')
- ref_s1 = ldsl1[ldsl1.index('/bds/acces/ref_service_activation_bipaire') +1]
- code_1 = ldsl1[ldsl1.index('/bds/acces/code_offre') +1]
- degro1 = ldsl1[ldsl1.index('/bds/acces/degroupage/type') +1]
- const1 = ldsl1[ldsl1.index('/bds/acces/constitution_ft') +1]
- nom_s1 = ldsl1[ldsl1.index('/bds/acces/nom_service') +1]
- condu1 = ldsl1[ldsl1.index('/bds/acces/conduit') +1]
- niv2_1 = ldsl1[ldsl1.index('/bds/acces/niv2_acces') +1]
- logi_1 = ldsl1[ldsl1.index('/bds/acces/login_ppp') +1]
- except:
- print('dsl file not found')
- return main()
- while True:
- text = prompt("EN1# ", history=history)
- while text == '':
- text = prompt("EN1# ", history=history)
- if text == 'main':
- if main_1 is None:
- list_of_main1 = [id_se1, nom_u1, siren1, nom_p1, telep1, cdp_n1, cdp_t1,
- cdp_e1, inter1]
- for c, value in enumerate(list_of_main1, 1):
- print(c, value)
- else:
- print(main_1)
- elif text == 'cpe':
- if cpe_1 is None:
- list_of_cpe1 = [id_co1, id_pa1, ip_lo1, data21, data21]
- print(list_of_cpe1)
- else:
- print(cpe_1)
- elif text == 'dsl':
- if dsl_1 is None:
- list_of_dsl1 = [ref_s1, code_1, degro1, const1, nom_s1, condu1, niv2_1, logi_1]
- print(list_of_dsl1)
- else:
- print(dsl_1)
- elif text == 'router':
- try:
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect('192.168.1.20', port=22, username='gregory', password='tirelli32')
- stdin, stdout, stderr = ssh.exec_command('ps x')
- stdin1, stdout1, stderr1 = ssh.exec_command('ls -la')
- stdin2, stdout2, stderr2 = ssh.exec_command('pwd')
- output = stdout.readlines()
- output1 = stdout1.readlines()
- output2 = stdout2.readlines()
- print('\n'.join(output))
- print('\n'.join(output1))
- print('\n'.join(output2))
- except:
- return main()
- elif text == 'exit':
- if main_1 is None:
- list_of_main1 = [id_se1, nom_u1, siren1, nom_p1, telep1, cdp_n1, cdp_t1, cdp_e1, inter1]
- list_of_cpe1 = [id_co1, id_pa1, ip_lo1, data21, data21]
- list_of_dsl1 = [ref_s1, code_1, degro1, const1, nom_s1, condu1, niv2_1, logi_1]
- return main(list_of_main1, list_of_cpe1, list_of_dsl1)
- else:
- return main(main_1, cpe_1, dsl_1)
- else:
- print('Unknown command:', text)
- elif text == 'del 1':
- if main_1 == None:
- print('No data found')
- else:
- print('1 is now empty')
- return main()
- else:
- print('Unknown command:', text)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement