Commit cb11fd11 authored by Christophe Le Clerc's avatar Christophe Le Clerc

create GUI for sip-backend admin

parent 869e514b
......@@ -16,7 +16,7 @@ from operator import itemgetter
import jwt
import websockets
from bottle import request, abort, Bottle, JSONPlugin
from bottle import request, abort, Bottle, JSONPlugin, template, static_file
from bottle_sqlite import SQLitePlugin
import ari
......@@ -479,6 +479,43 @@ def originate(db, callid=None):
bottle_logger.exception(e)
abort(400, "Missing or incorrect fields, the call cannot be processed")
@app.get('/static/<filepath:path>')
def static_files(filepath):
"""
take care of static files.
should use apache/nginx instead.
"""
return static_file(filepath, root='./views')
@app.get('/admin')
def little_admin():
users = db.execute('SELECT api, token, admin FROM users').fetchall()
return template('index', users=users)
@app.post('/admin')
def medium_admin():
api = request.forms.get('api')
token = request.forms.get('token')
admin = request.forms.get('admin')
action = request.forms.get('action')
if action == 'delete':
db.execute("DELETE FROM users WHERE api = ?", (api, ))
db.commit()
elif action == 'add':
db.execute("INSERT INTO users (api, token, admin) VALUES (?, ?, ?)", (api, token, admin))
db.commit()
elif action == 'update':
db.execute("UPDATE users set token = ?, admin = ? where api = ?", (token, admin, api ))
db.commit()
users = db.execute('SELECT api, token, admin FROM users').fetchall()
return template('index', users=users)
if __name__ == '__main__':
db = sqlite3.connect(config['piphone']['db'])
phone_logger.info("Starting the piphone SIP backend")
......
This source diff could not be displayed because it is too large. You can view the blob instead.
.navbar-static-top {
margin-bottom:20px;
}
i {
font-size:18px;
}
footer {
margin-top:20px;
padding-top:20px;
padding-bottom:20px;
background-color:#efefef;
}
.nav>li .count {
position: absolute;
top: 10%;
right: 25%;
font-size: 10px;
font-weight: normal;
background: rgba(41,200,41,0.75);
color: rgb(255,255,255);
line-height: 1em;
padding: 2px 4px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
-o-border-radius: 10px;
border-radius: 10px;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>PiPhone Control Panel</title>
<meta name="generator" content="Bootply" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="static/css/styles.css" rel="stylesheet">
</head>
<body>
<div id="top-nav" class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-toggle"></span>
</button>
<a class="navbar-brand" href="#">PiPhone Control Panel</a>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<a href="#"><strong><i class="glyphicon glyphicon-list-alt"></i> Users</strong></a>
<hr>
</div>
<div class="col-md-8">
<form class="form" action="admin" method="post">
<table class="table table-striped">
<thead>
<tr>
<th>API</th>
<th>Token</th>
<th>admin</th>
<th>delete?</th>
</tr>
</thead>
<tbody>
% for user in users:
<tr>
<td>{{user[0]}}</td>
<td>{{user[1]}}</td>
<td>{{user[2]}}</td>
<td><input type="checkbox" name="api" value="{{ user[0] }}"></td>
</tr>
%end
</tbody>
</table>
<button name="action" value="delete" type="submit" class="btn btn-danger pull-right">
Delete
</button>
</form>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<h4>Add a user</h4>
</div>
</div>
<div class="panel-body">
<form name="action2" class="form form-vertical" action="admin" method="post">
<div class="control-group">
<label>API</label>
<div class="controls">
<input name="api" type="text" class="form-control" placeholder="API">
</div>
</div>
<div class="control-group">
<label>Token</label>
<div class="controls">
<input name="token" type="text" class="form-control" placeholder="Token">
</div>
</div>
<div class="control-group">
<label>Admin</label>
<div class="controls">
<input name="admin" type="text" class="form-control" placeholder="admin">
</div>
</div>
<div class="control-group">
<label></label>
<div class="controls">
<div class="btn-group pull-right" role="group">
<button class="btn btn-warning" name="action" value="update" type="submit">Update</button>
<button class="btn btn-success" name="action" value="add" type="submit">Add</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="static/js/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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