-
Notifications
You must be signed in to change notification settings - Fork 0
/
addToTrustedDomainsHTTP.py
executable file
·69 lines (41 loc) · 1.29 KB
/
addToTrustedDomainsHTTP.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import paramiko
import sys
import fileinput
usage = '''
Execute the script with this parameters port for ssh connection.
host port user password
'''
if len(sys.argv) < 4:
print usage
sys.exit()
host = str(sys.argv[1])
port = int(sys.argv[2])
user = str(sys.argv[3])
password = str(sys.argv[4])
transport = paramiko.Transport((host, port))
transport.connect(username = user, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
filepath = '/opt/owncloud/config/config.php'
localpath = './config.php'
sftp.get(filepath, localpath)
processing_config = False
for line in fileinput.input('config.php', inplace=1):
if line.startswith(" 0 => '{0}:".format(host)):
processing_config = True
else:
if processing_config:
print ' 1 => \'{0}:{1}\','.format(host, port-2)
processing_config = False
print line,
sftp.put(localpath, filepath)
sftp.close()
transport.close()
#FOR CHECKING IT IS EDITED WELL
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=user, password=password, port=port)
stdin, stdout, stderr = ssh.exec_command("sudo cat /opt/owncloud/config/config.php")
output = stdout.readlines()
for line in output:
print line