Commit a80ea4e6 authored by Hardik Juneja's avatar Hardik Juneja

monitor: allow to view and modify empty monitor config parameter

parent d1ed4bf0
...@@ -136,14 +136,23 @@ class Monitoring(object): ...@@ -136,14 +136,23 @@ class Monitoring(object):
title=config_list[1], title=config_list[1],
value=' '.join(config_list[2:]) value=' '.join(config_list[2:])
)) ))
elif (config_list[0] == 'file' or config_list[0] == 'htpasswd') and \ elif (config_list[0] == 'file' or config_list[0] == 'htpasswd'):
os.path.exists(config_list[2]) and os.path.isfile(config_list[2]): directory = os.path.dirname(config_list[2])
if not os.path.exists(directory) or not os.access(directory, os.W_OK):
raise OSError("Directory does not exists or does not have write acess")
if os.path.exists(config_list[2]) and os.path.isfile(config_list[2]):
try: try:
with open(config_list[2]) as cfile: with open(config_list[2]) as cfile:
param_value = cfile.read()
except OSError, e:
print 'Cannot read file %s, Error is: %s' % (config_list[2], str(e))
pass
else:
param_value = ""
parameter = dict( parameter = dict(
key=config_list[1], key=config_list[1],
title=config_list[1], title=config_list[1],
value=cfile.read(), value=param_value,
description={ description={
"type": config_list[0], "type": config_list[0],
"file": config_list[2] "file": config_list[2]
...@@ -156,9 +165,6 @@ class Monitoring(object): ...@@ -156,9 +165,6 @@ class Monitoring(object):
parameter['description']['user'] = config_list[3] parameter['description']['user'] = config_list[3]
parameter['description']['htpasswd'] = config_list[4] parameter['description']['htpasswd'] = config_list[4]
configuration_list.append(parameter) configuration_list.append(parameter)
except OSError, e:
print 'Cannot read file %s, Error is: %s' % (config_list[2], str(e))
pass
elif config_list[0] == 'httpdcors' and os.path.exists(config_list[2]) and \ elif config_list[0] == 'httpdcors' and os.path.exists(config_list[2]) and \
os.path.exists(config_list[3]): os.path.exists(config_list[3]):
old_cors_file = os.path.join( old_cors_file = os.path.join(
......
...@@ -36,18 +36,16 @@ class MonitorConfigWrite(object): ...@@ -36,18 +36,16 @@ class MonitorConfigWrite(object):
self.monitor_https_cors = monitor_https_cors self.monitor_https_cors = monitor_https_cors
def _fileWrite(self, file_path, content): def _fileWrite(self, file_path, content):
if os.path.exists(file_path):
try: try:
with open(file_path, 'w') as wf: with open(file_path, 'w') as wf:
wf.write(content) print file_path, content
wf.write(content.strip())
return True return True
except OSError, e: except OSError, e:
print "ERROR while writing changes to %s.\n %s" % (file_path, str(e)) print "ERROR while writing changes to %s.\n %s" % (file_path, str(e))
return False return False
def _htpasswdWrite(self, htpasswd_bin, parameter_dict, value): def _htpasswdWrite(self, htpasswd_bin, parameter_dict, value):
if not os.path.exists(parameter_dict['file']):
return False
command = [htpasswd_bin, '-cb', parameter_dict['htpasswd'], parameter_dict['user'], value] command = [htpasswd_bin, '-cb', parameter_dict['htpasswd'], parameter_dict['user'], value]
process = subprocess.Popen( process = subprocess.Popen(
command, command,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment