Skip to content

Commit

Permalink
Merge pull request #19 from Jayx239/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Jayx239 authored Apr 27, 2019
2 parents 5b64a05 + d59b58e commit 67e01f2
Show file tree
Hide file tree
Showing 54 changed files with 3,709 additions and 667 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright 2018 Jason Gallagher

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ A Raspberry Pi management WebApp
PiDash is a remote web server management application that allows a user to view server hardware measurements as well as manage applications running on the server.



#### Features:
* Server health monitoring on PiDash page
* Remote WebApp management through Server Manager page
* User account security features. Ability to create acounts and admins.
* User account security features. Ability to create accounts and admins.

#### Install
1. Clone Repository
Expand All @@ -25,6 +24,7 @@ PiDash is a remote web server management application that allows a user to view
make all
```
4. Create configuration files by running configurator
* Requires python, tested for v2.x.x or v3.x.x
```bash
make configurator
```
Expand Down Expand Up @@ -53,6 +53,7 @@ PiDash is a remote web server management application that allows a user to view
#Run config file
node ConfigureSql.js
```
6. Create default admin
#### Running PiDash
In the project node directory run:
```bash
Expand All @@ -64,7 +65,7 @@ node index.js
1. Navigate to url:port/LogonRegister/Register
2. Enter in registration details.
3. Submit details
* Loging in:
* Logging in:
1. Navigate to url:port/LogonRegister/Logon
2. Enter user credentials
3. Submit details
Expand All @@ -75,8 +76,25 @@ node index.js
* A basic dashboard with drag and drop angular apps for monitoring server memory usage and cpu usage. Apps are draggable.
* Server Manager
* url:port/ServerManager
* Requires Admin Privilages
* Requires Admin Privileges
* A management page for running and monitoring web apps running on the server.
* Run remote commands on server.
* Run web apps and monitor the log printed to stdout and stderr.
* Execute web app commands.
* Execute web app commands.
* Changing password
1. Navigate to Account page from the top menu.
2. Enter password details.
3. Click reset
* Granting admin privileges (Requires granting account to be an admin account)
1. Navigate to Account page from top menu
2. Enter desired admin username in'New Admin' field
3. Click Submit
* Revoke admin privieges
1. Navigate to Account page from top menu
2. Click 'Revoke My Privilege' button

Notes:
* Applications are run from the base directory (PiDash/node/), so any application references to
local directories will start from this directory. For example, log files printed to ./logs/ will print to
the /PiDash/node/logs.

227 changes: 204 additions & 23 deletions node/angular-app/servermanager/servermanagercontroller.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,124 @@
//var piDashApp = require('../../content/js/PiDashApp');
angular.module('PiDashApp.ServerManagerController',[])
.controller('serverManagerController',function($scope, $interval, serverManagerService){
var refreshRate = 1000; // ms, TODO: abstract this
$scope.processes = [];
$scope.apps = [];

$scope.piDashApps = new Object();
$scope.activeApp = [];
$scope.activeAppPermissions = [];
$scope.activeAppLogs = [];
$scope.activeAppIndex = 0;
$scope.command = "";
$scope.startAppButtonText = "Start App";
var Statuses = {"Starting":"Starting","Running":"Running","Stopped":"Stopped"};
$scope.deleteAppButtonText = "Delete App";
$scope.userId = "";
$scope.userName = "";
$scope.appUser;
$scope.selectedConfigMenu;
$scope.configMenus = {
App: 'App',
Permissions: 'Permissions',
Log: 'Log'
};



$scope.setMenu = function(menuId) {
$scope.selectedConfigMenu = menuId;
};

var maxNewApps = 100;

var Statuses = {"Starting":"Starting","Running":"Running","Stopped":"Stopped", "Loading": "Loading"};
var MessageSourceTypes = {"Out": "stdout", "In":"stdin","Error":"stderr","Close": "close"};

var initialize = function(){
serverManagerService.getUser(function(res) {
$scope.userId = res.userId;
$scope.userName = res.userName;
$scope.appUser = new AppUser($scope.userName, $scope.userId);
$scope.retrieveApps();
$scope.selectedConfigMenu = $scope.configMenus.App;
})
};
initialize();
$interval(function(){
if($scope.apps.length > 0) {
if($scope.activeApp.status === Statuses.Running ) {
$scope.refreshConsole($scope.activeApp);
if(!$scope.piDashApps[$scope.activeApp.appId].process.isRunning())
$scope.activeApp.status = Statuses.Stopped;
}
},refreshRate);


var getNextNewAppId = function() {
var i;
for(i=-1; i>-maxNewApps; i--) {
if($scope.piDashApps[i])
continue;
return i;
}
return i;
};

$scope.setActiveApp = function(index) {
$scope.activeApp = $scope.apps[index];
$scope.activeApp = $scope.piDashApps[index].app;

if(!$scope.activeApp.messages)
$scope.activeApp.messages = [];
if(!$scope.activeApp.status)
$scope.activeApp.status = Statuses.Stopped;
$scope.activeApp.pid = $scope.piDashApps[$scope.activeApp.appId].pid;
if(!$scope.piDashApps[index].appPermissions)
$scope.piDashApps[index].appPermissions = [];
$scope.activeAppPermissions = $scope.piDashApps[index].appPermissions;

if(!$scope.piDashApps[index].app.logs)
$scope.piDashApps[index].app.logs = [];

$scope.activeAppLogs = $scope.piDashApps[index].app.logs;
if($scope.piDashApps[index].process && $scope.piDashApps[index].process.isRunning())
$scope.activeApp.status = Statuses.Running;
else
$scope.activeApp.status = Statuses.Stopped;
updateStartButton();
};

$scope.addApplication = function() {
if($scope.activeApp)
$scope.activeApp = angular.copy($scope.activeApp);
$scope.activeApp.appName = "New App";
$scope.activeApp.status = Statuses.Stopped;
$scope.apps.push($scope.activeApp);
/*$scope.apps.push(angular.copy($scope.activeApp));*/
console.log($scope.apps.length + " " + $scope.activeApp.appName);
var newPiDashApp = createDefaultPiDashApp($scope.userName, $scope.userId);
newPiDashApp.app.appId = getNextNewAppId();
newPiDashApp.app.name = "New App";
$scope.piDashApps[newPiDashApp.app.appId] = newPiDashApp;
$scope.setActiveApp(newPiDashApp.app.appId);
console.log($scope.apps.length + " " + $scope.activeApp.name);
};

$scope.deleteActiveApplication = function(){
serverManagerService.deletePiDashApp($scope.activeApp.appId, function(response) {
if(response.status === "Success") {
deleteActiveAppLocally();
alert("App Deleted");
}
else
alert("Error Deleting App")

});
};

var deleteActiveAppLocally = function() {
deleteAppLocally($scope.activeApp.appId);
};

var deleteAppLocally = function(appId) {
delete $scope.piDashApps[appId];
};

$scope.deleteApplication = function(){
delete $scope.piDashApps[appId];
};

var deleteApplication = function(appId){
delete $scope.piDashApps[appId];
};

$scope.saveApplication = function() {
Expand All @@ -41,7 +130,7 @@ angular.module('PiDashApp.ServerManagerController',[])
};

$scope.refreshConsoles = function() {
for(var app in $scope.apps) {
for(var app in $scope.piDashApps) {
$scope.refreshConsole(app);
}
};
Expand All @@ -62,12 +151,11 @@ angular.module('PiDashApp.ServerManagerController',[])

if(isStopped(response)) {
app.status = Statuses.Stopped;
$scope.startAppButtonText = "Start App";
}
else {
app.status = Statuses.Running;
$scope.startAppButtonText = "Stop App";
}
updateStartButton();

});
};
Expand All @@ -86,7 +174,7 @@ angular.module('PiDashApp.ServerManagerController',[])
var formatMessageOutput = function(messages) {
var output = "";
for(var i=0; i<messages.length; i++) {
output += messages[i].Message + "\n";
output += messages[i].Message;
}
return output;
};
Expand All @@ -101,31 +189,124 @@ angular.module('PiDashApp.ServerManagerController',[])
});
};

$scope.toggleActiveAppStart = function() {
if($scope.activeApp.status === Statuses.Stopped) {
$scope.startActiveApp();
var updateStartButton = function() {
if($scope.activeApp.status === Statuses.Running) {
$scope.startAppButtonText = "Stop App";
}
else
$scope.startAppButtonText = "Start App";
};

$scope.toggleActiveAppStart = function() {
if($scope.activeApp.status === Statuses.Stopped) {
$scope.startActivePiDashApp();
}
else {
$scope.stopActiveApp();
$scope.startAppButtonText = "Start App";
}
updateStartButton();
};

$scope.startActiveApp = function(){
$scope.startActiveApp = function() {
spawnProcess($scope.activeApp);

};

$scope.stopActiveApp = function(){
$scope.stopActiveApp = function() {
$scope.killApp($scope.activeApp);
};

$scope.killApp = function(app) {
serverManagerService.killProcess(app.pid,function() {
$scope.refreshConsole(app);
});
}
};

$scope.retrieveApps = function() {
serverManagerService.getPiDashApps(function(res) {
if(res) {
var userApps = buildPiDashAppsFromResponse(res);
if(userApps)
for( var i in userApps)
$scope.piDashApps[userApps[i].app.appId] = userApps[i];
}
});
};

$scope.addPiDashApp = function() {
var activePiDashApp = $scope.piDashApps[$scope.activeApp.appId];
if(activePiDashApp.app.appId <= 0)
addPiDashApp(activePiDashApp);
else
updatePiDashApp(activePiDashApp);
};

var addPiDashApp = function(piDashApp) {
serverManagerService.addPiDashApp(piDashApp, function(res) {
delete $scope.piDashApps[piDashApp.app.appId];
$scope.retrieveApps();
alert("App Added!");
});
};

var updatePiDashApp = function(piDashApp) {
serverManagerService.updatePiDashApp(piDashApp, function(res) {
if(res.app)
$scope.piDashApps[$scope.activeApp.appId] = buildPiDashAppFromResponse(res.app);
$scope.setActiveApp($scope.activeApp.appId);
});
};

$scope.addActiveAppPermission = function() {
if(!$scope.activeAppPermissions)
$scope.activeAppPermissions = [];
$scope.activeAppPermissions.push(new AppPermission(-1,$scope.activeApp.appId,new AppUser("",-1),-1,false,false,false));
};

$scope.deleteActiveAppPermission = function(index) {
serverManagerService.deleteAppPermissionByPermissionId($scope.piDashApps[$scope.activeApp.appId].appPermissions[index].permissionId, $scope.activeApp.appId, function(){
$scope.activeAppPermissions.splice(index,1);
});
};

$scope.addActiveAppLog = function() {
if(!$scope.activeAppLogs)
$scope.activeAppLogs = [];
$scope.activeAppLogs.push(new AppLog(-1,$scope.activeApp.appId,"",""));
};

$scope.deleteActiveAppLog = function(index) {
serverManagerService.deleteAppLogByLogId($scope.piDashApps[$scope.activeApp.appId].app.logs[index].id, $scope.activeApp.appId, function(){
$scope.piDashApps[$scope.activeApp.appId].app.logs.splice(index,1);
});
};

$scope.startActivePiDashApp = function() {
startPiDashApp($scope.activeApp.appId,function(response){
console.log(response)
});
};

var startPiDashApp = function(appId, callback) {
$scope.activeApp.status = Statuses.Starting;
serverManagerService.startPiDashApp($scope.piDashApps[appId], function(response){

var piDashAppRes = JSON.parse(response);
if(piDashAppRes.piDashApp) {
var updatedPiDashApp = buildPiDashAppFromResponse(piDashAppRes.piDashApp);
if(updatedPiDashApp)
$scope.piDashApps[updatedPiDashApp.app.appId] = updatedPiDashApp;
$scope.setActiveApp(updatedPiDashApp.app.appId);
$scope.activeApp.status = Statuses.Running;
}
else if(piDashAppRes.Status === "Error") {

}
if(callback)
callback(response);
});
};
$scope.resetPermissionUserId = function(appPermission) {
appPermission.appUser.userId = -1;
}
});
Loading

0 comments on commit 67e01f2

Please sign in to comment.