Browse Source

draft work

main
david 5 years ago
parent
commit
7ba18be952
  1. 1
      factoriocp.conf.sample
  2. 46
      factoriocp.py
  3. BIN
      static/favicon.ico
  4. 129
      views/default.tpl
  5. 17
      views/footer.tpl
  6. 31
      views/header.tpl
  7. 15
      views/login.tpl
  8. 98
      views/server.tpl

1
factoriocp.conf.sample

@ -12,6 +12,7 @@ static_files=/path/to/static/files
host=localhost
port=8000
debug=True
fqdn=factorio.socialnerds.org
[factorio]
path=/path/to/factorio/servers

46
factoriocp.py

@ -41,15 +41,16 @@ def log_in(username, password):
# get a list of server dicts
def get_servers():
pass
return [{ "name": "Creative fun", "version": "0.14.20", "status": "online" },
{ "name": "Mad enemies", "version": "0.14.19", "status": "offline" }]
return [{ "name": "Creative fun", "version": "0.14.20", "status": "online", "port": "43564" },
{ "name": "Mad enemies", "version": "0.14.19", "status": "offline", "port": "65432" },
{ "name": "Mad enemies2", "version": "0.14.19", "status": "offline", "port": "65431" }]
# routing
# render main page
@get('/')
def home():
def view_home():
username = logged_in()
message = request.get_cookie(config['DEFAULT']['cookie_name'] + "_message",
secret=config['DEFAULT']['cookie_secret'])
@ -70,7 +71,7 @@ def home():
# get login credentials
@post('/login')
def post_login():
def login():
username = request.forms.get('username')
password = request.forms.get('password')
if log_in(username, password):
@ -90,7 +91,6 @@ def post_login():
# delete cookie
@get('/logout')
@get('/logout/')
def logout():
if logged_in():
response.delete_cookie(config['DEFAULT']['cookie_name'])
@ -108,6 +108,42 @@ def logout():
def send_static(filename):
return static_file(filename, root=config['DEFAULT']['static_files'])
# render server page
@get('/server/<port:int>')
def view_server(port):
username = logged_in()
message = request.get_cookie(config['DEFAULT']['cookie_name'] + "_message",
secret=config['DEFAULT']['cookie_secret'])
if username:
servers = get_servers()
server = [ server for server in servers if int(server['port']) == int(port) ]
if server:
return template('server',
app_name=config['DEFAULT']['app_name'],
server=server[0],
username=username,
fqdn=config['server']['fqdn'],
message=message)
else:
message = { "message": "Server does not exist", "alert": "danger" }
response.set_cookie(config['DEFAULT']['cookie_name'] + "_message",
message,
secret=config['DEFAULT']['cookie_secret'],
max_age=5,
path="/")
redirect("/")
else:
redirect("/")
# create new server
@get('/create')
def create_server():
pass
# run webserver
if __name__ == "__main__":

BIN
static/favicon.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 15 KiB

129
views/default.tpl

@ -1,71 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/favicon.ico">
<title>{{ app_name }}</title>
<!-- Bootstrap core CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/static/css/sticky-footer.css" rel="stylesheet">
</head>
<body>
<div class="container">
<p>
%if message:
<div class="alert alert-{{ message['alert'] }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{{ message['message'] }}.
</div>
%end
</p>
%include('header.tpl', app_name=app_name, message=message)
<!-- Begin page content -->
<div class="container">
<div class="row">
<div class="col-sm-8">
<h1>Servers</h1>
</div>
<!-- Begin page content -->
<div class="container">
<div class="mt-1">
<h1>{{ app_name }}</h1>
<div class="col-sm-4 text-xs-right">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ username }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="/">Server overview</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Create server</a>
<a class="dropdown-item" href="#">Create server from .zip</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/logout">Logout</a>
</div>
</div>
<p class="lead">{{ username }} (<a href="/logout">logout</a>)</p>
<p>This is your Factorio server control panel.</p>
<p>It is <a href="https://en.wikipedia.org/wiki/Free_software">free software</a> and its code is hosted <a href="https://socialg.it/david/factoriocp">here</a>.</p>
<h2>Servers</h2>
<hr>
%for server in servers:
%if server['status'] == "online":
<h4>{{ server['name'] }} <span class="tag tag-success">{{ server['status'] }}</span></h4>
%else:
<h4>{{ server['name'] }} <span class="tag tag-danger">{{ server['status'] }}</span></h4>
%end
Version: <b>{{ server['version'] }}</b>
<br><br>
%end
</div>
</div>
<p class="lead">Control your <a href="http://factorio.com">Factorio</a> game servers from here.</p>
<footer class="footer">
<div class="container">
<span class="text-muted">factoriocp v0.1</span>
</div>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/static/js/vendor/jquery.min.js"><\/script>')</script>
<script src="/static/js/bootstrap.min.js"></script>
</body>
</html>
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Version</th>
<th>Port</th>
<th>Status</th>
<th class="text-xs-right">Actions</th>
</tr>
</thead>
<tbody>
%for server in servers:
%if server['status'] == "online":
<tr>
<th>{{ server['name'] }}</th>
<td>{{ server['version'] }}</td>
<td>{{ server['port'] }}</td>
<td><span class="tag tag-success">{{ server['status'] }}</span></td>
<td class="text-xs-right">
<a href="/stop/{{ server['port' ]}}" type="button" class="btn btn-outline-danger btn-sm">Stop</a>
<a href="/server/{{ server['port'] }}" type="button" class="btn btn-outline-primary btn-sm">Edit</a>
</td>
</tr>
%else:
<tr>
<th>{{ server['name'] }}</th>
<td>{{ server['version'] }}</td>
<td>{{ server['port'] }}</td>
<td><span class="tag tag-danger">{{ server['status'] }}</span></td>
<td class="text-xs-right">
<a href="/start/{{ server['port'] }}" type="button" class="btn btn-outline-success btn-sm">Start</a>
<a href="/delete/{{ server['port'] }}" type="button" class="btn btn-outline-danger btn-sm">Delete</a>
<a href="/server/{{ server['port'] }}" type="button" class="btn btn-outline-primary btn-sm">Edit</a>
</td>
</tr>
%end
%end
</tbody>
</table>
</div> <!-- Page content -->
%include('footer.tpl', username=username)

17
views/footer.tpl

@ -0,0 +1,17 @@
<footer class="footer">
<div class="container">
<div class="text-muted">
factoriocp v0.1
</div>
</div>
</footer>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/static/js/vendor/jquery.min.js"><\/script>')</script>
<script src="/static/js/bootstrap.min.js"></script>
</body>
</html>

31
views/header.tpl

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/static/favicon.ico">
<title>{{ app_name }}</title>
<!-- Bootstrap core CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/static/css/sticky-footer.css" rel="stylesheet">
</head>
<body>
<!-- Begin alert message -->
<div class="container">
<p>
%if message:
<div class="alert alert-{{ message['alert'] }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{{ message['message'] }}.
</div>
%end
</p>
</div> <!-- alert message -->

15
views/login.tpl

@ -20,15 +20,7 @@
<body>
<div class="container">
%if message:
<div class="alert alert-{{ message['alert'] }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{{ message['message'] }}.
</div>
%end
</div>
<!-- Begin page content -->
<div class="container">
<form class="form-signin" action="/login" method="post">
<h2 class="form-signin-heading">{{ app_name }}</h2>
@ -39,10 +31,7 @@
<p>For security reasons every session will expire {{ int(cookie_max_age/60) }} minutes after login.</p>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
</form>
</div> <!-- /container -->
</div> <!-- Page content -->
<!-- Bootstrap core JavaScript
================================================== -->

98
views/server.tpl

@ -0,0 +1,98 @@
%include('header.tpl', app_name=app_name, message=message)
<!-- Begin page content -->
<div class="container">
<div class="row">
<div class="col-sm-8">
%if server['status'] == "online":
<h1>{{ server['name'] }}<sup><span class="tag tag-success tag-sm">Online</span></sup></h1>
%else:
<h1>{{ server['name'] }}<sup><span class="tag tag-danger tag-sm">Offline</span></sup></h1>
%end
</div>
<div class="col-sm-4 text-xs-right">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ username }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="/">Server overview</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Create server</a>
<a class="dropdown-item" href="#">Create server from .zip</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/logout">Logout</a>
</div>
</div>
</div>
</div>
<p class="lead">Some fon server description goes here.</p>
<table class="table">
<tr>
<th>Address</th>
<th>Version</th>
<th class="text-xs-right">Actions</th>
</tr>
%if server['status'] == "online":
<tr>
<td><code>{{ fqdn }}:{{ server['port'] }}</code></td>
<td><code>{{ server['version'] }}</code></td>
<td class="text-xs-right">
<a href="/stop/{{ server['port'] }}" type="button" class="btn btn-outline-danger btn-sm">Stop</a>
</td>
</tr>
%else:
<tr>
<td><code>{{ fqdn }}:{{ server['port'] }}</code></td>
<td><code>{{ server['version'] }}</code></td>
<td class="text-xs-right">
<a href="/start" type="button" class="btn btn-outline-success btn-sm">Start</a>
<a href="/delete/{{ server['port'] }}" type="button" class="btn btn-outline-danger btn-sm">Delete</a>
</td>
</tr>
%end
</table>
<p>
<h4>Settings</h4>
<hr>
<form class="form-inline">
<input>
</form>
</p>
<p>
<h4>Backups</h4>
<hr>
<form class="form-inline">
<input>
</form>
</p>
<p>
<h4>Mods</h4>
<hr>
<form class="form-inline">
<input>
</form>
</p>
<p>
<h4>Screenshots</h4>
<hr>
<form class="form-inline">
<input>
</form>
</p>
<p>
<h4>Console</h4>
<hr>
<form class="form-inline">
<input>
</form>
</p>
</div> <!-- Page content -->
%include('footer.tpl', username=username)