mirror of https://github.com/Aidaho12/haproxy-wi
				
				
				
			
							parent
							
								
									fe7b682cba
								
							
						
					
					
						commit
						5f4879177b
					
				| 
						 | 
				
			
			@ -76,7 +76,8 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
 | 
			
		|||
		
 | 
			
		||||
	stderr = funct.upload_and_restart(serv, cfg, just_save=save)
 | 
			
		||||
		
 | 
			
		||||
	os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs')))
 | 
			
		||||
	funct.diff_config(oldcfg, cfg)
 | 
			
		||||
		
 | 
			
		||||
	os.system("/bin/rm -f " + hap_configs_dir + "*.old")
 | 
			
		||||
 | 
			
		||||
output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig HAProxy config",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										29
									
								
								app/funct.py
								
								
								
								
							
							
						
						
									
										29
									
								
								app/funct.py
								
								
								
								
							| 
						 | 
				
			
			@ -17,7 +17,7 @@ def get_config_var(sec, var):
 | 
			
		|||
		config = ConfigParser(interpolation=ExtendedInterpolation())
 | 
			
		||||
		config.read(path_config)
 | 
			
		||||
	except:
 | 
			
		||||
		print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be in: app/haproxy-webintarface.config</div>')
 | 
			
		||||
		print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be: app/haproxy-webintarface.config</div>')
 | 
			
		||||
 | 
			
		||||
	try:
 | 
			
		||||
		var = config.get(sec, var)
 | 
			
		||||
| 
						 | 
				
			
			@ -31,17 +31,18 @@ def get_data(type):
 | 
			
		|||
		fmt = "%Y-%m-%d.%H:%M:%S"
 | 
			
		||||
	if type == 'logs':
 | 
			
		||||
		fmt = '%Y%m%d'
 | 
			
		||||
	if type == "date_in_log":
 | 
			
		||||
		fmt = "%b %d %H:%M:%S"
 | 
			
		||||
		
 | 
			
		||||
	return now_utc.strftime(fmt)
 | 
			
		||||
			
 | 
			
		||||
def logging(serv, action):
 | 
			
		||||
	import sql
 | 
			
		||||
	dateFormat = "%b  %d %H:%M:%S"
 | 
			
		||||
	now_utc = datetime.now(timezone(get_config_var('main', 'time_zone')))
 | 
			
		||||
	IP = cgi.escape(os.environ["REMOTE_ADDR"])
 | 
			
		||||
	cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
 | 
			
		||||
	user_uuid = cookie.get('uuid')
 | 
			
		||||
	login = sql.get_user_name_by_uuid(user_uuid.value)
 | 
			
		||||
	mess = now_utc.strftime(dateFormat) + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
 | 
			
		||||
	mess = get_data('date_in_log') + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
 | 
			
		||||
	log_path = get_config_var('main', 'log_path')
 | 
			
		||||
	
 | 
			
		||||
	try:		
 | 
			
		||||
| 
						 | 
				
			
			@ -241,6 +242,26 @@ def show_config(cfg):
 | 
			
		|||
	print('</div></div>')
 | 
			
		||||
	conf.close
 | 
			
		||||
 | 
			
		||||
def diff_config(oldcfg, cfg):
 | 
			
		||||
	import subprocess 
 | 
			
		||||
	cmd="/bin/diff -ub %s %s" % (oldcfg, cfg)
 | 
			
		||||
	p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
 | 
			
		||||
	stdout, stderr = p.communicate()
 | 
			
		||||
	output = stdout.splitlines()
 | 
			
		||||
	log_path = get_config_var('main', 'log_path')
 | 
			
		||||
	diff = ""
 | 
			
		||||
	date = get_data('date_in_log') 
 | 
			
		||||
	
 | 
			
		||||
	for line in output:
 | 
			
		||||
		diff += date + " " + line + "\n"
 | 
			
		||||
	try:		
 | 
			
		||||
		log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
 | 
			
		||||
		log.write(diff)
 | 
			
		||||
		log.close
 | 
			
		||||
	except IOError:
 | 
			
		||||
		print('<center><div class="alert alert-danger">Can\'t read write change to log. %s</div></center>' % stderr)
 | 
			
		||||
		pass
 | 
			
		||||
		
 | 
			
		||||
def install_haproxy(serv):
 | 
			
		||||
	script = "install_haproxy.sh"
 | 
			
		||||
	tmp_config_path = get_config_var('haproxy', 'tmp_config_path')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -69,7 +69,8 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
 | 
			
		|||
		
 | 
			
		||||
	stderr = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1)
 | 
			
		||||
		
 | 
			
		||||
	os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs')))
 | 
			
		||||
	funct.diff_config(oldcfg, cfg)
 | 
			
		||||
	
 | 
			
		||||
	os.system("/bin/rm -f " + kp_save_configs_dir + "*.old")
 | 
			
		||||
 | 
			
		||||
output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig Keepalived config",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								app/ovw.py
								
								
								
								
							
							
						
						
									
										10
									
								
								app/ovw.py
								
								
								
								
							| 
						 | 
				
			
			@ -193,9 +193,15 @@ def show_compare_configs(serv):
 | 
			
		|||
	print('<a class="ui-button ui-widget ui-corner-all" id="show" title="Compare" onclick="showCompare()">Show</a></p></form></center></center>')
 | 
			
		||||
	
 | 
			
		||||
def comapre_show():
 | 
			
		||||
	import subprocess 
 | 
			
		||||
	left = form.getvalue('left')
 | 
			
		||||
	right = form.getvalue('right')
 | 
			
		||||
	haproxy_configs_server = funct.get_config_var('configs', 'haproxy_configs_server')
 | 
			
		||||
	commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
 | 
			
		||||
	cmd='diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right)
 | 
			
		||||
	
 | 
			
		||||
	funct.ssh_command(haproxy_configs_server, commands, compare="1")
 | 
			
		||||
	p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
 | 
			
		||||
	stdout, stderr = p.communicate()
 | 
			
		||||
	output = stdout.splitlines()
 | 
			
		||||
	
 | 
			
		||||
	funct.compare(output)
 | 
			
		||||
	print(stderr)
 | 
			
		||||
		Loading…
	
		Reference in New Issue