Commit 70646bc3 authored by Leo Iannacone's avatar Leo Iannacone

check code style

parent 18c0c552
......@@ -33,7 +33,8 @@ app.get "/", routes.index
app.get config.routes.distribution, routes.distribution
# parefernces page
app.get config.routes.preferences, routes.preferences if config.routes.preferences
if config.routes.preferences
app.get config.routes.preferences, routes.preferences
# commands page
app.get config.routes.commands, routes.commands if config.routes.commands
......@@ -50,8 +51,10 @@ if 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/*
if match.length >= 2 and
((match[0] is match[1]) or # case unstable/unstable
(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()
......@@ -77,7 +80,8 @@ server.listen config.port, config.host, null, (err) ->
# 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
console.log "Please do not run nodejs with sudo. " +
"Changing user to %d", uid
process.setgid uid
process.setuid uid
......@@ -91,7 +95,10 @@ server.listen config.port, config.host, null, (err) ->
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
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) ->
......
......@@ -15,7 +15,9 @@ __watch_status = (socket, status) ->
try
data = JSON.parse(new_content)
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
# looking for same status already in statuses lists
......@@ -55,21 +57,26 @@ __watch_distributions = (socket) ->
return
__watch_pidfile = (socket) ->
fs.watchFile config.debomatic.pidfile,
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
# if === 0 means pidfile does not exists
status_debomatic = running: curr.ino isnt 0
try
socket.emit socket.emit(config.events.broadcast.status_debomatic, status_debomatic)
socket.emit socket.emit(
config.events.broadcast.status_debomatic,
status_debomatic)
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")
......
......@@ -6,22 +6,26 @@ __get_files_list_from_package = (data, callback) ->
data.package.sources = []
files.forEach (f) ->
file = {}
file.path = path.join(package_path, f).replace(config.debomatic.path, config.routes.debomatic)
file.path = path.join(package_path, f)
.replace(config.debomatic.path,
config.routes.debomatic)
file.orig_name = f
file.name = f.split("_")[0]
file.extension = f.split(".").pop()
return if config.debomatic.excluded_files.indexOf(file.extension) >= 0
if file.extension is "deb" or file.extension is "ddeb" or file.extension is "udeb"
data.package.debs.push file
else if f.indexOf(".tar") >= 0 or file.extension is "changes" or file.extension is "dsc"
file.name = f.replace(data.package.name + "_" + data.package.version + ".", "")
return if file.extension in config.debomatic.excluded_files
if file.extension in ["deb", "ddeb", "udeb"]
data.package.debs.push(file)
else if file.extension in ["changes", "dsc"] or
f.indexOf('.tar') > 0
file.name = f.replace(data.package.orig_name + ".", "")
if file.extension is "changes"
file.name = file.extension
else file.name = "orig." + f.split(".orig.").pop() if f.indexOf(".tar") >= 0 and f.indexOf(".orig.") > 0
data.package.sources.push file
else if f.indexOf('.orig.tar') > 0
file.name = "orig." + f.split(".orig.").pop()
data.package.sources.push(file)
else
file.name = file.extension
data.package.files.push file
data.package.files.push(file)
return
callback data
......@@ -46,7 +50,9 @@ __read_package_status = (data, cb) ->
try
content = JSON.parse(content)
catch parse_err
utils.errors_handler "Client:__read_package_status:parse_err:", parse_err
utils.errors_handler("Client:" +
"__read_package_status:parse_err:",
parse_err)
return
cb content
return
......@@ -93,26 +99,30 @@ __send_file = (event_name, socket, data, last_lines) ->
return
data.file.orig_name = file_path.split("/").pop()
if last_lines > 0
data.file.content = content.split("\n").slice(-last_lines).join("\n")
data.file.content = content.split("\n")[-last_lines..].join("\n")
else
data.file.content = content
data.file.path = file_path.replace(config.debomatic.path, config.routes.debomatic)
data.file.path = file_path.replace(config.debomatic.path,
config.routes.debomatic)
socket.emit event_name, data
return
return
__handler_get_file = (socket, data) ->
file_path = utils.get_file_path(data)
utils.watch_path_onsocket _e.file_newcontent, socket, data, file_path, (event_name, socket, data) ->
send = (event_name, socket, data) ->
data.file.content = null
socket.emit event_name, data
return
utils.watch_path_onsocket _e.file_newcontent, socket, data, file_path, send
if config.web.file.preview.indexOf(data.file.name) >= 0 and not data.file.force
__send_file _e.file, socket, data, config.web.file.num_lines
if data.file.name in config.web.file.preview and not data.file.force
__send_file(_e.file, socket, data, config.web.file.num_lines)
else
__send_file _e.file, socket, data
__send_file(_e.file, socket, data)
return
Client = (socket) ->
@start = ->
......@@ -122,15 +132,25 @@ Client = (socket) ->
# init events
socket.on _e.distribution_packages, (data) ->
return unless utils.check_data_distribution(data)
distribution_path = path.join(config.debomatic.path, data.distribution.name, "pool")
utils.generic_handler_watcher _e.distribution_packages, socket, data, distribution_path, __send_distribution_packages
distribution_path = path.join(config.debomatic.path,
data.distribution.name,
"pool")
utils.generic_handler_watcher(_e.distribution_packages,
socket,
data,
distribution_path,
__send_distribution_packages)
data = null
return
socket.on _e.package_files_list, (data) ->
return unless utils.check_data_package(data)
package_path = utils.get_package_path(data)
utils.generic_handler_watcher _e.package_files_list, socket, data, package_path, __send_package_files_list
utils.generic_handler_watcher(_e.package_files_list,
socket,
data,
package_path,
__send_package_files_list)
data = null
return
......
......@@ -3,24 +3,40 @@ __errors_handler = (from, err, 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
__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.orig_name)
__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.orig_name + "." + data.file.name)
__get_files_list = (dir, onlyDirectories, callback) ->
fs.readdir dir, (err, files) ->
result = []
......@@ -76,7 +92,10 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) ->
return
catch err
__errors_handler "__watch_path_onsocket <- " + arguments_.callee.caller.name, err, socket
__errors_handler("__watch_path_onsocket <- " +
arguments_.callee.caller.name,
err,
socket)
return
return
__generic_handler_watcher = (event_name, socket, data, watch_path, callback) ->
......@@ -96,13 +115,13 @@ __send_distributions = (socket) ->
socket.emit config.events.broadcast.distributions, distributions
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
......
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