"Fossies" - the Fresh Open Source Software Archive

Member "OCSNG_UNIX_SERVER_2.6/Apache/Ocsinventory/Server/Capacities/Download.pm" (17 Apr 2019, 19370 Bytes) of package /linux/privat/OCSNG_UNIX_SERVER_2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 ###############################################################################
    2 ## Copyright 2005-2016 OCSInventory-NG/OCSInventory-Server contributors.
    3 ## See the Contributors file for more details about them.
    4 ## 
    5 ## This file is part of OCSInventory-NG/OCSInventory-ocsreports.
    6 ##
    7 ## OCSInventory-NG/OCSInventory-Server is free software: you can redistribute
    8 ## it and/or modify it under the terms of the GNU General Public License as
    9 ## published by the Free Software Foundation, either version 2 of the License,
   10 ## or (at your option) any later version.
   11 ##
   12 ## OCSInventory-NG/OCSInventory-Server is distributed in the hope that it
   13 ## will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   14 ## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15 ## GNU General Public License for more details.
   16 ##
   17 ## You should have received a copy of the GNU General Public License
   18 ## along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
   19 ## Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   20 ## MA 02110-1301, USA.
   21 ################################################################################
   22 package Apache::Ocsinventory::Server::Capacities::Download;
   23 
   24 use strict;
   25 
   26 BEGIN{
   27   if($ENV{'OCS_MODPERL_VERSION'} == 1){
   28     require Apache::Ocsinventory::Server::Modperl1;
   29     Apache::Ocsinventory::Server::Modperl1->import();
   30   }elsif($ENV{'OCS_MODPERL_VERSION'} == 2){
   31     require Apache::Ocsinventory::Server::Modperl2;
   32     Apache::Ocsinventory::Server::Modperl2->import();
   33   }
   34 }
   35 
   36 use Apache::Ocsinventory::Server::System;
   37 use Apache::Ocsinventory::Server::Communication;
   38 use Apache::Ocsinventory::Server::Constants;
   39 use Apache::Ocsinventory::Server::Capacities::Download::Inventory;
   40 
   41 # Initialize option
   42 push @{$Apache::Ocsinventory::OPTIONS_STRUCTURE},{
   43   'NAME' => 'DOWNLOAD',
   44   'HANDLER_PROLOG_READ' => undef,
   45   'HANDLER_PROLOG_RESP' => \&download_prolog_resp,
   46   'HANDLER_PRE_INVENTORY' => undef,
   47   'HANDLER_POST_INVENTORY' => \&download_post_inventory,
   48   'REQUEST_NAME' => 'DOWNLOAD',
   49   'HANDLER_REQUEST' => \&download_handler,
   50   'HANDLER_DUPLICATE' => \&download_duplicate,
   51   'TYPE' => OPTION_TYPE_ASYNC,
   52   'XML_PARSER_OPT' => {
   53       'ForceArray' => ['PACKAGE']
   54   }
   55 };
   56 
   57 sub download_prolog_resp{
   58   
   59   my $current_context = shift;
   60   my $resp = shift;
   61 
   62   my $dbh = $current_context->{'DBI_HANDLE'};
   63   my $groups = $current_context->{'MEMBER_OF'};
   64   my $hardware_id = $current_context->{'DATABASE_ID'};
   65   
   66   my $groupsParams = $current_context->{'PARAMS_G'};
   67   my ( $downloadSwitch, $cycleLatency, $fragLatency, $periodLatency, $periodLength, $timeout,$execTimeout);
   68   
   69 
   70   my($pack_sql, $hist_sql);
   71   my($pack_req, $hist_req);
   72   my($hist_row, $pack_row);
   73   my(@packages, @history, @forced_packages, @scheduled_packages, @postcmd_packages, @dont_repeat);
   74   my $blacklist;
   75   
   76   if($ENV{'OCS_OPT_DOWNLOAD'}){
   77     $downloadSwitch = 1;
   78     # Group's parameters
   79     for(keys(%$groupsParams)){
   80 
   81       $downloadSwitch = $$groupsParams{$_}->{'DOWNLOAD_SWITCH'}->{'IVALUE'}
   82         if exists( $$groupsParams{$_}->{'DOWNLOAD_SWITCH'}->{'IVALUE'} ) 
   83         and $$groupsParams{$_}->{'DOWNLOAD_SWITCH'}->{'IVALUE'} < $downloadSwitch;
   84       
   85       $cycleLatency = $$groupsParams{$_}->{'DOWNLOAD_CYCLE_LATENCY'}->{'IVALUE'} 
   86         if ( (exists($$groupsParams{$_}->{'DOWNLOAD_CYCLE_LATENCY'}->{'IVALUE'}) 
   87         and $$groupsParams{$_}->{'DOWNLOAD_CYCLE_LATENCY'}->{'IVALUE'} > $cycleLatency)
   88         or !$cycleLatency);
   89       
   90       $fragLatency = $$groupsParams{$_}->{'DOWNLOAD_FRAG_LATENCY'}->{'IVALUE'} 
   91         if ( (exists($$groupsParams{$_}->{'DOWNLOAD_FRAG_LATENCY'}->{'IVALUE'}) 
   92         and $$groupsParams{$_}->{'DOWNLOAD_FRAG_LATENCY'}->{'IVALUE'} > $fragLatency)
   93         or !$fragLatency);
   94       
   95       $periodLatency = $$groupsParams{$_}->{'DOWNLOAD_PERIOD_LATENCY'}->{'IVALUE'} 
   96         if ( (exists($$groupsParams{$_}->{'DOWNLOAD_PERIOD_LATENCY'}->{'IVALUE'}) 
   97         and $$groupsParams{$_}->{'DOWNLOAD_PERIOD_LATENCY'}->{'IVALUE'} > $periodLatency)
   98         or !$periodLatency);
   99 
  100       $periodLength = $$groupsParams{$_}->{'DOWNLOAD_PERIOD_LENGTH'}->{'IVALUE'}
  101         if ( (exists($$groupsParams{$_}->{'DOWNLOAD_PERIOD_LENGTH'}->{'IVALUE'}) 
  102         and $$groupsParams{$_}->{'DOWNLOAD_PERIOD_LENGTH'}->{'IVALUE'} < $periodLength) 
  103         or !$periodLength); 
  104       
  105       $timeout = $$groupsParams{$_}->{'DOWNLOAD_TIMEOUT'}->{'IVALUE'} 
  106         if ( (exists($$groupsParams{$_}->{'DOWNLOAD_TIMEOUT'}->{'IVALUE'}) 
  107         and $$groupsParams{$_}->{'DOWNLOAD_TIMEOUT'}->{'IVALUE'} < $timeout) 
  108         or !$timeout);
  109 
  110       $execTimeout = $$groupsParams{$_}->{'DOWNLOAD_EXECUTION_TIMEOUT'}->{'IVALUE'} 
  111         if ( (exists($$groupsParams{$_}->{'DOWNLOAD_EXECUTION_TIMEOUT'}->{'IVALUE'}) 
  112         and $$groupsParams{$_}->{'DOWNLOAD_EXECUTION_TIMEOUT'}->{'IVALUE'} < $execTimeout) 
  113         or !$execTimeout);
  114     }  
  115   }
  116   else{
  117     $downloadSwitch = 0;
  118   }
  119   
  120   $downloadSwitch = $current_context->{'PARAMS'}{'DOWNLOAD_SWITCH'}->{'IVALUE'} 
  121       if defined($current_context->{'PARAMS'}{'DOWNLOAD_SWITCH'}->{'IVALUE'}) and $downloadSwitch;
  122       
  123   $cycleLatency   = $ENV{'OCS_OPT_DOWNLOAD_CYCLE_LATENCY'} unless $cycleLatency;
  124   $fragLatency   = $ENV{'OCS_OPT_DOWNLOAD_FRAG_LATENCY'} unless $fragLatency;
  125   $periodLatency   = $ENV{'OCS_OPT_DOWNLOAD_PERIOD_LATENCY'} unless $periodLatency;
  126   $periodLength   = $ENV{'OCS_OPT_DOWNLOAD_PERIOD_LENGTH'} unless $periodLength;
  127   $timeout  = $ENV{'OCS_OPT_DOWNLOAD_TIMEOUT'} unless $timeout;
  128   $execTimeout  = $ENV{'OCS_OPT_DOWNLOAD_EXECUTION_TIMEOUT'} unless $execTimeout;
  129   
  130   push @packages,{
  131     'TYPE'       => 'CONF',
  132     'ON'       => $downloadSwitch,
  133     'CYCLE_LATENCY'   => $current_context->{'PARAMS'}{'DOWNLOAD_CYCLE_LATENCY'}->{'IVALUE'}   
  134             || $cycleLatency,
  135     'FRAG_LATENCY'     => $current_context->{'PARAMS'}{'DOWNLOAD_FRAG_LATENCY'}->{'IVALUE'}   
  136             || $fragLatency,
  137     'PERIOD_LATENCY'   => $current_context->{'PARAMS'}{'DOWNLOAD_PERIOD_LATENCY'}->{'IVALUE'} 
  138             || $periodLatency,
  139     'PERIOD_LENGTH'   => $current_context->{'PARAMS'}{'DOWNLOAD_PERIOD_LENGTH'}->{'IVALUE'}   
  140             || $periodLength,
  141     'TIMEOUT'     => $current_context->{'PARAMS'}{'DOWNLOAD_TIMEOUT'}->{'IVALUE'}
  142             || $timeout,
  143     'EXECUTION_TIMEOUT'     => $current_context->{'PARAMS'}{'DOWNLOAD_EXECUTION_TIMEOUT'}->{'IVALUE'}
  144             || $execTimeout
  145   };
  146   
  147   if($downloadSwitch){
  148   
  149     # If this option is set, we send only the needed package to the agent
  150     # Can be a performance issue
  151     # Agents prior to 4.0.3.0 do not send history data
  152     $hist_sql = q {
  153       SELECT PKG_ID
  154       FROM download_history
  155       WHERE HARDWARE_ID=?
  156     };
  157     $hist_req = $dbh->prepare( $hist_sql );
  158     $hist_req->execute( $hardware_id );
  159     
  160     while( $hist_row = $hist_req->fetchrow_hashref ){
  161       push @history, $hist_row->{'PKG_ID'};
  162     }
  163 
  164     #We get scheduled packages affected to the computer 
  165     &get_scheduled_packages($dbh, $hardware_id, \@scheduled_packages);
  166 
  167     #We get scheduled packages affected with a postcmd command 
  168     &get_postcmd_packages($dbh, $hardware_id, \@postcmd_packages);
  169 
  170     #We get packages marked as forced affeted to the computer
  171     &get_forced_packages($dbh, $hardware_id, \@forced_packages);
  172 
  173     #We get packages for groups that computer is member of 
  174     if( $current_context->{'EXIST_FL'} && $ENV{'OCS_OPT_ENABLE_GROUPS'} && @$groups ){
  175       $pack_sql =  q {
  176         SELECT IVALUE,FILEID,INFO_LOC,PACK_LOC,CERT_PATH,CERT_FILE
  177         FROM devices,download_enable
  178         WHERE HARDWARE_ID=? 
  179         AND devices.NAME='DOWNLOAD'
  180         AND download_enable.ID=devices.IVALUE
  181       };
  182 
  183       my $verif_affected = 'SELECT TVALUE FROM devices WHERE HARDWARE_ID=? AND IVALUE=? AND NAME="DOWNLOAD"';
  184       my $trace_event = 'INSERT INTO devices(HARDWARE_ID,NAME,IVALUE,TVALUE) VALUES(?,"DOWNLOAD",?,NULL)';
  185 
  186       $pack_req = $dbh->prepare( $pack_sql );
  187             
  188       for( @$groups ){
  189         $pack_req->execute( $_ );
  190 
  191         #We get scheduled packages affected to the group
  192         &get_scheduled_packages($dbh, $_, \@scheduled_packages);
  193 
  194         #We get packages affected to the group which contain postcmd command
  195         &get_postcmd_packages($dbh, $_, \@postcmd_packages);
  196 
  197         while( $pack_row = $pack_req->fetchrow_hashref ){
  198           my $fileid = $pack_row->{'FILEID'};
  199           my ($schedule, $scheduled_package, $postcmd, $postcmd_package);
  200 
  201           if( (grep /^$fileid$/, @history) or (grep /^$fileid$/, @dont_repeat)){
  202             next;
  203           }
  204 
  205           if( $ENV{'OCS_OPT_DOWNLOAD_GROUPS_TRACE_EVENTS'} ){
  206             # We verify if the package is already traced and not already in history
  207             my $verif_affected_sth = $dbh->prepare($verif_affected);
  208             $verif_affected_sth->execute($hardware_id, $pack_row->{'IVALUE'});
  209             if($verif_affected_sth->rows){
  210               my $verif_affected_row = $verif_affected_sth->fetchrow_hashref();
  211               if($verif_affected_row!~/NULL/ && $verif_affected_row!~/NOTIFIED/){
  212                 $verif_affected_sth->finish();
  213                 # We do not send package if the current state is fed
  214                 next;
  215               }
  216             }
  217             else{
  218               $dbh->do($trace_event, {}, $hardware_id, $pack_row->{'IVALUE'})
  219             }
  220           }
  221 
  222           #We check if package is scheduled 
  223           for $scheduled_package (@scheduled_packages) {
  224             if ( $scheduled_package->{'FILEID'} =~ /^$fileid$/ ) {
  225           $schedule = $scheduled_package->{'SCHEDULE'};
  226           last;
  227             }
  228           }
  229 
  230           #We check if package is affected with a postcmd command
  231           for $postcmd_package (@postcmd_packages) {
  232             if ( $postcmd_package->{'FILEID'} =~ /^$fileid$/ ) {
  233           $postcmd = $postcmd_package->{'POSTCMD'};
  234           last;
  235             }
  236           }
  237           
  238           push @packages,{
  239             'TYPE'       => 'PACK',
  240             'ID'         => $pack_row->{'FILEID'},
  241             'INFO_LOC'   => $pack_row->{'INFO_LOC'},
  242             'PACK_LOC'   => $pack_row->{'PACK_LOC'},
  243             'CERT_PATH'  => $pack_row->{'CERT_PATH'}?$pack_row->{'CERT_PATH'}:'INSTALL_PATH',
  244             'CERT_FILE'  => $pack_row->{'CERT_FILE'}?$pack_row->{'CERT_FILE'}:'INSTALL_PATH',
  245             'SCHEDULE'   => $schedule?$schedule:'',
  246             'POSTCMD'    => $postcmd?$postcmd:'',
  247             'FORCE'      => 0 
  248           };
  249 
  250           push @dont_repeat, $fileid;
  251         }
  252       }
  253     }
  254 
  255     #We get packages for this computer 
  256     $pack_sql =  q {
  257       SELECT ID, FILEID, INFO_LOC, PACK_LOC, CERT_PATH, CERT_FILE, SERVER_ID
  258       FROM devices,download_enable 
  259       WHERE HARDWARE_ID=? 
  260       AND devices.IVALUE=download_enable.ID 
  261       AND devices.NAME='DOWNLOAD'
  262       AND (TVALUE IS NULL OR TVALUE='NOTIFIED')
  263     };
  264 
  265       
  266     $pack_req = $dbh->prepare( $pack_sql );
  267     # Retrieving packages associated to the current device
  268     $pack_req->execute( $hardware_id );
  269     
  270     while($pack_row = $pack_req->fetchrow_hashref()){
  271       my $fileid = $pack_row->{'FILEID'};
  272       my $enable_id = $pack_row->{'ID'};
  273       my $pack_loc = $pack_row->{'PACK_LOC'};
  274       my ($forced, $schedule, $scheduled_package, $postcmd, $postcmd_package);
  275 
  276       #We check if package is scheduled 
  277       for $scheduled_package (@scheduled_packages) {
  278         if ( $scheduled_package->{'FILEID'} == $fileid ) {
  279       $schedule = $scheduled_package->{'SCHEDULE'};
  280       last;
  281         }
  282       }
  283 
  284       #We check if package is affected with a postcmd command
  285       for $postcmd_package (@postcmd_packages) {
  286         if ( $postcmd_package->{'FILEID'} == $fileid ) {
  287       $postcmd = $postcmd_package->{'POSTCMD'};
  288       last;
  289         }
  290       }
  291 
  292       #We check if package is marcked as forced
  293       if ( grep /^$fileid$/, @forced_packages ) {
  294          $forced = 1; 
  295       } else {
  296          $forced = 0;
  297       }
  298 
  299       # If the package is in history, the device will not be notified
  300       # We have to show this behaviour to user. We use the package events.
  301       if ($forced == 0){
  302         if ( grep /^$fileid$/, @history ){
  303           $dbh->do(q{ UPDATE devices SET TVALUE='SUCCESS_ALREADY_IN_HISTORY', COMMENTS=? WHERE NAME='DOWNLOAD' AND HARDWARE_ID=? AND IVALUE=? }, {},  scalar localtime(), $current_context->{'DATABASE_ID'}, $enable_id ) ;
  304           next ;
  305         }
  306       }
  307 
  308       if( grep /^$fileid$/, @dont_repeat){
  309         next;
  310       }
  311       
  312       # Substitude $IP$ with server ipaddress or $NAME with server name
  313       my %substitute = (
  314         '$IP$'   => {'table' => 'hardware', 'field' => 'IPADDR'},
  315         '$NAME$' => {'table' => 'hardware', 'field' => 'NAME'}
  316       );
  317 
  318       for my $motif (keys(%substitute)){
  319         if($pack_loc=~/\Q$motif\E/){
  320           
  321           my( $srvreq, $srvreq_sth, $srvreq_row);
  322           my $field = $substitute{$motif}->{field};
  323           my $table = $substitute{$motif}->{table};
  324 
  325           $srvreq = "select $field from $table where ID=?";
  326           $srvreq_sth = $dbh->prepare($srvreq);
  327           $srvreq_sth->execute($pack_row->{'SERVER_ID'});
  328 
  329           if($srvreq_row=$srvreq_sth->fetchrow_hashref()){
  330             my $template = $srvreq_row->{$field};
  331             $pack_loc =~ s/(.*)\Q$motif\E(.*)/${1}${template}${2}/g;
  332           }
  333           else{
  334             $pack_loc='';
  335           }
  336         }
  337       }
  338 
  339       next if $pack_loc eq '';
  340 
  341       push @packages,{
  342         'TYPE'       => 'PACK',
  343         'ID'         => $pack_row->{'FILEID'},
  344         'INFO_LOC'   => $pack_row->{'INFO_LOC'},
  345         'PACK_LOC'   => $pack_loc,
  346         'CERT_PATH'  => $pack_row->{'CERT_PATH'}?$pack_row->{'CERT_PATH'}:'INSTALL_PATH',
  347         'CERT_FILE'  => $pack_row->{'CERT_FILE'}?$pack_row->{'CERT_FILE'}:'INSTALL_PATH',
  348         'SCHEDULE'   => $schedule?$schedule:'',
  349         'POSTCMD'    => $postcmd?$postcmd:'',
  350         'FORCE'      => $forced
  351       };
  352 
  353       push @dont_repeat, $fileid;
  354     }
  355     $dbh->do(q{ UPDATE devices SET TVALUE='NOTIFIED', COMMENTS=? WHERE NAME='DOWNLOAD' AND HARDWARE_ID=? AND TVALUE IS NULL }
  356     ,{},  scalar localtime(), $current_context->{'DATABASE_ID'} ) if $pack_req->rows;
  357   }
  358 
  359   push @{ $resp->{'OPTION'} },{
  360     'NAME'   => ['DOWNLOAD'],
  361     'PARAM' => \@packages
  362   };
  363     
  364   return 0;
  365 }
  366 
  367 sub download_post_inventory{
  368   my $current_context = shift;
  369   
  370   return if !$ENV{'OCS_OPT_DOWNLOAD'};
  371   
  372   my $dbh = $current_context->{'DBI_HANDLE'};
  373   my $hardwareId = $current_context->{'DATABASE_ID'};
  374   my $result = $current_context->{'XML_ENTRY'}; 
  375     
  376   my @fromXml = get_history_xml( $result );
  377   my @fromDb;
  378   
  379   if( $ENV{OCS_OPT_INVENTORY_WRITE_DIFF} ){
  380     @fromDb = get_history_db( $hardwareId, $dbh );
  381     &update_history_diff( $hardwareId, $dbh, \@fromXml, \@fromDb );
  382   }
  383   else{
  384     &update_history_full( $hardwareId, $dbh, \@fromXml );
  385   }
  386 }
  387 
  388 sub download_handler{
  389   # Initialize data
  390   my $current_context = shift;
  391   
  392   my $dbh    = $current_context->{'DBI_HANDLE'};
  393   my $result  = $current_context->{'XML_ENTRY'};
  394   my $r     = $current_context->{'APACHE_OBJECT'};
  395   my $hardware_id = $current_context->{'DATABASE_ID'};
  396 
  397   my $request;
  398   
  399   $request = $dbh->prepare('
  400     SELECT ID FROM download_enable 
  401     WHERE FILEID=? 
  402     AND ID IN (SELECT IVALUE FROM devices WHERE NAME="download" AND HARDWARE_ID=?)');
  403   $request->execute( $result->{'ID'}, $hardware_id);
  404 
  405   &_log(2001, 'download', "$result->{'ID'}(".($result->{'ERR'}?$result->{'ERR'}:'UNKNOWN_CODE').")");
  406   
  407   if(my $row = $request->fetchrow_hashref()){
  408     $dbh->do('UPDATE devices SET TVALUE=?, COMMENTS=?
  409       WHERE NAME="DOWNLOAD" 
  410       AND HARDWARE_ID=? 
  411       AND IVALUE=?',
  412     {}, $result->{'ERR'}?$result->{'ERR'}:'UNKNOWN_CODE', scalar localtime(), $hardware_id, $row->{'ID'} ) 
  413       or return(APACHE_SERVER_ERROR);
  414     &_set_http_header('content-length', 0, $r);
  415     &_send_http_headers($r);
  416     return(APACHE_OK);
  417   }else{
  418     &_log(2501, 'download', "$result->{'ID'}(".($result->{'ERR'}?$result->{'ERR'}:'UNKNOWN_CODE').")");
  419     &_set_http_header('content-length', 0, $r);
  420     &_send_http_headers($r);
  421     return(APACHE_OK);
  422   }
  423 }
  424 
  425 sub download_duplicate {
  426   my $current_context = shift;
  427   my $device = shift;
  428   
  429   my $dbh = $current_context->{'DBI_HANDLE'};
  430 
  431   # Handle deployment servers
  432   $dbh->do('UPDATE download_enable SET SERVER_ID=? WHERE SERVER_ID=?', {}, $current_context->{'DATABASE_ID'}, $device);
  433   $dbh->do('UPDATE download_servers SET HARDWARE_ID=? WHERE HARDWARE_ID=?', {}, $current_context->{'DATABASE_ID'}, $device);
  434 
  435   # If we encounter problems, it aborts whole replacement
  436   return $dbh->do('DELETE FROM download_history WHERE HARDWARE_ID=?', {}, $device);
  437 }
  438 
  439 
  440 # Subroutine to get packagesmarked as scheduled 
  441 sub get_scheduled_packages {
  442   my ($dbh, $hardware_id, $scheduled_packages) = @_;
  443 
  444   my ($scheduled_sql, $scheduled_req, $scheduled_row, $package, @package_ids);
  445 
  446   $scheduled_sql =  q {
  447     SELECT FILEID,TVALUE 
  448     FROM devices,download_enable 
  449     WHERE HARDWARE_ID=? 
  450     AND devices.IVALUE=download_enable.ID 
  451     AND devices.NAME='DOWNLOAD_SCHEDULE'
  452     AND TVALUE IS NOT NULL
  453   };
  454 
  455   $scheduled_req = $dbh->prepare( $scheduled_sql );
  456   $scheduled_req->execute( $hardware_id );
  457  
  458   for $package (@$scheduled_packages) {
  459       push @package_ids, $package->{'FILEID'}; 
  460   }
  461   
  462   while( $scheduled_row = $scheduled_req->fetchrow_hashref ){
  463     # If package is not already in array (to prevent problems with groups) 
  464     unless ( grep /^$scheduled_row->{'FILEID'}$/, @$scheduled_packages ) {
  465       push @$scheduled_packages, {
  466         'FILEID'     => $scheduled_row->{'FILEID'},
  467         'SCHEDULE'   => $scheduled_row->{'TVALUE'}
  468       };
  469     }
  470   }
  471 }
  472 
  473 # Subroutine to get packagesmarked as forced 
  474 sub get_forced_packages {
  475   my ($dbh, $hardware_id, $forced_packages) = @_;
  476 
  477   my ($forced_sql, $forced_req, $forced_row);
  478 
  479   $forced_sql =  q {
  480     SELECT FILEID 
  481     FROM devices,download_enable 
  482     WHERE HARDWARE_ID=? 
  483     AND devices.IVALUE=download_enable.ID 
  484     AND devices.NAME='DOWNLOAD_FORCE'
  485     AND TVALUE=1
  486   };
  487 
  488   $forced_req = $dbh->prepare( $forced_sql );
  489   $forced_req->execute( $hardware_id );
  490    
  491   while( $forced_row = $forced_req->fetchrow_hashref ){
  492     # If package is not already in array (to prevent problems with groups) 
  493     unless ( grep /^$forced_row->{'FILEID'}$/, @$forced_packages ) {
  494       push @$forced_packages, $forced_row->{'FILEID'};
  495     }
  496   }
  497 }
  498 
  499 
  500 # Subroutine to get packages affected with a postcmd command 
  501 sub get_postcmd_packages {
  502   my ($dbh, $hardware_id, $postcmd_packages) = @_;
  503 
  504   my ($postcmd_sql, $postcmd_req, $postcmd_row, $package, @package_ids);
  505 
  506   $postcmd_sql =  q {
  507     SELECT FILEID,TVALUE 
  508     FROM devices,download_enable 
  509     WHERE HARDWARE_ID=? 
  510     AND devices.IVALUE=download_enable.ID 
  511     AND devices.NAME='DOWNLOAD_POSTCMD'
  512     AND TVALUE IS NOT NULL
  513   };
  514 
  515   $postcmd_req = $dbh->prepare( $postcmd_sql );
  516   $postcmd_req->execute( $hardware_id );
  517  
  518   for $package (@$postcmd_packages) {
  519       push @package_ids, $package->{'FILEID'}; 
  520   }
  521   
  522   while( $postcmd_row = $postcmd_req->fetchrow_hashref ){
  523     # If package is not already in array (to prevent problems with groups) 
  524     unless ( grep /^$postcmd_row->{'FILEID'}$/, @$postcmd_packages ) {
  525       push @$postcmd_packages, {
  526         'FILEID'     => $postcmd_row->{'FILEID'},
  527         'POSTCMD'   => $postcmd_row->{'TVALUE'}
  528       };
  529     }
  530   }
  531 }
  532 
  533 
  534 1;
  535