Commit 18c0c552 authored by Leo Iannacone's avatar Leo Iannacone

indentation 4 spaces

parent 8e2d5d18
......@@ -18,11 +18,11 @@ server = http.createServer(app)
io = require("socket.io")(server)
env = process.env.NODE_ENV or "development"
if "development" is env
app.use errorhandler(
dumpExceptions: true
showStack: true
)
else app.use errorhandler() if "production" is env
app.use errorhandler(
dumpExceptions: true
showStack: true
)
else app.use errorhandler() if "production" is env
app.set "views", __dirname + "/views"
app.set "view engine", "ejs"
......@@ -33,35 +33,35 @@ app.get "/", routes.index
app.get config.routes.distribution, routes.distribution
# parefernces page
app.get config.routes.preferences, routes.preferences if config.routes.preferences
app.get config.routes.preferences, routes.preferences if config.routes.preferences
# commands page
app.get config.routes.commands, routes.commands if config.routes.commands
app.get config.routes.commands, routes.commands if config.routes.commands
# debomatic static page
if config.routes.debomatic
app.all config.routes.debomatic + "*", (req, res, next) ->
app.all config.routes.debomatic + "*", (req, res, next) ->
# send 403 status when users want to browse the chroots:
# - unstable/unstable
# - unstable/build/*
# this prevents system crashes
base = config.routes.debomatic
base += (if base[base.length - 1] isnt "/" then "/" else "") # append /
match = req.url.replace(base, "").split("/")
match.pop() if match[match.length - 1] is ""
# case unstable/unstable
if match.length >= 2 and ((match[0] is match[1]) or (match[1] is "build" and match.length > 2)) # case unstable/build/*
res.status(403).send "<h1>403 Forbidden</h1>"
else # call next() here to move on to next middleware/router
next()
return
# send 403 status when users want to browse the chroots:
# - unstable/unstable
# - unstable/build/*
# this prevents system crashes
base = config.routes.debomatic
base += (if base[base.length - 1] isnt "/" then "/" else "") # append /
match = req.url.replace(base, "").split("/")
match.pop() if match[match.length - 1] is ""
# case unstable/unstable
if match.length >= 2 and ((match[0] is match[1]) or (match[1] is "build" and match.length > 2)) # case unstable/build/*
res.status(403).send "<h1>403 Forbidden</h1>"
else # call next() here to move on to next middleware/router
next()
return
app.use config.routes.debomatic, serve_static(config.debomatic.path)
app.use config.routes.debomatic, serve_index(config.debomatic.path,
view: "details"
icons: true
)
app.use config.routes.debomatic, serve_static(config.debomatic.path)
app.use config.routes.debomatic, serve_index(config.debomatic.path,
view: "details"
icons: true
)
# serve stylesheet-javascript
app.use serve_static(__dirname + "/public")
......@@ -72,32 +72,32 @@ serve_static.mime.define "application/octet-stream": ["dsc"]
# Listening
server.listen config.port, config.host, null, (err) ->
# Checking nodejs with sudo:
# Find out which user used sudo through the environment variable
# and set his user id
uid = parseInt(process.env.SUDO_UID)
if uid
console.log "Please do not run nodejs with sudo. Changing user to %d", uid
process.setgid uid
process.setuid uid
# Checking nodejs with sudo:
# Find out which user used sudo through the environment variable
# and set his user id
uid = parseInt(process.env.SUDO_UID)
if uid
console.log "Please do not run nodejs with sudo. Changing user to %d", uid
process.setgid uid
process.setuid uid
# statuses
status = []
broadcast = new Broadcaster(io.sockets, status)
io.sockets.on "connection", (socket) ->
client = new Client(socket)
client.start()
client.send_status status if status.length > 0
client.send_status_debomatic()
return
# statuses
status = []
broadcast = new Broadcaster(io.sockets, status)
io.sockets.on "connection", (socket) ->
client = new Client(socket)
client.start()
client.send_status status if status.length > 0
client.send_status_debomatic()
return
console.log "Debomatic-webui listening on %s:%d in %s mode", server.address().address, server.address().port, app.settings.env
return
console.log "Debomatic-webui listening on %s:%d in %s mode", server.address().address, server.address().port, app.settings.env
return
server.on "error", (e) ->
if e.code is "EADDRINUSE"
console.log "Address in use %s:%d. Exit.", config.host, config.port
process.exit 1
else
console.error e
return
if e.code is "EADDRINUSE"
console.log "Address in use %s:%d. Exit.", config.host, config.port
process.exit 1
else
console.error e
return
__watch_status_check_same_obj = (obj1, obj2) ->
if obj1.status is obj2.status
if obj1.distribution is obj2.distribution
if obj1.hasOwnProperty("package") and obj2.hasOwnProperty("package")
return true if obj1.package is obj2.package
return false
return true
false
if obj1.status is obj2.status
if obj1.distribution is obj2.distribution
if obj1.hasOwnProperty("package") and obj2.hasOwnProperty("package")
return true if obj1.package is obj2.package
return false
return true
false
# watcher on build_status
__watch_status = (socket, status) ->
watcher = new Tail(config.debomatic.jsonfile)
watcher.on "line", (new_content) ->
data = null
try
data = JSON.parse(new_content)
catch err
utils.errors_handler "Broadcaster:__watch_status:JSON.parse(new_content) - ", err, socket
return
watcher = new Tail(config.debomatic.jsonfile)
watcher.on "line", (new_content) ->
data = null
try
data = JSON.parse(new_content)
catch err
utils.errors_handler "Broadcaster:__watch_status:JSON.parse(new_content) - ", err, socket
return
# looking for same status already in statuses lists
if data.hasOwnProperty("success")
i = 0
# looking for same status already in statuses lists
if data.hasOwnProperty("success")
i = 0
while i < status.length
if __watch_status_check_same_obj(data, status[i])
status.splice i, 1
break
while i < status.length
if __watch_status_check_same_obj(data, status[i])
status.splice i, 1
break
else
continue
i++
else
continue
i++
else
status.push data
socket.emit config.events.broadcast.status_update, data
return
status.push data
socket.emit config.events.broadcast.status_update, data
return
watcher.on "error", (msg) ->
socket.emit config.events.error, msg
return
watcher.on "error", (msg) ->
socket.emit config.events.error, msg
return
return
return
# watcher on new distributions
__watch_distributions = (socket) ->
fs.watch config.debomatic.path,
persistent: true
, (event, fileName) ->
fs.watch config.debomatic.path,
persistent: true
, (event, fileName) ->
# wait half a second to get pool subdir created
setTimeout (->
utils.send_distributions socket
return
), 500
return
# wait half a second to get pool subdir created
setTimeout (->
utils.send_distributions socket
return
), 500
return
return
__watch_pidfile = (socket) ->
fs.watchFile config.debomatic.pidfile,
persistent: false
interval: 1007
, (curr, prev) ->
status_debomatic = running: curr.ino isnt 0 # if === 0 means pidfile does not exists
try
socket.emit socket.emit(config.events.broadcast.status_debomatic, status_debomatic)
return
__watch_pidfile = (socket) ->
fs.watchFile config.debomatic.pidfile,
persistent: false
interval: 1007
, (curr, prev) ->
status_debomatic = running: curr.ino isnt 0 # if === 0 means pidfile does not exists
try
socket.emit socket.emit(config.events.broadcast.status_debomatic, status_debomatic)
return
return
return
Broadcaster = (sockets, status) ->
__watch_status sockets, status
__watch_distributions sockets
__watch_pidfile sockets
{}
__watch_status sockets, status
__watch_distributions sockets
__watch_pidfile sockets
{}
"use strict"
config = require("./config")
fs = require("fs")
......
This diff is collapsed.
#
# * Please DO NOT edit this file.
# * Please DO NOT edit this file.
# *
# * Edit auto-generated 'user.config.js' file instead.
# * Edit auto-generated 'user.config.js' file instead.
# *
#
......@@ -10,8 +10,8 @@
#
# * Configure host and port.
# * Please for ports < 1000 use authbind. DO NOT RUN nodejs as root.
# * $ authbind nodejs index.js
# * Please for ports < 1000 use authbind. DO NOT RUN nodejs as root.
# * $ authbind nodejs index.js
#
# web configuration
......@@ -38,16 +38,16 @@
# * update object1 with object2 values
#
_merge = (object1, object2) ->
result = {}
for p of object1
if object2.hasOwnProperty(p)
if typeof object1[p] is "object" and typeof object2[p] is "object"
result[p] = _merge(object1[p], object2[p])
else
result[p] = object2[p]
else
result[p] = object1[p]
result
result = {}
for p of object1
if object2.hasOwnProperty(p)
if typeof object1[p] is "object" and typeof object2[p] is "object"
result[p] = _merge(object1[p], object2[p])
else
result[p] = object2[p]
else
result[p] = object1[p]
result
"use strict"
config = {}
config.host = "localhost"
......@@ -87,8 +87,8 @@ config.web.preferences.file_fontsize = 13
config.web.preferences.debug = 0
config.version = "0.6.0"
config.debomatic.excluded_files = [
"datestamp"
"json"
"datestamp"
"json"
]
config.events = {}
config.events.error = "server-error"
......@@ -111,29 +111,29 @@ config.status.update = "update"
config.status.success = true
config.status.fail = false
try
Parser = require("./parser")
parser = new Parser()
user_config = parser.getUserConfig()
if user_config
console.log "Reading user configutation ..."
config = _merge(config, require(user_config))
else
console.log "No user config specified. Using global settings."
Parser = require("./parser")
parser = new Parser()
user_config = parser.getUserConfig()
if user_config
console.log "Reading user configutation ..."
config = _merge(config, require(user_config))
else
console.log "No user config specified. Using global settings."
catch err
if err.code is "MODULE_NOT_FOUND"
console.log "File %s not found.", user_config
process.exit 1
else
console.error "Error reading user configutation", err
process.exit 1
if err.code is "MODULE_NOT_FOUND"
console.log "File %s not found.", user_config
process.exit 1
else
console.error "Error reading user configutation", err
process.exit 1
finally
# export some variable
config.web.paths = config.routes
config.web.events = config.events
config.web.status = config.status
config.web.host = config.host
# calculate pidfile
config.debomatic.pidfile = "/var/run/debomatic-" + require("crypto").createHash("sha256").update(config.debomatic.path).digest("hex")
module.exports = config
# export some variable
config.web.paths = config.routes
config.web.events = config.events
config.web.status = config.status
config.web.host = config.host
# calculate pidfile
config.debomatic.pidfile = "/var/run/debomatic-" + require("crypto").createHash("sha256").update(config.debomatic.path).digest("hex")
module.exports = config
#jshint multistr: true
Parser = ->
args = process.argv.slice(2)
help = ->
console.log "Usage: %s [-c config]\n -h print this help \n -c set user configuration file", process.argv[1].split("/").pop()
process.exit 0
return
args = process.argv.slice(2)
help = ->
console.log "Usage: %s [-c config]\n -h print this help \n -c set user configuration file", process.argv[1].split("/").pop()
process.exit 0
return
@getUserConfig = ->
configFile = null
args.forEach (val, index) ->
if val is "-c"
configFile = args[index + 1]
return
if configFile
process.cwd() + "/" + configFile
else
null
@getUserConfig = ->
configFile = null
args.forEach (val, index) ->
if val is "-c"
configFile = args[index + 1]
help() if val is "-h"
return
if configFile
process.cwd() + "/" + configFile
else
null
args.forEach (val, index) ->
help() if val is "-h"
return
return
"use strict"
module.exports = Parser
......@@ -2,28 +2,28 @@
fs = require("fs")
Tail = require("tail").Tail
Tail::watchEvent = (e) ->
_this = this
if e is "change"
fs.stat @filename, (err, stats) ->
if err
_this.emit "error", err
return
_this.pos = stats.size if stats.size < _this.pos
if stats.size > _this.pos
_this.queue.push
start: _this.pos
end: stats.size
_this = this
if e is "change"
fs.stat @filename, (err, stats) ->
if err
_this.emit "error", err
return
_this.pos = stats.size if stats.size < _this.pos
if stats.size > _this.pos
_this.queue.push
start: _this.pos
end: stats.size
_this.pos = stats.size
_this.internalDispatcher.emit "next" if _this.queue.length is 1
_this.pos = stats.size
_this.internalDispatcher.emit "next" if _this.queue.length is 1
else if e is "rename"
@unwatch()
_this.emit "error", "File " + @filename + " deleted."
return
else if e is "rename"
@unwatch()
_this.emit "error", "File " + @filename + " deleted."
return
Tail::close = ->
@unwatch()
return
@unwatch()
return
module.exports = Tail
__errors_handler = (from, err, socket) ->
from = "NO SOCKET: " + from unless socket
console.error from, err.message
socket.emit config.events.error, err.message if socket
return
from = "NO SOCKET: " + from unless socket
console.error from, err.message
socket.emit config.events.error, err.message if socket
return
__check_no_backward = (backward_path) ->
try
return backward_path.indexOf("..") < 0
catch err
return true
return
try
return backward_path.indexOf("..") < 0
catch err
return true
return
__check_data_distribution = (data) ->
__check_no_backward(data) and __check_no_backward(data.distribution) and __check_no_backward(data.distribution.name)
__check_no_backward(data) and __check_no_backward(data.distribution) and __check_no_backward(data.distribution.name)
__check_data_package = (data) ->
__check_data_distribution(data) and __check_no_backward(data.package) and __check_no_backward(data.package.name) and __check_no_backward(data.package.version)
__check_data_distribution(data) and __check_no_backward(data.package) and __check_no_backward(data.package.name) and __check_no_backward(data.package.version)
__check_data_file = (data) ->
__check_data_package(data) and __check_no_backward(data.file) and __check_no_backward(data.file.name)
__check_data_package(data) and __check_no_backward(data.file) and __check_no_backward(data.file.name)
__get_distribution_pool_path = (data) ->
path.join config.debomatic.path, data.distribution.name, "pool"
path.join config.debomatic.path, data.distribution.name, "pool"
__get_package_path = (data) ->
path.join __get_distribution_pool_path(data), data.package.name + "_" + data.package.version
path.join __get_distribution_pool_path(data), data.package.name + "_" + data.package.version
__get_file_path = (data) ->
path.join __get_package_path(data), data.package.name + "_" + data.package.version + "." + data.file.name
path.join __get_package_path(data), data.package.name + "_" + data.package.version + "." + data.file.name
__get_files_list = (dir, onlyDirectories, callback) ->
fs.readdir dir, (err, files) ->
result = []
if err
__errors_handler "__get_files_list", err
return
files.forEach (f) ->
try
complete_path = path.join(dir, f)
stat = fs.statSync(complete_path)
if onlyDirectories
result.push f if stat.isDirectory()
else
result.push f if stat.isFile()
catch fs_error
__errors_handler "__get_files_list:forEach", fs_error
fs.readdir dir, (err, files) ->
result = []
if err
__errors_handler "__get_files_list", err
return
files.forEach (f) ->
try
complete_path = path.join(dir, f)
stat = fs.statSync(complete_path)
if onlyDirectories
result.push f if stat.isDirectory()
else
result.push f if stat.isFile()
catch fs_error
__errors_handler "__get_files_list:forEach", fs_error
return
return
callback result
return
return
callback result
return
return
__watch_path_onsocket = (event_name, socket, data, watch_path, updater) ->
socket_watchers = socket.watchers or {}
try
watcher = socket_watchers[event_name]
watcher.close() if watcher
fs.stat watch_path, (err, stats) ->
if err
__errors_handler "__watch_path_onsocket:fs.stat", err, socket
socket_watchers = socket.watchers or {}
try
watcher = socket_watchers[event_name]
watcher.close() if watcher
fs.stat watch_path, (err, stats) ->
if err
__errors_handler "__watch_path_onsocket:fs.stat", err, socket
return
if stats.isDirectory()
watcher = fs.watch(watch_path,
persistent: true
, (event, fileName) ->
updater event_name, socket, data if event is "rename"
return
)
else if stats.isFile()
watcher = new Tail(watch_path)
watcher.on "line", (new_content, tailInfo) ->
data.file.new_content = new_content + "\n"
updater event_name, socket, data
return
watcher.on "error", (msg) ->
socket.emit config.events.error, msg
return
socket_watchers[event_name] = watcher
socket.watchers = socket_watchers
return
catch err
__errors_handler "__watch_path_onsocket <- " + arguments_.callee.caller.name, err, socket
return
if stats.isDirectory()
watcher = fs.watch(watch_path,
persistent: true
, (event, fileName) ->
updater event_name, socket, data if event is "rename"
return
)
else if stats.isFile()
watcher = new Tail(watch_path)
watcher.on "line", (new_content, tailInfo) ->
data.file.new_content = new_content + "\n"
updater event_name, socket, data
return
watcher.on "error", (msg) ->
socket.emit config.events.error, msg
return
socket_watchers[event_name] = watcher
socket.watchers = socket_watchers
return
catch err
__errors_handler "__watch_path_onsocket <- " + arguments_.callee.caller.name, err, socket
return
return
__generic_handler_watcher = (event_name, socket, data, watch_path, callback) ->
callback event_name, socket, data
__watch_path_onsocket event_name, socket, data, watch_path, callback
return
__send_distributions = (socket) ->
__get_files_list config.debomatic.path, true, (directories) ->
distributions = []
directories.forEach (dir) ->
data = {}
data.distribution = {}
data.distribution.name = dir
pool_path = __get_distribution_pool_path(data)
distributions.push dir if fs.existsSync(pool_path)
return
socket.emit config.events.broadcast.distributions, distributions
callback event_name, socket, data
__watch_path_onsocket event_name, socket, data, watch_path, callback
return
__send_distributions = (socket) ->
__get_files_list config.debomatic.path, true, (directories) ->
distributions = []
directories.forEach (dir) ->
data = {}
data.distribution = {}
data.distribution.name = dir
pool_path = __get_distribution_pool_path(data)
distributions.push dir if fs.existsSync(pool_path)
return
socket.emit config.events.broadcast.distributions, distributions
return
return
return
"use strict"
path = require("path")
fs = require("fs")
config = require("./config")
Tail = require("./tail")
utils =
check_data_distribution: (data) ->
__check_data_distribution data
check_data_distribution: (data) ->
__check_data_distribution data
check_data_package: (data) ->
__check_data_package data
check_data_package: (data) ->
__check_data_package data
check_data_file: (data) ->
__check_data_file data
check_data_file: (data) ->
__check_data_file data
get_distribution_pool_path: (data) ->
__get_distribution_pool_path data
get_distribution_pool_path: (data) ->
__get_distribution_pool_path data
get_package_path: (data) ->
__get_package_path data
get_package_path: (data) ->
__get_package_path data
get_file_path: (data) ->
__get_file_path data
get_file_path: (data) ->
__get_file_path data
get_files_list: (dir, onlyDirectories, callback) ->
__get_files_list dir, onlyDirectories, callback
get_files_list: (dir, onlyDirectories, callback) ->
__get_files_list dir, onlyDirectories, callback
watch_path_onsocket: (event_name, socket, data, watch_path, updater) ->
__watch_path_onsocket event_name, socket, data, watch_path, updater
watch_path_onsocket: (event_name, socket, data, watch_path, updater) ->
__watch_path_onsocket event_name, socket, data, watch_path, updater
generic_handler_watcher: (event_name, socket, data, watch_path, callback) ->
__generic_handler_watcher event_name, socket, data, watch_path, callback
generic_handler_watcher: (event_name, socket, data, watch_path, callback) ->
__generic_handler_watcher event_name, socket, data, watch_path, callback
send_distributions: (socket) ->
__send_distributions socket
send_distributions: (socket) ->
__send_distributions socket
errors_handler: (from, error, socket) ->
__errors_handler from, error, socket
errors_handler: (from, error, socket) ->
__errors_handler from, error, socket
module.exports = utils
"use strict"
config = require("../lib/config")
exports.index = (req, res) ->
res.render "index", config
return
res.render "index", config
return
exports.distribution = (req, res) ->
res.render "distribution", config
return
res.render "distribution", config
return
exports.preferences = (req, res) ->
res.render "preferences", config
return
res.render "preferences", config
return
exports.commands = (req, res) ->
res.render "commands", config
return
res.render "commands", config
return
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment