` ran as www-data, // defeating the sudo on the truncation step). system('sudo truncate -s 0 /var/log/pi-star/pi-star_upgrade.log'); system('sudo /usr/local/sbin/pistar-upgrade > /dev/null 2>&1 &'); } // Sanity Check Passed. header('Cache-Control: no-cache'); // session_start() is no longer called here — csrf_verify() at // the top already started the session via csrf_session_start(). // The existing $_SESSION['update_offset'] log-tail logic below // works unchanged against the already-active session. // Initialize session offset only if upgrade has been confirmed if (!isset($_GET['ajax']) && !empty($_POST) && isset($_POST['confirm_update'])) { //unset($_SESSION['update_offset']); if (file_exists('/var/log/pi-star/pi-star_upgrade.log')) { $_SESSION['update_offset'] = filesize('/var/log/pi-star/pi-star_upgrade.log'); } else { $_SESSION['update_offset'] = 0; } } if (isset($_GET['ajax'])) { //session_start(); if (!file_exists('/var/log/pi-star/pi-star_upgrade.log')) { exit(); } $handle = fopen('/var/log/pi-star/pi-star_upgrade.log', 'rb'); if (isset($_SESSION['update_offset'])) { fseek($handle, 0, SEEK_END); if ($_SESSION['update_offset'] > ftell($handle)) //log rotated/truncated $_SESSION['update_offset'] = 0; //continue at beginning of the new log $data = stream_get_contents($handle, -1, $_SESSION['update_offset']); $_SESSION['update_offset'] += strlen($data); echo nl2br($data); } else { fseek($handle, 0, SEEK_END); $_SESSION['update_offset'] = ftell($handle); } exit(); } ?>
| Upgrade Running |
|---|
Starting upgrade, please wait... |