Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
debomatic-webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
debomatic-webui-admins
debomatic-webui
Commits
08e14f2f
Commit
08e14f2f
authored
Jun 04, 2014
by
Leo Iannacone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslinted code
parent
a6c6a245
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
508 additions
and
507 deletions
+508
-507
debomatic-webui/lib/broadcaster.js
debomatic-webui/lib/broadcaster.js
+59
-59
debomatic-webui/lib/client.js
debomatic-webui/lib/client.js
+158
-161
debomatic-webui/lib/config.js
debomatic-webui/lib/config.js
+94
-97
debomatic-webui/lib/parser.js
debomatic-webui/lib/parser.js
+30
-29
debomatic-webui/lib/tail.js
debomatic-webui/lib/tail.js
+32
-30
debomatic-webui/lib/utils.js
debomatic-webui/lib/utils.js
+135
-131
No files found.
debomatic-webui/lib/broadcaster.js
View file @
08e14f2f
var
config
=
require
(
'
./config.js
'
)
,
fs
=
require
(
'
fs
'
)
,
Tail
=
require
(
'
./tail.js
'
)
'
use strict
'
;
function
__watch_status_check_same_obj
(
obj1
,
obj2
)
{
if
(
obj1
.
status
==
obj2
.
status
)
{
if
(
obj1
.
distribution
==
obj2
.
distribution
)
{
if
(
obj1
.
hasOwnProperty
(
'
package
'
)
&&
obj2
.
hasOwnProperty
(
'
package
'
))
{
if
(
obj1
.
package
==
obj2
.
package
)
return
true
;
return
false
}
return
true
var
config
=
require
(
'
./config.js
'
),
fs
=
require
(
'
fs
'
),
utils
=
require
(
'
./utils.js
'
),
Tail
=
require
(
'
./tail.js
'
);
function
__watch_status_check_same_obj
(
obj1
,
obj2
)
{
if
(
obj1
.
status
==
obj2
.
status
)
{
if
(
obj1
.
distribution
==
obj2
.
distribution
)
{
if
(
obj1
.
hasOwnProperty
(
'
package
'
)
&&
obj2
.
hasOwnProperty
(
'
package
'
))
{
if
(
obj1
.
package
==
obj2
.
package
)
return
true
;
return
false
;
}
return
true
;
}
}
}
return
false
return
false
;
}
// watcher on build_status
function
__watch_status
(
socket
,
status
)
{
function
__watch_status
(
socket
,
status
)
{
var
watcher
=
new
Tail
(
config
.
debomatic
.
jsonfile
)
watcher
.
on
(
'
line
'
,
function
(
new_content
)
{
var
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
'
))
{
for
(
i
=
0
;
i
<
status
.
length
;
i
++
)
{
if
(
__watch_status_check_same_obj
(
data
,
status
[
i
]))
{
status
.
splice
(
i
,
1
)
break
;
var
watcher
=
new
Tail
(
config
.
debomatic
.
jsonfile
);
watcher
.
on
(
'
line
'
,
function
(
new_content
)
{
var
data
=
null
;
try
{
data
=
JSON
.
parse
(
new_content
);
}
catch
(
err
)
{
utils
.
errors_handler
(
'
Broadcaster:__watch_status:JSON.parse(new_content) -
'
,
err
,
socket
);
return
;
}
else
continue
;
}
}
else
{
status
.
push
(
data
)
}
socket
.
emit
(
config
.
events
.
broadcast
.
status_update
,
data
)
})
watcher
.
on
(
'
error
'
,
function
(
msg
)
{
socket
.
emit
(
config
.
events
.
error
,
msg
)
})
// looking for same status already in statuses lists
if
(
data
.
hasOwnProperty
(
'
success
'
))
{
for
(
var
i
=
0
;
i
<
status
.
length
;
i
++
)
{
if
(
__watch_status_check_same_obj
(
data
,
status
[
i
]))
{
status
.
splice
(
i
,
1
);
break
;
}
else
continue
;
}
}
else
{
status
.
push
(
data
);
}
socket
.
emit
(
config
.
events
.
broadcast
.
status_update
,
data
);
});
watcher
.
on
(
'
error
'
,
function
(
msg
)
{
socket
.
emit
(
config
.
events
.
error
,
msg
);
});
}
// watcher on new distributions
function
__watch_distributions
(
socket
)
{
fs
.
watch
(
config
.
debomatic
.
path
,
{
persistent
:
true
},
function
(
event
,
fileName
)
{
// wait half a second to get pool subdir created
setTimeout
(
function
()
{
utils
.
send_distributions
(
socket
)
},
500
)
})
function
__watch_distributions
(
socket
)
{
fs
.
watch
(
config
.
debomatic
.
path
,
{
persistent
:
true
},
function
(
event
,
fileName
)
{
// wait half a second to get pool subdir created
setTimeout
(
function
()
{
utils
.
send_distributions
(
socket
);
},
500
);
});
}
function
Broadcaster
(
sockets
,
status
)
{
var
sockets
=
sockets
function
Broadcaster
(
sockets
,
status
)
{
__watch_status
(
sockets
,
status
)
__watch_status
(
sockets
,
status
);
__watch_distributions
(
sockets
)
__watch_distributions
(
sockets
);
return
{
return
{
}
};
}
module
.
exports
=
Broadcaster
module
.
exports
=
Broadcaster
;
debomatic-webui/lib/client.js
View file @
08e14f2f
var
fs
=
require
(
'
fs
'
)
,
path
=
require
(
'
path
'
)
,
config
=
require
(
'
./config.js
'
)
,
utils
=
require
(
'
./utils.js
'
)
'
use strict
'
;
var
fs
=
require
(
'
fs
'
),
path
=
require
(
'
path
'
),
config
=
require
(
'
./config.js
'
),
utils
=
require
(
'
./utils.js
'
);
var
_e
=
config
.
events
.
client
var
_e
=
config
.
events
.
client
;
function
__get_files_list_from_package
(
data
,
callback
)
{
package_path
=
utils
.
get_package_path
(
data
)
utils
.
get_files_list
(
package_path
,
false
,
function
(
files
)
{
data
.
package
.
files
=
[]
data
.
package
.
debs
=
[]
data
.
package
.
sources
=
[]
files
.
forEach
(
function
(
f
)
{
file
=
{}
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
();
if
(
file
.
extension
==
"
deb
"
||
file
.
extension
==
"
ddeb
"
)
{
data
.
package
.
debs
.
push
(
file
);
}
else
if
(
f
.
indexOf
(
'
.tar
'
)
>=
0
||
file
.
extension
==
"
changes
"
||
file
.
extension
==
"
dsc
"
)
{
file
.
name
=
f
.
replace
(
data
.
package
.
name
+
'
_
'
+
data
.
package
.
version
+
'
.
'
,
'
'
)
if
(
file
.
extension
==
'
changes
'
)
file
.
name
=
file
.
extension
else
if
(
f
.
indexOf
(
'
.tar
'
)
>=
0
&&
f
.
indexOf
(
'
.orig.
'
)
>
0
)
file
.
name
=
'
orig.
'
+
f
.
split
(
'
.orig.
'
).
pop
()
data
.
package
.
sources
.
push
(
file
)
}
else
{
file
.
name
=
file
.
extension
data
.
package
.
files
.
push
(
file
)
}
var
package_path
=
utils
.
get_package_path
(
data
);
utils
.
get_files_list
(
package_path
,
false
,
function
(
files
)
{
data
.
package
.
files
=
[];
data
.
package
.
debs
=
[];
data
.
package
.
sources
=
[];
files
.
forEach
(
function
(
f
)
{
var
file
=
{};
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
();
if
(
file
.
extension
==
'
deb
'
||
file
.
extension
==
'
ddeb
'
)
{
data
.
package
.
debs
.
push
(
file
);
}
else
if
(
f
.
indexOf
(
'
.tar
'
)
>=
0
||
file
.
extension
==
'
changes
'
||
file
.
extension
==
'
dsc
'
)
{
file
.
name
=
f
.
replace
(
data
.
package
.
name
+
'
_
'
+
data
.
package
.
version
+
'
.
'
,
''
);
if
(
file
.
extension
==
'
changes
'
)
file
.
name
=
file
.
extension
;
else
if
(
f
.
indexOf
(
'
.tar
'
)
>=
0
&&
f
.
indexOf
(
'
.orig.
'
)
>
0
)
file
.
name
=
'
orig.
'
+
f
.
split
(
'
.orig.
'
).
pop
();
data
.
package
.
sources
.
push
(
file
);
}
else
{
file
.
name
=
file
.
extension
;
data
.
package
.
files
.
push
(
file
);
}
});
callback
(
data
);
});
callback
(
data
);
});
}
function
__send_package_files_list
(
event_name
,
socket
,
data
)
{
__get_files_list_from_package
(
data
,
function
(
new_data
)
{
socket
.
emit
(
event_name
,
new_data
)
});
function
__send_package_files_list
(
event_name
,
socket
,
data
)
{
__get_files_list_from_package
(
data
,
function
(
new_data
)
{
socket
.
emit
(
event_name
,
new_data
);
});
}
function
__send_package_status
(
socket
,
data
,
package_data
)
{
var
event_name
=
config
.
events
.
client
.
distribution_packages
.
status
var
new_data
=
{}
new_data
.
distribution
=
data
.
distribution
new_data
.
package
=
package_data
var
status_data
=
{}
status_data
.
status
=
config
.
status
.
build
status_data
.
distribution
=
data
.
distribution
.
name
status_data
.
package
=
package_data
.
orig_name
var
package_path
=
utils
.
get_package_path
(
new_data
)
// status policy:
// + successed: exists .dsc
// + building: wc -l .datestamp == 1 (FIX_ME)
// + failed: else
var
base_path
=
path
.
join
(
package_path
,
package_data
.
orig_name
)
fs
.
exists
(
base_path
+
'
.dsc
'
,
function
(
dsc_exists
){
if
(
dsc_exists
)
{
status_data
.
success
=
config
.
status
.
success
socket
.
emit
(
event_name
,
status_data
)
}
else
{
// emulate wc -l .datestamp in nodejs
var
count
=
0
var
datestamp
=
base_path
+
'
.datestamp
'
fs
.
exists
(
datestamp
,
function
(
datestamp_exists
){
if
(
datestamp_exists
)
{
// count lines
fs
.
createReadStream
(
datestamp
)
.
on
(
'
data
'
,
function
(
chunk
)
{
for
(
var
i
=
0
;
i
<
chunk
.
length
;
++
i
)
if
(
chunk
[
i
]
==
10
)
count
++
;
})
.
on
(
'
end
'
,
function
()
{
if
(
count
>
1
)
status_data
.
success
=
config
.
status
.
fail
socket
.
emit
(
event_name
,
status_data
)
});
var
event_name
=
config
.
events
.
client
.
distribution_packages
.
status
;
var
new_data
=
{};
new_data
.
distribution
=
data
.
distribution
;
new_data
.
package
=
package_data
;
var
status_data
=
{};
status_data
.
status
=
config
.
status
.
build
;
status_data
.
distribution
=
data
.
distribution
.
name
;
status_data
.
package
=
package_data
.
orig_name
;
var
package_path
=
utils
.
get_package_path
(
new_data
);
// status policy:
// + successed: exists .dsc
// + building: wc -l .datestamp == 1 (FIX_ME)
// + failed: else
var
base_path
=
path
.
join
(
package_path
,
package_data
.
orig_name
);
fs
.
exists
(
base_path
+
'
.dsc
'
,
function
(
dsc_exists
)
{
if
(
dsc_exists
)
{
status_data
.
success
=
config
.
status
.
success
;
socket
.
emit
(
event_name
,
status_data
);
}
else
{
// emulate wc -l .datestamp in nodejs
var
count
=
0
;
var
datestamp
=
base_path
+
'
.datestamp
'
;
fs
.
exists
(
datestamp
,
function
(
datestamp_exists
)
{
if
(
datestamp_exists
)
{
// count lines
fs
.
createReadStream
(
datestamp
)
.
on
(
'
data
'
,
function
(
chunk
)
{
for
(
var
i
=
0
;
i
<
chunk
.
length
;
++
i
)
if
(
chunk
[
i
]
==
10
)
count
++
;
})
.
on
(
'
end
'
,
function
()
{
if
(
count
>
1
)
status_data
.
success
=
config
.
status
.
fail
;
socket
.
emit
(
event_name
,
status_data
);
});
}
});
}
})
}
})
}
function
__send_distribution_packages
(
event_name
,
socket
,
data
)
{
distro_path
=
utils
.
get_distribution_pool_path
(
data
)
utils
.
get_files_list
(
distro_path
,
true
,
function
(
packages
)
{
data
.
distribution
.
packages
=
[]
packages
.
forEach
(
function
(
p
)
{
pack
=
{}
info
=
p
.
split
(
'
_
'
)
pack
.
name
=
info
[
0
]
pack
.
version
=
info
[
1
]
pack
.
orig_name
=
p
data
.
distribution
.
packages
.
push
(
pack
)
__send_package_status
(
socket
,
data
,
pack
)
});
socket
.
emit
(
event_name
,
data
)
});
}
function
__send_file
(
event_name
,
socket
,
data
)
{
var
file_path
=
utils
.
get_file_path
(
data
)
fs
.
readFile
(
file_path
,
'
utf8
'
,
function
(
err
,
content
)
{
if
(
err
)
{
utils
.
errors_handler
(
'
client:__send_file
'
,
err
,
socket
)
return
}
data
.
file
.
orig_name
=
file_path
.
split
(
'
/
'
).
pop
()
data
.
file
.
content
=
content
data
.
file
.
path
=
file_path
.
replace
(
config
.
debomatic
.
path
,
config
.
routes
.
debomatic
)
socket
.
emit
(
event_name
,
data
)
});
}
function
__handler_get_file
(
socket
,
data
)
{
var
file_path
=
utils
.
get_file_path
(
data
)
utils
.
watch_path_onsocket
(
_e
.
file_newcontent
,
socket
,
data
,
file_path
,
function
(
event_name
,
socket
,
data
)
{
data
.
file
.
content
=
null
socket
.
emit
(
event_name
,
data
)
})
__send_file
(
_e
.
file
.
set
,
socket
,
data
)
function
__send_distribution_packages
(
event_name
,
socket
,
data
)
{
var
distro_path
=
utils
.
get_distribution_pool_path
(
data
);
utils
.
get_files_list
(
distro_path
,
true
,
function
(
packages
)
{
data
.
distribution
.
packages
=
[];
packages
.
forEach
(
function
(
p
)
{
var
pack
=
{};
var
info
=
p
.
split
(
'
_
'
);
pack
.
name
=
info
[
0
];
pack
.
version
=
info
[
1
];
pack
.
orig_name
=
p
;
data
.
distribution
.
packages
.
push
(
pack
);
__send_package_status
(
socket
,
data
,
pack
);
});
socket
.
emit
(
event_name
,
data
);
});
}
function
Client
(
socket
)
{
var
socket
=
socket
this
.
start
=
function
()
{
// init send distributions
utils
.
send_distributions
(
socket
)
// init events
socket
.
on
(
_e
.
distribution_packages
.
get
,
function
(
data
)
{
if
(
!
utils
.
check_data_distribution
(
data
))
return
distribution_path
=
path
.
join
(
config
.
debomatic
.
path
,
data
.
distribution
.
name
,
'
pool
'
)
utils
.
generic_handler_watcher
(
_e
.
distribution_packages
.
set
,
socket
,
data
,
distribution_path
,
__send_distribution_packages
)
})
socket
.
on
(
_e
.
package_files_list
.
get
,
function
(
data
)
{
if
(
!
utils
.
check_data_package
(
data
))
return
package_path
=
utils
.
get_package_path
(
data
)
utils
.
generic_handler_watcher
(
_e
.
package_files_list
.
set
,
socket
,
data
,
package_path
,
__send_package_files_list
)
})
socket
.
on
(
_e
.
file
.
get
,
function
(
data
){
if
(
!
utils
.
check_data_file
(
data
))
return
__handler_get_file
(
socket
,
data
)
})
// on client disconnection close all watchers
socket
.
on
(
'
disconnect
'
,
function
()
{
socket
.
get
(
"
watchers
"
,
function
(
err
,
socket_watchers
){
if
(
!
socket_watchers
)
return
;
for
(
key
in
socket_watchers
)
{
try
{
socket_watchers
[
key
].
close
()
}
catch
(
err
)
{}
function
__send_file
(
event_name
,
socket
,
data
)
{
var
file_path
=
utils
.
get_file_path
(
data
);
fs
.
readFile
(
file_path
,
'
utf8
'
,
function
(
err
,
content
)
{
if
(
err
)
{
utils
.
errors_handler
(
'
client:__send_file
'
,
err
,
socket
);
return
;
}
})
data
.
file
.
orig_name
=
file_path
.
split
(
'
/
'
).
pop
();
data
.
file
.
content
=
content
;
data
.
file
.
path
=
file_path
.
replace
(
config
.
debomatic
.
path
,
config
.
routes
.
debomatic
);
socket
.
emit
(
event_name
,
data
);
});
}
}
function
__handler_get_file
(
socket
,
data
)
{
var
file_path
=
utils
.
get_file_path
(
data
);
utils
.
watch_path_onsocket
(
_e
.
file_newcontent
,
socket
,
data
,
file_path
,
function
(
event_name
,
socket
,
data
)
{
data
.
file
.
content
=
null
;
socket
.
emit
(
event_name
,
data
);
});
__send_file
(
_e
.
file
.
set
,
socket
,
data
);
}
this
.
send_status
=
function
(
status
)
{
socket
.
emit
(
_e
.
status
,
status
)
}
function
Client
(
socket
)
{
this
.
start
=
function
()
{
// init send distributions
utils
.
send_distributions
(
socket
);
// init events
socket
.
on
(
_e
.
distribution_packages
.
get
,
function
(
data
)
{
if
(
!
utils
.
check_data_distribution
(
data
))
return
;
var
distribution_path
=
path
.
join
(
config
.
debomatic
.
path
,
data
.
distribution
.
name
,
'
pool
'
);
utils
.
generic_handler_watcher
(
_e
.
distribution_packages
.
set
,
socket
,
data
,
distribution_path
,
__send_distribution_packages
);
});
socket
.
on
(
_e
.
package_files_list
.
get
,
function
(
data
)
{
if
(
!
utils
.
check_data_package
(
data
))
return
;
var
package_path
=
utils
.
get_package_path
(
data
);
utils
.
generic_handler_watcher
(
_e
.
package_files_list
.
set
,
socket
,
data
,
package_path
,
__send_package_files_list
);
});
socket
.
on
(
_e
.
file
.
get
,
function
(
data
)
{
if
(
!
utils
.
check_data_file
(
data
))
return
;
__handler_get_file
(
socket
,
data
);
});
// on client disconnection close all watchers
socket
.
on
(
'
disconnect
'
,
function
()
{
socket
.
get
(
'
watchers
'
,
function
(
err
,
socket_watchers
)
{
if
(
!
socket_watchers
)
return
;
for
(
var
key
in
socket_watchers
)
{
try
{
socket_watchers
[
key
].
close
();
}
catch
(
err
)
{}
}
});
});
};
this
.
send_status
=
function
(
status
)
{
socket
.
emit
(
_e
.
status
,
status
);
};
}
module
.
exports
=
Client
module
.
exports
=
Client
;
debomatic-webui/lib/config.js
View file @
08e14f2f
'
use strict
'
;
/*
* Please DO NOT edit this file.
*
* Edit auto-generated
"user.config.js"
file instead.
* Edit auto-generated
'user.config.js'
file instead.
*
*/
// #start config-auto-export
var
config
=
{}
var
config
=
{}
;
/*
* Configure host and port.
* Please for ports < 1000 use authbind. DO NOT RUN nodejs as root.
* $ authbind nodejs index.js
*/
config
.
host
=
'
localhost
'
config
.
port
=
3000
config
.
host
=
'
localhost
'
;
config
.
port
=
3000
;
config
.
socket
=
{}
config
.
socket
.
log
=
false
config
.
socket
=
{}
;
config
.
socket
.
log
=
false
;
config
.
debomatic
=
{}
config
.
debomatic
.
path
=
'
/srv/debomatic-amd64
'
config
.
debomatic
.
jsonfile
=
'
/var/log/debomatic-json.log
'
config
.
debomatic
=
{}
;
config
.
debomatic
.
path
=
'
/srv/debomatic-amd64
'
;
config
.
debomatic
.
jsonfile
=
'
/var/log/debomatic-json.log
'
;
config
.
routes
=
{}
config
.
routes
.
debomatic
=
'
/debomatic
'
config
.
routes
.
distribution
=
'
/distribution
'
config
.
routes
.
preferences
=
'
/preferences
'
config
.
routes
=
{}
;
config
.
routes
.
debomatic
=
'
/debomatic
'
;
config
.
routes
.
distribution
=
'
/distribution
'
;
config
.
routes
.
preferences
=
'
/preferences
'
;
config
.
web
=
{}
config
.
web
.
title
=
"
Deb-o-Matic web.ui
"
config
.
web
.
description
=
"
This is a web interface for debomatic
"
config
.
web
=
{}
;
config
.
web
.
title
=
'
Deb-o-Matic web.ui
'
;
config
.
web
.
description
=
'
This is a web interface for debomatic
'
;
// debomatic configuration exportable for web
config
.
web
.
debomatic
=
{}
config
.
web
.
debomatic
.
admin
=
{}
config
.
web
.
debomatic
.
admin
.
name
=
"
Your Name
"
config
.
web
.
debomatic
.
admin
.
email
=
"
you AT debian DOT org
"
// please use this SPAMFREE form - it will be converted client side by javascript
config
.
web
.
debomatic
.
architecture
=
'
amd64
'
config
.
web
.
debomatic
.
dput
=
{}
config
.
web
.
debomatic
.
dput
.
incoming
=
config
.
debomatic
.
path
config
.
web
.
debomatic
.
dput
.
host
=
config
.
host
config
.
web
.
debomatic
.
dput
.
login
=
"
debomatic
"
config
.
web
.
debomatic
.
dput
.
method
=
"
scp
"
config
.
web
.
debomatic
.
dput
.
unsigned_uploads
=
false
config
.
web
.
debomatic
=
{}
;
config
.
web
.
debomatic
.
admin
=
{}
;
config
.
web
.
debomatic
.
admin
.
name
=
'
Your Name
'
;
config
.
web
.
debomatic
.
admin
.
email
=
'
you AT debian DOT org
'
;
// please use this SPAMFREE form - it will be converted client side by javascript
config
.
web
.
debomatic
.
architecture
=
'
amd64
'
;
config
.
web
.
debomatic
.
dput
=
{}
;
config
.
web
.
debomatic
.
dput
.
incoming
=
config
.
debomatic
.
path
;
config
.
web
.
debomatic
.
dput
.
host
=
config
.
host
;
config
.
web
.
debomatic
.
dput
.
login
=
'
debomatic
'
;
config
.
web
.
debomatic
.
dput
.
method
=
'
scp
'
;
config
.
web
.
debomatic
.
dput
.
unsigned_uploads
=
false
;
// default ui settings
config
.
web
.
preferences
=
{}
config
.
web
.
preferences
.
autoscroll
=
true
config
.
web
.
preferences
.
header
=
true
config
.
web
.
preferences
.
sidebar
=
true
config
.
web
.
preferences
.
glossy_theme
=
true
config
.
web
.
preferences
.
file_background
=
true
config
.
web
.
preferences
.
file_fontsize
=
13
// valid values are [13..16]
config
.
web
.
preferences
.
debug
=
0
// debug level - 0 means disabled
config
.
web
.
preferences
=
{}
;
config
.
web
.
preferences
.
autoscroll
=
true
;
config
.
web
.
preferences
.
header
=
true
;
config
.
web
.
preferences
.
sidebar
=
true
;
config
.
web
.
preferences
.
glossy_theme
=
true
;
config
.
web
.
preferences
.
file_background
=
true
;
config
.
web
.
preferences
.
file_fontsize
=
13
;
// valid values are [13..16]
config
.
web
.
preferences
.
debug
=
0
;
// debug level - 0 means disabled
// #end config-auto-export
// DO NOT TOUCH these ones
config
.
version
=
'
0.2.2
'
config
.
version
=
'
0.2.2
'
;
// A simple function to quickly have
// get and set strings for client events
function
_event_get_set
(
event_name
)
{
return
{
set
:
event_name
,
get
:
'
get_
'
+
event_name
}
return
{
set
:
event_name
,
get
:
'
get_
'
+
event_name
};
}
config
.
events
=
{}
config
.
events
.
error
=
'
error
'
config
.
events
.
broadcast
=
{}
config
.
events
.
broadcast
.
distributions
=
'
distributions
'
config
.
events
.
broadcast
.
status_update
=
'
status_update
'
config
.
events
=
{}
;
config
.
events
.
error
=
'
error
'
;
config
.
events
.
broadcast
=
{}
;
config
.
events
.
broadcast
.
distributions
=
'
distributions
'
;
config
.
events
.
broadcast
.
status_update
=
'
status_update
'
;
config
.
events
.
client
=
{}
config
.
events
.
client
.
distribution_packages
=
_event_get_set
(
'
distribution_packages
'
)
config
.
events
.
client
.
distribution_packages
.
status
=
'
package_status
'
config
.
events
.
client
.
package_files_list
=
_event_get_set
(
'
package_files_list
'
)
config
.
events
.
client
.
file
=
_event_get_set
(
'
file
'
)
config
.
events
.
client
.
file_newcontent
=
'
file_newcontent
'
config
.
events
.
client
.
status
=
'
status
'
config
.
events
.
client
=
{}
;
config
.
events
.
client
.
distribution_packages
=
_event_get_set
(
'
distribution_packages
'
)
;
config
.
events
.
client
.
distribution_packages
.
status
=
'
package_status
'
;
config
.
events
.
client
.
package_files_list
=
_event_get_set
(
'
package_files_list
'
)
;
config
.
events
.
client
.
file
=
_event_get_set
(
'
file
'
)
;
config
.
events
.
client
.
file_newcontent
=
'
file_newcontent
'
;
config
.
events
.
client
.
status
=
'
status
'
;
// debomatic status according with JSONLogger.py module
config
.
status
=
{}
config
.
status
.
build
=
'
build
'
config
.
status
.
create
=
'
create
'
config
.
status
.
update
=
'
update
'
config
.
status
.
success
=
true
config
.
status
.
fail
=
false
config
.
status
=
{}
;
config
.
status
.
build
=
'
build
'
;
config
.
status
.
create
=
'
create
'
;
config
.
status
.
update
=
'
update
'
;
config
.
status
.
success
=
true
;
config
.
status
.
fail
=
false
;
// read user configuration and merge it
/*
* update object1 with object2 values
*/
function
_merge
(
object1
,
object2
)
{
var
result
=
{}
for
(
p
in
object1
)
{
if
(
object2
.
hasOwnProperty
(
p
))
{
if
(
typeof
object1
[
p
]
===
'
object
'
&&
typeof
object2
[
p
]
===
'
object
'
)
{
result
[
p
]
=
_merge
(
object1
[
p
],
object2
[
p
])
}
else
{
result
[
p
]
=
object2
[
p
]
}
var
result
=
{};
for
(
var
p
in
object1
)
{
if
(
object2
.
hasOwnProperty
(
p
))
{
if
(
typeof
object1
[
p
]
===
'
object
'
&&
typeof
object2
[
p
]
===
'
object
'
)
{
result
[
p
]
=
_merge
(
object1
[
p
],
object2
[
p
]);
}
else
{
result
[
p
]
=
object2
[
p
];
}
}
else
{
result
[
p
]
=
object1
[
p
];
}
}
else
{
result
[
p
]
=
object1
[
p
]
}
}
return
result
return
result
;
}
try
{
var
Parser
=
require
(
'
./parser.js
'
)
var
parser
=
new
Parser
()
var
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.
"
)
}
var
Parser
=
require
(
'
./parser.js
'
);
var
parser
=
new
Parser
();
var
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
==
'
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
==
'
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
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
;
module
.
exports
=
config
;
}
debomatic-webui/lib/parser.js
View file @
08e14f2f
function
Parser
()
{
'
use strict
'
;
var
args
=
process
.
argv
.
slice
(
2
);
function
Parser
()
{
var
help
=
function
()
{
console
.
log
(
"
\
var
args
=
process
.
argv
.
slice
(
2
);
var
help
=
function
()
{
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
);
}
-c set user configuration file
'
,
process
.
argv
[
1
].
split
(
'
/
'
).
pop
());
this
.
getUserConfig
=
function
()
{
var
configFile
=
null
;
args
.
forEach
(
function
(
val
,
index
)
{
if
(
val
==
'
-c
'
)
{
configFile
=
args
[
index
+
1
]
return
}
})
if
(
configFile
)
return
process
.
cwd
()
+
'
/
'
+
configFile
;
else
return
null
}
process
.
exit
(
0
);
};
args
.
forEach
(
function
(
val
,
index
)
{
if
(
val
==
'
-h
'
)
{
help
()
}
})
this
.
getUserConfig
=
function
()
{
var
configFile
=
null
;
args
.
forEach
(
function
(
val
,
index
)
{
if
(
val
==
'
-c
'
)
{
configFile
=
args
[
index
+
1
];
return
;
}
});
if
(
configFile
)
return
process
.
cwd
()
+
'
/
'
+
configFile
;
else
return
null
;
};
args
.
forEach
(
function
(
val
,
index
)
{
if
(
val
==
'
-h
'
)
{
help
();
}
});
}
module
.
exports
=
Parser
\ No newline at end of file
module
.
exports
=
Parser
debomatic-webui/lib/tail.js
View file @
08e14f2f
var
fs
=
require
(
'
fs
'
)
,
Tail
=
require
(
'
tail
'
).
Tail
'
use strict
'
;
Tail
.
prototype
.
watchEvent
=
function
(
e
)
{
var
_this
=
this
;
var
fs
=
require
(
'
fs
'
),
Tail
=
require
(
'
tail
'
).
Tail
;
if
(
e
===
'
change
'
)
{
return
fs
.
stat
(
this
.
filename
,
function
(
err
,
stats
)
{
if
(
err
)
{
_this
.
emit
(
'
error
'
,
err
);
}
if
(
stats
.
size
<
_this
.
pos
)
{
_this
.
pos
=
stats
.
size
;
}
if
(
stats
.
size
>
_this
.
pos
)
{
_this
.
queue
.
push
({
start
:
_this
.
pos
,
end
:
stats
.
size
Tail
.
prototype
.
watchEvent
=
function
(
e
)
{
var
_this
=
this
;
if
(
e
===
'
change
'
)
{
return
fs
.
stat
(
this
.
filename
,
function
(
err
,
stats
)
{
if
(
err
)
{
_this
.
emit
(
'
error
'
,
err
);
}
if
(
stats
.
size
<
_this
.
pos
)
{
_this
.
pos
=
stats
.
size
;
}
if
(
stats
.
size
>
_this
.
pos
)
{
_this
.
queue
.
push
({
start
:
_this
.
pos
,
end
:
stats
.
size
});
_this
.
pos
=
stats
.
size
;
if
(
_this
.
queue
.
length
===
1
)
{
return
_this
.
internalDispatcher
.
emit
(
'
next
'
);
}
}
});
_this
.
pos
=
stats
.
size
;
if
(
_this
.
queue
.
length
===
1
)
{
return
_this
.
internalDispatcher
.
emit
(
"
next
"
);
}
}
});
}
else
if
(
e
===
'
rename
'
)
{
this
.
unwatch
();
_this
.
emit
(
'
error
'
,
"
File
"
+
this
.
filename
+
"
deleted.
"
);
}
}
else
if
(
e
===
'
rename
'
)
{
this
.
unwatch
();
_this
.
emit
(
'
error
'
,
'
File
'
+
this
.
filename
+
'
deleted.
'
);
}
};
Tail
.
prototype
.
close
=
function
()
{
this
.
unwatch
()
}
Tail
.
prototype
.
close
=
function
()
{
this
.
unwatch
();
}
;
module
.
exports
=
Tail
\ No newline at end of file
module
.
exports
=
Tail
;
debomatic-webui/lib/utils.js
View file @
08e14f2f
var
path
=
require
(
'
path
'
)
,
fs
=
require
(
'
fs
'
)
,
config
=
require
(
'
./config.js
'
)
,
Tail
=
require
(
'
./tail.js
'
)
'
use strict
'
;
var
path
=
require
(
'
path
'
),
fs
=
require
(
'
fs
'
),
config
=
require
(
'
./config.js
'
),
Tail
=
require
(
'
./tail.js
'
);
function
__errors_handler
(
from
,
err
,
socket
)
{
if
(
!
socket
)
from
=
"
NO SOCKET:
"
+
from
console
.
error
(
from
,
err
)
if
(
socket
)
socket
.
emit
(
config
.
events
.
error
,
err
.
message
)
if
(
!
socket
)
from
=
'
NO SOCKET:
'
+
from
;
console
.
error
(
from
,
err
);
if
(
socket
)
socket
.
emit
(
config
.
events
.
error
,
err
.
message
);
}
function
__check_no_backward
(
backward_path
)
{
try
{
return
backward_path
.
indexOf
(
'
..
'
)
<
0
}
catch
(
err
)
{
return
true
}
try
{
return
backward_path
.
indexOf
(
'
..
'
)
<
0
;
}
catch
(
err
)
{
return
true
;
}
}
function
__check_data_distribution
(
data
)
{
return
__check_no_backward
(
data
)
&&
__check_no_backward
(
data
.
distribution
)
&&
__check_no_backward
(
data
.
distribution
.
name
)
return
__check_no_backward
(
data
)
&&
__check_no_backward
(
data
.
distribution
)
&&
__check_no_backward
(
data
.
distribution
.
name
);
}
function
__check_data_package
(
data
)
{
return
__check_data_distribution
(
data
)
&&
__check_no_backward
(
data
.
package
)
&&
__check_no_backward
(
data
.
package
.
name
)
&&
__check_no_backward
(
data
.
package
.
version
)
return
__check_data_distribution
(
data
)
&&
__check_no_backward
(
data
.
package
)
&&
__check_no_backward
(
data
.
package
.
name
)
&&
__check_no_backward
(
data
.
package
.
version
);
}
function
__check_data_file
(
data
)
{
return
__check_data_package
(
data
)
&&
__check_no_backward
(
data
.
file
)
&&
__check_no_backward
(
data
.
file
.
name
)
return
__check_data_package
(
data
)
&&
__check_no_backward
(
data
.
file
)
&&
__check_no_backward
(
data
.
file
.
name
);
}
function
__get_distribution_pool_path
(
data
)
{
return
path
.
join
(
config
.
debomatic
.
path
,
data
.
distribution
.
name
,
'
pool
'
)
return
path
.
join
(
config
.
debomatic
.
path
,
data
.
distribution
.
name
,
'
pool
'
);
}
function
__get_package_path
(
data
)
{
return
path
.
join
(
__get_distribution_pool_path
(
data
),
data
.
package
.
name
+
'
_
'
+
data
.
package
.
version
)
return
path
.
join
(
__get_distribution_pool_path
(
data
),
data
.
package
.
name
+
'
_
'
+
data
.
package
.
version
);
}
function
__get_file_path
(
data
)
{
return
path
.
join
(
__get_package_path
(
data
),
data
.
package
.
name
+
'
_
'
+
data
.
package
.
version
+
'
.
'
+
data
.
file
.
name
)
return
path
.
join
(
__get_package_path
(
data
),
data
.
package
.
name
+
'
_
'
+
data
.
package
.
version
+
'
.
'
+
data
.
file
.
name
);
}
function
__get_files_list
(
dir
,
onlyDirectories
,
callback
)
{
fs
.
readdir
(
dir
,
function
(
err
,
files
){
result
=
[];
if
(
err
)
{
__errors_handler
(
"
__get_files_list
"
,
err
)
return
;
}
files
.
forEach
(
function
(
f
)
{
try
{
complete_path
=
path
.
join
(
dir
,
f
);
stat
=
fs
.
statSync
(
complete_path
)
if
(
onlyDirectories
)
{
if
(
stat
.
isDirectory
())
{
result
.
push
(
f
);
}
}
else
{
if
(
stat
.
isFile
())
{
result
.
push
(
f
);
}
fs
.
readdir
(
dir
,
function
(
err
,
files
)
{
var
result
=
[];
if
(
err
)
{
__errors_handler
(
'
__get_files_list
'
,
err
);
return
;
}
}
catch
(
fs_error
)
{
__errors_handler
(
"
__get_files_list:forEach
"
,
fs_error
)
return
}
files
.
forEach
(
function
(
f
)
{
try
{
var
complete_path
=
path
.
join
(
dir
,
f
);
var
stat
=
fs
.
statSync
(
complete_path
);
if
(
onlyDirectories
)
{
if
(
stat
.
isDirectory
())
{
result
.
push
(
f
);
}
}
else
{
if
(
stat
.
isFile
())
{
result
.
push
(
f
);
}
}
}
catch
(
fs_error
)
{
__errors_handler
(
'
__get_files_list:forEach
'
,
fs_error
);
return
;
}
});
callback
(
result
);
});
callback
(
result
);
});
}
function
__watch_path_onsocket
(
event_name
,
socket
,
data
,
watch_path
,
updater
)
{
socket
.
get
(
"
watchers
"
,
function
(
err
,
socket_watchers
){
if
(
!
socket_watchers
)
{
// init socket watchers
socket_watchers
=
{}
}
try
{
var
watcher
=
socket_watchers
[
event_name
]
if
(
watcher
)
watcher
.
close
()
fs
.
stat
(
watch_path
,
function
(
err
,
stats
)
{
if
(
err
)
{
__errors_handler
(
"
__watch_path_onsocket:fs.stat
"
,
err
,
socket
)
return
}
if
(
stats
.
isDirectory
())
{
watcher
=
fs
.
watch
(
watch_path
,
{
persistent
:
true
},
function
(
event
,
fileName
)
{
if
(
event
==
'
rename
'
)
updater
(
event_name
,
socket
,
data
)
})
socket
.
get
(
'
watchers
'
,
function
(
err
,
socket_watchers
)
{
if
(
!
socket_watchers
)
{
// init socket watchers
socket_watchers
=
{};
}
else
if
(
stats
.
isFile
())
{
watcher
=
new
Tail
(
watch_path
)
watcher
.
on
(
'
line
'
,
function
(
new_content
,
tailInfo
)
{
data
.
file
.
new_content
=
new_content
+
'
\n
'
updater
(
event_name
,
socket
,
data
)
});
watcher
.
on
(
'
error
'
,
function
(
msg
)
{
socket
.
emit
(
config
.
events
.
error
,
msg
);
});
try
{
var
watcher
=
socket_watchers
[
event_name
];
if
(
watcher
)
watcher
.
close
();
fs
.
stat
(
watch_path
,
function
(
err
,
stats
)
{
if
(
err
)
{
__errors_handler
(
'
__watch_path_onsocket:fs.stat
'
,
err
,
socket
);
return
;
}
if
(
stats
.
isDirectory
())
{
watcher
=
fs
.
watch
(
watch_path
,
{
persistent
:
true
},
function
(
event
,
fileName
)
{
if
(
event
==
'
rename
'
)
updater
(
event_name
,
socket
,
data
);
});
}
else
if
(
stats
.
isFile
())
{
watcher
=
new
Tail
(
watch_path
);
watcher
.
on
(
'
line
'
,
function
(
new_content
,
tailInfo
)
{
data
.
file
.
new_content
=
new_content
+
'
\n
'
;
updater
(
event_name
,
socket
,
data
);
});
watcher
.
on
(
'
error
'
,
function
(
msg
)
{
socket
.
emit
(
config
.
events
.
error
,
msg
);
});
}
socket_watchers
[
event_name
]
=
watcher
;
socket
.
set
(
'
watchers
'
,
socket_watchers
);
});
}
catch
(
err
)
{
__errors_handler
(
'
__watch_path_onsocket <-
'
+
arguments
.
callee
.
caller
.
name
,
err
,
socket
);
return
;
}
socket_watchers
[
event_name
]
=
watcher
socket
.
set
(
"
watchers
"
,
socket_watchers
)
})
}
catch
(
err
)
{
__errors_handler
(
"
__watch_path_onsocket <-
"
+
arguments
.
callee
.
caller
.
name
,
err
,
socket
)
return
}
})
});
}
function
__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
)
callback
(
event_name
,
socket
,
data
);
__watch_path_onsocket
(
event_name
,
socket
,
data
,
watch_path
,
callback
);
}
function
__send_distributions
(
socket
)
{
__get_files_list
(
config
.
debomatic
.
path
,
true
,
function
(
directories
)
{
var
distributions
=
[]
directories
.
forEach
(
function
(
dir
)
{
var
data
=
{}
data
.
distribution
=
{}
data
.
distribution
.
name
=
dir
var
pool_path
=
__get_distribution_pool_path
(
data
)
if
(
fs
.
existsSync
(
pool_path
))
{
distributions
.
push
(
dir
)
}
})
socket
.
emit
(
config
.
events
.
broadcast
.
distributions
,
distributions
);
})
__get_files_list
(
config
.
debomatic
.
path
,
true
,
function
(
directories
)
{
var
distributions
=
[];
directories
.
forEach
(
function
(
dir
)
{
var
data
=
{};
data
.
distribution
=
{};
data
.
distribution
.
name
=
dir
;
var
pool_path
=
__get_distribution_pool_path
(
data
);
if
(
fs
.
existsSync
(
pool_path
))
{
distributions
.
push
(
dir
);
}
});
socket
.
emit
(
config
.
events
.
broadcast
.
distributions
,
distributions
);
});
}
utils
=
{
check_data_distribution
:
function
(
data
)
{
return
__check_data_distribution
(
data
)
},
check_data_package
:
function
(
data
)
{
return
__check_data_package
(
data
)
},
check_data_file
:
function
(
data
)
{
return
__check_data_file
(
data
)
},
get_distribution_pool_path
:
function
(
data
)
{
return
__get_distribution_pool_path
(
data
)
},
get_package_path
:
function
(
data
)
{
return
__get_package_path
(
data
)
},
get_file_path
:
function
(
data
)
{
return
__get_file_path
(
data
)
},
get_files_list
:
function
(
dir
,
onlyDirectories
,
callback
)
{
return
__get_files_list
(
dir
,
onlyDirectories
,
callback
)
},
watch_path_onsocket
:
function
(
event_name
,
socket
,
data
,
watch_path
,
updater
)
{
return
__watch_path_onsocket
(
event_name
,
socket
,
data
,
watch_path
,
updater
)
},
generic_handler_watcher
:
function
(
event_name
,
socket
,
data
,
watch_path
,
callback
)
{
return
__generic_handler_watcher
(
event_name
,
socket
,
data
,
watch_path
,
callback
);
},
send_distributions
:
function
(
socket
)
{
return
__send_distributions
(
socket
)
},
errors_handler
:
function
(
from
,
error
,
socket
)
{
return
__errors_handler
(
from
,
error
,
socket
)
}
}
var
utils
=
{
check_data_distribution
:
function
(
data
)
{
return
__check_data_distribution
(
data
);
},
check_data_package
:
function
(
data
)
{
return
__check_data_package
(
data
);
},
check_data_file
:
function
(
data
)
{
return
__check_data_file
(
data
);
},
get_distribution_pool_path
:
function
(
data
)
{
return
__get_distribution_pool_path
(
data
);
},
get_package_path
:
function
(
data
)
{
return
__get_package_path
(
data
);
},
get_file_path
:
function
(
data
)
{
return
__get_file_path
(
data
);
},
get_files_list
:
function
(
dir
,
onlyDirectories
,
callback
)
{
return
__get_files_list
(
dir
,
onlyDirectories
,
callback
);
},
watch_path_onsocket
:
function
(
event_name
,
socket
,
data
,
watch_path
,
updater
)
{
return
__watch_path_onsocket
(
event_name
,
socket
,
data
,
watch_path
,
updater
);
},
generic_handler_watcher
:
function
(
event_name
,
socket
,
data
,
watch_path
,
callback
)
{
return
__generic_handler_watcher
(
event_name
,
socket
,
data
,
watch_path
,
callback
);
},
send_distributions
:
function
(
socket
)
{
return
__send_distributions
(
socket
);
},
errors_handler
:
function
(
from
,
error
,
socket
)
{
return
__errors_handler
(
from
,
error
,
socket
);
}
}
;
module
.
exports
=
utils
module
.
exports
=
utils
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment