/usr/bin/wg-changeIobStatus is in webgui 7.10.28-1.
This file is owned by root:root, with mode 0o755.
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 181 182 183 184 185 186 187 | #!/usr/bin/perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use File::Basename ();
use File::Spec;
my $webguiRoot;
BEGIN {
$webguiRoot = '/usr/share/webgui';
unshift @INC, File::Spec->catdir($webguiRoot, 'lib');
}
use Getopt::Long;
use Pod::Usage;
use WebGUI::Session;
use WebGUI::User;
use WebGUI::Inbox;
$|=1;
my $configFile;
my $help;
my $quiet;
my $whatsHappening = "Automatically signed out.";
my $newStatus = "Out";
my $currentStatus = "In";
my $userMessage = "You were logged out of the In/Out Board automatically.";
my $userMessageFile;
GetOptions(
'configfile=s'=>\$configFile,
'help'=>\$help,
'quiet'=>\$quiet,
'whatsHappening:s'=>\$whatsHappening,
'userMessage:s'=>\$userMessage,
'userMessageFile:s'=>\$userMessageFile,
'currentStatus:s'=>\$currentStatus,
'newStatus:s'=>\$newStatus
);
pod2usage( verbose => 2 ) if $help;
pod2usage() unless $configFile;
print "Starting up...\n" unless ($quiet);
my $session = WebGUI::Session->open($webguiRoot,$configFile);
if ($userMessageFile) {
print "Opening message file.." unless ($quiet);
if (open(FILE,"<".$userMessageFile)) {
print "OK\n" unless ($quiet);
my $contents;
while (<FILE>) {
$contents .= $_;
}
close(FILE);
if (length($contents) == 0) {
print "Message file empty, reverting to original message.\n";
} else {
$userMessage = $contents;
}
} else {
print "Failed to open message file.\n";
}
}
print "Searching for users with a status of $currentStatus ...\n" unless ($quiet);
my $userList;
my $now = time();
my $inbox = WebGUI::Inbox->new($session);
my $sth = $session->db->read("select userId,assetId from InOutBoard_status where status=?",[$currentStatus]);
while (my ($userId,$assetId) = $sth->array) {
my $user = WebGUI::User->new($session, $userId);
print "\tFound user ".$user->username."\n" unless ($quiet);
$userList .= $user->username." (".$userId.")\n";
$session->db->write("update InOutBoard_status set dateStamp=?, message=?, status=? where userId=? and assetId=?",[$now, $whatsHappening, $newStatus, $userId, $assetId]);
$session->db->write("insert into InOutBoard_statusLog (userId, createdBy, dateStamp, message, status, assetId) values (?,?,?,?,?,?)",
[$userId,3,$now, $whatsHappening, $newStatus, $assetId]);
$inbox->addMessage({
userId=>$userId,
subject=>"IOB Update",
message=>$userMessage
});
}
if (length($userList) > 0) {
print "Alerting admins of changes\n" unless ($quiet);
my $message = "The following users had their status changed:\n\n".$userList;
$inbox->addMessage({
groupId=>3,
subject=>"IOB Update",
message=>$userMessage
});
}
print "Cleaning up..." unless ($quiet);
$session->var->end;
$session->close;
print "OK\n" unless ($quiet);
__END__
=head1 NAME
changeIobStatus - Automate WebGUI's InOut Board User status switching.
=head1 SYNOPSIS
changeIobStatus --configFile config.conf
[--currentStatus status]
[--newStatus status]
[--userMessage text|--userMessageFile pathname]
[--whatsHappening text]
[--quiet]
changeIobStatus --help
=head1 DESCRIPTION
This WebGUI utility script helps you switch one or more user status
in the InOut Board (IOB). For instance, you might want to run it
from cron each night to automatically mark out all users that haven't
already marked out.
=over
=item B<--configFile config.conf>
The WebGUI config file to use. Only the file name needs to be specified,
since it will be looked up inside WebGUI's configuration directory.
This parameter is required.
=item B<--currentStatus status>
Check users in the IOB having B<status> status. If left unspecified,
it will default to C<In>.
=item B<--newStatus status>
Change users status in the IOB to B<status> status. If left unspecified,
it will default to C<Out>.
=item B<--userMessage msg>
Text of the message to be sent to the user after changing the status.
If left unspecified it will default to
You were logged out of the In/Out Board automatically.
=item B<--userMessageFile pathname>
Pathname to a file whose contents will be sent to the user after changing
the status. Using this option overrides whatever messages is set
with B<--userMessage> (see above).
=item B<--whatsHappening text>
The message attached to the InOut Board when changing status. If left
unspecified it defaults to
Automatically signed out.
=item B<--quiet>
Disable all output unless there's an error.
=item B<--help>
Shows this documentation, then exits.
=back
=head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation.
=cut
|