gui
This commit is contained in:
		| @ -4,10 +4,10 @@ | ||||
| 		<input type="hidden" name="host" value="<< host >>" /> | ||||
| 		<td><a target="_blank" href="http://<<host>>"><<host>></a></td> | ||||
| 		<td><<ip>></td> | ||||
| 		<td class="hidden-xs"><<date>></td> | ||||
| 		<td class="hidden-xs"><<updated_on>></td> | ||||
| 		<td> | ||||
| 			<button type="button" data-host="<< host >>" onclick="editHost(this);" class="btn btn-sm btn-default">Edit</button> | ||||
| 			<button type="button" onclick="formAJAX(this, true)" class="btn btn-sm btn-default">Delete</button> | ||||
| 			<button type="button" onclick="app.host.remove({host:'<<host>>'}, function(){tableAJAX('Host <<host>> delete.')})" class="btn btn-sm btn-default">Delete</button> | ||||
| 		</td> | ||||
| 	</tr> | ||||
| </script> | ||||
| @ -18,22 +18,24 @@ | ||||
| 		var btn = $(btn); | ||||
| 		currentEditHost = btn.data('host'); | ||||
| 		$('.editWindow').slideDown('fast'); | ||||
| 		$('.editWindow .panel-body').slideDown('fast'); | ||||
| 		$('.editWindow .panel-title .pull-left').html("Edit "+btn.data('host')) | ||||
| 		$('.editWindow .panel-title .pull-left').html("Edit "+ btn.data('host')) | ||||
|  | ||||
| 		$('div.editWindow .panel-body span').html($('#addHost').html()) | ||||
| 		$('div.editWindow .panel-body span button').remove() | ||||
|  | ||||
| 		app.hosts.get(currentEditHost, function(error, data){ | ||||
| 			console.log(data) | ||||
| 			$.each( data.results, function( key, val ) { | ||||
| 		$(".editWindow input[name='edit_host']").val(btn.data('host')); | ||||
|  | ||||
| 				$(".editWindow input[name='" + key + "']").val(val); | ||||
| 		app.host.get(currentEditHost, function(error, data){ | ||||
| 			console.log(data) | ||||
| 			$.each( data.results, function( key, value ) { | ||||
| 				if(typeof value == "boolean"){ | ||||
| 					$(".editWindow #"+ key +"-"+ value).prop('checked', true) | ||||
| 				}else{ | ||||
| 					$(".editWindow input[name='" + key + "']").val(value); | ||||
| 				} | ||||
| 				$('.editWindow .panel-body').slideDown('fast'); | ||||
| 			}); | ||||
| 		}); | ||||
| 		// $.getJSON('api/hosts/' + btn.data('host'), function( data ) { | ||||
| 		// 	$("input[name='old_host']").attr('value', btn.data('host')); | ||||
| 		// }); | ||||
| 	} | ||||
|  | ||||
| 	function tableAJAX(actionMessage){ | ||||
| @ -41,16 +43,17 @@ | ||||
| 		$('#tableAJAX').html('').hide(); | ||||
| 		app.util.actionMessage('') | ||||
|  | ||||
| 		app.hosts.list(function(err, data){ | ||||
| 			if(err) return app.util.actionMessage(err);	 | ||||
| 		app.host.list(function(err, data){ | ||||
| 			if(err) return app.util.actionMessage(err, {type: 'danger'});	 | ||||
| 			if(data){ | ||||
| 				$.each(data, function( key, value ) { | ||||
| 					host_row = ich.rowTemplate(value); | ||||
| 					$('#tableAJAX').append(host_row); | ||||
| 				}); | ||||
| 				app.util.actionMessage(actionMessage || '', {type: 'info'}); | ||||
| 				$('#tableAJAX').fadeIn('slow'); | ||||
| 			}else{ | ||||
| 				app.util.actionMessage('No hosts...') | ||||
| 				app.util.actionMessage('No hosts...', {type: 'info'}); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| @ -59,16 +62,33 @@ | ||||
| 		tableAJAX(); //populate the table | ||||
| 		setInterval(tableAJAX, 30000); | ||||
|  | ||||
| 		$('#addHost').on('submit', function(){ | ||||
| 		$('form.addHost').on('submit', function(){ | ||||
| 			event.preventDefault(); | ||||
|  | ||||
| 			$form = $(this); | ||||
|  | ||||
| 			var action = $($form.find('button[type="submit"]')[0]).data('type') | ||||
|  | ||||
| 			app.util.actionMessage('') | ||||
|  | ||||
| 			if($form.attr('isValid') === 'true'){ | ||||
| 				app.hosts.add($form.serializeObject(), function(error, data){					 | ||||
| 					app.util.actionMessage(data.message || 'Error!'); | ||||
| 					if(!error) $form.trigger('reset'); | ||||
| 				var formdata = $form.serializeObject(); | ||||
| 				if(formdata.targetport) formdata.targetport = Number(formdata.targetport); | ||||
| 				if(formdata.targetssl) formdata.targetssl = formdata.targetssl == 'true' ? true : false; | ||||
| 				if(formdata.forcessl) formdata.forcessl = formdata.forcessl == 'true' ? true : false; | ||||
|  | ||||
| 				app.host[action](formdata, function(error, data){ | ||||
| 					if(error){ | ||||
| 						console.log('error data',data) | ||||
| 						app.util.actionMessage(error + data.message, {type: 'danger'}); | ||||
| 						return; | ||||
| 					} | ||||
| 					 | ||||
| 					if(action == 'edit') $('.editWindow').slideUp('fast'); | ||||
|  | ||||
| 					app.util.actionMessage(data.message || 'Error!', {type: 'info'}); | ||||
| 					tableAJAX("Added "+ formdata.host); | ||||
| 					$form.trigger('reset'); | ||||
| 				}) | ||||
| 			} | ||||
| 		}); | ||||
| @ -88,9 +108,10 @@ | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="panel-body"> | ||||
| 				<form action="api" evalAJAX="$('div.editWindow').slideUp();currentEditHost = null;"> | ||||
| 				<form class="addHost" onsubmit="$(this).validate()"> | ||||
| 					<span></span> | ||||
| 					<button type="button" class="btn btn-danger">Update</button> | ||||
| 					<input type="hidden" name="edit_host" /> | ||||
| 					<button type="submit" data-type="edit" class="btn btn-danger host-submit">Update</button> | ||||
| 					<button class="btn btn-link" type="reset">Cancel</button> | ||||
| 				</form> | ||||
| 			</div> | ||||
| @ -106,19 +127,19 @@ | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="panel-body"> | ||||
| 				<form id="addHost" onsubmit="$(this).validate()"> | ||||
| 				<form class="addHost" id="addHost" onsubmit="$(this).validate()"> | ||||
| 					 | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Incoming SSL</label> | ||||
| 						<div class="radio"> | ||||
| 							<label> | ||||
| 								<input type="radio" name="forceSSL" id="forceSSL1" value="true" checked> | ||||
| 								<input type="radio" name="forcessl" id="forcessl-true" value="true" checked> | ||||
| 								Force incoming connections over HTTPS <b>Recommended</b> | ||||
| 							</label> | ||||
| 						</div> | ||||
| 						<div class="radio"> | ||||
| 							<label> | ||||
| 								<input type="radio" name="forceSSL" id="forceSSL2" value="false"> | ||||
| 								<input type="radio" name="forcessl" id="forcessl-false" value="false"> | ||||
| 								Allow use of both HTTP and HTTPS | ||||
| 							</label> | ||||
| 						</div> | ||||
| @ -126,38 +147,38 @@ | ||||
|  | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Hostname</label> | ||||
| 						<input type="text" name="host" class="form-control" placeholder="ex: proxy.cloud-ops.net" validate="host:3" > | ||||
| 						<input type="text" name="host" class="form-control" placeholder="ex: proxy.cloud-ops.net" validate=":3" > | ||||
| 					</div> | ||||
|  | ||||
| 					<hr /> | ||||
|  | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Target IP or Host Name</label> | ||||
| 						<input type="text" name="ip" class="form-control" placeholder="ex: 10.10.10.10" /> | ||||
| 						<input type="text" name="ip" class="form-control" placeholder="ex: 10.10.10.10" validate=":3" /> | ||||
| 					</div> | ||||
|  | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Target TCP Port</label> | ||||
| 						<input type="number"  name="targetPort" class="form-control" value="80" min="0" max="65535" /> | ||||
| 						<input type="number"  name="targetport" class="form-control" value="80" min="0" max="65535" /> | ||||
| 					</div> | ||||
|  | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Target SSL</label> | ||||
| 						<div class="radio"> | ||||
| 							<label> | ||||
| 								<input type="radio" name="targetSSL" id="targetSSL1" value="true"> | ||||
| 								<input type="radio" name="targetssl" id="targetssl-true" value="true"> | ||||
| 								Proxt to HTTPS  | ||||
| 							</label> | ||||
| 						</div> | ||||
| 						<div class="radio"> | ||||
| 							<label> | ||||
| 								<input type="radio" name="targetSSL" id="targetSSL2" value="false" checked> | ||||
| 								<input type="radio" name="targetssl" id="targetssl-false" value="false" checked> | ||||
| 								Proxy to HTTP <b>Recommended</b> | ||||
| 							</label> | ||||
| 						</div> | ||||
| 					</div> | ||||
| 	 | ||||
| 					<button type="submit" class="btn btn-default">Add</button> | ||||
| 					<button type="submit" data-type="add" class="btn btn-default host-submit">Add</button> | ||||
| 				</form> | ||||
| 			</div> | ||||
| 		</div> | ||||
| @ -195,4 +216,4 @@ | ||||
| 		</div> | ||||
| 	</div> | ||||
| </div> | ||||
| <%- include('bottom') %> | ||||
| <%- include('bottom') %> | ||||
|  | ||||
| @ -1,27 +1,32 @@ | ||||
| <%- include('top') %> | ||||
| <script type="text/javascript"> | ||||
|  | ||||
| 	app.auth.isLoggedIn(function(error, isLoggedIn){ | ||||
| 		if(isLoggedIn){ | ||||
| 			window.location.href = app.util.getUrlParameter('redirect') || '/'; | ||||
| 		} | ||||
| 	}) | ||||
|  | ||||
| 	$(document).ready(function(){ | ||||
| 		$( "form[action='login']" ).submit(function( event ) { | ||||
| 			event.preventDefault(); | ||||
| 			$form = $(this); | ||||
| 			app.util.actionMessage('') | ||||
| 			if($form.attr('isValid') === 'true'){ | ||||
|  | ||||
| 				app.auth.logIn($form.serializeObject(), function(error, data){ | ||||
|  | ||||
| 					if(data){ | ||||
| 						app.util.actionMessage('Login successful!'); | ||||
| 						window.location.href = app.util.getUrlParameter('redirect') || '/hosts/'; | ||||
|  | ||||
| 					}else{ | ||||
| 						app.util.actionMessage('Login Failed, please try again');						 | ||||
| 					} | ||||
| 				}); | ||||
|  | ||||
| 			}else{ | ||||
| 				app.util.actionMessage('Please fix the errors bellow!') | ||||
| 			if($form.attr('isValid') !== 'true'){ | ||||
| 				console.log('') | ||||
| 				return app.util.actionMessage('Please fix the errors bellow!') | ||||
| 			} | ||||
| 			event.preventDefault(); | ||||
|  | ||||
| 			app.auth.logIn($form.serializeObject(), function(error, data){ | ||||
| 				if(data){ | ||||
| 					app.util.actionMessage('Login successful!'); | ||||
| 					window.location.href = app.util.getUrlParameter('redirect') || '/'; | ||||
|  | ||||
| 				}else{ | ||||
| 					app.util.actionMessage('Login Failed, please try again');						 | ||||
| 				} | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
| </script> | ||||
| @ -35,7 +40,7 @@ | ||||
| 			<div class="panel-body"> | ||||
| 				<div class="alert alert-warning actionMessage" style="display:none"> | ||||
| 				</div> | ||||
| 				<form method="post" action="login" onsubmit="$(this).validate()"> | ||||
| 				<form action="login" onsubmit="$(this).validate()"> | ||||
| 					<input type="hidden" name="redirect" value="<%= redirect %>"> | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">User name</label> | ||||
|  | ||||
| @ -1,27 +0,0 @@ | ||||
| <% include top %> | ||||
| <div class="row"> | ||||
| 	<div class="col-md-4"> | ||||
| 		<div class="panel panel-default"> | ||||
| 			<div class="panel-heading"> | ||||
| 				<div class="panel-title">Log in</div> | ||||
| 			</div> | ||||
| 			<div class="panel-body"> | ||||
| 				<div class="alert alert-warning actionMessage" style="display:none"> | ||||
| 				</div> | ||||
| 				<form method="post" action="login" onsubmit="$(this).validate()"> | ||||
| 					<input type="hidden" name="redirect" value="<%= redirect %>"> | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Username</label> | ||||
| 						<input type="text" name="username" class="form-control" placeholder="User" validate="user:3" /> | ||||
| 					</div> | ||||
| 					<div class="form-group"> | ||||
| 						<label class="control-label">Password</label> | ||||
| 						<input type="password" name="password" class="form-control" placeholder="Password" validate="password:5" /> | ||||
| 					</div> | ||||
| 					<button type="submit" class="btn btn-default" >Log in</button> | ||||
| 				</form> | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	</div> | ||||
| </div> | ||||
| <% include bottom %> | ||||
| @ -13,7 +13,7 @@ | ||||
| 		<script type="text/javascript" src='/static/js/jquery.min.js'></script> | ||||
| 		<script type="text/javascript" src='/static/js/bootstrap.min.js'></script> | ||||
| 		<script type="text/javascript" src='/static/js/ICanHaz.js'></script> | ||||
| 		<script type="text/javascript" src="/static/js/layout.js"></script> | ||||
| 		<script type="text/javascript" src="/static/js/app.js"></script> | ||||
| 		<script type="text/javascript" src="/static/js/val.js"></script> | ||||
|  | ||||
|  | ||||
| @ -21,7 +21,6 @@ | ||||
| 		<!--[if lt IE 9]> | ||||
| 		<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | ||||
| 		<![endif]--> | ||||
|  | ||||
| 	</head> | ||||
|         <body> | ||||
| 		<nav class="navbar navbar-default" role="navigation"> | ||||
| @ -37,9 +36,9 @@ | ||||
| 			</div> | ||||
| 			<div id="navbar-collapse-1" class="collapse navbar-collapse navbar-ex4-collapse"> | ||||
| 				<ul class="nav navbar-nav navbar-right"> | ||||
| 					<li><a href="hosts">Hosts</a> | ||||
| 					<li><a href="users">User Panel</a> | ||||
| 					<li><a href="logout">Log out</a> | ||||
| 					<li><a href="/hosts">Hosts</a> | ||||
| 					<li><a href="/users">User Panel</a> | ||||
| 					<li><a href="/" onclick="app.auth.logOut()">Log out</a> | ||||
| 				</ul> | ||||
| 			</div> | ||||
| 		</div> | ||||
|  | ||||
| @ -1,38 +1,45 @@ | ||||
| <% include top %> | ||||
| <%- include('top') %> | ||||
| <script id="rowTemplate" type="text/html"> | ||||
| 	<tr action="users" evalAJAX="$form.trigger('reset')"> | ||||
| 		<td><< user >></td> | ||||
| 		<input type="hidden" name="username" value="<< user >>" /> | ||||
| 	<tr action="user/password/<< username >>" method="put" evalAJAX="$form.trigger('reset')"> | ||||
| 		<td> | ||||
| 			<label></label> | ||||
| 			<div class="col-xs-10 form-group"> | ||||
| 				<input type="password" size="30" class="form-control" name="password" placeholder="New password" validate="password:5"/> | ||||
| 			</div> | ||||
| 			<button type="button" onclick="formAJAX(this)" class="btn btn-sm btn-default">Change</button> | ||||
| 			<< uid >>:<< username >>	 | ||||
| 		</td> | ||||
| 		<td> | ||||
| 			<input type="hidden" name="username" value="<< username >>" /> | ||||
| 			<div class="col-xs-10 form-group"> | ||||
| 				<label class="control-label"></label> | ||||
| 				<input type="password" size="15" class="form-control" name="password" placeholder="New password" validate="password:5"/> | ||||
| 			</div> | ||||
|  | ||||
| 			<button type="button btn-warn" onclick="formAJAX(this)" class="btn btn-sm btn-warn"> | ||||
| 				Change | ||||
| 			</button> | ||||
| 		</td> | ||||
| 		<td> | ||||
| 			<button type="button" onclick="app.user.remove({username: '<<username>>'}, function(){tableAJAX('username <<username>> delete.')})" class="btn btn-sm btn-danger"> | ||||
| 				Delete | ||||
| 			</button> | ||||
| 		</td> | ||||
| 		<td><button type="button" onclick="formAJAX(this, true)" class="btn btn-sm btn-default">Delete</button><td> | ||||
| 	</tr> | ||||
| </script> | ||||
| <script type="text/javascript"> | ||||
|  | ||||
| 	function tableAJAX(actionMessage){ | ||||
| 		$('#tableAJAX').html('').hide(); | ||||
| 		$('div.actionMessage').html('Refreshing user list...').show(); | ||||
| 		$.get('users',function(data){ | ||||
| 			$.each( data, function(key, value) { | ||||
| 				user_row = ich.rowTemplate({user : value}); | ||||
| 		app.util.actionMessage('Refreshing user list...') | ||||
|  | ||||
| 		app.user.list(function(error, data){ | ||||
| 			$.each( data.results, function(key, value) { | ||||
| 				if(value.uid+'' && value.uid < 1000) return; | ||||
| 				user_row = ich.rowTemplate(value); | ||||
| 				$('#tableAJAX').append(user_row); | ||||
| 			}); | ||||
|  | ||||
| 			$('#tableAJAX').fadeIn('slow'); | ||||
|  | ||||
| 			if(!actionMessage){ | ||||
| 				$('div.actionMessage').slideUp('fast');  | ||||
| 			}else{ | ||||
| 				$('div.actionMessage').html(actionMessage).slideDown('fast'); | ||||
| 			} | ||||
| 		}); | ||||
| 			app.util.actionMessage(actionMessage || '', {type: 'info'}); | ||||
|  | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	$(document).ready(function(){ | ||||
| @ -51,7 +58,7 @@ | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="panel-body"> | ||||
| 			<form action="users" evalAJAX="$form.trigger('reset')"> | ||||
| 			<form action="user/" evalAJAX="$form.trigger('reset')"> | ||||
| 				<input type="hidden" class="form-control" name="delete" value="false" /> | ||||
| 				<div class="form-group"> | ||||
| 					<label class="control-label">User-name</label> | ||||
| @ -100,4 +107,4 @@ | ||||
| 		</div> | ||||
| 	</div> | ||||
| </div> | ||||
| <% include bottom %> | ||||
| <%- include('bottom') %> | ||||
|  | ||||
| @ -1,103 +0,0 @@ | ||||
| <% include top %> | ||||
| <script id="rowTemplate" type="text/html"> | ||||
| 	<tr action="users" evalAJAX="$form.trigger('reset')"> | ||||
| 		<td><< user >></td> | ||||
| 		<input type="hidden" name="username" value="<< user >>" /> | ||||
| 		<td> | ||||
| 			<label></label> | ||||
| 			<div class="col-xs-10 form-group"> | ||||
| 				<input type="password" size="30" class="form-control" name="password" placeholder="New password" validate="password:5"/> | ||||
| 			</div> | ||||
| 			<button type="button" onclick="formAJAX(this)" class="btn btn-sm btn-default">Change</button> | ||||
| 		</td> | ||||
| 		<td><button type="button" onclick="formAJAX(this, true)" class="btn btn-sm btn-default">Delete</button><td> | ||||
| 	</tr> | ||||
| </script> | ||||
| <script type="text/javascript"> | ||||
|  | ||||
| 	function tableAJAX(actionMessage){ | ||||
| 		$('#tableAJAX').html('').hide(); | ||||
| 		$('div.actionMessage').html('Refreshing user list...').show(); | ||||
| 		$.get('users',function(data){ | ||||
| 			$.each( data, function(key, value) { | ||||
| 				user_row = ich.rowTemplate({user : value}); | ||||
| 				$('#tableAJAX').append(user_row); | ||||
| 			}); | ||||
|  | ||||
| 			$('#tableAJAX').fadeIn('slow'); | ||||
|  | ||||
| 			if(!actionMessage){ | ||||
| 				$('div.actionMessage').slideUp('fast');  | ||||
| 			}else{ | ||||
| 				$('div.actionMessage').html(actionMessage).slideDown('fast'); | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	$(document).ready(function(){ | ||||
| 		tableAJAX(); //populate the table | ||||
| 	}); | ||||
| </script> | ||||
| <div class="row" style="display:none"> | ||||
| 	<div class="col-md-4"> | ||||
| 		<div class="panel panel-default"> | ||||
| 			<div class="panel-heading"> | ||||
| 				<div class="panel-title"> | ||||
| 					Add new user | ||||
| 					<div class="pull-right"> | ||||
| 						<label class="glyphicon glyphicon-circle-arrow-down panel-toggle"></label> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="panel-body"> | ||||
| 			<form action="users" evalAJAX="$form.trigger('reset')"> | ||||
| 				<input type="hidden" class="form-control" name="delete" value="false" /> | ||||
| 				<div class="form-group"> | ||||
| 					<label class="control-label">User-name</label> | ||||
| 					<input type="text" class="form-control" name="username" placeholder="Letter, numbers, -, _, . and @ only" validate="user:3" /> | ||||
| 				</div> | ||||
| 				<div class="form-group"> | ||||
| 					<label class="control-label">Password</label> | ||||
| 					<input type="password" class="form-control" name="password" placeholder="Atleast 5 char. long" validate="password:5"/> | ||||
| 				</div> | ||||
| 				<div class="form-group"> | ||||
| 					<label class="control-label">Again</label> | ||||
| 					<input type="password" class="form-control" name="passwordMatch" placeholder="Retype password" validate="eq:password"/> | ||||
| 				</div> | ||||
| 				<button type="button" onclick="formAJAX(this)" class="btn btn-default">Add</button> | ||||
| 			</form> | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	</div> | ||||
| 	<div class="col-md-8"> | ||||
| 		<div class="panel panel-default"> | ||||
| 			<div class="panel-heading"> | ||||
| 				<div class="panel-title"> | ||||
| 					User List | ||||
| 					<div class="pull-right"> | ||||
| 						<label class="glyphicon glyphicon-circle-arrow-down panel-toggle"></label> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div class="panel-body" style="padding-bottom:0"> | ||||
| 				<div class="alert alert-warning actionMessage" style="display:none"> | ||||
| 					<!-- Message after AJAX action is preformed --> | ||||
| 				</div> | ||||
| 				<div class="table-responsive"> | ||||
| 					<table class="table"> | ||||
| 						<thead> | ||||
| 							<th>Name</th> | ||||
| 							<th>Password</th> | ||||
| 							<th>Delete</th> | ||||
| 						</thead> | ||||
| 						<tbody id="tableAJAX"> | ||||
| 							<!-- ajax loaded table --> | ||||
| 						</tbody> | ||||
| 					</table> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	</div> | ||||
| </div> | ||||
| <% include bottom %> | ||||
		Reference in New Issue
	
	Block a user