Advertisement
Guest User

en 1, 2, 3,...

a guest
Aug 15th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.65 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from __future__ import unicode_literals
  4. from prompt_toolkit import prompt
  5. from prompt_toolkit.history import InMemoryHistory
  6. from urllib.request import urlopen
  7. import bs4 as BeautifulSoup
  8. import webbrowser
  9. import paramiko
  10. import getpass
  11.  
  12. def main(main_1=None, cpe_1=None, dsl_1=None):
  13.     history = InMemoryHistory()
  14.    
  15.     #login = input('Login as: ')
  16.     #passd = getpass.getpass(prompt='Password for ' + login + ': ')
  17.  
  18.     while True:
  19.         text = prompt("# ", history=history)
  20.         while text == '':
  21.             text = prompt("# ", history=history)
  22.            
  23.         if text == 'en 1':
  24.             try:
  25.                 if main_1 is None:
  26.                     main1 = urlopen('file:///C:/Users/gperru/Desktop/main1.jsp').read()
  27.                     print('loading main')
  28.                     msoup1 = BeautifulSoup.BeautifulSoup(main1, 'lxml')
  29.                     lmain1 = msoup1.get_text().split('\n')
  30.                     id_se1 = lmain1[lmain1.index('/bds/id_service_administratif') +1]
  31.                     nom_u1 = lmain1[lmain1.index('/bds/contrat/site_coord/nom_usuel') +1]
  32.                     siren1 = lmain1[lmain1.index('/bds/contrat/siren') +1]
  33.                     nom_p1 = lmain1[lmain1.index('/facturation/gestionnaire_flotte/nom_prenom') + 1]
  34.                     telep1 = lmain1[lmain1.index('/facturation/gestionnaire_flotte/telephone') + 1]
  35.                     cdp_n1 = lmain1[lmain1.index('/bds/Cdp_Nom') +1]
  36.                     cdp_t1 = lmain1[lmain1.index('/bds/Cdp_Tel') +1]
  37.                     cdp_e1 = lmain1[lmain1.index('/bds/Cdp_Email') +1]
  38.                     inter1 = lmain1[lmain1.index('/intervention/installateur/@value') +1]
  39.             except:
  40.                 print('main file not found')
  41.                 return main()
  42.             try:
  43.                 if cpe_1 is None:
  44.                     cpe1 = urlopen('file:///C:/Users/gperru/Desktop/cpe1.jsp').read()
  45.                     print('loading cpe')
  46.                     csoup1 = BeautifulSoup.BeautifulSoup(cpe1, 'lxml')
  47.                     lcpe1 = csoup1.get_text().split('\n')
  48.                     id_co1 = lcpe1[lcpe1.index('/bds/id_commande') +1]
  49.                     id_pa1 = lcpe1[lcpe1.index('/bds/cpe/config/id_package') +1]
  50.                     ip_lo1 = lcpe1[lcpe1.index('/bds/confip/ip_loopback_ce') +1]
  51.                     data21 = lcpe1[lcpe1.index('/temp/data224') +1]
  52.                     adres1 = lcpe1[lcpe1.index('/bds/config/priseip/vlan1/adresse_lan1') +1]
  53.                    
  54.             except:
  55.                 print('cpe file not found')
  56.                 return main()
  57.             try:
  58.                 if dsl_1 is None:
  59.                     dsl1 = urlopen('file:///C:/Users/gperru/Desktop/dsl1.jsp').read()
  60.                     print('loading dsl')
  61.                     dsoup1 = BeautifulSoup.BeautifulSoup(dsl1, 'lxml')
  62.                     ldsl1 = dsoup1.get_text().split('\n')
  63.                     ref_s1 = ldsl1[ldsl1.index('/bds/acces/ref_service_activation_bipaire') +1]
  64.                     code_1 = ldsl1[ldsl1.index('/bds/acces/code_offre') +1]
  65.                     degro1 = ldsl1[ldsl1.index('/bds/acces/degroupage/type') +1]
  66.                     const1 = ldsl1[ldsl1.index('/bds/acces/constitution_ft') +1]
  67.                     nom_s1 = ldsl1[ldsl1.index('/bds/acces/nom_service') +1]
  68.                     condu1 = ldsl1[ldsl1.index('/bds/acces/conduit') +1]
  69.                     niv2_1 = ldsl1[ldsl1.index('/bds/acces/niv2_acces') +1]
  70.                     logi_1 = ldsl1[ldsl1.index('/bds/acces/login_ppp') +1]
  71.             except:
  72.                 print('dsl file not found')
  73.                 return main()
  74.                
  75.             while True:
  76.                 text = prompt("EN1# ", history=history)
  77.                 while text == '':
  78.                     text = prompt("EN1# ", history=history)
  79.                
  80.                 if text == 'main':
  81.                     if main_1 is None:
  82.                         list_of_main1 = [id_se1, nom_u1, siren1, nom_p1, telep1, cdp_n1, cdp_t1,
  83.                         cdp_e1, inter1]
  84.                         for c, value in enumerate(list_of_main1, 1):
  85.                             print(c, value)
  86.                     else:
  87.                         print(main_1)
  88.        
  89.                 elif text == 'cpe':
  90.                     if cpe_1 is None:
  91.                         list_of_cpe1 = [id_co1, id_pa1, ip_lo1, data21, data21]
  92.                         print(list_of_cpe1)
  93.                     else:
  94.                         print(cpe_1)
  95.            
  96.                 elif text == 'dsl':
  97.                     if dsl_1 is None:
  98.                         list_of_dsl1 = [ref_s1, code_1, degro1, const1, nom_s1, condu1, niv2_1, logi_1]
  99.                         print(list_of_dsl1)
  100.                     else:
  101.                         print(dsl_1)
  102.            
  103.                 elif text == 'router':
  104.                     try:
  105.                         ssh = paramiko.SSHClient()
  106.                         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  107.                         ssh.connect('192.168.1.20', port=22, username='gregory', password='tirelli32')
  108.                         stdin, stdout, stderr = ssh.exec_command('ps x')
  109.                         stdin1, stdout1, stderr1 = ssh.exec_command('ls -la')
  110.                         stdin2, stdout2, stderr2 = ssh.exec_command('pwd')
  111.                         output = stdout.readlines()
  112.                         output1 = stdout1.readlines()
  113.                         output2 = stdout2.readlines()
  114.                         print('\n'.join(output))
  115.                         print('\n'.join(output1))
  116.                         print('\n'.join(output2))
  117.                     except:
  118.                         return main()
  119.                        
  120.                 elif text == 'exit':
  121.                     if main_1 is None:
  122.                         list_of_main1 = [id_se1, nom_u1, siren1, nom_p1, telep1, cdp_n1, cdp_t1, cdp_e1, inter1]
  123.                         list_of_cpe1 = [id_co1, id_pa1, ip_lo1, data21, data21]
  124.                         list_of_dsl1 = [ref_s1, code_1, degro1, const1, nom_s1, condu1, niv2_1, logi_1]
  125.                         return main(list_of_main1, list_of_cpe1, list_of_dsl1)
  126.                     else:
  127.                         return main(main_1, cpe_1, dsl_1)
  128.                 else:
  129.                     print('Unknown command:', text)
  130.                    
  131.         elif text == 'del 1':
  132.             if main_1 == None:
  133.                 print('No data found')
  134.             else:
  135.                 print('1 is now empty')
  136.                 return main()
  137.            
  138.         else:
  139.             print('Unknown command:', text)
  140.  
  141. if __name__ == '__main__':
  142.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement