Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lea9250 committed Nov 21, 2022
0 parents commit c4e7c11
Show file tree
Hide file tree
Showing 12 changed files with 573 additions and 0 deletions.
36 changes: 36 additions & 0 deletions APACHE/Map.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
###############################################################################
## OCSINVENTORY-NG
## Copyleft Léa DROGUET 2022
## Web : http://www.ocsinventory-ng.org
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################

package Apache::Ocsinventory::Plugins::Driveinfos::Map;

use strict;

use Apache::Ocsinventory::Map;
$DATA_MAP{driveinfos} = {
mask => 0,
multi => 1,
auto => 1,
delOnReplace => 1,
sortBy => 'NAME',
writeDiff => 0,
cache => 0,
fields => {
NAME => {},
DRIVELABEL => {},
DRIVELETTER => {},
DRIVETYPE => {},
FILESYSTEM => {},
CAPACITY => {},
FREESPACE => {},

}

};
1;
1 change: 1 addition & 0 deletions APACHE/driveinfos.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PerlModule Apache::Ocsinventory::Plugins::Driveinfos::Map;
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# driveinfos
Retrieve volumes returned by Win32 Volume

Powershell script used by the agent gets drives from win32_logicaldisk (already returned by the agent core) and win32_volume, and compares the outputs.
If entries in win32_volume are not found in win32_logicaldisk output, they are added to the plugin's data.
56 changes: 56 additions & 0 deletions agent/driveinfos.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# script retrieves drives from win32_logicaldisk and win32_volume
# both outputs are compared, if entries in win32_volume are not found in win32_logicaldisk output,
# they are added to returned data
$drives = Get-WmiObject -Class Win32_LogicalDisk | select DeviceID
$volumes = Get-WmiObject Win32_Volume

# both drives and volumes are not empty
if ($drives -and $volumes) {
foreach ($volume in $volumes) {
foreach ($drive in $drives) {
$match = 1
# drive letter does not equal volume letter or drive letter is empty
if ( $drive.DeviceID -eq "" -or $drive.DeviceID -ne $volume.DriveLetter) {
$match = 0
# volume does correspond to a drive
} else {
break
}
}

if ($match -eq 0) {
# translate numeric drive type to string value
switch ($volume.DriveType) {
0 { $driveType = "Unknown" }
1 { $driveType = "No Root Directory" }
2 { $driveType = "Removable Disk" }
3 { $driveType = "Local Disk" }
4 { $driveType = "Network Drive" }
5 { $driveType = "Compact Disc" }
6 { $driveType = "RAM Disk" }
}

# get driveletter
if ($volume.DriveLetter -eq '' -or $volume.Name -match "^[A-Z]:") {
$driveLetter = $Matches.0
} else {
$driveLetter = ""
}


$xml += "<DRIVEINFOS>`n"
$xml += "<NAME>"+ $volume.name +"</NAME>`n"
$xml += "<LABEL>"+ $volume.label +"</LABEL>`n"
$xml += "<DRIVETYPE>"+ $driveType +"</DRIVETYPE>`n"
$xml += "<DRIVELETTER>"+ $driveLetter +"</DRIVELETTER>`n"
$xml += "<FILESYSTEM>"+ $volume.FileSystem +"</FILESYSTEM>`n"
$xml += "<CAPACITY>"+ ($volume.Capacity /1MB) +"</CAPACITY>`n"
$xml += "<FREESPACE>"+ ($volume.FreeSpace /1MB) +"</FREESPACE>`n"
$xml += "</DRIVEINFOS>`n"
}
}
} else {
$xml += "<DRIVEINFOS />"
}
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::WriteLine($xml)
52 changes: 52 additions & 0 deletions cd_driveinfos/cd_driveinfos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
//====================================================================================
// OCS INVENTORY REPORTS
// Copyleft Léa Droguet 2022
// Web: http://www.ocsinventory-ng.org
//
// This code is open source and may be copied and modified as long as the source
// code is always made freely available.
// Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
//====================================================================================

if(AJAX){
parse_str($protectedPost['ocs']['0'], $params);
$protectedPost+=$params;
ob_start();
$ajax = true;
}
else{
$ajax=false;
}
print_item_header($l->g(51000));
if (!isset($protectedPost['SHOW']))
$protectedPost['SHOW'] = 'NOSHOW';
$form_name="driveinfos";
$table_name=$form_name;
$tab_options=$protectedPost;
$tab_options['form_name']=$form_name;
$tab_options['table_name']=$table_name;
echo open_form($form_name);
$list_fields=array( $l->g(51001) => 'name',
$l->g(51002) => 'drivelabel',
$l->g(51003) => 'drivetype',
$l->g(51004) => 'driveletter',
$l->g(51005) => 'filesystem',
$l->g(51006) . ' (MB)' => 'capacity',
$l->g(51007) . ' (MB)' => 'freespace',
);
$list_col_cant_del=$list_fields;
$default_fields= $list_fields;
$sql=prepare_sql_tab($list_fields);
$sql['SQL'] .= "FROM $table_name WHERE (hardware_id=$systemid)";
array_push($sql['ARG'],$systemid);
$tab_options['ARG_SQL']=$sql['ARG'];
$tab_options['ARG_SQL_COUNT']=$systemid;
ajaxtab_entete_fixe($list_fields,$default_fields,$tab_options,$list_col_cant_del);
echo close_form();
if ($ajax){
ob_end_clean();
tab_req($list_fields,$default_fields,$list_col_cant_del,$sql['SQL'],$tab_options);
ob_start();
}
?>
13 changes: 13 additions & 0 deletions hook.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<hookstore>
<hook type="lang">
<value>en_GB</value>
<value>fr_FR</value>
</hook>
<hook type="cdentry">
<identifier>cd_driveinfos</identifier>
<translation>51000</translation>
<category>hardware</category>
<available>driveinfos</available>
</hook>
</hookstore>
12 changes: 12 additions & 0 deletions infos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"displayName" : "Drive Infos",
"author" : ["Léa DROGUET"],
"contributor" : [],
"supportedAgent" : ["Windows"],
"version" : "1.0",
"licence" : "GPLv2",
"description" : {
"fr" : "Remonte les disques récupérés par Win32 Volume",
"en" : "Retrieve drives returned by Win32 Volume"
}
}
43 changes: 43 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* This function is called on installation and is used to create database schema for the plugin
*/
function extension_install_driveinfos()
{
$commonObject = new ExtensionCommon;

// Drop table first
$commonObject -> sqlQuery("DROP TABLE `driveinfos`;");

$commonObject -> sqlQuery("CREATE TABLE `driveinfos` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`HARDWARE_ID` INT(11) NOT NULL,
`NAME` VARCHAR(255) DEFAULT NULL,
`DRIVELABEL` VARCHAR(255) DEFAULT NULL,
`DRIVETYPE` VARCHAR(255) DEFAULT NULL,
`DRIVELETTER` VARCHAR(255) DEFAULT NULL,
`FILESYSTEM` VARCHAR(255) DEFAULT NULL,
`CAPACITY` INTEGER(11) DEFAULT NULL,
`FREESPACE` INTEGER(11) DEFAULT NULL,
PRIMARY KEY (`ID`,`HARDWARE_ID`)
) ENGINE=InnoDB ;");
}

/**
* This function is called on removal and is used to destroy database schema for the plugin
*/
function extension_delete_driveinfos()
{
$commonObject = new ExtensionCommon;
$commonObject -> sqlQuery("DROP TABLE `driveinfos`;");
}

/**
* This function is called on plugin upgrade
*/
function extension_upgrade_driveinfos()
{

}
8 changes: 8 additions & 0 deletions language/en_GB/en_GB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
51000 Drive Information
51001 Name
51002 Label
51003 Drive Type
51004 Drive Letter
51005 File System
51006 Capacity
51007 Free Space
8 changes: 8 additions & 0 deletions language/fr_FR/fr_FR.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
51000 Informations Disques
51001 Nom
51002 Label
51003 Type
51004 Lettre
51005 Sytème de fichiers
51006 Capacité
51007 Espace libre
Binary file added preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c4e7c11

Please sign in to comment.