Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. import paramiko
  2.  
  3. from flask import render_template, redirect, url_for, flash
  4. from buvr import app
  5.  
  6. @app.route("/")
  7. def index1():
  8.     return render_template('first.html')
  9.  
  10. @app.route("/single_units")
  11. def index2():
  12.     return render_template('second.html')  
  13.  
  14. @app.route("/start_all")
  15. def start_all():
  16.     host = '16.10.155.2'
  17.     user = 'bkc'
  18.     secret = 'buvr2016'
  19.     port = 30022
  20.  
  21.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  22.     do_ssh_action(host, user, secret, port, command)
  23.     return redirect(url_for('index1'))
  24.    
  25.    
  26. @app.route("/stop_all")
  27. def stop_all():
  28.     host = '16.10.155.2'
  29.     user = 'bkc'
  30.     secret = 'buvr2016'
  31.     port = 30022
  32.  
  33.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  34.     do_ssh_action(host, user, secret, port, command)
  35.     return redirect(url_for('index1'))
  36.  
  37.    
  38. @app.route("/start3")
  39. def start3():
  40.     host = '16.10.155.3'
  41.     user = 'bkc'
  42.     secret = 'buvr2016'
  43.     port = 30022
  44.    
  45.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  46.     do_ssh_action(host, user, secret, port, command)
  47.     return redirect(url_for('index2'))
  48.    
  49. @app.route("/start4")
  50. def start4():
  51.     host = '16.10.155.4'
  52.     user = 'bkc'
  53.     secret = 'buvr2016'
  54.     port = 30022
  55.    
  56.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  57.     do_ssh_action(host, user, secret, port, command)
  58.     return redirect(url_for('index2'))
  59.    
  60. @app.route("/start5")
  61. def start5():
  62.     host = '16.10.155.5'
  63.     user = 'bkc'
  64.     secret = 'buvr2016'
  65.     port = 30022
  66.    
  67.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  68.     do_ssh_action(host, user, secret, port, command)
  69.     return redirect(url_for('index2'))
  70.    
  71. @app.route("/start6")
  72. def start6():
  73.     host = '16.10.155.6'
  74.     user = 'bkc'
  75.     secret = 'buvr2016'
  76.     port = 30022
  77.  
  78.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  79.     do_ssh_action(host, user, secret, port, command)
  80.     return redirect(url_for('index2'))
  81.    
  82. @app.route("/start7")
  83. def start7():
  84.     host = '16.10.155.7'
  85.     user = 'bkc'
  86.     secret = 'buvr2016'
  87.     port = 30022
  88.    
  89.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  90.     do_ssh_action(host, user, secret, port, command)
  91.     return redirect(url_for('index2'))
  92.    
  93. @app.route("/start8")
  94. def start8():
  95.     host = '16.10.155.8'
  96.     user = 'bkc'
  97.     secret = 'buvr2016'
  98.     port = 30022
  99.    
  100.     command = 'vlc -vvv --play-and-exit /home/buvr/sirena8.mp3'
  101.     do_ssh_action(host, user, secret, port, command)
  102.     return redirect(url_for('index2'))
  103.  
  104.  
  105. def do_ssh_action(host, user, secret, port, command):
  106.     result = []
  107.     try:
  108.         client = paramiko.SSHClient()
  109.         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  110.         client.connect(hostname=host, username=user, password=secret, port=port)
  111.  
  112.         # start execute command
  113.         stdin, stdout, stderr = client.exec_command(command)
  114.        
  115.         result = stdout.read().splitlines() + stderr.read().splitlines()
  116.         client.close()
  117.         flash("End of ssh connection")
  118.     except Exception as ex:
  119.         flash(ex.message)
  120.  
  121.     finally:
  122.         for msg in result:
  123.             flash(unicode(msg))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement