log all NCP actions to /var/log/ncp.log

This commit is contained in:
nachoparker 2018-02-16 14:35:16 +01:00
parent 51b1e5dd52
commit f8381f42cd
5 changed files with 30 additions and 17 deletions

View File

@ -105,13 +105,26 @@ function is_active_script()
)
}
function run_and_log()
{
local SCRIPT=$1
touch /var/log/ncp.log
chmod 640 /var/log/ncp.log
chown root:www-data /var/log/ncp.log
echo -e "[ $( basename "$SCRIPT" .sh ) ]" >> /var/log/ncp.log
configure 2>&1 | tee -a /var/log/ncp.log
local RET="${PIPESTATUS[0]}"
echo "" >> /var/log/ncp.log
return "$RET"
}
function launch_script()
{
(
local SCRIPT=$1
source ./"$SCRIPT"
set +x
configure
run_and_log "$SCRIPT"
)
}
@ -140,7 +153,7 @@ function configure_script()
printf '\033[2J' && tput cup 0 0 # clear screen, don't clear scroll, cursor on top
echo -e "Launching $( basename "$SCRIPT" .sh )"
set +x
configure
run_and_log "$SCRIPT"
return 0
)
}

View File

@ -45,7 +45,7 @@ function pingClient()
*/
function follow($file)
{
$size = 0;
$size = filesize($file);
while (true)
{
if ( !file_exists($file) )
@ -78,7 +78,8 @@ function follow($file)
session_write_close();
echo str_pad('',1024*1024*4); // make sure the browser buffer becomes full
follow( '/run/ncp.log' );
touch( '/var/log/ncp.log' );
follow( '/var/log/ncp.log' );
// License
//

View File

@ -32,8 +32,6 @@ $(document).ready(function(){
$('button').prop('disabled', true);
addNotification( action, 'gray-bg' ) ;
logOutput( '\n[ ' + action + ' ]' + '\n' );
$.post('../ncp-launcher.php',
{ action:'launch',
ref: action,

View File

@ -107,17 +107,7 @@ DIR=/usr/local/etc/nextcloudpi-config.d
test -f $DIR/$1 || { echo "File not found"; exit 1; }
source /usr/local/etc/library.sh
cd $DIR
touch /run/ncp.log
chmod 640 /run/ncp.log
chown root:www-data /run/ncp.log
launch_script $1 &> /run/ncp.log
RET=$?
# clean log for the next PHP backend call to start clean,
# but wait until everything from current execution is read
sleep 0.5 && echo "" > /run/ncp.log
exit $RET
launch_script $1
EOF
chmod 700 /home/www/ncp-launcher.sh
echo "www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt" >> /etc/sudoers

View File

@ -249,6 +249,17 @@ EOF
sed -i 's|^ServerSignature .*|ServerSignature Off|' /etc/apache2/conf-enabled/security.conf
sed -i 's|^ServerTokens .*|ServerTokens Prod|' /etc/apache2/conf-enabled/security.conf
# upgrade launcher after logging improvements
cat > /home/www/ncp-launcher.sh <<'EOF'
#!/bin/bash
DIR=/usr/local/etc/nextcloudpi-config.d
test -f $DIR/$1 || { echo "File not found"; exit 1; }
source /usr/local/etc/library.sh
cd $DIR
launch_script $1
EOF
chmod 700 /home/www/ncp-launcher.sh
} # end - only live updates
exit 0