Commit 434d98b9 authored by Hermann Mayer's avatar Hermann Mayer

Initial commit.

parents
Version 0.1.0
=============
* [Common] Bootstraped the project
* [Common] Created the applicaiton structure
* [Common] Written the REST API documentation
* [Service] Implemented REST service for:
- /system/volume
- /system/power
- /desktop/kde/windows
This diff is collapsed.
# remotekit
Remotekit is lightweight service which can be easily installed and used.
All you need is a Linux environment you want to control with your Android
phone.
## remotekit-server
The Remotekit-Server is a Node.js applicaiton which delivers a powerfull
REST service which is used by the Android applicaiton.
### Requirements
* node.js >= 0.10.5
* npm >= 1.2.18
* wmiface (KDE wm-control, http://kde-apps.org/content/show.php?content=40425) >= 2.1
* pm-utils >= 1.4.1
* alsa-utils >= 1.0.27
### Installation
git clone git://gitorious.hermann-mayer.net/remotekit/remotekit-server.git
cd remotekit-server
npm install
### Usage
Start the server in debug/development mode:
./bin/start -d
Start the server in production mode:
./bin/start
/**
* Application Worker
*
* @module app/worker
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
// Load all required global modules
express = require('express');
app = express();
fs = require('fs');
http = require('http');
async = require('async');
cache = require('memory-cache');
winston = require('winston');
// Load all require private modules
var expressValidator = require('express-validator');
var expressWinston = require('express-winston');
// Configure worker and print some information
process.title = 'remotekit-server';
// Bootstrap the winston logger
var loggerConf = {
colors: {
debug : 'blue',
info : 'grey',
warn : 'yellow',
error : 'red'
},
transports: [
new (require('winston').transports.Console)({
colorize : true,
timestampe : true,
"level" : 'debug',
"silent" : false
})
]
};
logger = new winston.Logger(loggerConf);
// General development asset configuration
app.configure('development', function() {
app.use(express.static(process.cwd() + '/public'));
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
// General production asset configuration
app.configure('production', function() {
var oneYear = 31557600000;
app.use(express.static(process.cwd() + '/public'), {maxAge: oneYear});
app.use(express.errorHandler());
});
// Add common middleware to the stack
app.use(express.bodyParser());
app.use(expressValidator);
// Add request logger to the middleware stack
app.use(expressWinston.logger({
transports: [
new winston.transports.Console({
json : false,
colorize : true
}),
new winston.transports.File({
json : false,
filename : process.cwd() + '/var/log/access.log'
})
]
}));
// Bootstrap all controllers
['service'].forEach(function(module) {
var modulePath = process.cwd() + '/modules/' + module + '/controllers/';
fs.readdirSync(modulePath).forEach(function(controllerName) {
if (!controllerName.match(/\.js$/)) {
return;
}
var controller = require(modulePath + controllerName);
var actions = Object.keys(controller.actions);
var basePath = (controller.options && controller.options.path)
? controller.options.path
: '/' + controllerName.replace(/\.js$/g, '');
actions.forEach(function(actionName) {
var action = controller.actions[actionName];
if (!action.methods) {
action.methods = ['GET', 'POST', 'PUT', 'DELETE'];
}
action.methods.forEach(function(method) {
var actionPath = (action.path) ? action.path : '/' + actionName;
app[method.toLowerCase()](basePath + actionPath, action.action);
logger.log('debug', '[Routing] [' + method + '] ' + basePath + actionPath);
});
});
});
});
// Bootstrap the HTTP server
var server = http.createServer(app);
server.listen(1337, '0.0.0.0');
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name maintenance
# Get the full path of the current file, no matter where it being called from
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Go in this path and change to the app directory
cd "${DIR}" && cd ../ && echo "Current working dir: `pwd`"
# Set the Commandline Args
TEMP=`getopt -o h --long build-package,update-package,clear-logs,generate-docs -- "$@"`
function print_todo()
{
echo -e "\n \E[0;33m${1} \E[0m..\n"
}
function clear-logs()
{
eval `find ./var/logs -type f -name '*.log' | awk '{print "echo \"\033[0;31mremove \033[0m" $0 "\" && rm " $0 ";"}'`
}
function generate-docs()
{
find modules/ -name '*.js' | xargs jsdoc -d ./docs/api/
}
function usage()
{
echo "Usage: $0";
echo
echo " -h, --help Print this Help";
echo
echo " --clear-logs Clear all log files";
echo " --generate-docs Generate documentation files";
exit 1;
}
if [ $? != 0 ] ; then
usage
fi
eval set -- "$TEMP"
while true ; do
case "$1" in
--help|-h|--)
shift
usage
break;;
--clear-logs)
shift
clear-logs
break;;
--generate-docs)
shift
generate-docs
break;;
*)
echo "Internal error!"
exit 1;;
esac
done
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name start
# Get the full path of the current file, no matter where it being called from
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Go in this path and change to the app directory
cd "${DIR}" && cd ../
if [ -z "${NODE_BIN}" ]; then
NODE_BIN="node"
fi
# Parse commandline parameters
while getopts ":d :h" opt; do
case $opt in
d)
# Start the Node.js server in foreground
bin/stop
clear
${NODE_BIN} app/worker.js
exit
;;
h)
echo "Usage: $0"
echo;
echo " -h Shows this help"
echo " -d Start the Node.js server in foreground (debug)"
exit;
;;
esac
done
nohup /bin/bash -c "${NODE_BIN} app/worker.js 1>/dev/null 2>>var/log/error-node.log" >/dev/null 2>&1 &
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name status
query="remotekit-server"
status=$(ps -eo pid,args | grep -P "${query}" | egrep -vi "grep(.)+${query}" | sed 's/^ *//g' | cut -d ' ' -f1)
echo 'Status of Node.js Remotekit-Server'
echo '=================================='
echo
if [ "x${status}" != "x" ]; then
ps -eo pid,args | grep -P "${query}" | egrep -vi "grep(.)+${query}"
else
echo 'Server is not running.'
fi
#!/bin/bash
#
# @author Hermann Mayer <hermann.mayer92@gmail.com>
# @name stop
function killByArgs()
{
for p in $(ps -eo pid,args | grep -P "${1}" | egrep -vi "grep(.)+${1}" | sed 's/^ *//g' | cut -d ' ' -f1); do
kill -9 ${p}
done
}
echo 'Stopping remotekit-server ..'
killByArgs "remotekit-server"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Module: service/helper/desktop</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Module: service/helper/desktop</h1>
<section>
<header>
<h2>
service/helper/desktop
</h2>
</header>
<article>
<div class="container-overview">
<div class="description">Adds helper functionality for the KDE window-management interface</div>
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li><a href="mailto:hermann.mayer92@gmail.com">Hermann Mayer</a></li>
</ul>
</dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="desktop.js.html">service/helpers/desktop.js</a>, <a href="desktop.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<dl>
<dt>
<h4 class="name" id="getMetadataForWindowId"><span class="type-signature">&lt;static> </span>getMetadataForWindowId<span class="signature">(wid, callback)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Get metadata for a given window id.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>wid</code></td>
<td class="type">
<span class="param-type">Integer</span>
</td>
<td class="description last">Window Id</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">Function</span>
</td>
<td class="description last">Callback to exec on finish</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="desktop.js.html">service/helpers/desktop.js</a>, <a href="desktop.js.html#line20">line 20</a>
</li></ul></dd>
</dl>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="kde.html">service/controller/desktop/kde</a></li><li><a href="power.html">service/controller/system/power</a></li><li><a href="volume.html">service/controller/system/volume</a></li><li><a href="desktop.html">service/helper/desktop</a></li></ul><h3>Namespaces</h3><ul><li><a href="kde.actions.html">actions</a></li><li><a href="power.actions.html">actions</a></li><li><a href="volume.actions.html">actions</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Sat Jun 29 2013 16:11:29 GMT+0200 (MESZ)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: service/helpers/desktop.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: service/helpers/desktop.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* Desktop Controller Helper
*
* @file Adds helper functionality for the KDE window-management interface
* @module service/helper/desktop
* @author Hermann Mayer &lt;hermann.mayer92@gmail.com>
*/
var childProcess = require('child_process');
/**
* Get metadata for a given window id.
*
* @type {HelperMethod}
* @public
*
* @param {Integer} wid Window Id
* @param {Function} callback Callback to exec on finish
*/
exports.getMetadataForWindowId = function(wid, callback)
{
var meta = {
wid : parseInt(wid),
pid : 0,
caption : '',
active : false,
maximized : false,
minimized : false
};
var dynamicArgsCommands = [
'wmiface activeWindow #',
'wmiface caption ',
'wmiface pid ',
'wmiface windowMaximized ',
'wmiface minimized '
];
async.map(dynamicArgsCommands, function(command, callback) {
childProcess.exec(command + wid, function(err, stdout, stderr) {
if (err || stderr) {
callback && callback({
err : err,
stderr : stderr
});
return;
}
callback && callback(undefined, stdout);
});
}, function(err, results) {
if (err) {
callback && callback(err);
return;
}
if (parseInt(results[0]) == wid) {
meta.active = true;
}
meta.caption = results[1].trim();
meta.pid = parseInt(results[2]);
meta.maximized = (3 == results[3]) ? true : false;
meta.minimized = (results[4].match(/true/i)) ? true : false;
callback && callback(undefined, meta);
});
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="kde.html">service/controller/desktop/kde</a></li><li><a href="power.html">service/controller/system/power</a></li><li><a href="volume.html">service/controller/system/volume</a></li><li><a href="desktop.html">service/helper/desktop</a></li></ul><h3>Namespaces</h3><ul><li><a href="kde.actions.html">actions</a></li><li><a href="power.actions.html">actions</a></li><li><a href="volume.actions.html">actions</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Sat Jun 29 2013 16:11:28 GMT+0200 (MESZ)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: service/controllers/desktop.kde.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: service/controllers/desktop.kde.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* Desktop/KDE Controller
*
* @module service/controller/desktop/kde
* @author Hermann Mayer &lt;hermann.mayer92@gmail.com>
*/
/**
* Controller actions pool.
*
* @namespace
* @type {ControllerActionsPool}