Skip to content

Commit

Permalink
log all NCP actions to /var/log/ncp.log
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Feb 18, 2018
1 parent 19b0609 commit ff33be9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
17 changes: 15 additions & 2 deletions etc/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

Expand Down Expand Up @@ -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
)
}
Expand Down
5 changes: 3 additions & 2 deletions ncp-web/ncp-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function pingClient()
*/
function follow($file)
{
$size = 0;
$size = filesize($file);
while (true)
{
if ( !file_exists($file) )
Expand Down Expand Up @@ -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
//
Expand Down
2 changes: 0 additions & 2 deletions ncp-web/wizard/JS/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions nextcloudpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff33be9

Please sign in to comment.