-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAvacomControl.py
More file actions
149 lines (105 loc) · 4.53 KB
/
AvacomControl.py
File metadata and controls
149 lines (105 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
This program attempts to modularize IOTCommander into reusable modules for usage scenarios.
Thomas Setzler
"""
import os,subprocess,random,time,datetime,sys,telnetlib
from selenium import webdriver
from playsound import playsound
""" AVACOM Webcam Modules"""
def telnetIntoAvacom(host):
#Code from IOT Commander
#telnets into Avacom webcam
#essential for any manipulation of the Avacom webcam
#host: <string> ip address of the target webcam
print ('Starting Telnet')
user = 'root'
password = 'hslwificam'
#start telnet connection
tn = telnetlib.Telnet(host)
tn.read_until(b"login:")
tn.write(user.encode("ascii")+ b"\n")
if password:
tn.read_until(b"Password:")
tn.write(password.encode("ascii")+b"\n")
return tn
def startWebcamCollection(host):
#code from IOT Commander
#collects lines from terminal during telnet session
tnet = telnetIntoAvacom(host)
print ("Starting Collection Script")
tnet.write(b"cd system \n")
tnet.write(b"sh collection.sh & \n")
tnet.write(b"exit\n")
print("Collection Script Started")
lines_to_read = 8 #lines to read from telnet session (equal to the number of commands + 5)
for i in range(lines_to_read):
line = tnet.read_until("\n")
print(line)
def removeWebcamData(host):
#code from IOT Commander
#Removes colleted data from the camera
tnet = telnetIntoAvacom(host)
print ("Removing Webcam Data")
tnet.write(b"cd system/www \n")
tnet.write(b"rm *webcam* \n")
tnet.write(b"exit\n")
print("Collection Script Started")
lines_to_read = 8 #lines to read from telnet session (equal to the number of commands + 5)
for i in range(lines_to_read):
line = tnet.read_until("\n")
print(line)
def downloadAvacomFiles(mainFolder,host):
#From IOT Commander
#Download files from webcam
username = 'admin'
password = '1234'
#ip = '192.168.1.116'
timestr = time.strftime("%Y-%m-%d_%H:%M:%S")
print("Downloading Files")
subprocess.call('wget -O ' + mainFolder + timestr + '_ps_data_webcam' + '.txt --user ' + username + ' --password ' + password + ' ' + host + '/ps_data_webcam.txt', shell=True)
time.sleep(1)
subprocess.call('wget -O ' + mainFolder + timestr + '_top_data_webcam' + '.txt --user ' + username + ' --password ' + password + ' ' + host + '/top_data_webcam.txt', shell=True)
time.sleep(1)
subprocess.call('wget -O ' + mainFolder + timestr + '_date_data_webcam' + '.txt --user ' + username + ' --password ' + password + ' ' + host + '/date_data_webcam.txt', shell=True)
time.sleep(1)
subprocess.call('wget -O ' + mainFolder + timestr +'_netstat_data_webcam' + '.txt --user ' + username + ' --password ' + password + ' ' + host + '/netstat_data_webcam.txt', shell=True)
def accessAvacomWebPortal(host):
#From IOT Commander
#Initates access to the Avacon portal for control of the webcam
#start web browser
browser = webdriver.Chrome('/home/carson/Documents/Commander/IOT-Commander/chromedriver') #FIX WITH RELATIVE PATH
#maximize window
browser.maximize_window()
#go to camera url
browser.get('http://admin:1234@' + host +'/')
time.sleep(1)
#go to frame where buttons are located
frame = browser.find_element_by_xpath('//*[@id="mainUrl"]')
browser.switch_to_frame(frame)
#the last 3 options have class 'cs5'
cs5list = browser.find_elements_by_class_name('cs5')
#pick the 2nd option which allows to view webcam without a plugin
cs5list[2].click()
return browser
def clickAvacomDirectionalButton(driver, direction, numClicks):
#From IOT Commander
#Direct camera movement using directional buttons on website
xpath = '//*[@title=' + direction + ']'
button = driver.find_element_by_xpath(xpath)
for clicks in range (numClicks):
button.click()
#time.sleep(5)
def avacomHorizPan(driver, duration):
#accepts the driver and the length of panning in iterations and performs a horizontal pan
for i in range(duration):
clickAvacomDirectionalButton(driver, "\"Right\"", 25)
time.sleep(3)
clickAvacomDirectionalButton(driver, "\"Left\"", 25)
time.sleep(3)
def avacomVertPan(driver, duration):
#accepts the driver and length of panning in iterations and performs a vertical pan
for i in range(duration):
clickAvacomDirectionalButton(driver, "\"Up\"", 25)
time.sleep(3)
clickAvacomDirectionalButton(driver, "\"Down\"", 25)
time.sleep(3)