"Fossies" - the Fresh Open Source Software Archive

Member "OCSNG_UNIX_SERVER_2.6/Apache/Ocsinventory/Interface.pm" (17 Apr 2019, 6581 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::Interface;
   23 
   24 use Apache::Ocsinventory::Interface::Internals;
   25 use Apache::Ocsinventory::Interface::Database;
   26 
   27 require Apache::Ocsinventory::Interface::Ipdiscover;
   28 require Apache::Ocsinventory::Interface::Inventory;
   29 require Apache::Ocsinventory::Interface::Config;
   30 require Apache::Ocsinventory::Interface::History;
   31 require Apache::Ocsinventory::Interface::Extensions;
   32 require Apache::Ocsinventory::Interface::Updates;
   33 require Apache::Ocsinventory::Interface::Snmp;
   34 
   35 use strict;
   36 
   37 $ENV{OCS_OPT_WEB_SERVICE_RESULTS_LIMIT} = 100 if !defined $ENV{OCS_OPT_WEB_SERVICE_RESULTS_LIMIT};
   38 
   39 eval{
   40   if( $ENV{OCS_OPT_WEB_SERVICE_PRIV_MODS_CONF} ){
   41     require $ENV{OCS_OPT_WEB_SERVICE_PRIV_MODS_CONF} or die($!);
   42   }
   43 };
   44 if($@){
   45   print STDERR "ocsinventory-server: $@\n";
   46   print STDERR "ocsinventory-server: Can't load $ENV{OCS_OPT_WEB_SERVICE_PRIV_MODS_CONF} - Web service Private extensions will be unavailable\n";
   47 };
   48 
   49 
   50 # ===== ACCESSOR TO COMPUTER'S DATA =====
   51 
   52 sub get_computers_V1{
   53   my $class = shift;
   54 # Xml request
   55   my $request = shift;
   56   return Apache::Ocsinventory::Interface::Inventory::get_computers( $request );
   57 }
   58 
   59 sub delete_computers_by_id_V1{
   60   my $class = shift ;
   61   my @ids = @_ ;
   62   return Apache::Ocsinventory::Interface::Updates::delete_computers_by_id( \@ids );
   63 }
   64 
   65 # ===== CONFIGURATION METHODS =====
   66 
   67 # Read a general config parameter
   68 # If a value is provided, set it to given parameters
   69 # If only a tvalue is given, set ivalue to NULL
   70 sub ocs_config_V1{
   71   my $class = shift;
   72   my ($key, $value) = @_;
   73   
   74   return send_error('BAD_KEY') unless $key =~ /^[_\w]+$/;
   75   
   76   if( defined( $key ) and defined( $value ) ){
   77     $key = decode_xml( $key );
   78     $value = decode_xml( $value );
   79     Apache::Ocsinventory::Interface::Config::ocs_config_write( $key, $value, undef ) if defined($value);
   80   }
   81   return Apache::Ocsinventory::Interface::Config::ocs_config_read( $key, 1 );
   82 }
   83 
   84 sub ocs_config_V2{
   85   my $class = shift;
   86   my ($key, $ivalue, $tvalue) = @_;
   87   
   88   return send_error('BAD_KEY') unless $key =~ /^[_\w]+$/;
   89   
   90   if( defined( $key ) and ( defined( $ivalue) or defined( $tvalue) ) ){
   91     $key = decode_xml( $key );
   92     $ivalue = decode_xml( $ivalue ) if defined $ivalue;
   93     $tvalue = decode_xml( $tvalue ) if defined $tvalue;
   94     my ($error, $result ) = Apache::Ocsinventory::Interface::Config::ocs_config_write( $key, $ivalue, $tvalue );
   95     return $result if $error;
   96   }
   97   return Apache::Ocsinventory::Interface::Config::ocs_config_read( $key, 0 );
   98 }
   99 
  100 # ===== SOFTWARE DICTIONARY =====
  101 
  102 # Get a software dictionary word
  103 sub get_dico_soft_element_V1{
  104   my( $class, $word ) = @_;
  105   $word = decode_xml( $word );
  106   return Apache::Ocsinventory::Interface::Inventory::get_dico_soft_extracted( $word );
  107 }
  108 
  109 # ===== CHECKSUM UPDATE =====
  110 
  111 sub reset_checksum_V1 {
  112   my $class = shift;
  113   my $checksum = shift;
  114   return send_error('BAD_CHECKSUM') unless $checksum =~ /^\d+$/;
  115   for(@_){
  116     return send_error('BAD_ID') unless $_ =~ /^\d+$/;
  117   }
  118   return Apache::Ocsinventory::Interface::Internals::reset_checksum( $checksum, \@_ );
  119 }
  120 
  121 # ===== EVENTS TRACKING =====
  122 
  123 # Get computer's history
  124 sub get_history_V1{
  125   my( $class, $offset ) = @_;
  126   return send_error('BAD_OFFSET') unless $offset =~ /^\d+$/;
  127   return Apache::Ocsinventory::Interface::History::get_history_events( $offset );
  128 }
  129 
  130 # Clear computer's history
  131 sub clear_history_V1{
  132   my( $class, $offset ) = @_;
  133   return send_error('BAD_OFFSET') unless $offset =~ /^\d+$/;
  134   return Apache::Ocsinventory::Interface::History::clear_history_events( $offset );
  135 }
  136 
  137 # ===== IPDISCOVER METHODS =====
  138 
  139 sub get_ipdiscover_devices_V1{
  140   my $class = shift;
  141   my ( $date, $offset, $nInv ) = @_;
  142   $nInv = 0 if !defined $nInv;
  143   return send_error('BAD_DATE') unless $date =~ /^\d{4}-\d{2}-\d{2}(\s\d\d(:\d\d){2})?$/; 
  144   return send_error('BAD_OFFSET') unless $offset =~ /^\d+$/;
  145   return send_error('BAD_THIRD_PARAMETER') unless $nInv =~ /^(?:0|1)$/;
  146   return Apache::Ocsinventory::Interface::Ipdiscover::get_ipdiscover_devices( $date, $offset, $nInv );
  147 }
  148 
  149 sub ipdiscover_tag_V1 {
  150   my $class = shift;
  151   my ( $device, $description, $type, $user ) = @_;
  152   $description = decode_xml( $description );
  153   $type = decode_xml( $type );
  154   $user = decode_xml( $user );
  155   return send_error('BAD_MAC') unless $device =~ /^\w\w(.\w\w){5}$/;
  156   return Apache::Ocsinventory::Interface::Ipdiscover::ipdiscover_tag( $device, $description, $type, $user );
  157 }
  158 
  159 sub ipdiscover_untag_V1{
  160   my $class = shift;
  161   my $device = shift;
  162   return send_error('BAD_MAC') unless $device =~ /^\w\w(.\w\w){5}$/;
  163   return Apache::Ocsinventory::Interface::Ipdiscover::ipdiscover_untag( $device );
  164 }
  165 
  166 sub ipdiscover_remove_V1{
  167   my $class = shift;
  168   my $device = shift;
  169   return send_error('BAD_MAC') unless $device =~ /^\w\w(.\w\w){5}$/;
  170   return Apache::Ocsinventory::Interface::Ipdiscover::ipdiscover_remove( $device );
  171 }
  172 
  173 sub ipdiscover_create_type_V1{
  174   my $class = shift;
  175   my $type = shift;
  176   $type = decode_xml( $type );
  177   return Apache::Ocsinventory::Interface::Ipdiscover::ipdiscover_add_type( $type );
  178 }
  179 
  180 sub ipdiscover_delete_type_V1{
  181   my $class = shift;
  182   my $type = shift;
  183   $type = decode_xml( $type );
  184   return Apache::Ocsinventory::Interface::Ipdiscover::ipdiscover_del_type( $type );
  185 }
  186 
  187 # ===== ACCESSOR TO SNMP DATA =====
  188 
  189 sub get_snmp_V1{
  190   my $class = shift;
  191 # Xml request
  192   my $request = shift;
  193   return Apache::Ocsinventory::Interface::Snmp::get_snmp( $request );
  194 }
  195 
  196 
  197 1;