Skip to content

Commit 88f2536

Browse files
author
Abhijit A. Mahajani
committed
Merge pull request #11 from mayank-sirotiya-imgtec/master
Merge dev to master
2 parents 8f5b061 + c141f42 commit 88f2536

25 files changed

+3451
-1
lines changed

CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Project Properties
2+
####################
3+
CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2)
4+
5+
PROJECT(webscripts)
6+
7+
SET(webscripts_VERSION_MAJOR 0)
8+
SET(webscripts_VERSION_MINOR 9)
9+
SET(webscripts_VERSION_PATCH 0)
10+
SET(webscripts_VERSION
11+
${webscripts_VERSION_MAJOR}.${webscripts_VERSION_MINOR}.${webscripts_VERSION_PATCH})
12+
13+
# Options
14+
###################
15+
SET(CMAKE_VERBOSE_MAKEFILE 1)
16+
SET(CMAKE_BUILD_TYPE DEBUG)
17+
18+
# Paths
19+
########
20+
ADD_SUBDIRECTORY(src)
21+
ADD_SUBDIRECTORY(data)

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# webscripts
1+
# Webscripts
2+
3+
## Overview
4+
5+
This package provides the web interface for provisioning Creator Kit devices. It includes webpages as well as webservices.
6+
7+
- Webpages provide a visual interface via web browsers.
8+
9+
- Webservices provide an interface to request a service and get the response.
10+
11+
- Webscripts use lua for scripting and cgilua for dynamic lua pages which are hosted on a webserver running on your Ci40.
12+
Creator Kit uses the <a href="http://wiki.openwrt.org/doc/howto/http.uhttpd">uhttpd</a> webserver.
13+
14+
## Revision History
15+
| Revision | Changes from previous revision |
16+
| :---- | :------------------------------|
17+
| 0.9.0 | External Beta Trial Release |
18+
19+
## Access to Ci40 Webpages
20+
21+
Connect your Ci40 to a network using Ethernet. Obtain the IP address of your Ci40 using "ifconfig" command from its serial console
22+
23+
Provisioning webpages can be accessed from your Ci40 by entering its IP address on a web browser which should re-direct to the following url:
24+
25+
http://<Ip Address>/cgi-bin/index.lp
26+
27+
## Provisioning Ci40
28+
29+
Refer to the [Provisioning Ci40](https://docs.imgcreator.io/creator/creatorKit/toolbox/#provisioning-ci40) section on the IMG Creator Docs website.

data/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Add install targets
2+
######################
3+
INSTALL(PROGRAMS cgilua DESTINATION bin)

data/cgilua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
LUA_PATH="/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;./?.lua;$LUA_PATH"
4+
LUA_CPATH="/usr/lib/lua/5.1/?.so;/usr/lib/lua/?.so;$LUA_CPATH"
5+
export LUA_PATH LUA_CPATH
6+
exec "/usr/bin/lua" "/usr/bin/cgilua.cgi" "$@"

src/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add install targets
2+
######################
3+
4+
SET(DIRS cgi-bin javascript css image)
5+
6+
FOREACH(DIR ${DIRS})
7+
FILE(GLOB DEPLOY_FILES_AND_DIRS "${DIR}/*")
8+
FOREACH(ITEM ${DEPLOY_FILES_AND_DIRS})
9+
IF(NOT IS_DIRECTORY "${ITEM}" )
10+
LIST(APPEND FILES_TO_DEPLOY "${ITEM}")
11+
ENDIF()
12+
ENDFOREACH()
13+
INSTALL(FILES ${FILES_TO_DEPLOY} DESTINATION /var/www/${DIR})
14+
SET(FILES_TO_DEPLOY)
15+
ENDFOREACH()
16+
17+
INSTALL(FILES index.html DESTINATION /var/www)

src/cgi-bin/client_list.lp

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?lua
2+
require("client_list")
3+
local client_list_array = get_client_list()
4+
?>
5+
6+
<!doctype html>
7+
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7 ie6" lang="en"><![endif]-->
8+
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8 ie7" lang="en"><![endif]-->
9+
<!--[if IE 8]><html class="no-js lt-ie9 ie8" lang="en"><![endif]-->
10+
<!--[if IE 9]><html class="no-js ie9" lang="en"><![endif]-->
11+
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
12+
<head>
13+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
16+
<meta http-equiv='cache-control' content='no-cache'>
17+
<meta http-equiv='expires' content='0'>
18+
<meta http-equiv='pragma' content='no-cache'>
19+
<title><%= STR_HOME_PAGE_TITLE %></title>
20+
<link href="/css/style.css" rel="stylesheet">
21+
<link rel="shortcut icon" href="/favicon.ico">
22+
<script>var a=document.getElementsByTagName("html")[0];a.className&&(a.className=a.className.replace(/no-js\s?/, ''));</script>
23+
</head>
24+
<body id="home">
25+
<div id="header">
26+
<div class="container">
27+
<div class="c-logo c-ate-logo"></div>
28+
<div class="c-cloud-illustration"></div>
29+
</div>
30+
</div>
31+
<div class="container">
32+
<noscript class="no-js-message">
33+
<div>
34+
<p><%= STR_JAVASCRIPT_MSG_3 %></p>
35+
<p><%= STR_JAVASCRIPT_MSG_2 %></p>
36+
</div>
37+
</noscript>
38+
<div id="config" class="page-container">
39+
<div id="message" class="message-container"></div>
40+
<div class="c-cloud-logo"></div>
41+
<div>
42+
<h2 class="c-title-c"><span class="c-checkbox-success"></span><%= STR_GATEWAY_NAME_PLACEHOLDER %></h2>
43+
</div>
44+
<div>
45+
<p class="c-description-c"><%= STR_GATEWAY_DESCRIPTION_PLACEHOLDER %></p>
46+
</div>
47+
<div>
48+
<h2 class="c-title">Connected Devices</h2>
49+
</div>
50+
<div class="c-devices-column-container span span-1">
51+
<form method="post" target="message" id="form-provision-constrained">
52+
<div class="c-devices-column span span-1-2">
53+
<div class="c-dc-title"><%= STR_PENDING_REGISTRATION %></div>
54+
<?lua
55+
for i=1, #client_list_array do
56+
local device = client_list_array[i]
57+
local device_id = device["clientId"]
58+
local is_provisioned = device["is_device_provisioned"]
59+
if not is_provisioned then
60+
print ("<div class='c-device'>" ..
61+
"<div class='c-device-checkbox'><input class='pending_checkbox' type='checkbox' name='' value=''></div>"..
62+
"<div class='c-device-details'>" ..
63+
"<input class='form-name-input' type='hidden' value='"..device_id.."' name='' />"..
64+
"<div class='c-device-name'>"..device_id.."</div>"..
65+
"<div class='c-device-description'></div>"..
66+
"</div>"..
67+
"</div>")
68+
end
69+
end
70+
?>
71+
<button type="submit" class="c-device-register-button c-device-form-button" disabled="disabled"><%= STR_REGISTER_DEVICE_BUTTON %></button>
72+
</div>
73+
<input type="hidden" id="config_action" name="config_action" value="register"/>
74+
</form>
75+
<form method="post" target="message" id="form-delete-constrained">
76+
<div class="c-devices-column span span-1-2">
77+
<div class="c-dc-title"><%= STR_REGISTERED_TO_FM2M %></div>
78+
<?lua
79+
for i=1, #client_list_array do
80+
local device = client_list_array[i]
81+
local device_id = device["clientId"]
82+
local is_provisioned = device["is_device_provisioned"]
83+
if is_provisioned then
84+
print ("<div class='c-device'>" ..
85+
"<div class='c-device-checkbox'><input class='pending_checkbox' type='checkbox' name='' value=''></div>"..
86+
"<div class='c-device-details'>" ..
87+
"<input class='form-name-input' type='hidden' value='"..device_id.."' name='' />"..
88+
"<div class='c-device-name'>"..device_id.."</div>"..
89+
"<div class='c-device-description'></div>"..
90+
"</div>"..
91+
"</div>")
92+
end
93+
end
94+
?>
95+
<button type="submit" class="c-device-delete-button c-device-form-button" disabled="disabled"><%= STR_DELETE_DEVICE_BUTTON %></button>
96+
</div>
97+
<input type="hidden" id="config_action" name="config_action" value="delete"/>
98+
</form>
99+
</div>
100+
</div>
101+
</div>
102+
<script id="STR_INVALID_DEVICE_NAME_MSG" type="text/template"><%= STR_INVALID_DEVICE_NAME_MSG %></script>
103+
<script id="STR_INVALID_DEVICE_NAME_MSG_2" type="text/template"><%= STR_INVALID_DEVICE_NAME_MSG_2 %></script>
104+
<script id="STR_INVALID_DEVICE_REG_CODE_MSG" type="text/template"><%= STR_INVALID_DEVICE_REG_CODE_MSG %></script>
105+
<script id="STR_NONE" type="text/template"><%= STR_NONE %></script>
106+
<script src="/javascript/jquery.js"></script>
107+
<script src="/javascript/jquery.validate.min.js"></script>
108+
<script src="/javascript/client_side_script.js"></script>
109+
<script>
110+
var element = document.getElementById("message");
111+
112+
var msg = getCookie("message");
113+
if (msg) {
114+
if (msg == 0) {
115+
element.innerHTML = "<%= STR_PROVISION_SUCCESS %>";
116+
element.className += ' success';
117+
} else if(msg == 1) {
118+
element.innerHTML = "<%= STR_PROVISION_FAIL %>";
119+
element.className += ' error';
120+
} else if(msg == 2) {
121+
element.innerHTML = "<%= STR_ALREADY_PROVISIONED %>";
122+
element.className += ' error';
123+
} else if(msg == 254) {
124+
element.innerHTML = "<%= STR_UBUS_CONNECTION_FAIL %>";
125+
element.className += ' error';
126+
} else if(msg == 255) {
127+
element.innerHTML = "<%= STR_UBUS_TIMEOUT %>";
128+
element.className += ' error';
129+
}
130+
document.cookie = 'message=null; expires=0; path=/';
131+
}
132+
</script>
133+
</body>
134+
</html>

src/cgi-bin/client_list.lua

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--[[
2+
Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies
3+
and/or licensors
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification, are permitted
8+
provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
11+
and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright notice, this list of
14+
conditions and the following disclaimer in the documentation and/or other materials provided
15+
with the distribution.
16+
17+
3. Neither the name of the copyright holder nor the names of its contributors may be used to
18+
endorse or promote products derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
22+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
23+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
28+
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
--]]
30+
31+
require("strings_en_GB")
32+
require("ubus")
33+
34+
function get_client_list()
35+
local ret, timeout = 60000
36+
37+
local conn = ubus.connect(nil, timeout)
38+
if not conn then
39+
return false
40+
end
41+
42+
ret = conn:call("device_manager", "get_client_list", {})
43+
conn:close()
44+
return ret["clients"]
45+
end

src/cgi-bin/index.lp

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?lua
2+
require("provision")
3+
local gateway_provision_status = is_gateway_device_provisioned()
4+
?>
5+
6+
<!doctype html>
7+
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7 ie6" lang="en"><![endif]-->
8+
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8 ie7" lang="en"><![endif]-->
9+
<!--[if IE 8]><html class="no-js lt-ie9 ie8" lang="en"><![endif]-->
10+
<!--[if IE 9]><html class="no-js ie9" lang="en"><![endif]-->
11+
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
12+
<head>
13+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
16+
<meta http-equiv='cache-control' content='no-cache'>
17+
<meta http-equiv='expires' content='0'>
18+
<meta http-equiv='pragma' content='no-cache'>
19+
<title><%= STR_HOME_PAGE_TITLE %></title>
20+
<link href="/css/style.css" rel="stylesheet">
21+
<link rel="shortcut icon" href="/favicon.ico">
22+
<script>var a=document.getElementsByTagName("html")[0];a.className&&(a.className=a.className.replace(/no-js\s?/, ''));</script>
23+
<script><?lua print ("if("..tostring(gateway_provision_status)..") window.location.href = 'client_list.lp';")?></script>
24+
</head>
25+
<body id="home">
26+
<div id="header">
27+
<div class="container">
28+
<div class="c-logo c-ate-logo"></div>
29+
<div class="c-cloud-illustration"></div>
30+
</div>
31+
</div>
32+
<div class="container">
33+
<noscript class="no-js-message">
34+
<div>
35+
<p><%= STR_JAVASCRIPT_MSG_3 %></p>
36+
<p><%= STR_JAVASCRIPT_MSG_2 %></p>
37+
</div>
38+
</noscript>
39+
<div id="main">
40+
<div id="message" class="message-container"></div>
41+
<div>
42+
<h2 class="c-title"><%= STR_REGISTER_CI40_TITLE %></h2>
43+
</div>
44+
<div>
45+
<p class="c-description"><%= STR_REGISTER_CI40_MSG %></p>
46+
</div>
47+
<form method="post" id="form-provision">
48+
<div id="provision" class="grid">
49+
<div class="form-item">
50+
<span class="span-1 c-label"><label for="device_name"><%= STR_CI40_DEVICE_NAME %></label></span>
51+
<span class="span-1 c-input"><input id="device_name" name="device_name" /></span>
52+
</div>
53+
<div class="form-item" style="display:none;">
54+
<span class="span-1 c-label"><label for="device_desc"><%= STR_DEVICE_DESC %></label></span>
55+
<span class="span-1 c-input"><textarea id="device_desc" rows="2" name="device_desc"></textarea></span>
56+
</div>
57+
<div class="form-item" style="display:none;">
58+
<span class="span-1 c-label"><label for="device_type">Device Type</label></span>
59+
<span class="span-1 c-input"><input id="device_type" name="device_type" /></span>
60+
</div>
61+
<div class="form-item" style="display:none;">
62+
<span class="span-1 c-label"><label for="licensee_id">Licensee ID</label></span>
63+
<span class="span-1 c-input"><input id="licensee_id" name="licensee_id" /></span>
64+
</div>
65+
<div class="form-item" >
66+
<span class="span-1 c-label"><label for="device_reg_code"><%= STR_DEVICE_REG_CODE %></label></span>
67+
<span class="span-1 c-input"><input id="device_reg_code" name="device_reg_code" /></span>
68+
</div>
69+
</div>
70+
<button type="submit" id="btn-provision" class="button-main"><%= STR_REGISTER %></button>
71+
<input type="hidden" id="config_method" name="config_method" value="web_page"/>
72+
</form>
73+
</div>
74+
</div>
75+
<script id="STR_CI40_INVALID_DEVICE_NAME_MSG" type="text/template"><%= STR_CI40_INVALID_DEVICE_NAME_MSG %></script>
76+
<script id="STR_CI40_INVALID_DEVICE_NAME_MSG_2" type="text/template"><%= STR_CI40_INVALID_DEVICE_NAME_MSG_2 %></script>
77+
<script id="STR_INVALID_DEVICE_REG_CODE_MSG" type="text/template"><%= STR_INVALID_DEVICE_REG_CODE_MSG %></script>
78+
<script id="STR_NONE" type="text/template"><%= STR_NONE %></script>
79+
<script src="/javascript/jquery.js"></script>
80+
<script src="/javascript/jquery.validate.min.js"></script>
81+
<script src="/javascript/client_side_script.js"></script>
82+
<script>
83+
var element = document.getElementById("message");
84+
85+
var msg = getCookie("message");
86+
if (msg) {
87+
if(msg == 1) {
88+
element.innerHTML = "<%= STR_PROVISION_FAIL %>";
89+
element.className += ' error';
90+
} else if(msg == 2) {
91+
element.innerHTML = "<%= STR_ALREADY_PROVISIONED %>";
92+
element.className += ' error';
93+
} else if(msg == 254) {
94+
element.innerHTML = "<%= STR_UBUS_CONNECTION_FAIL %>";
95+
element.className += ' error';
96+
} else if(msg == 255) {
97+
element.innerHTML = "<%= STR_UBUS_TIMEOUT %>";
98+
element.className += ' error';
99+
}
100+
document.cookie = 'message=null; expires=0; path=/';
101+
}
102+
</script>
103+
</body>
104+
</html>

0 commit comments

Comments
 (0)