addMessage('Adblock configuration updated successfully', 'success'); } else { $status->addMessage('Adblock configuration failed to be updated.', 'danger'); } } else { $status->addMessage($errors, 'danger'); } } elseif (isset($_POST['restartadblock']) || isset($_POST['startadblock'])) { exec('sudo /bin/systemctl restart dnsmasq.service', $dnsmasq, $return); if ($return == 0) { $status->addMessage('Adblock restart successful', 'success'); } else { $status->addMessage('Adblock failed to restart.', 'danger'); } } } exec('cat '. RASPI_ADBLOCK_CONFIG, $return); $arrConf = ParseConfig($return); if (sizeof($arrConf) > 0) { $enabled = true; } exec('pidof dnsmasq | wc -l', $dnsmasq); $dnsmasq_state = ($dnsmasq[0] > 0); $serviceStatus = $dnsmasq_state && $enabled ? "up" : "down"; if (file_exists(RASPI_ADBLOCK_LISTPATH .'custom.txt')) { $adblock_custom_content = file_get_contents(RASPI_ADBLOCK_LISTPATH .'custom.txt'); } else { $adblock_custom_content = ''; } $adblock_log = ''; exec('sudo chmod o+r '.RASPI_DHCPCD_LOG); $handle = fopen(RASPI_DHCPCD_LOG, "r"); if ($handle) { while (($line = fgets($handle)) !== false) { if (preg_match('/(0.0.0.0)/', $line)) { $adblock_log .= $line; } } fclose($handle); } else { $adblock_log = "Unable to open log file"; } echo renderTemplate( "adblock", compact( "status", "serviceStatus", "dnsmasq_state", "enabled", "custom_enabled", "adblock_custom_content", "adblock_log" ) ); }