Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SODA Experience server base code implemented #711

Open
wants to merge 1 commit into
base: soda-experience
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions sodaexpserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
31 changes: 31 additions & 0 deletions sodaexpserver/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const cors = require('cors');
const cookieParser = require("cookie-parser");
const router = express.Router();
// Controllers
projectDashboard = require('./controllers/projectDashboardCtrl');
systemCheckCtrl = require('./controllers/systemCheckCtrl');

app.use(cors());

// To parse URL encoded data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// To parse json data
app.use(cookieParser());
app.use(express.static(__dirname + '/dist/sodaexp'));

// Dashboard Route
app.post('/api/checkDashboardStatus', projectDashboard.projectStatus);

//System Check Route
app.post('/api/checkSystemRequirements', systemCheckCtrl.systemCheck);

app.all('*', function (req, res) {
res.sendFile('dist/sodaexp/index.html', { root: __dirname });
});

app.listen(3000, () => console.log('SODA Experience server listening on port 3000!'));
50 changes: 50 additions & 0 deletions sodaexpserver/controllers/projectDashboardCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const axios = require('axios');



projectStatus = async (req, res, next) => {
try{
console.log('EXECUTING THE TRY BLOCK ');
const status = await checkProjectDashboard(req, res);
res.status(200);
res.json(status)
} catch {
console.log('EXECUTING THE CATCH BLOCK ');
var errResp = {
dashboard: 'notInstalled',
status: 404,
responseText: 'Bad Gatway'
}
res.status(404);
res.json(errResp)
}
}

function checkProjectDashboard(req, res, next){
return new Promise((resolve, reject) => {
reqParam = req.body;
console.log(reqParam);
axios.get(reqParam.dashboardUrl).then(response => {
var status = response.status;
var responseText = response.statusText;
if(status === 200){
var resp = {
dashboard: 'installed',
status: status,
responseText
}
resolve(resp);
}
}).catch(error => {
console.log('ERROR');
console.log(error.message);
reject(error.message);
});
});
}

const projectDashboardCtrl = {
projectStatus,
};

module.exports = projectDashboardCtrl;
110 changes: 110 additions & 0 deletions sodaexpserver/controllers/systemCheckCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const { exec } = require("child_process");

systemCheck = async (req, res, next) => {
var reqParam = req.body;
var responseBody = [];
for(var i = 0; i < reqParam.length; i++){
var check = reqParam[i];
if(check.type == 'OS'){
var result = await checkOS(check);
responseBody.push(result);
}
if(check.type == 'software'){
var result = await checkSoftware(check);
responseBody.push(result);
}
}
res.json(responseBody);
}

checkOS = async (check) => {
return new Promise((resolve, reject) => {
var requirement = check.requirement;
exec("cat /etc/os-release", (error, stdout, stderr) => {
var result = {
type: check.type,
status: {
name: false,
version: false
},
error: true,
errorMessage: ''
};
if (error) {
result.errorMessage = error.message;
reject(result);
}
if (stderr) {
result.errorMessage = stderr;
reject(result);
}
var data = stdout.split('\n');
result.error = false;
for(var j = 0; j < data.length; j++){
if(data[j].toLowerCase().indexOf('name') != -1 && data[j].toLowerCase().indexOf(requirement.name.toLowerCase()) != -1){
result.status.name = true;
}
if(data[j].toLowerCase().indexOf('version') != -1 && data[j].toLowerCase().indexOf(requirement.version) != -1){
result.status.version = true;
}
}
resolve(result);
});
})
}

checkSoftware = async (check) => {
return new Promise((resolve, reject) => {
console.log(check);
var requirement = check.requirement;
var cmd = requirement.name.toLowerCase() + ' --version';
exec(cmd, (error, stdout, stderr) => {
var result = {
type: check.type,
software: requirement.name,
status: {
name: false,
version: false
},
error: true,
errorMessage: ''
};
if (error) {
result.errorMessage = error.message;
resolve(result);
}
if (stderr) {
result.errorMessage = stderr;
resolve(result);
}

var data = stdout.split('\n');
console.log(data);
result.error = false;
if(data.length == 1){
if(data[0].toLowerCase().indexOf(requirement.name.toLowerCase()) != -1){
result.status.name = true;
}
if(data[0].toLowerCase().indexOf(requirement.version) != -1){
result.status.version = true;
}
} else {
for(var j = 0; j < data.length; j++){
if(data[j].toLowerCase().indexOf('name') != -1 && data[j].toLowerCase().indexOf(requirement.name.toLowerCase()) != -1){
result.status.name = true;
}
if(data[j].toLowerCase().indexOf('version') != -1 && data[j].toLowerCase().indexOf(requirement.version) != -1){
result.status.version = true;
}
}
}
resolve(result);
});
})
}

const systemCheckCtrl = {
systemCheck,
};

module.exports = systemCheckCtrl;
Loading