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
|
###############################################################################
## Copyright 2005-2016 OCSInventory-NG/OCSInventory-Server contributors.
## See the Contributors file for more details about them.
##
## This file is part of OCSInventory-NG/OCSInventory-ocsreports.
##
## OCSInventory-NG/OCSInventory-Server is free software: you can redistribute
## it and/or modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation, either version 2 of the License,
## or (at your option) any later version.
##
## OCSInventory-NG/OCSInventory-Server is distributed in the hope that it
## will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
## Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
## MA 02110-1301, USA.
################################################################################
package Apache::Ocsinventory::Plugins::Modules;
use SOAP::Lite;
use strict;
use LWP::Simple;
use Archive::Zip;
use File::Copy;
use File::Path;
use DBI;
sub InstallPlugins {
my $pluginName = $_[1];
# Download the created archive from the ocsreports which contain the communication server code (.conf and map.pm)
my $url = "http://$ENV{OCS_DB_HOST}/ocsreports/upload/$pluginName.zip";
my $file = "$ENV{OCS_PLUGINS_CONF_DIR}/$pluginName.zip";
our $result;
our $perm = 1;
#Up case plugin directory in OCS server for match with actual template
our $pluginNameUc = ucfirst($pluginName);
if (-e "$ENV{OCS_PLUGINS_CONF_DIR}/$pluginName.conf") {
$result = "Err_01";
}
elsif(-e "$ENV{OCS_PLUGINS_PERL_DIR}/Apache/Ocsinventory/Plugins/$pluginNameUc"){
$result = "Err_05";
}
else
{
my $status = getstore($url, $file);
# If download succes, unzip, create dir, move files.
if (is_success($status))
{
# Check for write perm in plugins dir
if(!(-w "$ENV{OCS_PLUGINS_CONF_DIR}"))
{
$result = "Err_03";
$perm = 0;
}
# Check for write perm in perl dir
if(!(-w "$ENV{OCS_PLUGINS_PERL_DIR}/Apache/Ocsinventory/Plugins"))
{
$result = "Err_04";
$perm = 0;
}
if($perm){
my $pluginsdir = "$ENV{OCS_PLUGINS_CONF_DIR}";
my $zipname = $file;
my $destinationDirectory = $pluginsdir;
my $zip = Archive::Zip->new($zipname);
my $member;
foreach my $member ($zip->members)
{
next if $member->isDirectory;
(my $extractName = $member->fileName) =~ s{.*/}{};
$member->extractToFileNamed("$destinationDirectory/$extractName");
}
my $dirtocreate = "$ENV{OCS_PLUGINS_PERL_DIR}/Apache/Ocsinventory/Plugins/$pluginNameUc";
mkdir $dirtocreate;
unlink $file;
move("$pluginsdir/Map.pm","$ENV{OCS_PLUGINS_PERL_DIR}/Apache/Ocsinventory/Plugins/$pluginNameUc/Map.pm");
$result = "Install_OK";
}
}else{
$result = "Err_02";
}
}
return( SOAP::Data->name( 'Result' => $result )->type( 'string' ) );
}
# Seek for deleted plugins // Delete map.pm and conf entry.
sub DeletePlugins {
my $pluginName = $_[1];
#Up case plugin directory in OCS server for match with actual template for deletion
my $pluginNameUc = ucfirst($pluginName);
my $pluginsdir = "$ENV{OCS_PLUGINS_CONF_DIR}";
if (-e "$ENV{OCS_PLUGINS_CONF_DIR}/$pluginName.conf"){
unlink "$ENV{OCS_PLUGINS_CONF_DIR}/$pluginName.conf";
}
if($pluginNameUc != ""){
my $dirToDel = "$ENV{OCS_PLUGINS_PERL_DIR}/Apache/Ocsinventory/Plugins/$pluginNameUc";
rmtree($dirToDel);
}
my $result = "Delete_OK";
return( SOAP::Data->name( 'Result' => $result )->type( 'string' ) );
}
1;
|