return ($count, $lines);
}
+sub dump_journal {
+ my ($start, $limit, $filter) = @_;
+
+ my $lines = [];
+ my $count = 0;
+
+ $start = 0 if !$start;
+ $limit = 50 if !$limit;
+
+ my $parser = sub {
+ my $line = shift;
+
+ return if $count++ < $start;
+ return if $limit <= 0;
+ push @$lines, { n => int($count), t => $line};
+ $limit--;
+ };
+
+ my $cmd = ['journalctl', '-o', 'short', '--no-pager'];
+ run_command($cmd, outfunc => $parser);
+
+ # HACK: ExtJS store.guaranteeRange() does not like empty array
+ # so we add a line
+ if (!$count) {
+ $count++;
+ push @$lines, { n => $count, t => "no content"};
+ }
+
+ return ($count, $lines);
+}
+
sub dir_glob_regex {
my ($dir, $regex) = @_;
return $res[0]->{family};
}
+# Parses any sane kind of host, or host+port pair:
+# The port is always optional and thus may be undef.
+sub parse_host_and_port {
+ my ($address) = @_;
+ if ($address =~ /^($IPV4RE|[[:alnum:]\-.]+)(?::(\d+))?$/ || # ipv4 or host with optional ':port'
+ $address =~ /^\[($IPV6RE|$IPV4RE|[[:alnum:]\-.]+)\](?::(\d+))?$/ || # anything in brackets with optional ':port'
+ $address =~ /^($IPV6RE)(?:\.(\d+))?$/) # ipv6 with optional port separated by dot
+ {
+ return ($1, $2, 1); # end with 1 to support simple if(parse...) tests
+ }
+ return; # nothing
+}
+
1;