/usr/share/perl5/X2Go/Utils.pm is in libx2go-server-perl 4.1.0.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | #!/usr/bin/perl
# Copyright (C) 2007-2015 X2Go Project - http://wiki.x2go.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2007-2015 Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>
# Copyright (C) 2007-2015 Heinz-Markus Graesing <heinz-m.graesing@obviously-nice.de>
# Copyright (C) 2013-2015 Guangzhou Nianguan Electronics Technology Co.Ltd. <opensource@gznianguan.com>
# Copyright (C) 2013-2015 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
package X2Go::Utils;
=head1 NAME
X2Go::Utils - X2Go utilities and helper functions for Perl
=head1 DESCRIPTION
X2Go::Utils Perl package.
=cut
use strict;
use base 'Exporter';
our @EXPORT = ( 'load_module', 'is_true',
'source_environment', 'clups', 'sanitizer',
'system_capture_merged_output', 'system_capture_stdout_output',
'check_x2go_sessionid');
use Sys::Syslog qw( :standard :macros );
use Capture::Tiny qw ( :all );
sub load_module {
for (@_) {
(my $file = "$_.pm") =~ s{::}{/}g;
require $file;
}
}
sub is_true {
my $value = shift;
if ( $value =~ m/(1|yes|Yes|YES|on|On|ON|True|true|TRUE)/ ) {
return 1
}
return 0
}
sub source_environment {
my $name = shift;
open my $fh, "<", $name
or return -1;
while (<$fh>) {
chomp;
my $line = $_;
if ( $line =~ m/^#.*/ )
{
next;
}
my ($k, $v) = split /=/, $line, 2;
$v =~ s/^(['"])(.*)\1/$2/; #' fix highlighter
$v =~ s/\$([a-zA-Z]\w*)/$ENV{$1}/g;
$v =~ s/`(.*?)`/`$1`/ge; #dangerous
$ENV{$k} = $v;
}
}
# Over-zealous string sanitizer that makes perl strict and perl -T happy...
sub sanitizer {
my $type = lc($_[0]);
my $string = $_[1];
if ($type eq "anumazcs") {
$string =~ s/[^a-zA-Z0-9]//g;
if ($string =~ /^([a-zA-Z0-9]*)$/) {
$string = $1;
return $string;
} else {return 0;}
} elsif ($type eq "anumazlc") {
$string = lc($string);
$string =~ s/[^a-z0-9]//g;
if ($string =~ /^([a-z0-9]*)$/) {
$string = $1;
return $string;
} else {return 0;}
} elsif ($type eq "num") {
$string =~ s/\D//g;
if ($string =~ /^([0-9]*)$/) {
$string = $1;
return $string;
} else {return 0;}
} elsif ($type eq "pnnum") {
$string =~ s/[^0-9\+\-]//g;
if ($string =~ /^([0-9\+\-]*)$/) {
$string = $1;
return $string;
} else {return 0;}
} elsif ($type eq "anumazcsdaus") {
$string =~ s/[^a-zA-Z0-9\_\-]//g;
if ($string =~ /^([a-zA-Z0-9\_\-]*)$/) {
$string = $1;
return $string;
} else {return 0;}
} elsif ($type eq "pnixusername") {
$string =~ s/[^a-zA-Z0-9\.\_\-\@]//g;
if ($string =~ /^([a-zA-Z0-9\.\_][a-zA-Z0-9\.\_\-\@]*)$/) {
$string = $1;
return $string;
} else {return 0;}
} elsif ($type eq "x2gosid") {
$string =~ s/[^a-zA-Z0-9\.\_\-\@]//g;
if ($string =~ /^([a-zA-Z0-9\.\_\-\@]*)$/) {
$string = $1;
if ($string =~ /^([a-zA-Z0-9\.\_][a-zA-Z0-9\.\_\-\@]*)\-([\d]{2,4})\-([\d]{9,12})\_[a-zA-Z0-9\.\_\-]*\_dp[\d]{1,2}$/) {
return $string;
} else {return 0;}
} else {return 0;}
} elsif ($type eq "SOMETHINGELSE") {
return 0;
} else {
return 0;
}
}
sub clups {
my $string = "@_";
$string =~ s/\n//g;
$string =~ s/\ //g;
$string =~ s/\s//g;
return $string;
}
sub system_capture_stdout_output {
my $cmd = shift;
my @args = @_;
syslog("debug", "executing external command ,,$cmd'' with args: ".join(",", @args));
my ($stdout, $stderr, @result) = capture { system( $cmd, @args ); };
return $stdout;
}
sub system_capture_merged_output {
my $cmd = shift;
my @args = @_;
syslog("debug", "executing external command ,,$cmd'' with args: ".join(",", @args));
return capture_merged { system( $cmd, @args ); };
}
sub check_x2go_sessionid {
if (sanitizer("x2gosid",$ARGV[0])) {
return sanitizer("x2gosid",$ARGV[0]);
} elsif (sanitizer("x2gosid",$ENV{'X2GO_SESSION'})) {
return sanitizer("x2gosid",$ENV{'X2GO_SESSION'});
} else {
die "No X2Go Session ID in ARGV or ENV!\n";
}
}
1;
|