add iot app store demo (#96)

This commit is contained in:
luhanzhl
2019-08-14 10:37:39 +08:00
committed by Wang Xin
parent 51ac31eaa1
commit 2f10027447
51 changed files with 3020 additions and 0 deletions

View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class DevicesConfig(AppConfig):
name = 'devices'

View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1,152 @@
<!-- /* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ -->
{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
<title> Wasm-Micro-Runtime </title>
<link rel="stylesheet" type="text/css" href="{%static 'css/application.css'%}"/>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body style="background-image: linear-gradient(to right, rgb(248, 248, 248) , rgb(194, 194, 190))">
<div id="container" style="background-image: url('{%static 'photo//totalblack.png'%}')">
<div id="content">
<div id= "mainnav">
<ul>
<li ><a href="https://github.com/intel/wasm-micro-runtime">GitHub</a></li>
<li ><a href="/">Devices</a></li>
<li ><a href="/appstore/">App Store</a></li>
<li ><a href="/help/">Help</a></li>
</ul>
</div>
</div>
<div class="headers" style="background-image: url('{%static 'photo/milky-way-2695569_1280.jpg'%}')">
<h1 id="maintitle">WebAssembly Micro Runtime - APP Store Demo</h1>
</div>
</div>
<div class="row">
<div class="col-sm-2 col-md-2 col-lg-2 col-xl-2"></div>
<div class="col-sm-8 col-md-8 col-lg-8 col-xl-8" id="section">
<div id="photo">
<p>
<img src="{%static 'photo/net_device.png'%}" ;height="65" width="65" />
</p>
</div>
<div id="IPs">IP : </div>
<div id="ports">Port : </div>
<div id="installs">Installed apps : </div>
</div>
<div class="col-sm-2 col-md-2 col-lg-2 col-xl-2"></div>
</div>
<div class="middlebox" style="display:none;">
<div class="warning">Dialog Box</div>
<div class="findapp"> APP </div>
<button class="surebtn" type="button" value="sure">OK</button>
</div>
<div class="deletebox" style="display:none;">
<div class="warning2">Dialog Box</div>
<div class="findapp"> APP </div>
<button class="suresbtn" type="button" value="sure">OK</button>
<button class="cancelsbtn" type="button" value="Cancel">Cancel</button>
</div>
<div id="loading">
<p class="loadapp"> app is downloading now </p>
<div id="preloader">
<div id="loader"></div>
</div>
</div>
<div class="main">
<div class="mainbox">
<div class= "close"> × </div>
<div class="hotapps">HOT Applications</div>
<div class="col-sm-6" id="searchbar">
<form method="post" action="/apps/" id="form_addServiceInfoAll">
{% csrf_token %}
<div class="input-group">
<input type="text" name="mykey" class="form-control" placeholder="Input the product name" required />
<input type="hidden" name="voip" id="aa" value="">
<input type="hidden" name="voport" id="bb" value="">
<span class="input-group-btn">
<input type="submit" class="btn btn-default" value="Search" />
</span>
</div>
</form>
</div>
<div id="scrollba">
<div id="Dapplications">
<div id="appslogo" style="width:45px; height:25px; float:left; "><img src="{%static 'photo/application.png'%}" ;height="35" width="35" /></div>
<p id="appsinfo1" style="font-size:15px;font-family:'sansationlight';width:310px; height:25px; float:left; "> Product Name: </p>
<p id="appsinfo2" style="font-size:15px;font-family:'sansationlight';width:120px; height:25px; float:left; "> Current Version: </p>
<button class="mybtn2" type="button" onclick="getthis(this)" value="downloadit"> ↓ Install</button>
</div>
</div>
</div>
</div>
<div class="col-sm-8 col-md-8 col-lg-8 col-xl-8" id="download">
<p class = "explain pull-left" >List of Installed Apps:</p>
<button id="btn" class="btn btn-outline-primary pull-right" style="float:right" type="button" value="add">Install Application</button>
</div>
<div id="APPS" class="sourceapp">
<div id="applications">
<div id="applogo"><img src="{%static 'photo/app(1).png'%}" ;height="35" width="35" /></div>
<div id="appinfo1"> Product Name: </div>
<div id="appinfo2"> Staus: </div>
<div id="appinfo3"> Current Version: </div>
</div>
<div id="delete" ><img class="mybtn" style="cursor:pointer" src="{%static 'photo/delete.png'%}" ;height="35" width="35" /></div>
</div>
<footer class="footer"> Copyright&copy; intel.com</footer>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var alist = {{alist|safe}}; /*alist is a list of downloaded apps under the current device*/
var dlist = {{dlist|safe}}; /*dlist saves the device info that includes its IP, Port and number of apps*/
var llist = {{llist|safe}}; /*llist is a list of apps avaliable for installing that are synchronously updated with appstore*/
var open_status ={{open_status|safe}};/*check is the search bar working&searching,otherwise, close window and return to the main page*/
var search_node ={{search_node|safe}};/*THe queried app node*/
</script>
<script type="text/javascript" src="{%static 'js/application.js'%}"></script>
</body>
</html>

View File

@ -0,0 +1,106 @@
<!-- /* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ -->
{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
<title> Wasm-Micro-Runtime </title>
<link rel="stylesheet" type="text/css" href="{%static 'css/appstore.css'%}"/>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body style="background-color:rgb(240, 240, 240)">
<div id="container" style="background-image: url('{%static 'photo//totalblack.png'%}')">
<div id="content">
<div id= "mainnav">
<ul>
<li ><a href="https://github.com/intel/wasm-micro-runtime">GitHub</a></li>
<li ><a href="/">Devices</a></li>
<li ><a href="/appstore/">App Store</a></li>
<li ><a href="/help/">Help</a></li>
</ul>
</div>
</div>
<div class="headers" style="background-image: url('{%static 'photo/milky-way-2695569_1280.jpg'%}')">
<h1 id="maintitle">WebAssembly Micro Runtime - APP Store Demo</h1>
</div>
</div>
<!-- <div id="introinfo"></div> -->
<!-- <div class="style-one"></div> -->
<div class="deletebox" style="display:none;">
<div class="warning2">Dialog Box</div>
<div class="findapp"> APP </div>
<button class="suresbtn" type="button" value="sure">OK</button>
<button class="delsbtn" type="button" value="Cancel">Cancel</button>
</div>
<div id = "introstore">
<div id="applicationlist">
<div class="bar">
<div class="leftpart">The products </div>
<div style="position:relative; float:left; left:50px; font-size:14px; height:50px; top:10px;">Application List</div>
<div class="rightpart">
<form action="/upload" method = "POST" enctype="multipart/form-data">
{%csrf_token%}
<div class="stylehere">
<input type ="file" required name="myfile" class = "file">
<a href="#" class="choosestyle">Choose File</a>
</div>
<div class="stylehere">
<input type="submit" value = "upload" class="btn btn-info">
</div>
</form>
</div>
</div>
<div class = "appbook">
<div id="applications">
<div id="appimage" ><img class="mysoftware" src="{%static 'photo/software-icon-32081.png'%}" ;height="50" width="40"/></div>
<p id="appinfo1" style="position:relative; font-size:15px;width:35%; height:25px; float:left; left:5%;"> Product Name: </p>
<p id="appinfo2" style="position:relative; font-size:15px;width:30%; height:25px; float:left; left:5%;"> Product Version: </p>
<p id="lable" style="position:relative;font-size:11px;font-family:'logo';width:10%; height:25px; float:left; left:5%;"> Preloaded Apps </p>
<button id="delbutton" type="button" style="position: relative; height:25px; float:left; left:5%;" onclick="deleteClick(this)" method = "get" name="delete">Remove</button>
</div>
</div>
<br>
</div>
</div>
</div>
<footer class="footer">
Copyright&copy; intel.com
</footer>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var elist = {{staticlist|safe}}/*saves all the apps that preloaded and are not able to be removed from applestore*/
var flist = {{flist|safe}} /*a list of locally uploaded apps installed by users*/
var ulist = {{ulist|safe}} /*Declare about is the app avaliable for uploading to the appstore: wasm_file OR preloaded already*/
</script>
<script type="text/javascript" src="{%static 'js/appstore.js'%}"></script>
</body>
</html>

View File

@ -0,0 +1,119 @@
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>wasm-micro-runtime</title>
<style type="text/css">
html, body{overflow:hidden;margin:0;background:#000;}
body{font-family:'Open Sans', 'Helvetica Neue', 'Hiragino Sans GB', 'LiHei Pro', Arial, sans-serif;color:#333;}
#wrapper{position:absolute;left:0;width:320px;text-align:center;top:50%;left:50%;margin-left:-160px;margin-top:-160px;-webkit-user-select:none;-moz-user-select:none;user-select:none;}
h1{font-family:'Montserrat', 'Helvetica Neue', Arial, sans-serif;font-weight:700;font-size:50px;letter-spacing:9px;text-transform:uppercase;color:#eee;margin:12px 0;left:4px;}
h2{color:#999;font-weight:normal;font-size:20px;letter-spacing:.200em;margin-bottom:30px;left:3px;}
h1, h2{position:relative;}
p{font-size:14px;line-height:2em;margin:0;letter-spacing:2px;}
canvas{position:absolute;top:0;left:0;z-index:0;width:100%;height:100%;pointer-events:none;}
a{color:#999;text-decoration:none;transition:color .2s ease;}
a:hover{color:#f33;}
</style>
</head>
<body>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<div id="wrapper">
<h1>404</h1>
<h2>Server Not Found</h2>
<p><a href="https://github.com/intel/wasm-micro-runtime" target="_blank">Github</a></p>
</div>
<canvas width="1920" height="917"></canvas>
<script type="text/javascript">
document.addEventListener('touchmove', function (e) {
e.preventDefault()
})
var c = document.getElementsByTagName('canvas')[0],
x = c.getContext('2d'),
pr = window.devicePixelRatio || 1,
w = window.innerWidth,
h = window.innerHeight,
f = 90,
q,
m = Math,
r = 0,
u = m.PI*2,
v = m.cos,
z = m.random
c.width = w*pr
c.height = h*pr
x.scale(pr, pr)
x.globalAlpha = 0.6
function i(){
x.clearRect(0,0,w,h)
q=[{x:0,y:h*.7+f},{x:0,y:h*.7-f}]
while(q[1].x<w+f) d(q[0], q[1])
}
function d(i,j){
x.beginPath()
x.moveTo(i.x, i.y)
x.lineTo(j.x, j.y)
var k = j.x + (z()*2-0.25)*f,
n = y(j.y)
x.lineTo(k, n)
x.closePath()
r-=u/-50
x.fillStyle = '#'+(v(r)*127+128<<16 | v(r+u/3)*127+128<<8 | v(r+u/3*2)*127+128).toString(16)
x.fill()
q[0] = q[1]
q[1] = {x:k,y:n}
}
function y(p){
var t = p + (z()*2-1.1)*f
return (t>h||t<0) ? y(p) : t
}
document.onclick = i
document.ontouchstart = i
i()
</script>
<script type="text/javascript">
var snow = function() {
if(1==1) {
$("body").append('<canvas id="christmasCanvas" style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;"></canvas>');
var b = document.getElementById("christmasCanvas"), a = b.getContext("2d"), d = window.innerWidth, c = window.innerHeight;
b.width = d;
b.height = c;
for(var e = [], b = 0;b < 70;b++) {
e.push({x:Math.random() * d, y:Math.random() * c, r:Math.random() * 4 + 1, d:Math.random() * 70})
}
var h = 0;
window.intervral4Christmas = setInterval(function() {
a.clearRect(0, 0, d, c);
a.fillStyle = "rgba(255, 255, 255, 0.6)";
a.shadowBlur = 5;
a.shadowColor = "rgba(255, 255, 255, 0.9)";
a.beginPath();
for(var b = 0;b < 70;b++) {
var f = e[b];
a.moveTo(f.x, f.y);
a.arc(f.x, f.y, f.r, 0, Math.PI * 2, !0)
}
a.fill();
h += 0.01;
for(b = 0;b < 70;b++) {
if(f = e[b], f.y += Math.cos(h + f.d) + 1 + f.r / 2, f.x += Math.sin(h) * 2, f.x > d + 5 || f.x < -5 || f.y > c) {
e[b] = b % 3 > 0 ? {x:Math.random() * d, y:-10, r:f.r, d:f.d} : Math.sin(h) > 0 ? {x:-5, y:Math.random() * c, r:f.r, d:f.d} : {x:d + 5, y:Math.random() * c, r:f.r, d:f.d}
}
}
}, 70)
}
}
snow();
</script><canvas id="christmasCanvas" style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;" width="1920" height="917"></canvas>
</body></html>

View File

@ -0,0 +1,110 @@
<!-- /* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ -->
{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Wasm-Micro-Runtime </title>
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="{%static%/css/index.css"/> -->
<!-- <link rel="stylesheet" type="text/css" href="/home/xujun/mysite/static/css/index.css"/> -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
<head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="jumbotron">
<h1>
How to use?
</h1>
<p>
1. Download a simple runtime (build for ubuntu 16.04 64 bits, other platforms please build
from the <a href="https://github.com/intel/wasm-micro-runtime">source code</a>)
</p>
<p>
2. In the terminal: <code>cd ~/Download && ./simple -a 39.106.110.7</code>
</p>
<div class="span12">
<div class="alert alert-info">
<!-- <button class="close" type="button" data-dismiss="alert">×</button> -->
<h5>
Notes:
</h5> We also have a <strong>UI-enabled runtime</strong>, please <a
href="../static/upload/simple">download here</a> and enjoy.</strong> It may require
a few more setups.
<p>Before running the UI-enabled runtime, please install some required softwares:</p>
<p><code>sudo apt-get install libsdl2-2.0-0:i386</code> </p>
<p>For more details please refer to this <a
href="https://github.com/intel/wasm-micro-runtime/tree/master/samples/littlevgl">guide</a>
</p>
<p><code>cd ~/Download && ./wasm_runtime_wgl -a 39.106.110.7</code></p>
</div>
</div>
<p>
3. Return to device page, find your device according to the IP address and click it, you
will enter application installation page
</p>
<p>
4. In the application installation page, click the Install Application button, and chose an
app to install. (The "ui_app" is only for UI_enabled_runtimes, simple runtime can't install
this app)
</p>
<p>
5. If you want to upload a new application, go to App Store page, choose a file and click
upload
</p>
<p>
<a class="btn btn-primary btn-large" href="/">Go Back</a>
<a class="btn btn-primary btn-large" href="../static/upload/simple">Download
simple_runtime</a>
<a class="btn btn-primary btn-large" href="../static/upload/wasm_runtime_wgl">Download
UI_enabled_runtime</a>
</p>
</div>
<div class="container">
<div class="card">
<div class="card-body">
<h4 class="card-title">Like this project?</h4>
<p class="card-text">Join us and build a powerful and interesting world for embedded
devices!</p>
<iframe
src="https://ghbtns.com/github-btn.html?user=intel&repo=wasm-micro-runtime&type=star&count=true&size=large"
frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
<iframe
src="https://ghbtns.com/github-btn.html?user=intel&repo=wasm-micro-runtime&type=fork&count=true&size=large"
frameborder="0" scrolling="0" width="158px" height="30px"></iframe>
<p>
<a href="https://github.com/intel/wasm-micro-runtime" class="btn btn-success">View
on GitHub</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,99 @@
<!-- /* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ -->
{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,shrink-to-fit=no">
<title> Wasm-Micro-Runtime </title>
<link rel="stylesheet" type="text/css" href="{%static 'css/index.css'%}"/>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div id="container" style="background-image: url('{%static 'photo/totalblack.png'%}')">
<div id="content">
<div id= "mainnav">
<ul>
<li ><a href="https://github.com/intel/wasm-micro-runtime">GitHub</a></li>
<li ><a href="/">Devices</a></li>
<li ><a href="/appstore/">App Store</a></li>
<li ><a href="/help/">Help</a></li>
</ul>
</div>
</div>
<div class="headers" style="background-image: url('{%static 'photo/milky-way-2695569_1280.jpg'%}')">
<h1 id="maintitle">WebAssembly Micro Runtime - APP Store Demo</h1>
</div>
</div>
<div class="row">
<div class="col-sm-1 col-md-1 col-lg-1 col-xl-1"></div>
<div class="col-sm-4 col-md-4 col-lg-4 col-xl-4">
<div id="photo2">
<p>
<img src="{%static 'photo/net_device.png'%}" ;height="45" width="45" />
</p>
</div>
<div id="devic"><p style="font-size:22px;">The devices</p></div>
</div>
</div>
<div id="dividebar"></div>
<div id="devices" class="devics">
<div class="deviceClick" style="cursor:pointer" onclick="deviceClick(this)">
<div id="section">
<div id="photo">
<p>
<img src="{%static 'photo/net_device.png'%}" ;height="60" width="60" />
</p>
</div>
<div id="IPs">IP : </div>
<div id="ports">Port : </div>
<div id="installs">Installed apps : </div>
</div>
<div class="smenu">
<p id="del" style="cursor:pointer">
<img class = "toapps" src="{%static 'photo/menu.png'%}" href= "javascript:void(0);" height="30" width="30" />
</p>
</div>
</div>
</div>
<!-- <button class="prev" type="button" value="prev" onclick="prevpage(this)">Previous</button>-->
<!-- <button class="next" type="button" value="next" onclick="nextpage(this)">Next</button> -->
<footer class="footer">
Copyright&copy; intel.com
</footer>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var dlist = {{dlist|safe}};/*Devices List that render to the current page*/
</script>
<script type="text/javascript" src="{%static 'js/index.js'%}"></script>
</body>
</html>

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,284 @@
'''
/* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'''
# _*_
from django.shortcuts import render, render_to_response
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
import json
import socket
import os
# Create your views here.
avaliable_list = [
{'ID': 'timer', 'Version': '1.0'},
{'ID': 'connection', 'Version': '1.0'},
{'ID': 'event_publisher', 'Version': '3.0'},
{'ID': 'event_subscriber', 'Version': '1.0'},
{'ID': 'request_handler', 'Version': '1.0'},
{'ID': 'sensor', 'Version': '1.0'},
{'ID': 'ui_app', 'Version': '1.0'}
]
# Help
def help(req):
# return "Help" page
return render(req, "help.html")
# View
def index(req):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '127.0.0.1'
port = 8889
msg = ""
err = ""
try:
s.connect((host, port))
s.send(bytes("query:all", encoding='utf8'))
s.settimeout(10)
msg = s.recv(1024)
except socket.timeout as e:
err = "empty"
print("no client connected")
except socket.error as e:
err = "refused"
print("server not started")
s.close()
device_list = []
if msg != "":
devices = msg.decode('utf-8').split("*")
for dev in devices:
dev_info = eval(dev)
addr = dev_info['addr']
port = dev_info['port']
apps = dev_info['num']
device_list.append({'IP': addr, 'Port': port, 'apps': apps})
else:
if err == "refused":
return render(req, "empty.html")
dlist = device_list
return render(req, 'mysite.html', {'dlist': json.dumps(dlist)})
def apps(req):
open_status = ''
search_node = []
if req.method == "POST":
dev_search = req.POST['mykey']
dev_addr = req.POST['voip']
dev_port = req.POST['voport']
open_status = 'open'
for i in avaliable_list:
if i['ID'] == dev_search:
search_node = [{'ID':dev_search, 'Version': '1.0'}]
print("search_node:",search_node)
break
else:
search_node = ["Nothing find"]
print( "final:",search_node)
else:
dev_addr = req.GET['ip']
dev_port = req.GET['port']
open_status = 'close'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '127.0.0.1'
port = 8889
msg = ""
err = ""
try:
s.connect((host, port))
s.send(bytes("query:"+dev_addr+":"+str(dev_port), encoding='utf8'))
msg = s.recv(1024)
except socket.error as e:
print("unable to connect to server")
msg = b"fail"
s.close()
app_list = []
if msg != "":
if msg.decode() == "fail":
return render(req, "empty.html")
else:
dic = eval(msg.decode(encoding='utf8'))
app_num = dic["num"]
for i in range(app_num):
app_list.append(
{'pname': dic["applet"+str(i+1)], 'status': 'Installed', 'current_version': '1.0'})
alist = app_list
device_info = []
device_info.append(
{'IP': dev_addr, 'Port': str(dev_port), 'apps': app_num})
print(device_info)
return render(req, 'application.html', {'alist': json.dumps(alist), 'dlist': json.dumps(device_info), 'llist': json.dumps(avaliable_list),
"open_status":json.dumps(open_status),"search_node": json.dumps(search_node),})
def appDownload(req):
dev_addr = req.GET['ip']
dev_port = req.GET['port']
app_name = req.GET['name']
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '127.0.0.1'
port = 8889
msg = ""
app_path = os.path.abspath(os.path.join(os.getcwd(), "static", "upload"))
if app_path[-1] != '/':
app_path += '/'
try:
s.connect((host, port))
s.send(bytes("install:"+dev_addr+":"+str(dev_port)+":"+app_name +
":"+app_path + app_name + ".wasm", encoding='utf8'))
msg = s.recv(1024)
except socket.error as e:
print("unable to connect to server")
s.close()
success = "ok"
fail = "Fail!"
status = [success, fail]
print(msg)
if msg == b"fail":
return HttpResponse(json.dumps({
"status": fail
}))
elif msg == b"success":
return HttpResponse(json.dumps({
"status": success
}))
else:
return HttpResponse(json.dumps({
"status": eval(msg.decode())["error message"].split(':')[1]
}))
def appDelete(req):
dev_addr = req.GET['ip']
dev_port = req.GET['port']
app_name = req.GET['name']
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = '127.0.0.1'
port = 8889
s.connect((host, port))
s.send(bytes("uninstall:"+dev_addr+":" +
str(dev_port)+":"+app_name, encoding='utf8'))
msg = s.recv(1024)
s.close()
r = HttpResponse("ok")
return r
static_list = [{'ID': 'timer', 'Version': '1.0'}, {'ID': 'connection', 'Version': '1.0'}, {'ID': 'event_publisher', 'Version': '3.0'}, {
'ID': 'event_subscriber', 'Version': '1.0'}, {'ID': 'reuqest_handler', 'Version': '1.0'}, {'ID': 'sensor', 'Version': '1.0'}, {'ID': 'ui_app', 'Version': '1.0'}]
def store(req):
store_path = os.path.join('static', 'upload')
status = []
print(user_file_list)
return render(req, 'appstore.html', {'staticlist': json.dumps(static_list), 'flist': json.dumps(user_file_list),'ulist':json.dumps(status)})
user_file_list = []
files_list = []
def uploadapps(req):
status = []
local_list = ['timer','connection','event_publisher','event_subscriber','reuqest_handler','sensor']
req.encoding = 'utf-8'
if req.method == 'POST':
myfile = req.FILES.get("myfile", None)
obj = req.FILES.get('myfile')
store_path = os.path.join('static', 'upload')
file_path = os.path.join('static', 'upload', obj.name)
if not os.path.exists(store_path):
os.makedirs(store_path)
file_name = obj.name.split(".")[0]
file_prefix = obj.name.split(".")[-1]
if file_prefix != "wasm":
status = ["Not a wasm file"]
elif file_name in local_list:
status = ["This App is preloaded"]
elif file_name in files_list:
status = ["This App is already uploaded"]
else:
status = []
avaliable_list.append({'ID': file_name, 'Version': '1.0'})
user_file_list.append({'ID': file_name, 'Version': '1.0'})
files_list.append(file_name)
print(user_file_list)
f = open(file_path, 'wb')
for chunk in obj.chunks():
f.write(chunk)
f.close()
return render(req, 'appstore.html', {'staticlist': json.dumps(static_list), 'flist': json.dumps(user_file_list),'ulist':json.dumps(status)})
appname_list = []
def addapps(request):
types = ''
print("enter addapps")
request.encoding = 'utf-8'
app_dic = {'ID': '', 'Version': ''}
# if request.method == 'get':
if "NAME" in request.GET:
a_name = request.GET['NAME']
if a_name != "" and a_name not in appname_list:
appname_list.append(a_name)
message = request.GET['NAME'] + request.GET['Version']
app_dic['ID'] = request.GET['NAME']
app_dic['Version'] = request.GET['Version']
avaliable_list.append(app_dic)
else:
types = "Exist"
print(avaliable_list)
return render(request, 'appstore.html', {'alist': json.dumps(avaliable_list)})
def removeapps(req):
app_name = req.GET['name']
app_version = req.GET['version']
remove_app = {'ID': app_name, 'Version': app_version}
avaliable_list.remove(remove_app)
user_file_list.remove(remove_app)
files_list.remove(app_name)
return render(req, 'appstore.html', {'alist': json.dumps(avaliable_list),'flist': json.dumps(user_file_list)})
# Test
if __name__ == "__main__":
print(device_list[0]['IP'])
print(device['IP'])