Skip to content

Commit

Permalink
Merge pull request #11 from mayank-sirotiya-imgtec/master
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
Abhijit A. Mahajani committed May 16, 2016
2 parents 8f5b061 + c141f42 commit 88f2536
Show file tree
Hide file tree
Showing 25 changed files with 3,451 additions and 1 deletion.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Project Properties
####################
CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2)

PROJECT(webscripts)

SET(webscripts_VERSION_MAJOR 0)
SET(webscripts_VERSION_MINOR 9)
SET(webscripts_VERSION_PATCH 0)
SET(webscripts_VERSION
${webscripts_VERSION_MAJOR}.${webscripts_VERSION_MINOR}.${webscripts_VERSION_PATCH})

# Options
###################
SET(CMAKE_VERBOSE_MAKEFILE 1)
SET(CMAKE_BUILD_TYPE DEBUG)

# Paths
########
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(data)
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# webscripts
# Webscripts

## Overview

This package provides the web interface for provisioning Creator Kit devices. It includes webpages as well as webservices.

- Webpages provide a visual interface via web browsers.

- Webservices provide an interface to request a service and get the response.

- Webscripts use lua for scripting and cgilua for dynamic lua pages which are hosted on a webserver running on your Ci40.
Creator Kit uses the <a href="http://wiki.openwrt.org/doc/howto/http.uhttpd">uhttpd</a> webserver.

## Revision History
| Revision | Changes from previous revision |
| :---- | :------------------------------|
| 0.9.0 | External Beta Trial Release |

## Access to Ci40 Webpages

Connect your Ci40 to a network using Ethernet. Obtain the IP address of your Ci40 using "ifconfig" command from its serial console

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:

http://<Ip Address>/cgi-bin/index.lp

## Provisioning Ci40

Refer to the [Provisioning Ci40](https://docs.imgcreator.io/creator/creatorKit/toolbox/#provisioning-ci40) section on the IMG Creator Docs website.
3 changes: 3 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add install targets
######################
INSTALL(PROGRAMS cgilua DESTINATION bin)
6 changes: 6 additions & 0 deletions data/cgilua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

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"
LUA_CPATH="/usr/lib/lua/5.1/?.so;/usr/lib/lua/?.so;$LUA_CPATH"
export LUA_PATH LUA_CPATH
exec "/usr/bin/lua" "/usr/bin/cgilua.cgi" "$@"
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add install targets
######################

SET(DIRS cgi-bin javascript css image)

FOREACH(DIR ${DIRS})
FILE(GLOB DEPLOY_FILES_AND_DIRS "${DIR}/*")
FOREACH(ITEM ${DEPLOY_FILES_AND_DIRS})
IF(NOT IS_DIRECTORY "${ITEM}" )
LIST(APPEND FILES_TO_DEPLOY "${ITEM}")
ENDIF()
ENDFOREACH()
INSTALL(FILES ${FILES_TO_DEPLOY} DESTINATION /var/www/${DIR})
SET(FILES_TO_DEPLOY)
ENDFOREACH()

INSTALL(FILES index.html DESTINATION /var/www)
134 changes: 134 additions & 0 deletions src/cgi-bin/client_list.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?lua
require("client_list")
local client_list_array = get_client_list()
?>

<!doctype html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7 ie6" lang="en"><![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8 ie7" lang="en"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9 ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="no-js ie9" lang="en"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
<title><%= STR_HOME_PAGE_TITLE %></title>
<link href="/css/style.css" rel="stylesheet">
<link rel="shortcut icon" href="/favicon.ico">
<script>var a=document.getElementsByTagName("html")[0];a.className&&(a.className=a.className.replace(/no-js\s?/, ''));</script>
</head>
<body id="home">
<div id="header">
<div class="container">
<div class="c-logo c-ate-logo"></div>
<div class="c-cloud-illustration"></div>
</div>
</div>
<div class="container">
<noscript class="no-js-message">
<div>
<p><%= STR_JAVASCRIPT_MSG_3 %></p>
<p><%= STR_JAVASCRIPT_MSG_2 %></p>
</div>
</noscript>
<div id="config" class="page-container">
<div id="message" class="message-container"></div>
<div class="c-cloud-logo"></div>
<div>
<h2 class="c-title-c"><span class="c-checkbox-success"></span><%= STR_GATEWAY_NAME_PLACEHOLDER %></h2>
</div>
<div>
<p class="c-description-c"><%= STR_GATEWAY_DESCRIPTION_PLACEHOLDER %></p>
</div>
<div>
<h2 class="c-title">Connected Devices</h2>
</div>
<div class="c-devices-column-container span span-1">
<form method="post" target="message" id="form-provision-constrained">
<div class="c-devices-column span span-1-2">
<div class="c-dc-title"><%= STR_PENDING_REGISTRATION %></div>
<?lua
for i=1, #client_list_array do
local device = client_list_array[i]
local device_id = device["clientId"]
local is_provisioned = device["is_device_provisioned"]
if not is_provisioned then
print ("<div class='c-device'>" ..
"<div class='c-device-checkbox'><input class='pending_checkbox' type='checkbox' name='' value=''></div>"..
"<div class='c-device-details'>" ..
"<input class='form-name-input' type='hidden' value='"..device_id.."' name='' />"..
"<div class='c-device-name'>"..device_id.."</div>"..
"<div class='c-device-description'></div>"..
"</div>"..
"</div>")
end
end
?>
<button type="submit" class="c-device-register-button c-device-form-button" disabled="disabled"><%= STR_REGISTER_DEVICE_BUTTON %></button>
</div>
<input type="hidden" id="config_action" name="config_action" value="register"/>
</form>
<form method="post" target="message" id="form-delete-constrained">
<div class="c-devices-column span span-1-2">
<div class="c-dc-title"><%= STR_REGISTERED_TO_FM2M %></div>
<?lua
for i=1, #client_list_array do
local device = client_list_array[i]
local device_id = device["clientId"]
local is_provisioned = device["is_device_provisioned"]
if is_provisioned then
print ("<div class='c-device'>" ..
"<div class='c-device-checkbox'><input class='pending_checkbox' type='checkbox' name='' value=''></div>"..
"<div class='c-device-details'>" ..
"<input class='form-name-input' type='hidden' value='"..device_id.."' name='' />"..
"<div class='c-device-name'>"..device_id.."</div>"..
"<div class='c-device-description'></div>"..
"</div>"..
"</div>")
end
end
?>
<button type="submit" class="c-device-delete-button c-device-form-button" disabled="disabled"><%= STR_DELETE_DEVICE_BUTTON %></button>
</div>
<input type="hidden" id="config_action" name="config_action" value="delete"/>
</form>
</div>
</div>
</div>
<script id="STR_INVALID_DEVICE_NAME_MSG" type="text/template"><%= STR_INVALID_DEVICE_NAME_MSG %></script>
<script id="STR_INVALID_DEVICE_NAME_MSG_2" type="text/template"><%= STR_INVALID_DEVICE_NAME_MSG_2 %></script>
<script id="STR_INVALID_DEVICE_REG_CODE_MSG" type="text/template"><%= STR_INVALID_DEVICE_REG_CODE_MSG %></script>
<script id="STR_NONE" type="text/template"><%= STR_NONE %></script>
<script src="/javascript/jquery.js"></script>
<script src="/javascript/jquery.validate.min.js"></script>
<script src="/javascript/client_side_script.js"></script>
<script>
var element = document.getElementById("message");

var msg = getCookie("message");
if (msg) {
if (msg == 0) {
element.innerHTML = "<%= STR_PROVISION_SUCCESS %>";
element.className += ' success';
} else if(msg == 1) {
element.innerHTML = "<%= STR_PROVISION_FAIL %>";
element.className += ' error';
} else if(msg == 2) {
element.innerHTML = "<%= STR_ALREADY_PROVISIONED %>";
element.className += ' error';
} else if(msg == 254) {
element.innerHTML = "<%= STR_UBUS_CONNECTION_FAIL %>";
element.className += ' error';
} else if(msg == 255) {
element.innerHTML = "<%= STR_UBUS_TIMEOUT %>";
element.className += ' error';
}
document.cookie = 'message=null; expires=0; path=/';
}
</script>
</body>
</html>
45 changes: 45 additions & 0 deletions src/cgi-bin/client_list.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--[[
Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group companies
and/or licensors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--]]

require("strings_en_GB")
require("ubus")

function get_client_list()
local ret, timeout = 60000

local conn = ubus.connect(nil, timeout)
if not conn then
return false
end

ret = conn:call("device_manager", "get_client_list", {})
conn:close()
return ret["clients"]
end
104 changes: 104 additions & 0 deletions src/cgi-bin/index.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?lua
require("provision")
local gateway_provision_status = is_gateway_device_provisioned()
?>

<!doctype html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7 ie6" lang="en"><![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8 ie7" lang="en"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9 ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="no-js ie9" lang="en"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
<title><%= STR_HOME_PAGE_TITLE %></title>
<link href="/css/style.css" rel="stylesheet">
<link rel="shortcut icon" href="/favicon.ico">
<script>var a=document.getElementsByTagName("html")[0];a.className&&(a.className=a.className.replace(/no-js\s?/, ''));</script>
<script><?lua print ("if("..tostring(gateway_provision_status)..") window.location.href = 'client_list.lp';")?></script>
</head>
<body id="home">
<div id="header">
<div class="container">
<div class="c-logo c-ate-logo"></div>
<div class="c-cloud-illustration"></div>
</div>
</div>
<div class="container">
<noscript class="no-js-message">
<div>
<p><%= STR_JAVASCRIPT_MSG_3 %></p>
<p><%= STR_JAVASCRIPT_MSG_2 %></p>
</div>
</noscript>
<div id="main">
<div id="message" class="message-container"></div>
<div>
<h2 class="c-title"><%= STR_REGISTER_CI40_TITLE %></h2>
</div>
<div>
<p class="c-description"><%= STR_REGISTER_CI40_MSG %></p>
</div>
<form method="post" id="form-provision">
<div id="provision" class="grid">
<div class="form-item">
<span class="span-1 c-label"><label for="device_name"><%= STR_CI40_DEVICE_NAME %></label></span>
<span class="span-1 c-input"><input id="device_name" name="device_name" /></span>
</div>
<div class="form-item" style="display:none;">
<span class="span-1 c-label"><label for="device_desc"><%= STR_DEVICE_DESC %></label></span>
<span class="span-1 c-input"><textarea id="device_desc" rows="2" name="device_desc"></textarea></span>
</div>
<div class="form-item" style="display:none;">
<span class="span-1 c-label"><label for="device_type">Device Type</label></span>
<span class="span-1 c-input"><input id="device_type" name="device_type" /></span>
</div>
<div class="form-item" style="display:none;">
<span class="span-1 c-label"><label for="licensee_id">Licensee ID</label></span>
<span class="span-1 c-input"><input id="licensee_id" name="licensee_id" /></span>
</div>
<div class="form-item" >
<span class="span-1 c-label"><label for="device_reg_code"><%= STR_DEVICE_REG_CODE %></label></span>
<span class="span-1 c-input"><input id="device_reg_code" name="device_reg_code" /></span>
</div>
</div>
<button type="submit" id="btn-provision" class="button-main"><%= STR_REGISTER %></button>
<input type="hidden" id="config_method" name="config_method" value="web_page"/>
</form>
</div>
</div>
<script id="STR_CI40_INVALID_DEVICE_NAME_MSG" type="text/template"><%= STR_CI40_INVALID_DEVICE_NAME_MSG %></script>
<script id="STR_CI40_INVALID_DEVICE_NAME_MSG_2" type="text/template"><%= STR_CI40_INVALID_DEVICE_NAME_MSG_2 %></script>
<script id="STR_INVALID_DEVICE_REG_CODE_MSG" type="text/template"><%= STR_INVALID_DEVICE_REG_CODE_MSG %></script>
<script id="STR_NONE" type="text/template"><%= STR_NONE %></script>
<script src="/javascript/jquery.js"></script>
<script src="/javascript/jquery.validate.min.js"></script>
<script src="/javascript/client_side_script.js"></script>
<script>
var element = document.getElementById("message");

var msg = getCookie("message");
if (msg) {
if(msg == 1) {
element.innerHTML = "<%= STR_PROVISION_FAIL %>";
element.className += ' error';
} else if(msg == 2) {
element.innerHTML = "<%= STR_ALREADY_PROVISIONED %>";
element.className += ' error';
} else if(msg == 254) {
element.innerHTML = "<%= STR_UBUS_CONNECTION_FAIL %>";
element.className += ' error';
} else if(msg == 255) {
element.innerHTML = "<%= STR_UBUS_TIMEOUT %>";
element.className += ' error';
}
document.cookie = 'message=null; expires=0; path=/';
}
</script>
</body>
</html>
Loading

0 comments on commit 88f2536

Please sign in to comment.