Exemple #1
0
def get_overview():
    listhap = sql.get_dick_permit()

    commands = ["ps -Af |grep [h]aproxy |wc -l"]
    commands1 = [
        "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path
    ]

    for server in listhap:
        print(
            '<tr><td class="padding10 first-collumn"><a href="#%s" title="Go to %s status" style="color: #000">%s</a></td><td  class="second-collumn">'
            % (server[1], server[1], server[1]))
        funct.ssh_command(server[2], commands, server_status="1")
        print('</td><td>')
        if funct.is_admin():
            print(
                '<a id="%s" class="start" title="Start HAproxy service"><img src=/image/pic/start.png alt="start" class="icon"></a>'
                % server[2])
            print(
                '<a id="%s" class="stop" title="Stop HAproxy service"><img src=/image/pic/stop.png alt="start" class="icon"></a>'
                % server[2])
            print(
                '<a id="%s" class="restart" title="Restart HAproxy service"><img src=/image/pic/update.png alt="restart" class="icon"></a>'
                % server[2])
        if funct.is_admin(level=2):
            print(
                '<a href="/app/configshow.py?serv=%s&open=open#conf"  title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>'
                % server[2])
            print(
                '<a href="/app/config.py?serv=%s&open=open#conf"  title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>'
                % server[2])
            print(
                '<a href="/app/diff.py?serv=%s&open=open#diff"  title="Compare config"><img src=/image/pic/compare.png alt="compare" class="icon"></a>'
                % server[2])
            print(
                '<a href="/app/map.py?serv=%s&open=open#map"  title="Map listen/frontend/backend"><img src=/image/pic/map.png alt="map" class="icon"></a>'
                % server[2])
        print('</td><td>')
        funct.ssh_command(server[2], commands1)
        print('</td><td></td></tr>')
            '<div class="alert alert-danger">Can\'t read import config file</div>'
        )

    from jinja2 import Environment, FileSystemLoader
    env = Environment(loader=FileSystemLoader('templates/ajax'),
                      autoescape=True,
                      trim_blocks=True,
                      lstrip_blocks=True,
                      extensions=["jinja2.ext.loopcontrols", "jinja2.ext.do"])
    template = env.get_template('config_show.html')

    template = template.render(conf=conf,
                               view=form.getvalue('view'),
                               serv=serv,
                               configver=form.getvalue('configver'),
                               role=funct.is_admin(level=2))
    print(template)

    if form.getvalue('configver') is None:
        os.system("/bin/rm -f " + cfg)

if form.getvalue('master'):
    master = form.getvalue('master')
    slave = form.getvalue('slave')
    ETH = form.getvalue('interface')
    IP = form.getvalue('vrrpip')
    syn_flood = form.getvalue('syn_flood')
    script = "install_keepalived.sh"
    fullpath = funct.get_config_var('main', 'fullpath')
    proxy = sql.get_setting('proxy')
    ssh_enable = ''
Exemple #3
0
      '<td>Save change</td>'
      '<td></td>'
      '</tr>'
      '<tr>'
      '<td class="padding10 first-collumn" style="width: 25%;">'
      '<form action="edit.py" method="get">'
      '<select required name="serv" id="serv">'
      '<option disabled selected>Choose server</option>')

funct.choose_only_select(serv, virt=1)

print('</select></td>'
      '<td style="width: 30%;">'
      '<select required name="servaction" id="servaction">'
      '<option disabled selected>Choose action</option>')
if funct.is_admin():
    print('<option value="disable">Disable</option>')
    print('<option value="enable">Enable</option>')
    print('<option value="set">Set</option>')
print(
    '<option value="show">Show</option>'
    '</select></td>'
    '<td>'
    '<input type="text" name="servbackend" id="servbackend" size=35 title="Frontend, backend/server, show: info, pools or help" required class="form-control">'
    '</td><td>'
    '<input type="checkbox" name="save" id="save" value="123">'
    '</td><td>'
    '<a class="ui-button ui-widget ui-corner-all" id="show" title="Enter" onclick="showRuntime()">Enter</a>'
    '</td></form>'
    '</tr></table>'
    '<div id="ajax">'
Exemple #4
0
	if form.getvalue('configver') is None:	
		cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
		funct.get_config(serv, cfg)
	else: 
		cfg = hap_configs_dir + form.getvalue('configver')
			
	try:
		conf = open(cfg, "r")
	except IOError:
		print('<div class="alert alert-danger">Can\'t read import config file</div>')
		
	from jinja2 import Environment, FileSystemLoader
	env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True, extensions=['jinja2.ext.loopcontrols'])
	template = env.get_template('config_show.html')
	
	template = template.render(conf=conf, view=form.getvalue('view'), serv=serv, configver=form.getvalue('configver'), role=funct.is_admin(level=2))											
	print(template)
	
	if form.getvalue('configver') is None:
		os.system("/bin/rm -f " + cfg)	
		
		
if form.getvalue('master'):
	master = form.getvalue('master')
	slave = form.getvalue('slave')
	interface = form.getvalue('interface')
	vrrpip = form.getvalue('vrrpip')
	tmp_config_path = sql.get_setting('tmp_config_path')
	script = "install_keepalived.sh"
	
	if form.getvalue('hap') == "1":
Exemple #5
0
def get_overview():
	USERS = sql.select_users()
	
	print('<table class="overview">')

	if funct.is_admin():
		print('<tr class="overviewHead">'
				'<td class="padding10 first-collumn">Login</td>'
				'<td class="padding10">Email</td>'
				'<td class="padding10">Group</td>'
				'<td class="padding10">Role</td>'
				'<td style="width: 200px;">'
					'<span class="add-button">'
						'<a href="#"  title="Show all users" id="show-all-users" style="color: #fff">'
							'Show all'
						'</a>'
					'</span>'
				'</td>'
			'</tr>')

		i = 0
		style = ""
		for users in USERS:
			i = i + 1
			if i is 4:
				style = 'style="display: none;" class="show-users"'
			print('<tr ' + style + '><td class="padding10 first-collumn">' + users[1] +'</td><td class="second-collumn">')
			print(users[2]+'</td><td>')
			GROUPS = sql.select_user_name_group(users[5])
			for group in GROUPS:
				print(group)
				print('</td><td>')
			print(users[4])
			print('</td><td></td></tr>')
		print('</table>')
		
	print('<table class="overview">'
		'<tr class="overviewHead">'
			'<td class="padding10 first-collumn"">Server</td>'
			'<td class="padding10">'
				'HAproxy status'
			'</td>'
			'<td class="padding10">'
				'Action'
			'</td>'
			'<td class="padding10">'
				'Last edit'
			'</td>'
			'<td></td>'
		'</tr>')
		
	listhap = sql.get_dick_permit()

	commands = [ "ps -Af |grep [h]aproxy |wc -l" ]
	commands1 = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]

	for server in listhap:
		print('<tr><td class="padding10 first-collumn"><a href="#%s" title="Go to %s status" style="color: #000">%s</a></td><td  class="second-collumn">' % (server[1], server[1], server[1]))
		funct.ssh_command(server[2], commands, server_status="1")
		print('</td><td>')
		if funct.is_admin():
			print('<a id="%s" class="start" title="Start HAproxy service" onclick = "if (! confirm(\'Start service?\')) return false;"><img src=/image/pic/start.png alt="start" class="icon"></a>' % server[2])
			print('<a id="%s" class="stop" title="Stop HAproxy service" onclick = "return confirm(\'Stop service?\')"><img src=/image/pic/stop.png alt="start" class="icon"></a>' % server[2])
			print('<a id="%s" class="restart" title="Restart HAproxy service" onclick = "if (! confirm(\'Restart service?\')) return false;"><img src=/image/pic/update.png alt="restart" class="icon"></a>' % server[2])
		print('<a href="/app/configshow.py?serv=%s&open=open#conf"  title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % server[2])
		print('<a href="/app/config.py?serv=%s&open=open#conf"  title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % server[2])
		print('<a href="/app/diff.py?serv=%s&open=open#diff"  title="Compare config"><img src=/image/pic/compare.png alt="compare" class="icon"></a>' % server[2])
		print('<a href="/app/map.py?serv=%s&open=open#map"  title="Map listen/frontend/backend"><img src=/image/pic/map.png alt="map" class="icon"></a>' % server[2])
		print('</td><td>')
		funct.ssh_command(server[2], commands1)
		print('</td><td></td></tr>')

	print('</table><table class="overview"><tr class="overviewHead">'
			'<td class="padding10 first-collumn" style="width: 15%;">Server</td>'
			'<td>'
				'HAproxy info'
			'</td>'
			'<td>'
				'Server status'
			'</td>'
		'</tr>')
	print('</td></tr>')
	commands = [ "cat " + haproxy_config_path + " |grep -E '^listen|^backend|^frontend' |grep -v stats |wc -l",  
				"uname -smor", 
				"haproxy -v |head -1", 
				status_command + "|grep Active | sed 's/^[ \t]*//'" ]
	commands1 =  [ "top -u haproxy -b -n 1" ]
	for server in sorted(listhap):
		print('<tr><td class="overviewTr first-collumn"><a name="'+server[1]+'"></a><h3 title="IP ' + server[2] + '">' + server[1] + ':</h3></td>')
		print('<td class="overviewTd"><span>Total listen/frontend/backend:</span><pre>')
		funct.ssh_command(server[2], commands)
		print('</pre></td><td class="overviewTd"><pre>')
		funct.ssh_command(server[2], commands1)
		print('</pre></td></tr>')
		
	print('<tr></table>')
Exemple #6
0
		funct.get_config(serv, cfg)
	else: 
		cfg = configs_dir + form.getvalue('configver')
	try:
		conf = open(cfg, "r")
	except IOError:
		print('<div class="alert alert-danger">Can\'t read config file</div>')
		
	from jinja2 import Environment, FileSystemLoader
	env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True, trim_blocks=True, lstrip_blocks=True, extensions=["jinja2.ext.loopcontrols", "jinja2.ext.do"])
	template = env.get_template('config_show.html')
	
	template = template.render(conf=conf,
								serv=serv, 
								configver=form.getvalue('configver'), 
								role=funct.is_admin(level=2), 
								service=form.getvalue('service'))											
	print(template)
	
	if form.getvalue('configver') is None:
		os.system("/bin/rm -f " + cfg)	
		
		
if form.getvalue('master'):
	master = form.getvalue('master')
	slave = form.getvalue('slave')
	ETH = form.getvalue('interface')
	IP = form.getvalue('vrrpip')
	syn_flood = form.getvalue('syn_flood')
	script = "install_keepalived.sh"
	fullpath = funct.get_config_var('main', 'fullpath')