diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index 6178902e..b1ab18d2 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -187,533 +187,533 @@ function addStaticDHCPLease($mac, $ip, $hostname) { } } - // Read available DNS server list - $DNSserverslist = readDNSserversList(); +// Read available DNS server list +$DNSserverslist = readDNSserversList(); - $error = ""; - $success = ""; +$error = ""; +$success = ""; - if(isset($_POST["field"])) - { - // Handle CSRF - check_csrf(isset($_POST["token"]) ? $_POST["token"] : ""); +if(isset($_POST["field"])) +{ + // Handle CSRF + check_csrf(isset($_POST["token"]) ? $_POST["token"] : ""); - // Process request - switch ($_POST["field"]) { - // Set DNS server - case "DNS": + // Process request + switch ($_POST["field"]) { + // Set DNS server + case "DNS": - $DNSservers = []; - // Add selected predefined servers to list - foreach ($DNSserverslist as $key => $value) - { - foreach(["v4_1", "v4_2", "v6_1", "v6_2"] as $type) - { - // Skip if this IP type does not - // exist (e.g. IPv4-only or only - // one IPv6 address upstream - // server) - if(!array_key_exists($type, $value)) - continue; + $DNSservers = []; + // Add selected predefined servers to list + foreach ($DNSserverslist as $key => $value) + { + foreach(["v4_1", "v4_2", "v6_1", "v6_2"] as $type) + { + // Skip if this IP type does not + // exist (e.g. IPv4-only or only + // one IPv6 address upstream + // server) + if(!array_key_exists($type, $value)) + continue; - // If server exists and is set - // (POST), we add it to the - // array of DNS servers - $server = str_replace(".", "_", $value[$type]); - if(array_key_exists("DNSserver".$server, $_POST)) - array_push($DNSservers, $value[$type]); - } - } + // If server exists and is set + // (POST), we add it to the + // array of DNS servers + $server = str_replace(".", "_", $value[$type]); + if(array_key_exists("DNSserver".$server, $_POST)) + array_push($DNSservers, $value[$type]); + } + } - // Test custom server fields - for($i=1;$i<=4;$i++) - { - if(array_key_exists("custom".$i,$_POST)) - { - $exploded = explode("#", $_POST["custom".$i."val"], 2); - $IP = trim($exploded[0]); + // Test custom server fields + for($i=1;$i<=4;$i++) + { + if(array_key_exists("custom".$i,$_POST)) + { + $exploded = explode("#", $_POST["custom".$i."val"], 2); + $IP = trim($exploded[0]); - if(!validIP($IP)) - { - $error .= "IP (".htmlspecialchars($IP).") is invalid!
"; - } - else - { - if(count($exploded) > 1) - { - $port = trim($exploded[1]); - if(!is_numeric($port)) - { - $error .= "Port (".htmlspecialchars($port).") is invalid!
"; - } - else - { - $IP .= "#".$port; - } - } + if(!validIP($IP)) + { + $error .= "IP (".htmlspecialchars($IP).") is invalid!
"; + } + else + { + if(count($exploded) > 1) + { + $port = trim($exploded[1]); + if(!is_numeric($port)) + { + $error .= "Port (".htmlspecialchars($port).") is invalid!
"; + } + else + { + $IP .= "#".$port; + } + } - array_push($DNSservers,$IP); - } - } - } - $DNSservercount = count($DNSservers); + array_push($DNSservers,$IP); + } + } + } + $DNSservercount = count($DNSservers); - // Check if at least one DNS server has been added - if($DNSservercount < 1) - { - $error .= "No DNS server has been selected.
"; - } + // Check if at least one DNS server has been added + if($DNSservercount < 1) + { + $error .= "No DNS server has been selected.
"; + } - // Check if domain-needed is requested - if(isset($_POST["DNSrequiresFQDN"])) - { - $extra = "domain-needed "; - } - else - { - $extra = "domain-not-needed "; - } + // Check if domain-needed is requested + if(isset($_POST["DNSrequiresFQDN"])) + { + $extra = "domain-needed "; + } + else + { + $extra = "domain-not-needed "; + } - // Check if domain-needed is requested - if(isset($_POST["DNSbogusPriv"])) - { - $extra .= "bogus-priv "; - } - else - { - $extra .= "no-bogus-priv "; - } + // Check if domain-needed is requested + if(isset($_POST["DNSbogusPriv"])) + { + $extra .= "bogus-priv "; + } + else + { + $extra .= "no-bogus-priv "; + } - // Check if DNSSEC is requested - if(isset($_POST["DNSSEC"])) - { - $extra .= "dnssec"; - } - else - { - $extra .= "no-dnssec"; - } + // Check if DNSSEC is requested + if(isset($_POST["DNSSEC"])) + { + $extra .= "dnssec"; + } + else + { + $extra .= "no-dnssec"; + } - // Check if rev-server is requested - if(isset($_POST["rev_server"])) - { - // Validate CIDR IP - $cidr = trim($_POST["rev_server_cidr"]); - if (!validCIDRIP($cidr)) - { - $error .= "Conditional forwarding subnet (\"".htmlspecialchars($cidr)."\") is invalid!
". - "This field requires CIDR notation for local subnets (e.g., 192.168.0.0/16).
"; - } + // Check if rev-server is requested + if(isset($_POST["rev_server"])) + { + // Validate CIDR IP + $cidr = trim($_POST["rev_server_cidr"]); + if (!validCIDRIP($cidr)) + { + $error .= "Conditional forwarding subnet (\"".htmlspecialchars($cidr)."\") is invalid!
". + "This field requires CIDR notation for local subnets (e.g., 192.168.0.0/16).
"; + } - // Validate target IP - $target = trim($_POST["rev_server_target"]); - if (!validIP($target)) - { - $error .= "Conditional forwarding target IP (\"".htmlspecialchars($target)."\") is invalid!
"; - } + // Validate target IP + $target = trim($_POST["rev_server_target"]); + if (!validIP($target)) + { + $error .= "Conditional forwarding target IP (\"".htmlspecialchars($target)."\") is invalid!
"; + } - // Validate conditional forwarding domain name (empty is okay) - $domain = trim($_POST["rev_server_domain"]); - if(strlen($domain) > 0 && !validDomain($domain)) - { - $error .= "Conditional forwarding domain name (\"".htmlspecialchars($domain)."\") is invalid!
"; - } + // Validate conditional forwarding domain name (empty is okay) + $domain = trim($_POST["rev_server_domain"]); + if(strlen($domain) > 0 && !validDomain($domain)) + { + $error .= "Conditional forwarding domain name (\"".htmlspecialchars($domain)."\") is invalid!
"; + } - if(!$error) - { - $extra .= " rev-server ".$cidr." ".$target." ".$domain; - } - } + if(!$error) + { + $extra .= " rev-server ".$cidr." ".$target." ".$domain; + } + } - // Check if DNSinterface is set - if(isset($_POST["DNSinterface"])) - { - if($_POST["DNSinterface"] === "single") - { - $DNSinterface = "single"; - } - elseif($_POST["DNSinterface"] === "bind") - { - $DNSinterface = "bind"; - } - elseif($_POST["DNSinterface"] === "all") - { - $DNSinterface = "all"; - } - else - { - $DNSinterface = "local"; - } - } - else - { - // Fallback - $DNSinterface = "local"; - } - pihole_execute("-a -i ".$DNSinterface." -web"); + // Check if DNSinterface is set + if(isset($_POST["DNSinterface"])) + { + if($_POST["DNSinterface"] === "single") + { + $DNSinterface = "single"; + } + elseif($_POST["DNSinterface"] === "bind") + { + $DNSinterface = "bind"; + } + elseif($_POST["DNSinterface"] === "all") + { + $DNSinterface = "all"; + } + else + { + $DNSinterface = "local"; + } + } + else + { + // Fallback + $DNSinterface = "local"; + } + pihole_execute("-a -i ".$DNSinterface." -web"); - // Add rate-limiting settings - if(isset($_POST["rate_limit_count"]) && isset($_POST["rate_limit_interval"])) - { - // Restart of FTL is delayed - pihole_execute("-a ratelimit " . intval($_POST["rate_limit_count"]) . " " . intval($_POST["rate_limit_interval"]) . " false"); - } + // Add rate-limiting settings + if(isset($_POST["rate_limit_count"]) && isset($_POST["rate_limit_interval"])) + { + // Restart of FTL is delayed + pihole_execute("-a ratelimit " . intval($_POST["rate_limit_count"]) . " " . intval($_POST["rate_limit_interval"]) . " false"); + } - // If there has been no error we can save the new DNS server IPs - if(!strlen($error)) - { - $IPs = implode (",", $DNSservers); - $return = pihole_execute("-a setdns \"".$IPs."\" ".$extra); - $success .= htmlspecialchars(end($return))."
"; - $success .= "The DNS settings have been updated (using ".$DNSservercount." DNS servers)"; - } - else - { - $error .= "The settings have been reset to their previous values"; - } + // If there has been no error we can save the new DNS server IPs + if(!strlen($error)) + { + $IPs = implode (",", $DNSservers); + $return = pihole_execute("-a setdns \"".$IPs."\" ".$extra); + $success .= htmlspecialchars(end($return))."
"; + $success .= "The DNS settings have been updated (using ".$DNSservercount." DNS servers)"; + } + else + { + $error .= "The settings have been reset to their previous values"; + } - break; + break; - // Set query logging - case "Logging": + // Set query logging + case "Logging": - if($_POST["action"] === "Disable") - { - pihole_execute("-l off"); - $success .= "Logging has been disabled and logs have been flushed"; - } - elseif($_POST["action"] === "Disable-noflush") - { - pihole_execute("-l off noflush"); - $success .= "Logging has been disabled, your logs have not been flushed"; - } - else - { - pihole_execute("-l on"); - $success .= "Logging has been enabled"; - } + if($_POST["action"] === "Disable") + { + pihole_execute("-l off"); + $success .= "Logging has been disabled and logs have been flushed"; + } + elseif($_POST["action"] === "Disable-noflush") + { + pihole_execute("-l off noflush"); + $success .= "Logging has been disabled, your logs have not been flushed"; + } + else + { + pihole_execute("-l on"); + $success .= "Logging has been enabled"; + } - break; + break; - // Set domains to be excluded from being shown in Top Domains (or Ads) and Top Clients - case "API": + // Set domains to be excluded from being shown in Top Domains (or Ads) and Top Clients + case "API": - // Explode the contents of the textareas into PHP arrays - // \n (Unix) and \r\n (Win) will be considered as newline - // array_filter( ... ) will remove any empty lines - $domains = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["domains"])); - $clients = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["clients"])); + // Explode the contents of the textareas into PHP arrays + // \n (Unix) and \r\n (Win) will be considered as newline + // array_filter( ... ) will remove any empty lines + $domains = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["domains"])); + $clients = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["clients"])); - $domainlist = ""; - $first = true; - foreach($domains as $domain) - { - if(!validDomainWildcard($domain) || validIP($domain)) - { - $error .= "Top Domains/Ads entry ".htmlspecialchars($domain)." is invalid (use only domains)!
"; - } - if(!$first) - { - $domainlist .= ","; - } - else - { - $first = false; - } - $domainlist .= $domain; - } + $domainlist = ""; + $first = true; + foreach($domains as $domain) + { + if(!validDomainWildcard($domain) || validIP($domain)) + { + $error .= "Top Domains/Ads entry ".htmlspecialchars($domain)." is invalid (use only domains)!
"; + } + if(!$first) + { + $domainlist .= ","; + } + else + { + $first = false; + } + $domainlist .= $domain; + } - $clientlist = ""; - $first = true; - foreach($clients as $client) - { - if(!validDomainWildcard($client) && !validIP($client)) - { - $error .= "Top Clients entry ".htmlspecialchars($client)." is invalid (use only host names and IP addresses)!
"; - } - if(!$first) - { - $clientlist .= ","; - } - else - { - $first = false; - } - $clientlist .= $client; - } + $clientlist = ""; + $first = true; + foreach($clients as $client) + { + if(!validDomainWildcard($client) && !validIP($client)) + { + $error .= "Top Clients entry ".htmlspecialchars($client)." is invalid (use only host names and IP addresses)!
"; + } + if(!$first) + { + $clientlist .= ","; + } + else + { + $first = false; + } + $clientlist .= $client; + } - // Set Top Lists options - if(!strlen($error)) - { - // All entries are okay - pihole_execute("-a setexcludedomains ".$domainlist); - pihole_execute("-a setexcludeclients ".$clientlist); - $success .= "The API settings have been updated
"; - } - else - { - $error .= "The settings have been reset to their previous values"; - } + // Set Top Lists options + if(!strlen($error)) + { + // All entries are okay + pihole_execute("-a setexcludedomains ".$domainlist); + pihole_execute("-a setexcludeclients ".$clientlist); + $success .= "The API settings have been updated
"; + } + else + { + $error .= "The settings have been reset to their previous values"; + } - // Set query log options - if(isset($_POST["querylog-permitted"]) && isset($_POST["querylog-blocked"])) - { - pihole_execute("-a setquerylog all"); - $success .= "All entries will be shown in Query Log"; - } - elseif(isset($_POST["querylog-permitted"])) - { - pihole_execute("-a setquerylog permittedonly"); - $success .= "Only permitted will be shown in Query Log"; - } - elseif(isset($_POST["querylog-blocked"])) - { - pihole_execute("-a setquerylog blockedonly"); - $success .= "Only blocked entries will be shown in Query Log"; - } - else - { - pihole_execute("-a setquerylog nothing"); - $success .= "No entries will be shown in Query Log"; - } + // Set query log options + if(isset($_POST["querylog-permitted"]) && isset($_POST["querylog-blocked"])) + { + pihole_execute("-a setquerylog all"); + $success .= "All entries will be shown in Query Log"; + } + elseif(isset($_POST["querylog-permitted"])) + { + pihole_execute("-a setquerylog permittedonly"); + $success .= "Only permitted will be shown in Query Log"; + } + elseif(isset($_POST["querylog-blocked"])) + { + pihole_execute("-a setquerylog blockedonly"); + $success .= "Only blocked entries will be shown in Query Log"; + } + else + { + pihole_execute("-a setquerylog nothing"); + $success .= "No entries will be shown in Query Log"; + } - break; + break; - case "webUI": - $adminemail = trim($_POST["adminemail"]); - if(strlen($adminemail) == 0 || !isset($adminemail)) - { - $adminemail = ''; - } - if(strlen($adminemail) > 0 && !validEmail($adminemail)) - { - $error .= "Administrator email address (".htmlspecialchars($adminemail).") is invalid!
"; - } - else - { - pihole_execute('-a -e \''.$adminemail.'\''); - } - if(isset($_POST["boxedlayout"])) - { - pihole_execute('-a layout boxed'); - } - else - { - pihole_execute('-a layout traditional'); - } - if(isset($_POST["webtheme"])) - { - global $available_themes; - if(array_key_exists($_POST["webtheme"], $available_themes)) - exec('sudo pihole -a theme '.$_POST["webtheme"]); - } - $success .= "The webUI settings have been updated"; - break; + case "webUI": + $adminemail = trim($_POST["adminemail"]); + if(strlen($adminemail) == 0 || !isset($adminemail)) + { + $adminemail = ''; + } + if(strlen($adminemail) > 0 && !validEmail($adminemail)) + { + $error .= "Administrator email address (".htmlspecialchars($adminemail).") is invalid!
"; + } + else + { + pihole_execute('-a -e \''.$adminemail.'\''); + } + if(isset($_POST["boxedlayout"])) + { + pihole_execute('-a layout boxed'); + } + else + { + pihole_execute('-a layout traditional'); + } + if(isset($_POST["webtheme"])) + { + global $available_themes; + if(array_key_exists($_POST["webtheme"], $available_themes)) + exec('sudo pihole -a theme '.$_POST["webtheme"]); + } + $success .= "The webUI settings have been updated"; + break; - case "poweroff": - pihole_execute("-a poweroff"); - $success = "The system will poweroff in 5 seconds..."; - break; + case "poweroff": + pihole_execute("-a poweroff"); + $success = "The system will poweroff in 5 seconds..."; + break; - case "reboot": - pihole_execute("-a reboot"); - $success = "The system will reboot in 5 seconds..."; - break; + case "reboot": + pihole_execute("-a reboot"); + $success = "The system will reboot in 5 seconds..."; + break; - case "restartdns": - pihole_execute("-a restartdns"); - $success = "The DNS server has been restarted"; - break; + case "restartdns": + pihole_execute("-a restartdns"); + $success = "The DNS server has been restarted"; + break; - case "flushlogs": - pihole_execute("-f"); - $success = "The Pi-hole log file has been flushed"; - break; + case "flushlogs": + pihole_execute("-f"); + $success = "The Pi-hole log file has been flushed"; + break; - case "DHCP": + case "DHCP": - if(isset($_POST["addstatic"])) - { - $mac = trim($_POST["AddMAC"]); - $ip = trim($_POST["AddIP"]); - $hostname = trim($_POST["AddHostname"]); + if(isset($_POST["addstatic"])) + { + $mac = trim($_POST["AddMAC"]); + $ip = trim($_POST["AddIP"]); + $hostname = trim($_POST["AddHostname"]); - addStaticDHCPLease($mac, $ip, $hostname); - break; - } + addStaticDHCPLease($mac, $ip, $hostname); + break; + } - if(isset($_POST["removestatic"])) - { - $mac = $_POST["removestatic"]; - if(!validMAC($mac)) - { - $error .= "MAC address (".htmlspecialchars($mac).") is invalid!
"; - } - $mac = strtoupper($mac); + if(isset($_POST["removestatic"])) + { + $mac = $_POST["removestatic"]; + if(!validMAC($mac)) + { + $error .= "MAC address (".htmlspecialchars($mac).") is invalid!
"; + } + $mac = strtoupper($mac); - if(!strlen($error)) - { - pihole_execute("-a removestaticdhcp ".$mac); - $success .= "The static address with MAC address ".htmlspecialchars($mac)." has been removed"; - } - break; - } + if(!strlen($error)) + { + pihole_execute("-a removestaticdhcp ".$mac); + $success .= "The static address with MAC address ".htmlspecialchars($mac)." has been removed"; + } + break; + } - if(isset($_POST["active"])) - { - // Validate from IP - $from = $_POST["from"]; - if (!validIP($from)) - { - $error .= "From IP (".htmlspecialchars($from).") is invalid!
"; - } + if(isset($_POST["active"])) + { + // Validate from IP + $from = $_POST["from"]; + if (!validIP($from)) + { + $error .= "From IP (".htmlspecialchars($from).") is invalid!
"; + } - // Validate to IP - $to = $_POST["to"]; - if (!validIP($to)) - { - $error .= "To IP (".htmlspecialchars($to).") is invalid!
"; - } + // Validate to IP + $to = $_POST["to"]; + if (!validIP($to)) + { + $error .= "To IP (".htmlspecialchars($to).") is invalid!
"; + } - // Validate router IP - $router = $_POST["router"]; - if (!validIP($router)) - { - $error .= "Router IP (".htmlspecialchars($router).") is invalid!
"; - } + // Validate router IP + $router = $_POST["router"]; + if (!validIP($router)) + { + $error .= "Router IP (".htmlspecialchars($router).") is invalid!
"; + } - $domain = $_POST["domain"]; + $domain = $_POST["domain"]; - // Validate Domain name - if(!validDomain($domain)) - { - $error .= "Domain name ".htmlspecialchars($domain)." is invalid!
"; - } + // Validate Domain name + if(!validDomain($domain)) + { + $error .= "Domain name ".htmlspecialchars($domain)." is invalid!
"; + } - $leasetime = $_POST["leasetime"]; + $leasetime = $_POST["leasetime"]; - // Validate Lease time length - if(!is_numeric($leasetime) || intval($leasetime) < 0) - { - $error .= "Lease time ".htmlspecialchars($leasetime)." is invalid!
"; - } + // Validate Lease time length + if(!is_numeric($leasetime) || intval($leasetime) < 0) + { + $error .= "Lease time ".htmlspecialchars($leasetime)." is invalid!
"; + } - if(isset($_POST["useIPv6"])) - { - $ipv6 = "true"; - $type = "(IPv4 + IPv6)"; - } - else - { - $ipv6 = "false"; - $type = "(IPv4)"; - } + if(isset($_POST["useIPv6"])) + { + $ipv6 = "true"; + $type = "(IPv4 + IPv6)"; + } + else + { + $ipv6 = "false"; + $type = "(IPv4)"; + } - if(isset($_POST["DHCP_rapid_commit"])) - { - $rapidcommit = "true"; - } - else - { - $rapidcommit = "false"; - } + if(isset($_POST["DHCP_rapid_commit"])) + { + $rapidcommit = "true"; + } + else + { + $rapidcommit = "false"; + } - if(!strlen($error)) - { - pihole_execute("-a enabledhcp ".$from." ".$to." ".$router." ".$leasetime." ".$domain." ".$ipv6." ".$rapidcommit); - $success .= "The DHCP server has been activated ".htmlspecialchars($type); - } - } - else - { - pihole_execute("-a disabledhcp"); - $success = "The DHCP server has been deactivated"; - } + if(!strlen($error)) + { + pihole_execute("-a enabledhcp ".$from." ".$to." ".$router." ".$leasetime." ".$domain." ".$ipv6." ".$rapidcommit); + $success .= "The DHCP server has been activated ".htmlspecialchars($type); + } + } + else + { + pihole_execute("-a disabledhcp"); + $success = "The DHCP server has been deactivated"; + } - break; + break; - case "privacyLevel": - $level = intval($_POST["privacylevel"]); - if($level >= 0 && $level <= 4) - { - // Check if privacylevel is already set - if (isset($piholeFTLConf["PRIVACYLEVEL"])) { - $privacylevel = intval($piholeFTLConf["PRIVACYLEVEL"]); - } else { - $privacylevel = 0; - } + case "privacyLevel": + $level = intval($_POST["privacylevel"]); + if($level >= 0 && $level <= 4) + { + // Check if privacylevel is already set + if (isset($piholeFTLConf["PRIVACYLEVEL"])) { + $privacylevel = intval($piholeFTLConf["PRIVACYLEVEL"]); + } else { + $privacylevel = 0; + } - // Store privacy level - pihole_execute("-a privacylevel ".$level); + // Store privacy level + pihole_execute("-a privacylevel ".$level); - if($privacylevel > $level) - { - pihole_execute("-a restartdns"); - $success .= "The privacy level has been decreased and the DNS resolver has been restarted"; - } - elseif($privacylevel < $level) - { - $success .= "The privacy level has been increased"; - } - else - { - $success .= "The privacy level has not been changed"; - } - } - else - { - $error .= "Invalid privacy level (".$level.")!"; - } - break; - // Flush network table - case "flusharp": - $output = pihole_execute("arpflush quiet"); - $error = ""; - if(is_array($output)) - { - $error = implode("
", $output); - } - if(strlen($error) == 0) - { - $success .= "The network table has been flushed"; - } - break; + if($privacylevel > $level) + { + pihole_execute("-a restartdns"); + $success .= "The privacy level has been decreased and the DNS resolver has been restarted"; + } + elseif($privacylevel < $level) + { + $success .= "The privacy level has been increased"; + } + else + { + $success .= "The privacy level has not been changed"; + } + } + else + { + $error .= "Invalid privacy level (".$level.")!"; + } + break; - default: - // Option not found - $debug = true; - break; - } - } + // Flush network table + case "flusharp": + $output = pihole_execute("arpflush quiet"); + $error = ""; + if(is_array($output)) + { + $error = implode("
", $output); + } + if(strlen($error) == 0) + { + $success .= "The network table has been flushed"; + } + break; - // Credit: http://stackoverflow.com/a/5501447/2087442 - function formatSizeUnits($bytes) - { - if ($bytes >= 1073741824) - { - $bytes = number_format($bytes / 1073741824, 2) . ' GB'; - } - elseif ($bytes >= 1048576) - { - $bytes = number_format($bytes / 1048576, 2) . ' MB'; - } - elseif ($bytes >= 1024) - { - $bytes = number_format($bytes / 1024, 2) . ' kB'; - } - elseif ($bytes > 1) - { - $bytes = $bytes . ' bytes'; - } - elseif ($bytes == 1) - { - $bytes = $bytes . ' byte'; - } - else - { - $bytes = '0 bytes'; - } + default: + // Option not found + $error = "Invalid option"; + } +} - return $bytes; - } +// Credit: http://stackoverflow.com/a/5501447/2087442 +function formatSizeUnits($bytes) +{ + if ($bytes >= 1073741824) + { + $bytes = number_format($bytes / 1073741824, 2) . ' GB'; + } + elseif ($bytes >= 1048576) + { + $bytes = number_format($bytes / 1048576, 2) . ' MB'; + } + elseif ($bytes >= 1024) + { + $bytes = number_format($bytes / 1024, 2) . ' kB'; + } + elseif ($bytes > 1) + { + $bytes = $bytes . ' bytes'; + } + elseif ($bytes == 1) + { + $bytes = $bytes . ' byte'; + } + else + { + $bytes = '0 bytes'; + } + + return $bytes; +} ?> diff --git a/settings.php b/settings.php index 8d00c3cf..4c55087e 100644 --- a/settings.php +++ b/settings.php @@ -43,15 +43,6 @@ if (isset($_POST["submit"])) { - - - - 0) { ?>