]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/cfgroot/general-functions.pl
general-functions.pl: Fix for bug#12937
[people/pmueller/ipfire-2.x.git] / config / cfgroot / general-functions.pl
index c7df464898e6a68b7a674d4baeddd34ac0b56b64..d871025eb657fe339f6542021c3855c4be113edf 100644 (file)
@@ -24,7 +24,6 @@ $|=1; # line buffering
 $General::version = 'VERSION';
 $General::swroot = 'CONFIG_ROOT';
 $General::noipprefix = 'noipg-';
-$General::adminmanualurl = 'http://wiki.ipfire.org';
 
 require "${General::swroot}/network-functions.pl";
 
@@ -722,6 +721,21 @@ sub validhostname
        return 1;
 }
 
+sub validccdname
+{
+       # Checks a ccdname for letters, numbers and spaces
+        my $ccdname = $_[0];
+
+       # ccdname should be at least one character in length
+       # but no more than 63 characters
+       if (length ($ccdname) < 1 || length ($ccdname) > 63) {
+               return 0;}
+       # Only valid characters are a-z, A-Z, 0-9, space and -
+       if ($ccdname !~ /^[a-zA-Z0-9 -]*$/) {
+               return 0;}
+       return 1;
+}
+
 sub validdomainname
 {
        my $part;
@@ -742,6 +756,17 @@ sub validdomainname
        return 1;
 }
 
+sub validwildcarddomainname($) {
+       my $domainname = shift;
+
+       # Ignore any leading dots
+       if ($domainname =~ m/^\*\.([^\*]*)\*?/) {
+               $domainname = $1;
+       }
+
+       return &validdomainname($domainname);
+}
+
 sub validfqdn
 {
        # Checks a fully qualified domain name against RFC1035 and RFC2181
@@ -1227,28 +1252,21 @@ sub firewall_reload() {
 }
 
 # Function which will return the used interface for the red network zone (red0, ppp0, etc).
+# if you change this also check speed.cgi that include a local copy for systemload reasons
 sub get_red_interface() {
-
-       open(IFACE, "${General::swroot}/red/iface") or die "Could not open /var/ipfire/red/iface";
-
-       my $interface = <IFACE>;
-       close(IFACE);
-       chomp $interface;
+       my $interface;
+       my $red_iface_file = "${General::swroot}/red/iface";
+
+       if (-e $red_iface_file) {
+               open(IFACE, "$red_iface_file") or die "Could not open $red_iface_file";
+               $interface = <IFACE>;
+               close(IFACE);
+               chomp $interface;
+       }
 
        return $interface;
 }
 
-sub dnssec_status() {
-       my $path = "${General::swroot}/red/dnssec-status";
-
-       open(STATUS, $path) or return 0;
-       my $status = <STATUS>;
-       close(STATUS);
-
-       chomp($status);
-
-       return $status;
-}
 sub number_cpu_cores() {
        open my $cpuinfo, "/proc/cpuinfo" or die "Can't open cpuinfo: $!\n";
        my $cores = scalar (map /^processor/, <$cpuinfo>);
@@ -1363,6 +1381,42 @@ sub formatBytes {
        return sprintf("%.2f %s", $bytes, $unit);
 }
 
+# Function to collect and generate a hash for translating protocol numbers into
+# their names.
+sub generateProtoTransHash () {
+       # File which contains the protocol definitions.
+       my $protocols_file = "/etc/protocols";
+
+       my %protocols = ();
+
+       # Open protocols file.
+       open(FILE, "$protocols_file") or die "Could not open $protocols_file. $!\n";
+
+       # Loop through the file.
+       while (my $line = <FILE>) {
+               # Skip comments.
+               next if ($line =~ /^\#/);
+
+               # Skip blank  lines.
+               next if ($line =~ /^\s*$/);
+
+               # Remove any newlines.
+               chomp($line);
+
+               # Split line content.
+               my ($protocol_lc, $number, $protocol_uc, $comment) = split(' ', $line);
+
+               # Add proto details to the hash of protocols.
+               $protocols{$number} = $protocol_uc;
+       }
+
+       # Close file handle.
+       close(FILE);
+
+       # Return the hash.
+       return %protocols;
+}
+
 # Cloud Stuff
 
 sub running_in_cloud() {