Skip to content

Commit

Permalink
Interim for #25 #26 #27 #28 #29 #30 #31
Browse files Browse the repository at this point in the history
  • Loading branch information
kneerunjun committed Jan 10, 2022
1 parent 31e84c3 commit a609c21
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG RUN
ARG ETC
ARG BIN
# making all the specific directories, refer to the env file which has the values
RUN mkdir -p ${SRC} && mkdir -p ${LOG} && mkdir -p ${RUN} && mkdir -p ${ETC}
RUN mkdir -p ${SRC} && mkdir -p ${LOG} && mkdir -p ${RUN} && mkdir -p ${ETC} && mkdir -p /var/www/luminapp/pages
WORKDIR ${SRC}
COPY go.sum go.mod ./
RUN go mod download
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
# for local development the volume mapping changes
# - "/home/niranjan/repos/eensymachines.in/luminapi/nginx/luminapp:/var/www/luminapp"
- "${HOSTSRCDIR}:/var/www/luminapp"
# now that the server needs to know where the pages are
depends_on:
- "luminapi"
mosquitto:
Expand Down Expand Up @@ -44,6 +45,7 @@ services:
- BIN=${BINDIR}
volumes:
- ${LOGDIR}:${LOGDIR}
- "${HOSTSRCDIR}/pages:/var/www/luminapp/pages"
ports:
- 8080:8080
environment:
Expand Down
34 changes: 33 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"bufio"
"flag"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
Expand All @@ -19,6 +21,7 @@ const (
broker = "mosquitto"
port = 1883
fMqttsecret = "/run/secrets/mqtt_secret"
pages = "/var/www/luminapp/pages" // this has to be loaded into the container from environment
)

var (
Expand All @@ -28,6 +31,13 @@ var (
FVerbose bool
)

// sendIndexHtml : handler for all the request to send back the index.html page
// you can customize this later to have the og:tags modified for SEO and preview links
func sendIndexHtml(c *gin.Context) {
log.Println("We have reached sendIndexHtml")
c.HTML(http.StatusOK, "index.html", gin.H{})
}

// Setting the environment variables here and prepare before the api server runs
func init() {
/*Reading in the command line params, at the entrypoint*/
Expand Down Expand Up @@ -79,14 +89,36 @@ func main() {
}
gin.SetMode(gin.DebugMode)
r := gin.Default()
r.Use(CORS)

// server needs access to the index.html and other error pages
// cause on all the routes the main page is to be sent from the server
// SEO and image og meta tags will be modified from the server side
r.LoadHTMLGlob(fmt.Sprintf("%s/*", pages))
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"app": "luminapi",
"logs": logFile,
"verblog": FVerbose,
})
})
r.GET("/", sendIndexHtml)
r.GET("/signup", sendIndexHtml)
r.GET("/about", sendIndexHtml)
r.GET("/admin/accounts", func(c *gin.Context) {
log.Println("Inside accounts list administration..")
c.HTML(http.StatusOK, "index.html", gin.H{})
})
r.GET("/admin/embargo", sendIndexHtml)
r.GET("/admin/devices", sendIndexHtml)
r.GET("/accounts/:email", func(c *gin.Context) {
log.Printf("Email param: %s", c.Param("email"))
c.HTML(http.StatusOK, "index.html", gin.H{})
})
r.GET("/accounts/:email/devices", sendIndexHtml)
r.GET("/schedules/:serial", sendIndexHtml)

r.Use(CORS)
// r.GET("/:email/devices", sendIndexHtml)
/*Admin related tasks here under one group. Check the nginx conf this has been appropriately */
grpAdmin := r.Group("/admin")
grpAdmin.GET("/logs", HndlLogs(os.Getenv("LOGF")))
Expand Down
55 changes: 26 additions & 29 deletions nginx/luminapp/index.html → nginx/luminapp/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.0/css/all.min.css"
integrity="sha512-BnbUDfEUfV0Slx6TunuB042k9tuKe3xrD6q4mg5Ed72LTgzDIcLPxg6yI2gcMFRyomt+yJJxE+zJwNmxki6/RA=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="/styles/lumin.css">
<link rel="stylesheet" href="/src/styles/lumin.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
Expand All @@ -32,52 +32,49 @@
integrity="sha512-93ytnvh8rdL66mhOsJBjZ5DtBzmdpLOmW63nckRrarG/sBkRHKiBbnOATXqk0JUxgdDqZRwRNwiVOPtG2nA/MA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- Custom javascript and styles -->
<script src="luminapp.js" type="text/javascript"></script>
<script src="/ctrls/loginCtrl.js" type="text/javascript"></script>
<script src="/ctrls/accCtrls.js" type="text/javascript"></script>
<script src="/ctrls/navbarCtrl.js" type="text/javascript"></script>
<script src="/ctrls/schedCtrl.js" type="text/javascript"></script>
<script src="/src/luminapp.js" type="text/javascript"></script>
<script src="/src/ctrls/loginCtrl.js" type="text/javascript"></script>
<script src="/src/ctrls/accCtrls.js" type="text/javascript"></script>
<script src="/src/ctrls/navbarCtrl.js" type="text/javascript"></script>
<script src="/src/ctrls/schedCtrl.js" type="text/javascript"></script>

<script src="/srvs/srvapi.js" type="text/javascript"></script>
<script src="/srvs/lclstorage.js" type="text/javascript"></script>
<script src="/srvs/misc.js" type="text/javascript"></script>
<script src="/src/srvs/srvapi.js" type="text/javascript"></script>
<script src="/src/srvs/lclstorage.js" type="text/javascript"></script>
<script src="/src/srvs/misc.js" type="text/javascript"></script>

<script src="/dirtvs/errModal.js" type="text/javascript"></script>
<script src="/dirtvs/socialFooter.js" type="text/javascript"></script>
<script src="/dirtvs/authorizeOnly.js" type="text/javascript"></script>
<script src="/dirtvs/submitConfirm.js" type="text/javascript"></script>
<script src="/dirtvs/accDetails.js" type="text/javascript"></script>
<script src="/dirtvs/tableLists.js" type="text/javascript"></script>
<script src="/dirtvs/timeSelect.js" type="text/javascript"></script>
<script src="/dirtvs/schedEdit.js" type="text/javascript"></script>
<script src="/src/dirtvs/errModal.js" type="text/javascript"></script>
<script src="/src/dirtvs/socialFooter.js" type="text/javascript"></script>
<script src="/src/dirtvs/authorizeOnly.js" type="text/javascript"></script>
<script src="/src/dirtvs/submitConfirm.js" type="text/javascript"></script>
<script src="/src/dirtvs/accDetails.js" type="text/javascript"></script>
<script src="/src/dirtvs/tableLists.js" type="text/javascript"></script>
<script src="/src/dirtvs/timeSelect.js" type="text/javascript"></script>
<script src="/src/dirtvs/schedEdit.js" type="text/javascript"></script>

</head>

<body ng-app="luminapp">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" ng-controller="navbarCtrl">
<a class="navbar-brand text-info" href="#">Eensymachines</a>
<a class="navbar-brand text-info" href="/">Eensymachines</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01"
aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<a class="nav-link" href="/">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#!/about">About</a>
<a class="nav-link" href="/about">About</a>
</li>
</ul>
<!-- this is the right rending user account drop down -->
<ul class="navbar-nav">
<li class="nav-item">
<h6><a class="nav-link" href="#!/signup">Signup</a></h6>
<h6><a class="nav-link" href="/signup">Signup</a></h6>
</li>
</ul>
<!-- Since the menu has right align -->
Expand All @@ -89,13 +86,13 @@ <h6><a class="nav-link" href="#!/signup">Signup</a></h6>
<span style="font-size:28px;"><i class="fas fa-user-circle"></i></span>
</a>
<div class="dropdown-menu dropdown-menu-right">
<h6><a class="dropdown-item" href="#!/{[authInfo.email]}/account"><i
<h6><a class="dropdown-item" href="/accounts/{[authInfo.email]}"><i
class="fas fa-sliders-h"></i>&nbsp;Account</a></h6>
<h6><a class="dropdown-item" href="#!/{[authInfo.email]}/devices"><i
<h6><a class="dropdown-item" href="/accounts/{[authInfo.email]}/devices"><i
class="fas fa-microchip"></i>&nbsp;Devices</a></h6>
<!-- <h6><a class="dropdown-item" href=""><i class="far fa-clock"></i>&nbsp;Schedules</a></h6> -->
<div class="dropdown-divider"></div>
<h6><a class="dropdown-item" href="#!/"><i class="bi bi-box-arrow-right"></i>&nbsp;Logout</a></h6>
<h6><a class="dropdown-item" href="/"><i class="bi bi-box-arrow-right"></i>&nbsp;Logout</a></h6>
</div>
</li>
</ul>
Expand All @@ -107,10 +104,10 @@ <h6><a class="dropdown-item" href="#!/"><i class="bi bi-box-arrow-right"></i>&nb
</a>
<div class="dropdown-menu dropdown-menu-right">
<!-- deal with the accounts and then the devices therein -->
<h6><a class="dropdown-item" href="#!/admin/accounts"><i class="fas fa-tools"></i>&nbsp;Manage accounts</a>
<h6><a class="dropdown-item" href="/admin/accounts"><i class="fas fa-tools"></i>&nbsp;Manage accounts</a>
</h6>
<!-- black listed devices can be reclaimed here -->
<h6><a class="dropdown-item" href="#!/admin/embargo"><i class="fas fa-shield-alt"></i>&nbsp;Embargo
<h6><a class="dropdown-item" href="/admin/embargo"><i class="fas fa-shield-alt"></i>&nbsp;Embargo
devices</a></h6>
</div>
</ul>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$scope.err = null;
$scope.wait = false;
// Ahead of feedback from the user, it makes more sense to show devices rather than account details
$location.url("/"+$scope.details.email+"/devices")
$location.url("/accounts/"+$scope.details.email+"/devices")
}, function(error){
error.upon_exit = function(){
$scope.$apply(function(){
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions nginx/luminapp/luminapp.js → nginx/luminapp/src/luminapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
.when("/", {
templateUrl:"/views/splash.html"
})
.when("/:email/account", {
.when("/accounts/:email", {
templateUrl:"/views/account.html",
})
.when("/:email/devices", {
.when("/accounts/:email/devices", {
templateUrl:"/views/user-devices.html",
})
// Schedules of devices
// .when("/:serial/schedules", {
// templateUrl:"/views/device-schedules.html",
// })
.when("/:serial/details", {
.when("/schedules/:serial", {
templateUrl:"/views/device-details.html",
})
.when("/signup", {
templateUrl:"/views/signup.html",
templateUrl:"/views/newuser.html",
})
.when("/about", {
templateUrl:"/views/about.html",
templateUrl:"/views/eensy.html",
})
.when("/admin/:email/devices", {
.when("/admin/devices/:email", {
templateUrl:"/views/admin-devices.html",
})
.when("/admin/accounts", {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

(function(){
angular.module("luminapp").service("srvApi",function($timeout, $q, baseURL, $http, $window,lclStorage){
angular.module("luminapp").service("srvApi",function($timeout, $q, baseURL, $http, $window,lclStorage, $location){
/*Use this $http.then error handler so that we can break down the error response (specific to the server into error response that is used by the web app)*/
var baseURL = {
auth: "http://auth.eensymachines.in",
lumin:$location.absUrl()+"api/v1/devices",
cmds:$location.absUrl()+"api/v1/cmds"
}
var err_message = function(response){
// err_message : breaks down the error response as required for modals / warning
var m = "Server unreachable, or responded invalid. Kindly wait for admins to fix this";
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion nginx/luminapp/templates/acc-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<td ng-if="locHide==false">{[a.loc|locFlt]}</td>
<td><h5><i class="bi role" ng-class="{0:'bi-person',1:'bi-person-plus',2:'bi-person-square'}[a.role]">
</i></h5></td>
<td><h6><a href="#!/admin/{[a.email]}/devices" style="cursor: pointer;">Devices</a></h6></td>
<td><h6><a href="/admin/devices/{[a.email]}" style="cursor: pointer;">Devices</a></h6></td>
<td><h5><i ng-click="a.mark_for_delete()" ng-if="a.role<2" class="bi bi-trash" style="cursor: pointer;"></i></h5></td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion nginx/luminapp/templates/device-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tbody>
<tr class="table-active" ng-repeat="ud in devices">
<!-- clicking on this shall take you to the schedules -->
<td ng-if="editable==false"><a href="#!/{[ud.serial]}/details">{[ud.serial|serialFlt]}</a></td>
<td ng-if="editable==false"><a href="/schedules/{[ud.serial]}">{[ud.serial|serialFlt]}</a></td>
<td ng-if="editable==true">{[ud.serial|serialFlt]}</td>
<td >{[ud.hw]}</td>
<td>{[ud.model|nameFlt:12]}</td>
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions nginx/luminapp/views/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>this is to test if the directory is visible</p>
39 changes: 36 additions & 3 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,40 @@ http {
}
server {
listen 80;
# for the physical directory see the volume mapping from docker-compose
root /var/www/luminapp;
index index.html;
include /etc/nginx/mime.types;
location / {
autoindex on;
location ~* /accounts/(?<email>[a-zA-Z0-9.@]) {
# incase we need to get the account details or the list of devices
# this shall be proxy passed
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Host $host;
proxy_pass http://apiservers$uri;
}
location ~* /admin/accounts/(?<email>[a-zA-Z0-9.@]) {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Host $host;
proxy_pass http://apiservers$uri;
}
location ~* /admin/(accounts|devices|embargo) {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Host $host;
proxy_pass http://apiservers$uri;
}
location ~* /schedules/(?<serial>[a-zA-Z0-9]) {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Host $host;
proxy_pass http://apiservers$uri;
}
location ~* /(signup|about) {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Host $host;
proxy_pass http://apiservers$uri;
}
location ~* /(src|templates|views|data|images)/{
# for the static files we can have the directories mapped one on one from the router
try_files $uri $uri/ /index.html =404;
}
location /api/admin/ {
auth_basic "Restricted area";
Expand All @@ -28,7 +57,11 @@ http {
proxy_set_header Host $http_host;
proxy_pass http://apiservers/;
}

location = / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Host $host;
proxy_pass http://apiservers$uri;
}
# # Media: images, icons, video, audio, HTC
# location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
# expires 1d;
Expand Down

0 comments on commit a609c21

Please sign in to comment.