This file is indexed.

/usr/share/perl5/Octopussy.pm is in octopussy 1.0.6-0ubuntu1.

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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# $HeadURL$
# $Revision: 596 $
# $Date: 2012-08-29 01:05:16 +0100 (Wed, 29 Aug 2012) $
# $Author: sebthebert $

=head1 NAME

Octopussy - Octopussy main module

=cut

package Octopussy;

use strict;
use warnings;
use Readonly;

use File::Basename;
use File::Path;
use Proc::PID::File;
use POSIX qw( mkfifo strftime );

use AAT::Application;
use AAT::Download;
use AAT::Syslog;
use AAT::Utils qw( ARRAY NOT_NULL );
use AAT::XML;
use Octopussy::Cache;
use Octopussy::FS;
use Octopussy::Info;

Readonly my $APPLICATION_NAME => 'Octopussy';
Readonly my $SF_SITE => 'http://sf.net/project/showfiles.php?group_id=154314';
Readonly my $IDX_STAT_UID => 4;
Readonly my $IDX_STAT_GID => 5;

$Octopussy::VERSION = '1.0.6';

=head1 FUNCTIONS

=head2 Valid_User($prog_name)

Checks that current user is Octopussy user for program $prog_name

=cut

sub Valid_User
{
    my $prog_name = shift;

    my @info      = getpwuid $<;
    my $octo_user = Octopussy::Info::User();

    return (1) if ($info[0] =~ /^$octo_user$/);

    AAT::Syslog::Message($prog_name,
        "You have to be Octopussy user to use $prog_name");
    printf "You have to be Octopussy user to use %s !\n", $prog_name;

    return (0);
}

=head2 Version()

Returns Octopussy main module Version

=cut

sub Version
{
    return ($Octopussy::VERSION);
}

=head2 Commander($cmd)

Add command $cmd to octo_commander commands list

=cut

sub Commander
{
    my $cmd = shift;

    my $cache = Octopussy::Cache::Init('octo_commander');
    if (defined $cache)
    {
        my $commands = $cache->get('commands') || ();
        push @{$commands}, $cmd;
        $cache->set('commands', $commands);

        return ($cmd);
    }

    return (undef);
}

=head2 Die($prog_name, $msg)

Syslog error $msg before dying

=cut

sub Die
{
    my ($prog_name, $msg) = @_;

    AAT::Syslog::Message($prog_name, $msg);
    die $msg;
}

=head2 Error

Syslogs error and prints it

=cut

sub Error
{
    my ($module, $msg, @args) = @_;

    my $message = AAT::Syslog::Message($module, $msg, @args);
    print "$module: $message\n";

    return ("$module: $message\n");
}

=head2 Parameter($param)

Returns Octopussy Parameter '$param' Default Value

=cut

sub Parameter
{
    my $param = shift;

    return (AAT::Application::Parameter($APPLICATION_NAME, $param));
}

=head2 Status_Progress($bin, $param)

Returns Status Progress line for ProgressBar of program $bin

=cut

sub Status_Progress
{
    my ($bin, $param) = @_;

    my $cache  = Octopussy::Cache::Init($bin);
    my $status = $cache->get("status_$param");

    return ($status);
}

=head2 Sourceforge_Version()

Get version of the last release on Sourceforge

=cut

sub Sourceforge_Version
{
    my $dir_running = Octopussy::FS::Directory('running');
    my $version     = undef;
    AAT::Download::File($APPLICATION_NAME, $SF_SITE,
        "${dir_running}/octopussy.sf_version");
    if (defined open my $UPDATE, '<', "${dir_running}/octopussy.sf_version")
    {
        while (<$UPDATE>)
        {
            $version = $1
                if ($_ =~
/showfiles.php\?group_id=154314&amp;package_id=\d+&amp;release_id=\d+">Octopussy (\S+)<\/a>/
                );
        }
        close $UPDATE;
        unlink "${dir_running}octopussy.sf_version";
    }

    return ($version);
}

=head2 Web_Updates($type)

Downloads Updates from the Web

=cut

sub Web_Updates
{
    my $type = shift;
    my $file = '_' . lc($type) . '.idx';
    my %update;
    my $website     = Octopussy::Info::WebSite();
    my $dir_running = Octopussy::FS::Directory('running');
    AAT::Download::File('Octopussy', "$website/Download/$type/$file",
        "$dir_running$file");
    if (defined open my $UPDATE, '<', "$dir_running$file")
    {
        while (<$UPDATE>) { $update{$1} = $2 if ($_ =~ /^(.+):(\d+)$/); }
        close $UPDATE;
        unlink "$dir_running$file";
    }

    return (\%update);
}

=head2 Create_Fifo($fifo)

Creates Fifo '$fifo'

=cut

sub Create_Fifo
{
    my $fifo = shift;

    if (!-p $fifo)
    {
        my ($file, $dir, $suffix) = fileparse($fifo);
        Octopussy::FS::Create_Directory($dir);
        mkfifo($fifo, '0700');
        Octopussy::FS::Chown($fifo);
    }

    return ($fifo);
}

=head2 PID_File

Returns PID File

=cut

sub PID_File
{
    my $name = shift;

    my $dir_pid  = Octopussy::FS::Directory('running');
    my $file_pid = $dir_pid . $name . '.pid';
    my $user     = Octopussy::Info::User();

    my $line = `id $user`;
    if ($line =~ /uid=(\d+)\($user\) gid=(\d+)\($user\)/)
    {
        my ($uid, $gid) = ($1, $2);
        my @attr = stat $file_pid;

        if ((-f $file_pid)
            && (   ($uid != $attr[$IDX_STAT_UID])
                || ($gid != $attr[$IDX_STAT_GID])))
        {
            AAT::Syslog::Message('octopussy',
                "ERROR: pid file '$file_pid' doesn't match octopussy uid/gid !"
            );
        }
        else
        {
            return (undef)
                if (Proc::PID::File->running(dir => $dir_pid, name => $name));
        }
    }

    return ($file_pid);
}

=head2 PID_Value

=cut

sub PID_Value
{
    my $file  = shift;
    my $value = undef;

    if (defined open my $F_PID, '<', $file)
    {
        $value = <$F_PID>;
        chomp $value;
        close $F_PID;
    }

    return ($value);
}

=head2 Dialog($id)

Returns Dialog properties for the Dialog '$id'

=cut

sub Dialog
{
    my $id = shift;

    my $conf = AAT::XML::Read(Octopussy::FS::File('dialogs'));
    foreach my $d (ARRAY($conf->{dialog}))
    {
        return ($d) if ($d->{d_id} eq $id);
    }

    return (undef);
}

=head2 Process_Status()

Returns Status of Processes syslog-ng, dispatcher & scheduler

=cut

sub Process_Status
{
    my %result = ();

    my @syslogng_lines = `ps -edf | grep "syslog-ng" | grep -v grep`;
    my @rsyslog_lines  = `ps -edf | grep "rsyslog" | grep -v grep`;

    if (scalar(@syslogng_lines) > scalar(@rsyslog_lines))
    {
        $result{"Syslog-ng"} = scalar(@syslogng_lines);
    }
    else
    {
        $result{'Rsyslog'} = scalar @rsyslog_lines;
    }

    my @lines = `ps -edf | grep "/usr/sbin/octo_dispatcher" | grep -v grep`;
    $result{'Dispatcher'} = scalar @lines;
    @lines = `ps -edf | grep "/usr/sbin/octo_scheduler" | grep -v grep`;
    $result{'Scheduler'} = scalar @lines;

    return (%result);
}

=head2 Timestamp_Version($conf)

Returns timestamp => yyyymmddxxxx

=cut

sub Timestamp_Version
{
    my $conf = shift;
    my $date = strftime("%Y%m%d", localtime);

    my $version = 1;
    if (NOT_NULL($conf->{version})
        && ($conf->{version} =~ /^$date(\d{4})/))
    {
        $version = $1 + 1;
    }
    $version = sprintf("%04d", $version);

    return ("$date$version");
}

=head2 Updates_Installation(@updates)

Installs Updates

=cut

sub Updates_Installation
{
    my @updates  = @_;
    my $web      = Octopussy::Info::WebSite();
    my $dir_main = Octopussy::FS::Directory('main');

    foreach my $u (@updates)
    {
        AAT::Download::File('Octopussy', "$web/Download/System/$u.xml",
            "$dir_main/$u.xml");
    }

    return (1);
}

=head2 Waiting_For_Process_Already_Running($prog_name, $device)

Waits (max 10 secs) for already running process to stop

=cut

sub Waiting_For_Process_Already_Running
{
    my ($prog_name, $device) = @_;

    my $file_pid = PID_File("${prog_name}_${device}");
    my $count    = 0;
    while ((!defined $file_pid) && ($count < 10))
    {    # wait 10 secs max that old parser stops
        sleep 1;
        $count++;
        $file_pid = PID_File("${prog_name}_${device}");
    }
    if (!defined $file_pid)
    {
        Die($prog_name,
            "[CRITICAL] Parsing $device - Process already running !");
    }
}

1;

=head1 AUTHOR

Sebastien Thebert <octo.devel@gmail.com>

=cut