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

indentation 4 spaces

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