Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lea9250 committed Feb 26, 2024
0 parents commit 196b8c5
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 0 deletions.
29 changes: 29 additions & 0 deletions APACHE/Map.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
###############################################################################
## OCSINVENTORY-NG
## Copyleft Silvan Raijer 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::Listeningports::Map;

use strict;

use Apache::Ocsinventory::Map;
$DATA_MAP{listeningports} = {
mask => 0,
multi => 1,
auto => 1,
delOnReplace => 1,
sortBy => 'PROCESS',
writeDiff => 0,
cache => 0,
fields => {
PROCESS => {},
PORT => {},
}
};
1;
1 change: 1 addition & 0 deletions APACHE/listeningports.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PerlModule Apache::Ocsinventory::Plugins::Listeningports::Map
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# OCS Inventory Plugin - Listening Ports
Gather Listening ports from NetTCPConnection

Currently Windows are supported.
46 changes: 46 additions & 0 deletions agent/Windows/listeningports.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[CmdletBinding()]
Param (
)

###
# Functions
###
function GenerateXML {
param (
[Parameter(Mandatory=$True)][string]$port,
[Parameter(Mandatory=$True)][string]$process
)

$port = $($($port.subString(0, [System.Math]::Min(255, $port.Length))))
$process = $($($process.subString(0, [System.Math]::Min(255, $process.Length))))

$generateXML += "<LISTENINGPORTS>`n"
$generateXML += "<PORT>"+ $port +"</PORT>`n"
$generateXML += "<PROCESS>"+ $process +"</PROCESS>`n"
$generateXML += "</LISTENINGPORTS>`n"
return $generateXML
}

###
# Core
###
Try {
$xml = ''
write-verbose "[INFO] Gathering listening ports"
$listening_ports = Get-NetTCPConnection -State Listen | Select-Object -Property LocalPort,@{'Name' = 'ProcessName';'Expression'={(Get-Process -Id $_.OwningProcess).Name}} -Unique | Sort-Object -Property LocalPort
foreach ($setting in $listening_ports) {
if ($setting.LocalPort -and $setting.ProcessName) {
$resultXML += $(GenerateXML $($setting.LocalPort) $($setting.ProcessName))
}
}

}
Catch {
write-verbose $Error[0]
}

write-verbose "[INFO] Sending report..."
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
[Console]::WriteLine($resultXML)
write-verbose "[INFO] Done sending report"
write-verbose "[INFO] Exiting"
69 changes: 69 additions & 0 deletions cd_listeningports/cd_listeningports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
###############################################################################
## OCSINVENTORY-NG
## Copyleft Silvan Raijer 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
################################################################################


/**
* This file is used to build a table refering to the plugin and define its
* default columns as well as SQL request.
*/

if (AJAX) {
parse_str($protectedPost['ocs']['0'], $params);
$protectedPost += $params;
ob_start();
$ajax = true;
} else {
$ajax = false;
}


// print a title for the table
print_item_header($l->g(79700));

if (!isset($protectedPost['SHOW'])) {
$protectedPost['SHOW'] = 'NOSHOW';
}

// form details and tab options
$form_name = "listeningports";
$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(
'Process' => 'PROCESS',
'Port' => 'PORT'
);
// columns to include at any time and default columns
$list_col_cant_del = $list_fields;
$default_fields = $list_fields;

// select columns for table display
$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_listeningports</identifier>
<translation>79700</translation>
<category>other</category>
<available>listeningports</available>
</hook>
</hookstore>
13 changes: 13 additions & 0 deletions infos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"displayName" : "Listening Ports",
"author" : ["Antoine ROBIN"],
"contributor" : ["Aaron Johnson"],
"supportedAgent" : ["Windows"],
"version" : "1.0",
"licence" : "GPLv2",
"description" :
{
"en" : "Gather Listening ports",
"fr" : "Liste les ports en écoute"
}
}
44 changes: 44 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* The following functions are used by the extension engine to generate a new table
* for the plugin / destroy it on removal.
*/


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

$commonObject -> sqlQuery(
"CREATE TABLE IF NOT EXISTS `listeningports` (
`ID` INTEGER NOT NULL AUTO_INCREMENT,
`HARDWARE_ID` INTEGER NOT NULL,
`PORT` VARCHAR(255) DEFAULT NULL,
`PROCESS` VARCHAR(255) 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_listeningports()
{
$commonObject = new ExtensionCommon;
$commonObject -> sqlQuery("DROP TABLE IF EXISTS `listeningports`");
}

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

}

?>
1 change: 1 addition & 0 deletions language/en_GB/en_GB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79700 Listening ports
1 change: 1 addition & 0 deletions language/fr_FR/fr_FR.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79700 Port en écoute

0 comments on commit 196b8c5

Please sign in to comment.