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

Initial commit.

parents
Loading
Loading
Loading
Loading

CHANGELOG.md

0 → 100644
+11 −0
Original line number Diff line number Diff line
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

LICENSE

0 → 100644
+674 −0

File added.

Preview size limit exceeded, changes collapsed.

README.md

0 → 100644
+35 −0
Original line number Diff line number Diff line
# 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

app/worker.js

0 → 100644
+118 −0
Original line number Diff line number Diff line
/**
 * 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/maintenance

0 → 100755
+66 −0
Original line number Diff line number Diff line
#!/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
Loading