$General::version = 'VERSION';
$General::swroot = 'CONFIG_ROOT';
$General::noipprefix = 'noipg-';
-$General::adminmanualurl = 'http://wiki.ipfire.org';
require "${General::swroot}/network-functions.pl";
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;
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
}
# 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>);
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() {