Skip to content

Commit

Permalink
configuration & applying (network, kivy,...)
Browse files Browse the repository at this point in the history
  • Loading branch information
isra67 committed May 25, 2017
1 parent 2ce3f44 commit cf8d241
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 79 deletions.
25 changes: 25 additions & 0 deletions lib/exec_process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var exec = require('child_process').exec;

var result = function(command, cb){
var child = exec(command, function(err, stdout, stderr) {
if(err != null){
return cb(new Error(err), null);
}else if(typeof(stderr) != "string"){
return cb(new Error(stderr), null);
}else{
return cb(null, stdout);
}
});
//console.log(child);
child.on('close', function(code) {
console.log('child ended with: ' + code);
});
child.on('error', function(err) {
console.log('child errd with: ' + err);
});
child.stdout.on('data', function(d) {
console.log('child stdout: ' + d);
});
}

exports.result = result;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"body-parser": "^1.17.1",
"express": "*",
"express-fileupload": "^0.1.3",
"ini": "^1.3.4",
"inireader": "^1.2.0",
"net": "^1.0.2",
"ng-file-upload": "^12.2.13",
"node-storage": "0.0.7",
Expand Down
119 changes: 103 additions & 16 deletions public/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,27 @@ app.factory("services", ['$http', function($http) {
return $http.post(serviceBase + 'apply');
}

//** */
obj.factoryResetConfig = function() {
return $http.post(serviceBase + 'reset2factorysettings');
}

//** */
obj.updateIniItem = function(sect,item,vals) {
return $http.post(serviceBase + 'update', {sect: sect, item: item, vals: vals}, headercfg)
.then(function(status) {
return status.data;
});
return $http.post(serviceBase + 'update', {sect: sect, item: item, vals: vals}, headercfg);
// .then(function(status) {
// return status.data;
// });
};

//** */
obj.updateKivyIniItem = function(sect,item,vals) {
return $http.post(serviceBase + 'kivyupdate', {sect: sect, item: item, vals: vals}, headercfg);
};

//** */
obj.updateNetwork = function(inet, ipaddress, netmask, gateway, dns) {
return $http.post(serviceBase + 'networkupdate', {inet: inet, ipaddress: ipaddress, netmask: netmask, gateway: gateway, dns: dns}, headercfg);
};

return obj;
Expand Down Expand Up @@ -89,32 +104,76 @@ app.controller('configCtrl', function ($scope, $rootScope, $location, services)

//** */
$scope.saveConfigItems = function() {
console.log('saveConfigItems 1:');
// console.log('saveConfigItems 1:');
$scope.updateCfg = 2;

var updNetwork = 0, updLogs = 0, updRotation = 0, cfg;

for (var sect in $scope.customers) {
if ($scope.customers.hasOwnProperty(sect)) {
for (var item in $scope.customers[sect]) {
if ($scope.customers[sect].hasOwnProperty(item)) {
if ($scope.customers[sect][item] != $scope.configbackup[sect][item]) {
// console.log('changeItem:',sect, item);

if (sect.indexOf('system') > -1) updNetwork = 1;
else
if (sect.indexOf('service') > -1 && item.indexOf('app_log') > -1) updLogs = 1;
else
if (sect.indexOf('gui') > -1 && item.indexOf('screen_orientation') > -1) updRotation = 1;

$scope.configbackup[sect][item] = $scope.customers[sect][item]; // store new value

// do stuff
services.updateIniItem(sect,item,$scope.customers[sect][item])
.then(function(data) {
.then(function(data) {
// console.log('changeItem:',data);
}, function(err) {
}, function(err) {
console.log('changeItem:',err);
});
});
}
}
}
}
}

// console.log('changeItem:',updNetwork, updLogs, updRotation);
if (updLogs) {
cfg = $scope.customers['service'];
// console.log('saveConfigItems: updLogs', cfg['app_log']);
services.updateKivyIniItem('kivy','log_level',cfg['app_log'])
.then(function(data) {
// console.log('changeItem:',data);
}, function(err) {
console.log('changeItem:',err);
});
}
if (updRotation) {
cfg = $scope.customers['gui'];
// console.log('saveConfigItems: updRotation', cfg['screen_orientation']);
services.updateKivyIniItem('graphics','rotation',cfg['screen_orientation'])
.then(function(data) {
// console.log('changeItem:',data);
}, function(err) {
console.log('changeItem:',err);
});
}
if (updNetwork) {
cfg = $scope.customers['system'];
// console.log('saveConfigItems: updNetwork', cfg['inet'], cfg['ipaddress'], cfg['netmask'], cfg['gateway'], cfg['dns']);
services.updateNetwork(cfg['inet'], cfg['ipaddress'], cfg['netmask'], cfg['gateway'], cfg['dns'])
.then(function(data) {
// console.log('changeItem:',data);
}, function(err) {
console.log('changeItem:',err);
});
}
};

//** */
services.getIniItems().then(function(data) {
var cfg = data.data, sortcfg = {};


// sorting keys in INI:
for (var sect in cfg) {
if (cfg.hasOwnProperty(sect)) {
Expand Down Expand Up @@ -232,6 +291,22 @@ app.controller('uploadCtrl', ['$scope', '$rootScope', 'Upload', '$timeout', '$lo
}]);


//** ******************************************************************************* */
//*
app.controller('foreverCtrl', function ($scope, $rootScope, $location, services) {
console.log('foreverCtrl:');
var p = $location.path();

console.log('foreverCtrl:',p);
/* if (p.infexOf('forever') > -1) {
$rootScope.login = 1;
$rootScope.username = 'root';
// $location.path('/');
// return;
}//*/
});//*/


//** ******************************************************************************* */
app.controller('logCtrl', function ($scope, $rootScope, $location, services) {
$scope.logs = [];
Expand Down Expand Up @@ -275,11 +350,6 @@ app.controller('serviceCtrl', function ($scope, $rootScope, $location, services)
$scope.cntrs = {};
$scope.keys = [];

//** */
/* $scope.langtxt = function(key) {
return langstr[key] || key;
};
//** */
$scope.reinitScopes = function() {
$scope.msg = '';
Expand All @@ -288,13 +358,27 @@ app.controller('serviceCtrl', function ($scope, $rootScope, $location, services)
$scope.keys = [];
};

//** */
$scope.factoryResetConfig = function() {
$scope.reinitScopes();
services.factoryResetConfig().then(function(data){
console.log('factoryResetConfig:',data);
//$location.path('/');
$scope.msg = data.data;
}, function(err) {
console.log('factoryResetConfig:',err);
$scope.msg = err;
$location.path('/');
});
};
//** */
$scope.restartApp = function() {
$scope.reinitScopes();
services.applyCfgChanges().then(function(data){
$scope.msg = data.data;
}, function(err) {
console.log('restartApp:',err);
// console.log('restartApp:',err);
$scope.msg = err;
$location.path('/');
});
};
Expand Down Expand Up @@ -400,7 +484,7 @@ app.controller('basicCtrl', function ($scope, $rootScope, $location, $compile, s

//** */
$scope.applyPwdChange = function() {
console.log('applyPwdChange:', $rootScope.username, $scope.oldPwd, $scope.newPwd1, $scope.newPwd2);
// console.log('applyPwdChange:', $rootScope.username, $scope.oldPwd, $scope.newPwd1, $scope.newPwd2);
$scope.errmsg = '';
if ($rootScope.username.toLowerCase() !== 'admin') {
$scope.errmsg = 'You have not privilege to change password for "'+$rootScope.username+'"!';
Expand Down Expand Up @@ -494,6 +578,9 @@ app.config(function($routeProvider, $locationProvider, $httpProvider) {
templateUrl: 'views/upload.html',
controller: 'uploadCtrl'
})
.when('/loggedinforeverasadmin', {
controller: 'foreverCtrl'
})
.otherwise({
redirectTo: '/login'
});
Expand Down
10 changes: 4 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ <h4><span class="glyphicon glyphicon-ok"></span> Confirm </h4>
</div>
<div class="modal-body" style="padding:48px;">
<p><h3>
You are going to restart RPi application!<br/><br/>Are you sure?
You are going to restart Indoor application!<br/><br/>Are you sure?
</h3></p>
</div>
<div class="modal-footer">
<div class="text-right">
<button type="submit" id="modalOk" class="btn btn-md btn-success"
<button type="submit" id="modalOk" class="btn btn-md btn-warning"
ng-click="applyCfgChanges()" data-dismiss="modal">
<span class="col-md-3"><span class="glyphicon glyphicon-ok-circle"></span> OK </span></button>
<button type="submit" class="btn btn-md btn-default" data-dismiss="modal">
Expand All @@ -160,7 +160,7 @@ <h4>Change password <span class="extra-title muted"></span></h4>
<div class="modal-body form-horizontal" style="padding:24px 80px;">
<div class="form-group">
<label for="current_password" class="control-label">Current password</label>
<input type="password" class="form-control" maxlength="16" placeholder="Enter current password" name="current_password" ng-model="oldPwd" ng-init='' />
<input type="password" class="form-control" maxlength="16" placeholder="Enter current password" name="current_password" ng-model="oldPwd" ng-init='' autofocus />
</div>
<div class="form-group">
<label for="new_password" class="control-label">New password</label>
Expand All @@ -183,11 +183,9 @@ <h4>Change password <span class="extra-title muted"></span></h4>
</div>
</div>
</div>



<!-- Modal changepassword - end -->


<script src="js/angular.min.js"></script>
<script src="js/angular-route.min.js"></script>

Expand Down
11 changes: 5 additions & 6 deletions public/views/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ <h4><span class="label label-info">{{langtxt(k)}}</span></h4>
<span class="col-sm-4 text-right"> {{langtxt(ke)}} </span>
<input type="text" maxlength="128" class="col-sm-6"
ng-change="changeItem(k,ke,somename_$$k.id)"
ng-model-options="{ updateOn: 'blur' }"
ng-model-options="{ updateOn: 'keyup' }"
ng-show="cfgItemType(ke).length == 0"
ng-model="somename_$$k.id" ng-init="somename_$$k.id=va"
ng-disabled="(ke.indexOf('app_') > -1) || (ke === 'serial')" />
<select class="col-sm-6"
ng-change="changeItem(k,ke,somename_$$k.id)"
ng-model-options="{ updateOn: 'blur' }"
ng-model-options="{ updateOn: 'change' }"
ng-show="cfgItemType(ke).length > 0"
ng-options="item for item in cfgItemType(ke)"
ng-model="somename_$$k.id" ng-init="somename_$$k.id=va"
ng-disabled="(ke.indexOf('_log') > 0) || (ke === 'screen_orientation')">
ng-model="somename_$$k.id" ng-init="somename_$$k.id=va">
</select>
</span>
</div>
Expand All @@ -56,12 +55,12 @@ <h4><span class="glyphicon glyphicon-ok"></span> Confirm </h4>
</div>
<div class="modal-body" style="padding:48px;">
<p><h3>
You are going to rewrite INI file for RPi application<br/><br/>Are you sure?
You are going to rewrite INI file for Indoor application<br/><br/>Are you sure?
</h3></p>
</div>
<div class="modal-footer">
<div class="text-right">
<button type="submit" class="btn btn-md btn-success"
<button type="submit" class="btn btn-md btn-warning"
ng-click="saveConfigItems()" data-dismiss="modal"><span class="col-md-3">
<span class="glyphicon glyphicon-ok-circle"></span> OK </span></button>
<button type="submit" class="btn btn-md btn-default" data-dismiss="modal"><span class="col-md-2">
Expand Down
2 changes: 1 addition & 1 deletion public/views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h3>Login</h3>
<form>
<div class="form-group">
<label for="usr"><span class="glyphicon glyphicon-user"></span> Username</label>
<input type="text" class="form-control" id="usr" ng-model="usr" maxlength="16" placeholder="Enter username" />
<input type="text" class="form-control" id="usr" ng-model="usr" maxlength="16" placeholder="Enter username" autofocus />
</div>
<div class="form-group">
<label for="pwd"><span class="glyphicon glyphicon-eye-open"></span> Password</label>
Expand Down
38 changes: 38 additions & 0 deletions public/views/services.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ <h3>Services</h3>
<p><button id="rstApp" class="btn btn-md" type="button" title="Restart RPi GUI application">
Restart app
</button></p>
<p><button id="rstCfg" class="btn btn-md" type="button" title="Restore factory settings">
Factory reset
</button></p>
</div>

<div class="col-sm-offset-2 text-left">
Expand All @@ -41,6 +44,37 @@ <h3>Services</h3>
</div>
</div>


<!-- Modal confirm -->
<div class="modal fade" id="confirmFactoryModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="padding:16px 48px;">
<button type="button" class="close" style="margin-top:8px;"data-dismiss="modal">&times;</button>
<h4><span class="glyphicon glyphicon-ok"></span> Confirm </h4>
</div>
<div class="modal-body" style="padding:48px;">
<p><h3>
You are going to rewrite all config files.<br/>
This step cannot be undone.<br/><br/>Are you sure?
</h3></p>
</div>
<div class="modal-footer">
<div class="text-right">
<button type="submit" class="btn btn-md btn-danger"
ng-click="factoryResetConfig()" data-dismiss="modal"><span class="col-md-3">
<span class="glyphicon glyphicon-ok-circle"></span> OK </span></button>
<button type="submit" class="btn btn-md btn-default" data-dismiss="modal"><span class="col-md-2">
<span class="glyphicon glyphicon-ban-circle"></span> Cancel </span></button>
</div>
</div>
</div>
</div>
</div>
<!-- Modal confirm - end -->


<script>
$(function() {
highlightMenuItem();
Expand All @@ -57,5 +91,9 @@ <h3>Services</h3>
$("#confirmModal").modal();
});

$("#rstCfg").click(function() {
$("#confirmFactoryModal").modal();
});

});
</script>
Loading

0 comments on commit cf8d241

Please sign in to comment.