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

check code style

parent 18c0c552
...@@ -33,7 +33,8 @@ app.get "/", routes.index ...@@ -33,7 +33,8 @@ 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 if config.routes.preferences
app.get config.routes.preferences, 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
...@@ -50,8 +51,10 @@ if config.routes.debomatic ...@@ -50,8 +51,10 @@ if 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
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>" 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()
...@@ -77,7 +80,8 @@ server.listen config.port, config.host, null, (err) -> ...@@ -77,7 +80,8 @@ server.listen config.port, config.host, null, (err) ->
# 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
...@@ -91,7 +95,10 @@ server.listen config.port, config.host, null, (err) -> ...@@ -91,7 +95,10 @@ server.listen config.port, config.host, null, (err) ->
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) ->
......
...@@ -15,7 +15,9 @@ __watch_status = (socket, status) -> ...@@ -15,7 +15,9 @@ __watch_status = (socket, status) ->
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
...@@ -55,21 +57,26 @@ __watch_distributions = (socket) -> ...@@ -55,21 +57,26 @@ __watch_distributions = (socket) ->
return return
__watch_pidfile = (socket) -> __watch_pidfile = (socket) ->
fs.watchFile config.debomatic.pidfile, fs.watchFile config.debomatic.pidfile, {
persistent: false persistent: false
interval: 1007 interval: 1007
}
, (curr, prev) -> , (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 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
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")
......
...@@ -6,22 +6,26 @@ __get_files_list_from_package = (data, callback) -> ...@@ -6,22 +6,26 @@ __get_files_list_from_package = (data, callback) ->
data.package.sources = [] data.package.sources = []
files.forEach (f) -> files.forEach (f) ->
file = {} 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.orig_name = f
file.name = f.split("_")[0] file.name = f.split("_")[0]
file.extension = f.split(".").pop() file.extension = f.split(".").pop()
return if config.debomatic.excluded_files.indexOf(file.extension) >= 0 return if file.extension in config.debomatic.excluded_files
if file.extension is "deb" or file.extension is "ddeb" or file.extension is "udeb" if file.extension in ["deb", "ddeb", "udeb"]
data.package.debs.push file data.package.debs.push(file)
else if f.indexOf(".tar") >= 0 or file.extension is "changes" or file.extension is "dsc" else if file.extension in ["changes", "dsc"] or
file.name = f.replace(data.package.name + "_" + data.package.version + ".", "") f.indexOf('.tar') > 0
file.name = f.replace(data.package.orig_name + ".", "")
if file.extension is "changes" if file.extension is "changes"
file.name = file.extension file.name = file.extension
else file.name = "orig." + f.split(".orig.").pop() if f.indexOf(".tar") >= 0 and f.indexOf(".orig.") > 0 else if f.indexOf('.orig.tar') > 0
data.package.sources.push file file.name = "orig." + f.split(".orig.").pop()
data.package.sources.push(file)
else else
file.name = file.extension file.name = file.extension
data.package.files.push file data.package.files.push(file)
return return
callback data callback data
...@@ -46,7 +50,9 @@ __read_package_status = (data, cb) -> ...@@ -46,7 +50,9 @@ __read_package_status = (data, cb) ->
try try
content = JSON.parse(content) content = JSON.parse(content)
catch parse_err 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 return
cb content cb content
return return
...@@ -93,26 +99,30 @@ __send_file = (event_name, socket, data, last_lines) -> ...@@ -93,26 +99,30 @@ __send_file = (event_name, socket, data, last_lines) ->
return return
data.file.orig_name = file_path.split("/").pop() data.file.orig_name = file_path.split("/").pop()
if last_lines > 0 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 else
data.file.content = content 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 socket.emit event_name, data
return return
return return
__handler_get_file = (socket, data) -> __handler_get_file = (socket, data) ->
file_path = utils.get_file_path(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 data.file.content = null
socket.emit event_name, data 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 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 __send_file(_e.file, socket, data, config.web.file.num_lines)
else else
__send_file _e.file, socket, data __send_file(_e.file, socket, data)
return return
Client = (socket) -> Client = (socket) ->
@start = -> @start = ->
...@@ -122,15 +132,25 @@ Client = (socket) -> ...@@ -122,15 +132,25 @@ Client = (socket) ->
# init events # init events
socket.on _e.distribution_packages, (data) -> socket.on _e.distribution_packages, (data) ->
return unless utils.check_data_distribution(data) return unless utils.check_data_distribution(data)
distribution_path = path.join(config.debomatic.path, data.distribution.name, "pool") distribution_path = path.join(config.debomatic.path,
utils.generic_handler_watcher _e.distribution_packages, socket, data, distribution_path, __send_distribution_packages data.distribution.name,
"pool")
utils.generic_handler_watcher(_e.distribution_packages,
socket,
data,
distribution_path,
__send_distribution_packages)
data = null data = null
return return
socket.on _e.package_files_list, (data) -> socket.on _e.package_files_list, (data) ->
return unless utils.check_data_package(data) return unless utils.check_data_package(data)
package_path = utils.get_package_path(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 data = null
return return
......
...@@ -3,24 +3,40 @@ __errors_handler = (from, err, socket) -> ...@@ -3,24 +3,40 @@ __errors_handler = (from, err, 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.orig_name)
__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.orig_name + "." + 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 = []
...@@ -76,7 +92,10 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) -> ...@@ -76,7 +92,10 @@ __watch_path_onsocket = (event_name, socket, data, watch_path, updater) ->
return return
catch err 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
return return
__generic_handler_watcher = (event_name, socket, data, watch_path, callback) -> __generic_handler_watcher = (event_name, socket, data, watch_path, callback) ->
...@@ -96,13 +115,13 @@ __send_distributions = (socket) -> ...@@ -96,13 +115,13 @@ __send_distributions = (socket) ->
socket.emit config.events.broadcast.distributions, distributions socket.emit config.events.broadcast.distributions, distributions
return return
return return
"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
......
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