line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Terminal::Identify; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Load the basic Perl pragmas. |
4
|
1
|
|
|
1
|
|
69758
|
use 5.010100; |
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Load the Perl pragma Exporter. |
9
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
10
|
1
|
|
|
1
|
|
7
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Export the implemented subroutines and the global variable. |
13
|
|
|
|
|
|
|
our @EXPORT = qw( |
14
|
|
|
|
|
|
|
whichterminalami |
15
|
|
|
|
|
|
|
whichtermami |
16
|
|
|
|
|
|
|
which_terminal |
17
|
|
|
|
|
|
|
identify_terminal |
18
|
|
|
|
|
|
|
terminal_identify |
19
|
|
|
|
|
|
|
$OutputFormat |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Base class of this module. |
23
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Set the package version. |
26
|
|
|
|
|
|
|
our $VERSION = '0.29'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Load the Perl modules. |
29
|
1
|
|
|
1
|
|
536
|
use POSIX qw(ttyname); |
|
1
|
|
|
|
|
6629
|
|
|
1
|
|
|
|
|
6
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Set the global output format. |
32
|
|
|
|
|
|
|
our $OutputFormat = ""; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Set the global term hash variable. |
35
|
|
|
|
|
|
|
our %termhash = (); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Define the Perl BEGIN block. |
38
|
|
|
|
|
|
|
BEGIN { |
39
|
|
|
|
|
|
|
# Set the subroutine aliases. |
40
|
1
|
|
|
1
|
|
1513
|
*whichtermami = \&whichterminalami; |
41
|
1
|
|
|
|
|
8
|
*which_terminal = \&whichterminalami; |
42
|
1
|
|
|
|
|
2
|
*identify_terminal = \&whichterminalami; |
43
|
1
|
|
|
|
|
2734
|
*terminal_identify = \&whichterminalami; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# ++++++++++++++++++++++++++++++++ |
47
|
|
|
|
|
|
|
# Perform some preliminary checks. |
48
|
|
|
|
|
|
|
# ++++++++++++++++++++++++++++++++ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Check if the operating system is Windows. |
51
|
|
|
|
|
|
|
if ($^O eq "MSWin32") { |
52
|
|
|
|
|
|
|
# Print a message into the terminal window. |
53
|
|
|
|
|
|
|
print "This module works not on Windows. Bye.\n"; |
54
|
|
|
|
|
|
|
# Exit the script with error code 1. |
55
|
|
|
|
|
|
|
exit 1; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Check if the Linux command 'which' exists. |
59
|
|
|
|
|
|
|
my $exitcode = system("which which > /dev/null 2>&1"); |
60
|
|
|
|
|
|
|
if ($exitcode != 0) { |
61
|
|
|
|
|
|
|
# Print a message into the terminal window. |
62
|
|
|
|
|
|
|
print "The Linux command 'which' does not exist. Bye.\n"; |
63
|
|
|
|
|
|
|
# Exit the script with error code 2. |
64
|
|
|
|
|
|
|
exit 1; |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Check if the Linux command 'grep' exists. |
68
|
|
|
|
|
|
|
if (!defined `which grep 2>/dev/null` || `which grep 2>/dev/null` eq "") { |
69
|
|
|
|
|
|
|
# Print a message into the terminal window. |
70
|
|
|
|
|
|
|
print "The Linux command 'grep' does not exist. Bye.\n"; |
71
|
|
|
|
|
|
|
# Exit the script with error code 3. |
72
|
|
|
|
|
|
|
exit 3; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Check if the Linux command 'users' exists. |
76
|
|
|
|
|
|
|
if (!defined `which users 2>/dev/null` || `which users 2>/dev/null` eq "") { |
77
|
|
|
|
|
|
|
# Print a message into the terminal window. |
78
|
|
|
|
|
|
|
print "The Linux command 'grep' does not exist. Bye.\n"; |
79
|
|
|
|
|
|
|
# Exit the script with error code 4. |
80
|
|
|
|
|
|
|
exit 4; |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Check if the Linux command 'ps' exists. |
84
|
|
|
|
|
|
|
if (!defined `which ps 2>/dev/null` || `which ps 2>/dev/null` eq "") { |
85
|
|
|
|
|
|
|
# Print a message into the terminal window. |
86
|
|
|
|
|
|
|
print "The Linux command 'ps' does not exist. Bye.\n"; |
87
|
|
|
|
|
|
|
# Exit the script with error code 5. |
88
|
|
|
|
|
|
|
exit 5; |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Set some variables. |
92
|
|
|
|
|
|
|
our $FN_PASSWD = "/etc/passwd"; |
93
|
|
|
|
|
|
|
our $FN_SHELLS = "/etc/shells"; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Check if passwd exists. |
96
|
|
|
|
|
|
|
if (! -e $FN_PASSWD) { |
97
|
|
|
|
|
|
|
die "$!, $FN_PASSWD not exists.\n"; |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Check if shells exists. |
101
|
|
|
|
|
|
|
if (! -e $FN_SHELLS) { |
102
|
|
|
|
|
|
|
die "$!, $FN_SHELLS not exists.\n"; |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# ++++++++++++++++++++++++++++++++++++++++++ |
106
|
|
|
|
|
|
|
# Create a dictionary from __DATA__ section. |
107
|
|
|
|
|
|
|
# ++++++++++++++++++++++++++++++++++++++++++ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Initialise some variables. |
110
|
|
|
|
|
|
|
my $line = ""; |
111
|
|
|
|
|
|
|
my $key = ""; |
112
|
|
|
|
|
|
|
my $value = ""; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Read data from __DATA__ section. |
115
|
|
|
|
|
|
|
while () { |
116
|
|
|
|
|
|
|
# Read data only between the two given boundaries. |
117
|
|
|
|
|
|
|
if (/# Begin terminals/../# End terminals/) { |
118
|
|
|
|
|
|
|
next if /# Begin terminals/ || /# End terminals/; |
119
|
|
|
|
|
|
|
$line = $_; |
120
|
|
|
|
|
|
|
my @parts = split /=>/, $line, 2; |
121
|
|
|
|
|
|
|
$key = $parts[0]; |
122
|
|
|
|
|
|
|
$key =~ s/^\s+|\s+$//g; |
123
|
|
|
|
|
|
|
$value = $parts[1]; |
124
|
|
|
|
|
|
|
$value =~ s/^\s+|\s+$//g; |
125
|
|
|
|
|
|
|
$termhash{$key} = $value; |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
}; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# ============================================================================ # |
130
|
|
|
|
|
|
|
# Subroutine trim # |
131
|
|
|
|
|
|
|
# # |
132
|
|
|
|
|
|
|
# Description: # |
133
|
|
|
|
|
|
|
# The subroutine removes white spaces from both ends of a string. This is done # |
134
|
|
|
|
|
|
|
# by a logical or operation and using \s from regular expressions. Anchors are # |
135
|
|
|
|
|
|
|
# begin ^ of string and end $ of string. # |
136
|
|
|
|
|
|
|
# # |
137
|
|
|
|
|
|
|
# @argument: $_[0] => $string String to trim (scalar) # |
138
|
|
|
|
|
|
|
# @return: $string Trimmed string (scalar) # |
139
|
|
|
|
|
|
|
# ============================================================================ # |
140
|
|
|
|
|
|
|
sub trim { |
141
|
|
|
|
|
|
|
# Assign the function argument to the local string variable $str. |
142
|
28
|
100
|
66
|
28
|
0
|
263
|
my $string = ((defined $_[0] && $_[0] ne "") ? $_[0] : ""); |
143
|
|
|
|
|
|
|
# Trim the string from the left side and the right side. |
144
|
28
|
|
|
|
|
184
|
$string =~ s/^\s+|\s+$//g; |
145
|
|
|
|
|
|
|
# Return the trimmed string. |
146
|
28
|
|
|
|
|
82
|
return $string; |
147
|
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# ============================================================================ # |
150
|
|
|
|
|
|
|
# Subroutine search_brackets # |
151
|
|
|
|
|
|
|
# # |
152
|
|
|
|
|
|
|
# Description: # |
153
|
|
|
|
|
|
|
# The subroutine adds the square brackets [ and ] to the searchstring for # |
154
|
|
|
|
|
|
|
# use with grep. E.g. shell becomes [s]hell. Therefor the string must have # |
155
|
|
|
|
|
|
|
# a minumum length of 1. # |
156
|
|
|
|
|
|
|
# # |
157
|
|
|
|
|
|
|
# @argument: $_[0] => $str Searchstring (scalar) # |
158
|
|
|
|
|
|
|
# @return: $str Searchstring with square brackets (scalar) # |
159
|
|
|
|
|
|
|
# ============================================================================ # |
160
|
|
|
|
|
|
|
sub search_brackets { |
161
|
|
|
|
|
|
|
# Initialise the local variable $searchstring. |
162
|
12
|
|
|
12
|
0
|
35
|
my $searchstring = ""; |
163
|
|
|
|
|
|
|
# Check if $searchstring is defined and is not empty. |
164
|
12
|
50
|
33
|
|
|
60
|
if ((defined $_[0]) && (length($_[0]) > 0)) { |
165
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable. |
166
|
12
|
|
|
|
|
25
|
$searchstring = $_[0]; |
167
|
|
|
|
|
|
|
} else { |
168
|
|
|
|
|
|
|
# Return string of length 0. |
169
|
0
|
|
|
|
|
0
|
return ""; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
# Add square brackets [ and ] to the given string. |
172
|
12
|
|
|
|
|
24
|
substr($searchstring, 0, 0) = '['; |
173
|
12
|
|
|
|
|
23
|
substr($searchstring, 2, 0) = ']'; |
174
|
|
|
|
|
|
|
# Return the modified string. |
175
|
12
|
|
|
|
|
25
|
return $searchstring; |
176
|
|
|
|
|
|
|
}; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# ============================================================================ # |
179
|
|
|
|
|
|
|
# Subroutine read_file # |
180
|
|
|
|
|
|
|
# # |
181
|
|
|
|
|
|
|
# Description: # |
182
|
|
|
|
|
|
|
# Read the complete content of a file in one chunk. The retrieved content is # |
183
|
|
|
|
|
|
|
# stored in a string variable. # |
184
|
|
|
|
|
|
|
# # |
185
|
|
|
|
|
|
|
# @argument: $_[0] => $file Text filename (scalar) # |
186
|
|
|
|
|
|
|
# @return: $content File content (scalar) # |
187
|
|
|
|
|
|
|
# ============================================================================ # |
188
|
|
|
|
|
|
|
sub read_file { |
189
|
|
|
|
|
|
|
# Assign the function argument to the local variable. |
190
|
8
|
|
|
8
|
0
|
44
|
my $file = $_[0]; |
191
|
|
|
|
|
|
|
# Initialise the return variable. |
192
|
8
|
|
|
|
|
45
|
my $content = ""; |
193
|
|
|
|
|
|
|
# If file not exists, return an empty string. |
194
|
8
|
50
|
|
|
|
178
|
if (-f $file) { |
195
|
|
|
|
|
|
|
# Open a file handler for reading the file. |
196
|
8
|
|
|
|
|
531
|
open(my $fh, "<", $file); |
197
|
|
|
|
|
|
|
# Read the complete content from the file. |
198
|
8
|
|
|
|
|
28
|
$content = do {local $/; <$fh>}; |
|
8
|
|
|
|
|
79
|
|
|
8
|
|
|
|
|
785
|
|
199
|
|
|
|
|
|
|
# Close the file handler. |
200
|
8
|
|
|
|
|
116
|
close($fh); |
201
|
|
|
|
|
|
|
}; |
202
|
|
|
|
|
|
|
# Return the file content. |
203
|
8
|
|
|
|
|
49
|
return $content; |
204
|
|
|
|
|
|
|
}; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# ============================================================================ # |
207
|
|
|
|
|
|
|
# Subroutine login_users # |
208
|
|
|
|
|
|
|
# # |
209
|
|
|
|
|
|
|
# Description: # |
210
|
|
|
|
|
|
|
# Split the logged-in users by sperator space and store them to an array. # |
211
|
|
|
|
|
|
|
# # |
212
|
|
|
|
|
|
|
# @argument: None # |
213
|
|
|
|
|
|
|
# @return: $user_arr Array with the logged-in users (array) # |
214
|
|
|
|
|
|
|
# ============================================================================ # |
215
|
|
|
|
|
|
|
sub login_users { |
216
|
|
|
|
|
|
|
# Initialise the return array. |
217
|
4
|
|
|
4
|
0
|
12
|
my @user_array = (); |
218
|
|
|
|
|
|
|
# Get the logged-in users from the Linux command users. |
219
|
4
|
|
|
|
|
11949
|
my $user = `users`; |
220
|
|
|
|
|
|
|
# Check if the variable $user is defined and not empty. |
221
|
4
|
50
|
33
|
|
|
511
|
if (defined $user && $user ne "") { |
222
|
|
|
|
|
|
|
# Split the logged-in users and store them to the array. |
223
|
0
|
|
|
|
|
0
|
@user_array = split ' ', $user; |
224
|
|
|
|
|
|
|
}; |
225
|
|
|
|
|
|
|
# Return the array with the logged-in users. |
226
|
4
|
|
|
|
|
96
|
return @user_array; |
227
|
|
|
|
|
|
|
}; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# ============================================================================ # |
230
|
|
|
|
|
|
|
# Subroutine login_shells # |
231
|
|
|
|
|
|
|
# # |
232
|
|
|
|
|
|
|
# Description: # |
233
|
|
|
|
|
|
|
# Read the content of the file /etc/shells and store the content in a string # |
234
|
|
|
|
|
|
|
# variable. Then the content is splited up into lines. In a loop the lines # |
235
|
|
|
|
|
|
|
# are used where a valid login shell is given. Then the path is removed from # |
236
|
|
|
|
|
|
|
# the line with the login shell. The login shell is added to an array. In a # |
237
|
|
|
|
|
|
|
# last step douple entries are removed from the array. # |
238
|
|
|
|
|
|
|
# # |
239
|
|
|
|
|
|
|
# @argument: None # |
240
|
|
|
|
|
|
|
# @return: @login_shells Array with valid login shells (array) # |
241
|
|
|
|
|
|
|
# ============================================================================ # |
242
|
|
|
|
|
|
|
sub login_shells { |
243
|
|
|
|
|
|
|
# Declare the login shells array. |
244
|
4
|
|
|
4
|
0
|
20
|
my @login_shells; |
245
|
|
|
|
|
|
|
# Set the file for reading. |
246
|
4
|
|
|
|
|
36
|
my $file = $FN_SHELLS; |
247
|
|
|
|
|
|
|
# Read the content from the file. |
248
|
4
|
|
|
|
|
42
|
my $content = read_file($file); |
249
|
|
|
|
|
|
|
# Loop over the lines of the file content. |
250
|
4
|
|
|
|
|
55
|
foreach (split '\n', $content) { |
251
|
|
|
|
|
|
|
# Trim the new line. |
252
|
20
|
|
|
|
|
48
|
my $line = trim($_); |
253
|
|
|
|
|
|
|
# Use only a line with a valid login shell. |
254
|
20
|
100
|
|
|
|
121
|
if ($line =~ /^\/.*\/(.*)$/) { |
255
|
|
|
|
|
|
|
# Remove the path from the line with the login shell. |
256
|
16
|
|
|
|
|
79
|
my ($shell) = $line =~ /^\/.*\/(.*)$/; |
257
|
|
|
|
|
|
|
# Add the login shell to the array. |
258
|
16
|
|
|
|
|
50
|
push(@login_shells, $shell); |
259
|
|
|
|
|
|
|
}; |
260
|
|
|
|
|
|
|
}; |
261
|
|
|
|
|
|
|
# Remove the double entries from the array. |
262
|
4
|
|
|
|
|
43
|
my %login_hash = map({$_, 1} @login_shells); |
|
16
|
|
|
|
|
110
|
|
263
|
4
|
|
|
|
|
21
|
@login_shells = keys %login_hash; |
264
|
|
|
|
|
|
|
# Return the array with the unique login shells. |
265
|
4
|
|
|
|
|
33
|
return @login_shells; |
266
|
|
|
|
|
|
|
}; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
# ============================================================================ # |
269
|
|
|
|
|
|
|
# Subroutine get_ppid # |
270
|
|
|
|
|
|
|
# # |
271
|
|
|
|
|
|
|
# Description: # |
272
|
|
|
|
|
|
|
# Determine the PPID of the calling Perl script using the Linux command ps. # |
273
|
|
|
|
|
|
|
# # |
274
|
|
|
|
|
|
|
# @argument: $_[0] => $pid PID (scalar) # |
275
|
|
|
|
|
|
|
# @return: $ppid PPID (scalar) # |
276
|
|
|
|
|
|
|
# ============================================================================ # |
277
|
|
|
|
|
|
|
sub get_ppid { |
278
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable $pid. |
279
|
4
|
|
|
4
|
0
|
15
|
my $pid = $_[0]; |
280
|
|
|
|
|
|
|
# Store the output of the Linux command ps in the local variable $ppid. |
281
|
4
|
|
|
|
|
25011
|
my $ppid = `ps --no-headers -o ppid:1 -p $pid --sort lstart 2>/dev/null`; |
282
|
|
|
|
|
|
|
# Split a multiline Perl scalar with the PPID's in parts. |
283
|
4
|
|
|
|
|
167
|
my @parts = split /\s+/, $ppid; |
284
|
|
|
|
|
|
|
# If there is more than one PPID, use the first PPID. |
285
|
4
|
|
|
|
|
18
|
$ppid = $parts[0]; |
286
|
|
|
|
|
|
|
# Trim the Perl scalar with the PPID. |
287
|
4
|
|
|
|
|
68
|
$ppid = trim($ppid); |
288
|
|
|
|
|
|
|
# Return the PPID. |
289
|
4
|
|
|
|
|
38
|
return $ppid; |
290
|
|
|
|
|
|
|
}; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# ============================================================================ # |
293
|
|
|
|
|
|
|
# Subroutine get_termpath # |
294
|
|
|
|
|
|
|
# ============================================================================ # |
295
|
|
|
|
|
|
|
sub get_termpath { |
296
|
|
|
|
|
|
|
# Initialise the local variables. |
297
|
4
|
|
|
4
|
0
|
15
|
my $fileno = fileno(STDIN); |
298
|
4
|
|
|
|
|
21
|
my $term_path = ""; |
299
|
|
|
|
|
|
|
# Get the terminal path. |
300
|
|
|
|
|
|
|
# $term_path = TermPath(); |
301
|
4
|
|
|
|
|
43
|
$term_path = ttyname($fileno); |
302
|
|
|
|
|
|
|
# Check the terminal path |
303
|
4
|
50
|
|
|
|
35
|
$term_path = (defined $term_path ? $term_path : ""); |
304
|
|
|
|
|
|
|
# Return the terminal path. |
305
|
4
|
|
|
|
|
20
|
return $term_path; |
306
|
|
|
|
|
|
|
}; |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# ============================================================================ # |
309
|
|
|
|
|
|
|
# Subroutine get_user_name # |
310
|
|
|
|
|
|
|
# ============================================================================ # |
311
|
|
|
|
|
|
|
sub get_username { |
312
|
|
|
|
|
|
|
# Initialise the username. |
313
|
4
|
|
|
4
|
0
|
22
|
my $username = ""; |
314
|
|
|
|
|
|
|
# Define the methods for getting the username. |
315
|
4
|
|
|
|
|
1114
|
my $method1 = getlogin(); |
316
|
4
|
|
|
|
|
466
|
my $method2 = (getpwuid($<))[0]; |
317
|
4
|
|
|
|
|
26
|
my $method3 = $ENV{LOGNAME}; |
318
|
4
|
|
|
|
|
9
|
my $method4 = $ENV{USER}; |
319
|
|
|
|
|
|
|
# Extract the username. |
320
|
4
|
|
33
|
|
|
51
|
$username = ($method1 || $method2 || $method3 || $method4); |
321
|
|
|
|
|
|
|
# Return the username. |
322
|
4
|
|
|
|
|
17
|
return $username; |
323
|
|
|
|
|
|
|
}; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
# ============================================================================ # |
326
|
|
|
|
|
|
|
# Subroutine term_user_shell # |
327
|
|
|
|
|
|
|
# # |
328
|
|
|
|
|
|
|
# Description: # |
329
|
|
|
|
|
|
|
# Create a multi dimensional array with term, user and shell. # |
330
|
|
|
|
|
|
|
# # |
331
|
|
|
|
|
|
|
# @arguments: $_[0] => $passwd_content Content of passwd (scalar) # |
332
|
|
|
|
|
|
|
# @{$_[1]} => @user_array User array (array) # |
333
|
|
|
|
|
|
|
# @{$_[2]} => @shell_array Shell array (array) # |
334
|
|
|
|
|
|
|
# @return: @result_array Array with the result (array) # |
335
|
|
|
|
|
|
|
# ============================================================================ # |
336
|
|
|
|
|
|
|
sub term_user_shell { |
337
|
|
|
|
|
|
|
# Assign the subroutine arguments to the local variables. |
338
|
4
|
|
|
4
|
0
|
9
|
my $passwd_content = $_[0]; |
339
|
4
|
|
|
|
|
9
|
my @user_array = @{$_[1]}; |
|
4
|
|
|
|
|
11
|
|
340
|
4
|
|
|
|
|
8
|
my @shell_array = @{$_[2]}; |
|
4
|
|
|
|
|
26
|
|
341
|
|
|
|
|
|
|
# Initialise variable $term. |
342
|
4
|
|
|
|
|
16
|
my $term = ""; |
343
|
|
|
|
|
|
|
# Get the username related to the terminal. |
344
|
4
|
|
|
|
|
12
|
my $username = get_username(); |
345
|
|
|
|
|
|
|
# Declare the return array. |
346
|
4
|
|
|
|
|
15
|
my @result_array = (); |
347
|
|
|
|
|
|
|
# Get the terminal path. |
348
|
4
|
|
|
|
|
13
|
my $term_path = get_termpath(); |
349
|
|
|
|
|
|
|
# If $term_path is not defined or empty set $term to ?. |
350
|
4
|
50
|
33
|
|
|
48
|
if (!defined $term_path || $term_path eq "") { |
351
|
|
|
|
|
|
|
# Set variable $term_path. |
352
|
4
|
|
|
|
|
27
|
$term = "?"; |
353
|
|
|
|
|
|
|
} else { |
354
|
|
|
|
|
|
|
# Check on pts and tty. |
355
|
0
|
0
|
|
|
|
0
|
if ($term_path =~ /^.*\/dev\/(pts\/\d+)$/) { |
|
|
0
|
|
|
|
|
|
356
|
|
|
|
|
|
|
# Extract the pseudo terminal slave. |
357
|
0
|
|
|
|
|
0
|
($term) = $term_path =~ /^.*\/dev\/(pts\/\d+)$/; |
358
|
|
|
|
|
|
|
} elsif ($term_path =~ /^.*\/dev\/(tty\d+)$/) { |
359
|
|
|
|
|
|
|
# Extract the terminal TeleTYpewriter. |
360
|
0
|
|
|
|
|
0
|
($term) = $term_path =~ /^.*\/dev\/(tty\d+)$/; |
361
|
|
|
|
|
|
|
} else { |
362
|
0
|
|
|
|
|
0
|
$term = "?"; |
363
|
|
|
|
|
|
|
}; |
364
|
|
|
|
|
|
|
}; |
365
|
|
|
|
|
|
|
# Loop over the array with the lines of $passwd_content. |
366
|
4
|
|
|
|
|
58
|
foreach (split '\n', $passwd_content) { |
367
|
|
|
|
|
|
|
# Get user and shell from each line of the content. |
368
|
92
|
|
|
|
|
285
|
my ($user) = $_ =~ /^(.*?):.*/; |
369
|
92
|
|
|
|
|
245
|
my ($shell) = $_ =~ /^.*\/(.*)$/; |
370
|
92
|
100
|
100
|
|
|
367
|
if ($shell ne "nologin" && $shell ne "sync" && $shell ne "false") { |
|
|
|
100
|
|
|
|
|
371
|
|
|
|
|
|
|
# Check user and shell against the given arrays. |
372
|
4
|
50
|
33
|
|
|
25
|
if (grep(/^$user$/, @user_array) && |
|
|
50
|
|
|
|
|
|
373
|
|
|
|
|
|
|
grep(/^$shell$/, @shell_array)) { |
374
|
|
|
|
|
|
|
# Assemble a new list. |
375
|
0
|
|
|
|
|
0
|
my @tmp = ($term, $user, $shell); |
376
|
|
|
|
|
|
|
# Add data to array. |
377
|
0
|
|
|
|
|
0
|
push(@result_array, \@tmp); |
378
|
|
|
|
|
|
|
} elsif ($user eq $username) { |
379
|
|
|
|
|
|
|
# Assemble a new list. |
380
|
4
|
|
|
|
|
15
|
my @tmp = ($term, $user, $shell); |
381
|
|
|
|
|
|
|
# Add data to array. |
382
|
4
|
|
|
|
|
29
|
push(@result_array, \@tmp); |
383
|
|
|
|
|
|
|
}; |
384
|
|
|
|
|
|
|
}; |
385
|
|
|
|
|
|
|
}; |
386
|
|
|
|
|
|
|
# Return the array. |
387
|
4
|
|
|
|
|
19
|
return @result_array; |
388
|
|
|
|
|
|
|
}; |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
# ============================================================================ # |
391
|
|
|
|
|
|
|
# Subroutine terminal_process # |
392
|
|
|
|
|
|
|
# # |
393
|
|
|
|
|
|
|
# Description: # |
394
|
|
|
|
|
|
|
# Get the process related to term, user and shell. # |
395
|
|
|
|
|
|
|
# # |
396
|
|
|
|
|
|
|
# @argument: @{$_[0]} => @data Array with term, user and shell (array) # |
397
|
|
|
|
|
|
|
# @return: @result Array with matching processes (array) # |
398
|
|
|
|
|
|
|
# ============================================================================ # |
399
|
|
|
|
|
|
|
sub terminal_process { |
400
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable. |
401
|
4
|
|
|
4
|
0
|
9
|
my @data = @{$_[0]}; |
|
4
|
|
|
|
|
13
|
|
402
|
|
|
|
|
|
|
# Initialise the return array. |
403
|
4
|
|
|
|
|
22
|
my @match = (); |
404
|
|
|
|
|
|
|
# Set command. |
405
|
4
|
|
|
|
|
15
|
my $ps_cmd = "ps aux --sort lstart 2>/dev/null"; |
406
|
|
|
|
|
|
|
# Loop over the elements of the array. |
407
|
4
|
|
|
|
|
26
|
foreach my $item (@data) { |
408
|
|
|
|
|
|
|
# Get term, user and shell from the array. |
409
|
4
|
|
|
|
|
14
|
my $term = $item->[0]; |
410
|
4
|
|
|
|
|
9
|
my $user = $item->[1]; |
411
|
4
|
|
|
|
|
8
|
my $shell = $item->[2]; |
412
|
4
|
|
|
|
|
14
|
$term = search_brackets($term); |
413
|
4
|
|
|
|
|
12
|
$user = search_brackets($user); |
414
|
4
|
|
|
|
|
10
|
$shell = search_brackets($shell); |
415
|
|
|
|
|
|
|
# Search for processes which is matching shell, user and terminal. |
416
|
4
|
|
|
|
|
14
|
my $grep_shell = "grep $shell 2>/dev/null"; |
417
|
4
|
|
|
|
|
41
|
my $grep_user = "grep $user 2>/dev/null"; |
418
|
4
|
|
|
|
|
15
|
my $grep_term = "grep $term 2>/dev/null"; |
419
|
4
|
|
|
|
|
36315
|
my $process = `${ps_cmd} | ${grep_shell} | ${grep_user} | ${grep_term}`; |
420
|
|
|
|
|
|
|
# Check if the result is not empty. |
421
|
4
|
50
|
|
|
|
113
|
if ($process ne "") { |
422
|
|
|
|
|
|
|
# Add the process to the return array. |
423
|
4
|
|
|
|
|
118
|
push(@match, $process); |
424
|
|
|
|
|
|
|
}; |
425
|
|
|
|
|
|
|
}; |
426
|
|
|
|
|
|
|
# If array @match is empty, it is not a local process. |
427
|
4
|
50
|
|
|
|
42
|
if (@match == 0) { |
428
|
|
|
|
|
|
|
# Loop over the elements of the array. |
429
|
0
|
|
|
|
|
0
|
foreach my $item (@data) { |
430
|
|
|
|
|
|
|
# Get term and user from the array. |
431
|
0
|
|
|
|
|
0
|
my $term = $item->[0]; |
432
|
0
|
|
|
|
|
0
|
my $user = $item->[1]; |
433
|
|
|
|
|
|
|
# Add square brackets to searchstrings. |
434
|
0
|
|
|
|
|
0
|
$term = search_brackets($term); |
435
|
0
|
|
|
|
|
0
|
$user = search_brackets($user); |
436
|
|
|
|
|
|
|
# Search for processes which is matching shell and terminal. |
437
|
0
|
|
|
|
|
0
|
my $grep_term = "grep $term 2>/dev/null"; |
438
|
0
|
|
|
|
|
0
|
my $grep_user = "grep $user 2>/dev/null"; |
439
|
0
|
|
|
|
|
0
|
my $process = `${ps_cmd} | ${grep_user} | ${grep_term} | grep "?" | grep "sshd"`; |
440
|
|
|
|
|
|
|
# Check if the result is not empty. |
441
|
0
|
0
|
|
|
|
0
|
if ($process ne "") { |
442
|
|
|
|
|
|
|
# Add the process to the return array. |
443
|
0
|
|
|
|
|
0
|
push(@match, $process); |
444
|
|
|
|
|
|
|
}; |
445
|
|
|
|
|
|
|
}; |
446
|
|
|
|
|
|
|
}; |
447
|
|
|
|
|
|
|
# Return the array. |
448
|
4
|
|
|
|
|
87
|
return @match; |
449
|
|
|
|
|
|
|
}; |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
# ============================================================================ # |
452
|
|
|
|
|
|
|
# Subroutine terminal_command_line # |
453
|
|
|
|
|
|
|
# # |
454
|
|
|
|
|
|
|
# Description: # |
455
|
|
|
|
|
|
|
# Use the Linux command ps to get the command line of the process which is # |
456
|
|
|
|
|
|
|
# related to the terminal in use. # |
457
|
|
|
|
|
|
|
# # |
458
|
|
|
|
|
|
|
# @argument $_[0] => $ppid PPID (scalar) # |
459
|
|
|
|
|
|
|
# @return $termproc Terminal command line (scalar) # |
460
|
|
|
|
|
|
|
# ============================================================================ # |
461
|
|
|
|
|
|
|
sub terminal_command_line { |
462
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable $ppid. |
463
|
4
|
|
|
4
|
0
|
19
|
my $ppid = $_[0]; |
464
|
|
|
|
|
|
|
# Get the command column from the ps output. |
465
|
4
|
|
|
|
|
20623
|
my $termproc = `ps --no-headers -o cmd:1 -p $ppid --sort lstart 2>/dev/null`; |
466
|
|
|
|
|
|
|
# Trim the command line output string. |
467
|
4
|
|
|
|
|
148
|
$termproc = trim($termproc); |
468
|
|
|
|
|
|
|
# Return the process related to the terminal in use. |
469
|
4
|
|
|
|
|
103
|
return $termproc |
470
|
|
|
|
|
|
|
}; |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
# ============================================================================ # |
473
|
|
|
|
|
|
|
# Subroutine terminal_identifier # |
474
|
|
|
|
|
|
|
# # |
475
|
|
|
|
|
|
|
# Description: # |
476
|
|
|
|
|
|
|
# Identify the process command line of the terminal in use. # |
477
|
|
|
|
|
|
|
# # |
478
|
|
|
|
|
|
|
# @argument: None # |
479
|
|
|
|
|
|
|
# @return: $terminal_command Process command line (scalar) # |
480
|
|
|
|
|
|
|
# ============================================================================ # |
481
|
|
|
|
|
|
|
sub terminal_identifier { |
482
|
|
|
|
|
|
|
# Declare the return variable $terminal_command. |
483
|
4
|
|
|
4
|
0
|
12
|
my $terminal_command; |
484
|
|
|
|
|
|
|
# Set the filename. |
485
|
4
|
|
|
|
|
22
|
my $filename = $FN_PASSWD; |
486
|
|
|
|
|
|
|
# Get the logged-in users. |
487
|
4
|
|
|
|
|
24
|
my @user_arr = login_users(); |
488
|
|
|
|
|
|
|
# Get the available login shells. |
489
|
4
|
|
|
|
|
31
|
my @shell_arr = login_shells(); |
490
|
|
|
|
|
|
|
# Read the file /etc/passwd in and store it in the variable $content. |
491
|
4
|
|
|
|
|
35
|
my $content = read_file($filename); |
492
|
|
|
|
|
|
|
# Create the array with user and shell. |
493
|
4
|
|
|
|
|
27
|
my @result = term_user_shell($content, \@user_arr, \@shell_arr); |
494
|
|
|
|
|
|
|
# check if @result is empty. |
495
|
4
|
50
|
|
|
|
14
|
if (@result == 0) { |
496
|
|
|
|
|
|
|
# Set terminal command. |
497
|
0
|
|
|
|
|
0
|
$terminal_command = ""; |
498
|
|
|
|
|
|
|
# Return an empty string. |
499
|
0
|
|
|
|
|
0
|
return $terminal_command; |
500
|
|
|
|
|
|
|
}; |
501
|
|
|
|
|
|
|
# Create the array with user and term. |
502
|
4
|
|
|
|
|
43
|
my @match = terminal_process(\@result); |
503
|
|
|
|
|
|
|
# Check if array is empty. |
504
|
4
|
50
|
|
|
|
49
|
if (@match > 0) { |
505
|
|
|
|
|
|
|
# Split up the process by lines and white spaces. |
506
|
4
|
|
|
|
|
158
|
my @columns = split /\s+/, $match[0]; |
507
|
|
|
|
|
|
|
# Extract the PID from the array. |
508
|
4
|
|
|
|
|
21
|
my $pid = $columns[1]; |
509
|
|
|
|
|
|
|
# Get the PPID from the command ps. |
510
|
4
|
|
|
|
|
23
|
my $ppid = get_ppid($pid); |
511
|
|
|
|
|
|
|
# Get the terminal in use from the command ps. |
512
|
4
|
|
|
|
|
41
|
$terminal_command = terminal_command_line($ppid); |
513
|
|
|
|
|
|
|
} else { |
514
|
|
|
|
|
|
|
# Set terminal command. |
515
|
0
|
|
|
|
|
0
|
$terminal_command = ""; |
516
|
|
|
|
|
|
|
}; |
517
|
|
|
|
|
|
|
# Return the terminal process command. |
518
|
4
|
|
|
|
|
179
|
return $terminal_command; |
519
|
|
|
|
|
|
|
}; |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
# ============================================================================ # |
522
|
|
|
|
|
|
|
# Subroutine get_terminal_path # |
523
|
|
|
|
|
|
|
# ============================================================================ # |
524
|
|
|
|
|
|
|
sub get_terminal_path { |
525
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable. |
526
|
0
|
|
|
0
|
0
|
0
|
my $terminal_command = $_[0]; |
527
|
|
|
|
|
|
|
# Initialise the return variable. |
528
|
0
|
|
|
|
|
0
|
my $terminal_path = ""; |
529
|
|
|
|
|
|
|
# Define the regular expression for white spaces. |
530
|
0
|
|
|
|
|
0
|
my $re_ws = qr/\s+/; |
531
|
|
|
|
|
|
|
# Define the regular expression for command line arguments. |
532
|
0
|
|
|
|
|
0
|
my $re_args = qr/(?<= )(-.*?)(?= |$)/; |
533
|
|
|
|
|
|
|
# Check terminal command on white spaces. |
534
|
0
|
0
|
|
|
|
0
|
if ($terminal_command =~ /$re_ws/) { |
535
|
|
|
|
|
|
|
# Initialise the progs array. |
536
|
0
|
|
|
|
|
0
|
my @progs = (); |
537
|
|
|
|
|
|
|
# Assign terminal command to raw string. |
538
|
0
|
|
|
|
|
0
|
my $raw_string = $terminal_command; |
539
|
|
|
|
|
|
|
# Remove all terminal command line arguments. |
540
|
0
|
|
|
|
|
0
|
$raw_string =~ s/$re_args//g; |
541
|
|
|
|
|
|
|
# Split the terminal command line by white spaces. |
542
|
0
|
|
|
|
|
0
|
my @parts = split /$re_ws/, $raw_string; |
543
|
|
|
|
|
|
|
# Loop over the elements of the array. |
544
|
0
|
|
|
|
|
0
|
foreach (@parts) { |
545
|
|
|
|
|
|
|
# Check if the element is an executable. |
546
|
0
|
0
|
|
|
|
0
|
if (`which $_` ne "") { |
547
|
|
|
|
|
|
|
# Add executable to new array. |
548
|
0
|
|
|
|
|
0
|
push(@progs, $_); |
549
|
|
|
|
|
|
|
}; |
550
|
|
|
|
|
|
|
}; |
551
|
|
|
|
|
|
|
# Check number of executables. |
552
|
0
|
0
|
|
|
|
0
|
if (@progs == 0) { |
553
|
|
|
|
|
|
|
# Assign first element to path. |
554
|
0
|
|
|
|
|
0
|
$terminal_path = $parts[0]; |
555
|
|
|
|
|
|
|
} else { |
556
|
0
|
0
|
|
|
|
0
|
if (@progs > 1) { |
557
|
|
|
|
|
|
|
# Assign first element to path. |
558
|
0
|
|
|
|
|
0
|
$terminal_path = $progs[1]; |
559
|
|
|
|
|
|
|
} else { |
560
|
|
|
|
|
|
|
# Assign second element to path. |
561
|
0
|
|
|
|
|
0
|
$terminal_path = $progs[0]; |
562
|
|
|
|
|
|
|
}; |
563
|
|
|
|
|
|
|
}; |
564
|
|
|
|
|
|
|
} else { |
565
|
|
|
|
|
|
|
# Set variable $terminal_path. |
566
|
0
|
|
|
|
|
0
|
$terminal_path = $terminal_command; |
567
|
|
|
|
|
|
|
}; |
568
|
|
|
|
|
|
|
# Return the terminal name. |
569
|
0
|
|
|
|
|
0
|
return $terminal_path; |
570
|
|
|
|
|
|
|
}; |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# ============================================================================ # |
573
|
|
|
|
|
|
|
# Subroutine get_terminal_name # |
574
|
|
|
|
|
|
|
# ============================================================================ # |
575
|
|
|
|
|
|
|
sub get_terminal_name { |
576
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable. |
577
|
0
|
|
|
0
|
0
|
0
|
my $terminal_path = $_[0]; |
578
|
|
|
|
|
|
|
# Initialise the return variable. |
579
|
0
|
|
|
|
|
0
|
my $terminal_name = ""; |
580
|
|
|
|
|
|
|
# Define the regular expression for program pathes. |
581
|
0
|
|
|
|
|
0
|
my $re_pp = qr/^\/.*\//; |
582
|
|
|
|
|
|
|
# Check the variable $terminal_path on the existence of a path. |
583
|
0
|
0
|
|
|
|
0
|
if ($terminal_path =~ /$re_pp/) { |
584
|
|
|
|
|
|
|
# Remove the path from variable $terminal_path. |
585
|
0
|
|
|
|
|
0
|
$terminal_name = $terminal_path =~ s/$re_pp//r; |
586
|
|
|
|
|
|
|
} else { |
587
|
|
|
|
|
|
|
# Assign variable $terminal_path to variable $terminal_name. |
588
|
0
|
|
|
|
|
0
|
$terminal_name = $terminal_path; |
589
|
|
|
|
|
|
|
}; |
590
|
|
|
|
|
|
|
# Return the terminal name. |
591
|
0
|
|
|
|
|
0
|
return $terminal_name; |
592
|
|
|
|
|
|
|
}; |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
# ============================================================================ # |
595
|
|
|
|
|
|
|
# Subroutine get_terminal_ftn # |
596
|
|
|
|
|
|
|
# ============================================================================ # |
597
|
|
|
|
|
|
|
sub get_terminal_ftn { |
598
|
|
|
|
|
|
|
# Assign the subroutine argument to the local variable. |
599
|
0
|
|
|
0
|
0
|
0
|
my $terminal_name = $_[0]; |
600
|
|
|
|
|
|
|
# Initialise the return variable. |
601
|
0
|
|
|
|
|
0
|
my $terminal_ftn = ""; |
602
|
|
|
|
|
|
|
# Convert terminal name to lower case. |
603
|
0
|
|
|
|
|
0
|
$terminal_name = lc($terminal_name); |
604
|
|
|
|
|
|
|
# Check terminal name. |
605
|
0
|
0
|
|
|
|
0
|
if (defined $termhash{$terminal_name}) { |
606
|
|
|
|
|
|
|
# Get the friendly terminal name. |
607
|
0
|
|
|
|
|
0
|
$terminal_ftn = $termhash{$terminal_name}; |
608
|
|
|
|
|
|
|
} else { |
609
|
|
|
|
|
|
|
# Set the friendly terminal name. |
610
|
0
|
|
|
|
|
0
|
$terminal_ftn = $terminal_name; |
611
|
|
|
|
|
|
|
}; |
612
|
|
|
|
|
|
|
# Return the friendly terminal name. |
613
|
0
|
|
|
|
|
0
|
return $terminal_ftn; |
614
|
|
|
|
|
|
|
}; |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
# ============================================================================ # |
617
|
|
|
|
|
|
|
# Subroutine whichterminalami # |
618
|
|
|
|
|
|
|
# # |
619
|
|
|
|
|
|
|
# Description: # |
620
|
|
|
|
|
|
|
# Identify the terminal emulator. # |
621
|
|
|
|
|
|
|
# # |
622
|
|
|
|
|
|
|
# @argument: $_[0] => $flag Output format flag (scalar) # |
623
|
|
|
|
|
|
|
# @return: $terminal Terminal name (scalar) # |
624
|
|
|
|
|
|
|
# ============================================================================ # |
625
|
|
|
|
|
|
|
sub whichterminalami { |
626
|
|
|
|
|
|
|
# Initialise the output format flag variable. |
627
|
4
|
|
|
4
|
0
|
767
|
my $flag = ""; |
628
|
|
|
|
|
|
|
# Set the output format flag. |
629
|
4
|
50
|
|
|
|
31
|
if ($OutputFormat ne "") { |
630
|
|
|
|
|
|
|
# Set the output format flag variable based on the global variable. |
631
|
0
|
|
|
|
|
0
|
$flag = $OutputFormat; |
632
|
|
|
|
|
|
|
} else { |
633
|
|
|
|
|
|
|
# Get the output format flag variable from the subroutine argument. |
634
|
4
|
100
|
|
|
|
32
|
$flag = (defined $_[0] ? $_[0] : ''); |
635
|
|
|
|
|
|
|
}; |
636
|
|
|
|
|
|
|
# Initialise the terminal variables. |
637
|
4
|
|
|
|
|
12
|
my $terminal = ""; |
638
|
4
|
|
|
|
|
20
|
my $terminal_ftn = ""; |
639
|
4
|
|
|
|
|
8
|
my $terminal_name = ""; |
640
|
4
|
|
|
|
|
8
|
my $terminal_path = ""; |
641
|
|
|
|
|
|
|
# Identify the terminal process command line. |
642
|
4
|
|
|
|
|
14
|
my $terminal_command = terminal_identifier(); |
643
|
|
|
|
|
|
|
# If terminal process command line is an empty string it is an unknown terminal. |
644
|
4
|
50
|
|
|
|
39
|
if ($terminal_command eq "") { |
645
|
|
|
|
|
|
|
# Return unknown terminal. |
646
|
4
|
|
|
|
|
190
|
return "Unknown Terminal"; |
647
|
|
|
|
|
|
|
}; |
648
|
|
|
|
|
|
|
# Get the terminal path. |
649
|
0
|
|
|
|
|
|
$terminal_path = get_terminal_path($terminal_command); |
650
|
|
|
|
|
|
|
# Get the terminal name. |
651
|
0
|
|
|
|
|
|
$terminal_name = get_terminal_name($terminal_path); |
652
|
|
|
|
|
|
|
# Get the friendly terminal name. |
653
|
0
|
|
|
|
|
|
$terminal_ftn = get_terminal_ftn($terminal_name); |
654
|
|
|
|
|
|
|
# Return remote console or system console based on sshd or login. |
655
|
0
|
0
|
|
|
|
|
if (($terminal_name) =~ /^sshd.*/) { |
|
|
0
|
|
|
|
|
|
656
|
0
|
|
|
|
|
|
return "Remote Console"; |
657
|
|
|
|
|
|
|
} elsif (($terminal_name) =~ /^login.*/) { |
658
|
0
|
|
|
|
|
|
return "System Console"; |
659
|
|
|
|
|
|
|
}; |
660
|
|
|
|
|
|
|
# Return the terminal string based on the flag setting. |
661
|
0
|
0
|
|
|
|
|
if ($flag eq "") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
662
|
0
|
|
|
|
|
|
$terminal = $terminal_name; |
663
|
|
|
|
|
|
|
} elsif ($flag eq "FTN") { |
664
|
0
|
|
|
|
|
|
$terminal = $terminal_ftn; |
665
|
|
|
|
|
|
|
} elsif ($flag eq "PATH") { |
666
|
0
|
|
|
|
|
|
$terminal = $terminal_path; |
667
|
|
|
|
|
|
|
} elsif ($flag eq "PROC") { |
668
|
0
|
|
|
|
|
|
$terminal = $terminal_command; |
669
|
|
|
|
|
|
|
}; |
670
|
|
|
|
|
|
|
# Return the found terminal string. |
671
|
0
|
|
|
|
|
|
return $terminal; |
672
|
|
|
|
|
|
|
}; |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
1; |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
__DATA__ |