-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_autobk_backup_Inca1.py
executable file
·53 lines (43 loc) · 1.66 KB
/
op_autobk_backup_Inca1.py
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
#!/usr/local/bin/python3
import sys as mSys
import base64 as mB64
from http.client import HTTPConnection
from lib_autobk import *
###############################
# Global Configurations and Constants
sBkUrlInca = '/sys/svc/core/api/v1/devices/1/configuration.bak'
sBkUrlIncaOld = '/devices/1/configuration.bak' # 1.62 and older
dnGetHdrsInca = {
'User-Agent': 'CtrlAutoBk/2.00',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
}
###############################
try:
# Configuration and Logging
(oINI, oLog, sAt) = LoadConfig('op-backup-Inca1')
sIniUsr = oINI.get('Inca1', 'Usr', fallback='admin')
sIniPwd = oINI.get('Inca1', 'Pwd', fallback='admin')
# Load arguments
if (len(mSys.argv) < 3): raise AutoBkError('Missing arguments')
sDeviceIP = mSys.argv[1]
sBkTarget = mSys.argv[2]
oLog.info(sAt, 'host', sDeviceIP)
oLog.info(sAt, 'path', sBkTarget)
# Perform Backup
dnGetHdrsInca['Authorization'] = 'Basic ' + mB64.b64encode(sAuthKey.format(sIniUsr, sIniPwd).encode()).decode()
# HTTP Connect to Inca
oHttp = HTTPConnection(sDeviceIP, 80)
oLog.info(sAt, 'session', 'connected')
# Request config update and download
xData = HttpRequest(oHttp, sBkUrlInca, dnGetHdrsInca, sFallbackURL=sBkUrlIncaOld)
oFile = open(sBkTarget, 'wb')
oFile.write(xData)
oFile.close()
# Cleanup, logoff, and disconnect HTTP session
oHttp.close()
oLog.info(sAt, 'session', 'complete')
except Exception as oErr:
if (oLog is not None): oLog.error(sAt, 'unknown', oErr)
print(str(oErr)) # used by calling thread to get error message
mSys.exit(1)