Skip to content

Commit 67e01f2

Browse files
authored
Merge pull request #19 from Jayx239/develop
Develop
2 parents 5b64a05 + d59b58e commit 67e01f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3709
-667
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2018 Jason Gallagher
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ A Raspberry Pi management WebApp
55
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.
66

77

8-
98
#### Features:
109
* Server health monitoring on PiDash page
1110
* Remote WebApp management through Server Manager page
12-
* User account security features. Ability to create acounts and admins.
11+
* User account security features. Ability to create accounts and admins.
1312

1413
#### Install
1514
1. Clone Repository
@@ -25,6 +24,7 @@ PiDash is a remote web server management application that allows a user to view
2524
make all
2625
```
2726
4. Create configuration files by running configurator
27+
* Requires python, tested for v2.x.x or v3.x.x
2828
```bash
2929
make configurator
3030
```
@@ -53,6 +53,7 @@ PiDash is a remote web server management application that allows a user to view
5353
#Run config file
5454
node ConfigureSql.js
5555
```
56+
6. Create default admin
5657
#### Running PiDash
5758
In the project node directory run:
5859
```bash
@@ -64,7 +65,7 @@ node index.js
6465
1. Navigate to url:port/LogonRegister/Register
6566
2. Enter in registration details.
6667
3. Submit details
67-
* Loging in:
68+
* Logging in:
6869
1. Navigate to url:port/LogonRegister/Logon
6970
2. Enter user credentials
7071
3. Submit details
@@ -75,8 +76,25 @@ node index.js
7576
* A basic dashboard with drag and drop angular apps for monitoring server memory usage and cpu usage. Apps are draggable.
7677
* Server Manager
7778
* url:port/ServerManager
78-
* Requires Admin Privilages
79+
* Requires Admin Privileges
7980
* A management page for running and monitoring web apps running on the server.
8081
* Run remote commands on server.
8182
* Run web apps and monitor the log printed to stdout and stderr.
82-
* Execute web app commands.
83+
* Execute web app commands.
84+
* Changing password
85+
1. Navigate to Account page from the top menu.
86+
2. Enter password details.
87+
3. Click reset
88+
* Granting admin privileges (Requires granting account to be an admin account)
89+
1. Navigate to Account page from top menu
90+
2. Enter desired admin username in'New Admin' field
91+
3. Click Submit
92+
* Revoke admin privieges
93+
1. Navigate to Account page from top menu
94+
2. Click 'Revoke My Privilege' button
95+
96+
Notes:
97+
* Applications are run from the base directory (PiDash/node/), so any application references to
98+
local directories will start from this directory. For example, log files printed to ./logs/ will print to
99+
the /PiDash/node/logs.
100+

node/angular-app/servermanager/servermanagercontroller.js

Lines changed: 204 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,124 @@
1+
//var piDashApp = require('../../content/js/PiDashApp');
12
angular.module('PiDashApp.ServerManagerController',[])
23
.controller('serverManagerController',function($scope, $interval, serverManagerService){
34
var refreshRate = 1000; // ms, TODO: abstract this
45
$scope.processes = [];
56
$scope.apps = [];
6-
7+
$scope.piDashApps = new Object();
78
$scope.activeApp = [];
9+
$scope.activeAppPermissions = [];
10+
$scope.activeAppLogs = [];
811
$scope.activeAppIndex = 0;
912
$scope.command = "";
1013
$scope.startAppButtonText = "Start App";
11-
var Statuses = {"Starting":"Starting","Running":"Running","Stopped":"Stopped"};
14+
$scope.deleteAppButtonText = "Delete App";
15+
$scope.userId = "";
16+
$scope.userName = "";
17+
$scope.appUser;
18+
$scope.selectedConfigMenu;
19+
$scope.configMenus = {
20+
App: 'App',
21+
Permissions: 'Permissions',
22+
Log: 'Log'
23+
};
24+
25+
26+
27+
$scope.setMenu = function(menuId) {
28+
$scope.selectedConfigMenu = menuId;
29+
};
30+
31+
var maxNewApps = 100;
32+
33+
var Statuses = {"Starting":"Starting","Running":"Running","Stopped":"Stopped", "Loading": "Loading"};
1234
var MessageSourceTypes = {"Out": "stdout", "In":"stdin","Error":"stderr","Close": "close"};
35+
36+
var initialize = function(){
37+
serverManagerService.getUser(function(res) {
38+
$scope.userId = res.userId;
39+
$scope.userName = res.userName;
40+
$scope.appUser = new AppUser($scope.userName, $scope.userId);
41+
$scope.retrieveApps();
42+
$scope.selectedConfigMenu = $scope.configMenus.App;
43+
})
44+
};
45+
initialize();
1346
$interval(function(){
14-
if($scope.apps.length > 0) {
47+
if($scope.activeApp.status === Statuses.Running ) {
1548
$scope.refreshConsole($scope.activeApp);
49+
if(!$scope.piDashApps[$scope.activeApp.appId].process.isRunning())
50+
$scope.activeApp.status = Statuses.Stopped;
1651
}
1752
},refreshRate);
1853

19-
54+
var getNextNewAppId = function() {
55+
var i;
56+
for(i=-1; i>-maxNewApps; i--) {
57+
if($scope.piDashApps[i])
58+
continue;
59+
return i;
60+
}
61+
return i;
62+
};
2063

2164
$scope.setActiveApp = function(index) {
22-
$scope.activeApp = $scope.apps[index];
65+
$scope.activeApp = $scope.piDashApps[index].app;
66+
67+
if(!$scope.activeApp.messages)
68+
$scope.activeApp.messages = [];
69+
if(!$scope.activeApp.status)
70+
$scope.activeApp.status = Statuses.Stopped;
71+
$scope.activeApp.pid = $scope.piDashApps[$scope.activeApp.appId].pid;
72+
if(!$scope.piDashApps[index].appPermissions)
73+
$scope.piDashApps[index].appPermissions = [];
74+
$scope.activeAppPermissions = $scope.piDashApps[index].appPermissions;
75+
76+
if(!$scope.piDashApps[index].app.logs)
77+
$scope.piDashApps[index].app.logs = [];
78+
79+
$scope.activeAppLogs = $scope.piDashApps[index].app.logs;
80+
if($scope.piDashApps[index].process && $scope.piDashApps[index].process.isRunning())
81+
$scope.activeApp.status = Statuses.Running;
82+
else
83+
$scope.activeApp.status = Statuses.Stopped;
84+
updateStartButton();
2385
};
2486

2587
$scope.addApplication = function() {
26-
if($scope.activeApp)
27-
$scope.activeApp = angular.copy($scope.activeApp);
28-
$scope.activeApp.appName = "New App";
29-
$scope.activeApp.status = Statuses.Stopped;
30-
$scope.apps.push($scope.activeApp);
31-
/*$scope.apps.push(angular.copy($scope.activeApp));*/
32-
console.log($scope.apps.length + " " + $scope.activeApp.appName);
88+
var newPiDashApp = createDefaultPiDashApp($scope.userName, $scope.userId);
89+
newPiDashApp.app.appId = getNextNewAppId();
90+
newPiDashApp.app.name = "New App";
91+
$scope.piDashApps[newPiDashApp.app.appId] = newPiDashApp;
92+
$scope.setActiveApp(newPiDashApp.app.appId);
93+
console.log($scope.apps.length + " " + $scope.activeApp.name);
94+
};
95+
96+
$scope.deleteActiveApplication = function(){
97+
serverManagerService.deletePiDashApp($scope.activeApp.appId, function(response) {
98+
if(response.status === "Success") {
99+
deleteActiveAppLocally();
100+
alert("App Deleted");
101+
}
102+
else
103+
alert("Error Deleting App")
104+
105+
});
106+
};
107+
108+
var deleteActiveAppLocally = function() {
109+
deleteAppLocally($scope.activeApp.appId);
110+
};
111+
112+
var deleteAppLocally = function(appId) {
113+
delete $scope.piDashApps[appId];
114+
};
115+
116+
$scope.deleteApplication = function(){
117+
delete $scope.piDashApps[appId];
118+
};
119+
120+
var deleteApplication = function(appId){
121+
delete $scope.piDashApps[appId];
33122
};
34123

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

43132
$scope.refreshConsoles = function() {
44-
for(var app in $scope.apps) {
133+
for(var app in $scope.piDashApps) {
45134
$scope.refreshConsole(app);
46135
}
47136
};
@@ -62,12 +151,11 @@ angular.module('PiDashApp.ServerManagerController',[])
62151

63152
if(isStopped(response)) {
64153
app.status = Statuses.Stopped;
65-
$scope.startAppButtonText = "Start App";
66154
}
67155
else {
68156
app.status = Statuses.Running;
69-
$scope.startAppButtonText = "Stop App";
70157
}
158+
updateStartButton();
71159

72160
});
73161
};
@@ -86,7 +174,7 @@ angular.module('PiDashApp.ServerManagerController',[])
86174
var formatMessageOutput = function(messages) {
87175
var output = "";
88176
for(var i=0; i<messages.length; i++) {
89-
output += messages[i].Message + "\n";
177+
output += messages[i].Message;
90178
}
91179
return output;
92180
};
@@ -101,31 +189,124 @@ angular.module('PiDashApp.ServerManagerController',[])
101189
});
102190
};
103191

104-
$scope.toggleActiveAppStart = function() {
105-
if($scope.activeApp.status === Statuses.Stopped) {
106-
$scope.startActiveApp();
192+
var updateStartButton = function() {
193+
if($scope.activeApp.status === Statuses.Running) {
107194
$scope.startAppButtonText = "Stop App";
195+
}
196+
else
197+
$scope.startAppButtonText = "Start App";
198+
};
108199

200+
$scope.toggleActiveAppStart = function() {
201+
if($scope.activeApp.status === Statuses.Stopped) {
202+
$scope.startActivePiDashApp();
109203
}
110204
else {
111205
$scope.stopActiveApp();
112-
$scope.startAppButtonText = "Start App";
113206
}
207+
updateStartButton();
114208
};
115209

116-
$scope.startActiveApp = function(){
210+
$scope.startActiveApp = function() {
117211
spawnProcess($scope.activeApp);
118212

119213
};
120214

121-
$scope.stopActiveApp = function(){
215+
$scope.stopActiveApp = function() {
122216
$scope.killApp($scope.activeApp);
123217
};
124218

125219
$scope.killApp = function(app) {
126220
serverManagerService.killProcess(app.pid,function() {
127221
$scope.refreshConsole(app);
128222
});
129-
}
223+
};
224+
225+
$scope.retrieveApps = function() {
226+
serverManagerService.getPiDashApps(function(res) {
227+
if(res) {
228+
var userApps = buildPiDashAppsFromResponse(res);
229+
if(userApps)
230+
for( var i in userApps)
231+
$scope.piDashApps[userApps[i].app.appId] = userApps[i];
232+
}
233+
});
234+
};
235+
236+
$scope.addPiDashApp = function() {
237+
var activePiDashApp = $scope.piDashApps[$scope.activeApp.appId];
238+
if(activePiDashApp.app.appId <= 0)
239+
addPiDashApp(activePiDashApp);
240+
else
241+
updatePiDashApp(activePiDashApp);
242+
};
130243

244+
var addPiDashApp = function(piDashApp) {
245+
serverManagerService.addPiDashApp(piDashApp, function(res) {
246+
delete $scope.piDashApps[piDashApp.app.appId];
247+
$scope.retrieveApps();
248+
alert("App Added!");
249+
});
250+
};
251+
252+
var updatePiDashApp = function(piDashApp) {
253+
serverManagerService.updatePiDashApp(piDashApp, function(res) {
254+
if(res.app)
255+
$scope.piDashApps[$scope.activeApp.appId] = buildPiDashAppFromResponse(res.app);
256+
$scope.setActiveApp($scope.activeApp.appId);
257+
});
258+
};
259+
260+
$scope.addActiveAppPermission = function() {
261+
if(!$scope.activeAppPermissions)
262+
$scope.activeAppPermissions = [];
263+
$scope.activeAppPermissions.push(new AppPermission(-1,$scope.activeApp.appId,new AppUser("",-1),-1,false,false,false));
264+
};
265+
266+
$scope.deleteActiveAppPermission = function(index) {
267+
serverManagerService.deleteAppPermissionByPermissionId($scope.piDashApps[$scope.activeApp.appId].appPermissions[index].permissionId, $scope.activeApp.appId, function(){
268+
$scope.activeAppPermissions.splice(index,1);
269+
});
270+
};
271+
272+
$scope.addActiveAppLog = function() {
273+
if(!$scope.activeAppLogs)
274+
$scope.activeAppLogs = [];
275+
$scope.activeAppLogs.push(new AppLog(-1,$scope.activeApp.appId,"",""));
276+
};
277+
278+
$scope.deleteActiveAppLog = function(index) {
279+
serverManagerService.deleteAppLogByLogId($scope.piDashApps[$scope.activeApp.appId].app.logs[index].id, $scope.activeApp.appId, function(){
280+
$scope.piDashApps[$scope.activeApp.appId].app.logs.splice(index,1);
281+
});
282+
};
283+
284+
$scope.startActivePiDashApp = function() {
285+
startPiDashApp($scope.activeApp.appId,function(response){
286+
console.log(response)
287+
});
288+
};
289+
290+
var startPiDashApp = function(appId, callback) {
291+
$scope.activeApp.status = Statuses.Starting;
292+
serverManagerService.startPiDashApp($scope.piDashApps[appId], function(response){
293+
294+
var piDashAppRes = JSON.parse(response);
295+
if(piDashAppRes.piDashApp) {
296+
var updatedPiDashApp = buildPiDashAppFromResponse(piDashAppRes.piDashApp);
297+
if(updatedPiDashApp)
298+
$scope.piDashApps[updatedPiDashApp.app.appId] = updatedPiDashApp;
299+
$scope.setActiveApp(updatedPiDashApp.app.appId);
300+
$scope.activeApp.status = Statuses.Running;
301+
}
302+
else if(piDashAppRes.Status === "Error") {
303+
304+
}
305+
if(callback)
306+
callback(response);
307+
});
308+
};
309+
$scope.resetPermissionUserId = function(appPermission) {
310+
appPermission.appUser.userId = -1;
311+
}
131312
});

0 commit comments

Comments
 (0)