Skip to content

Commit

Permalink
Fix and update application filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Aug 4, 2024
1 parent 0b87ede commit 5acd1a8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 26 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ Shows information about applications on the client.

Data can be viewed under the Applications tab on the client details page or using the Applications listing view

Configuration
-------------

The inventory module has two settings that can be managed by adding them to the server environment variables or the `.env` file.


#### APPS\_BUNDLEPATH_IGNORELIST

List of bundle-paths to be ignored when processing inventory. The list is processed using regex, examples:

Skip all apps in /System/Library/:
```
APPS_BUNDLEPATH_IGNORELIST='/System/Library/.*'
```

Skip all apps that are contained in an app bundle (Please note that backslashes need to be escaped):
```
APPS_BUNDLEPATH_IGNORELIST='.*\\.app\\/.*\\.app'
```

Defaults:
```
APPS_BUNDLEPATH_IGNORELIST='/System/Library/.*, '/System/Applications/.*', .*/Library/AutoPkg.*, /.DocumentRevisions-V100/.*, /Library/Application Support/Adobe/Uninstall/.*, .*/Library/Application Support/Google/Chrome/Default/Web Applications/.*', '.*/Library/Application Support/Firefox/Profiles/.*.default/storage/default/.*'
```

Table Schema
------
Expand Down
36 changes: 18 additions & 18 deletions applications_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
**/
class Applications_controller extends Module_controller
{

/*** Protect methods with auth! ****/
function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);
}
/*** Protect methods with auth! ****/
function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);
}

/**
* Default method
* @author tuxudo
*
**/
* Default method
* @author tuxudo
*
**/
function index()
{
echo "You've loaded the applications module!";
}
{
echo "You've loaded the applications module!";
}

/**
* Retrieve data in json format for widget
*
Expand All @@ -43,7 +42,7 @@ public function get_32_bit_apps()
$queryobj = new Applications_model();
jsonView($queryobj->query($sql));
}

/**
* Retrieve data in json format
*
Expand All @@ -55,10 +54,11 @@ public function get_data($serial_number = '')

$sql = "SELECT name, path, last_modified, obtained_from, runtime_environment, version, bundle_version, info, signed_by, has64bit
FROM applications
WHERE serial_number = '$serial_number'";
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
AND serial_number = '$serial_number'";

$queryobj = new Applications_model();
jsonView($queryobj->query($sql));
}

} // End class Applications_controller
8 changes: 6 additions & 2 deletions applications_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function __construct($serial='')

$this->serial_number = $serial;
}
// ------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -59,11 +59,15 @@ function process($plist)
);

// List of paths to ignore
$bundlepath_ignorelist = is_array(conf('bundlepath_ignorelist')) ? conf('bundlepath_ignorelist') : array();
configAppendFile(__DIR__ . '/config.php');

// List of paths to ignore
$bundlepath_ignorelist = is_array(conf('apps_bundlepath_ignorelist')) ? conf('apps_bundlepath_ignorelist') : array();
$path_regex = ':^'.implode('|', $bundlepath_ignorelist).'$:';

// Process each app
foreach ($myList as $app) {

// Check if we have a name
if( ! array_key_exists("name", $app)){
continue;
Expand Down
13 changes: 13 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
'apps_bundlepath_ignorelist' => env('APPSBUNDLEPATH_IGNORELIST', [
'/System/Library/.*',
'/System/Applications/.*',
'.*/Library/AutoPkg.*',
'/.DocumentRevisions-V100/.*',
'/Library/Application Support/Adobe/Uninstall/.*',
'.*/Library/Application Support/Google/Chrome/Default/Web Applications/.*',
'.*/Library/Application Support/Firefox/Profiles/.*.default/storage/default/.*',
]),
];
2 changes: 1 addition & 1 deletion migrations/2017_12_24_085405_applications.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function up()
$table->index('has64bit');
});
}

public function down()
{
$capsule = new Capsule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
$table->index('bundle_version');
});
}

public function down()
{
$capsule = new Capsule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function up()
$table->bigInteger('last_modified')->nullable()->change();
});
}

public function down()
{
$capsule = new Capsule();
Expand Down
2 changes: 1 addition & 1 deletion scripts/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def flatten_applications_info(array):
app['has64bit'] = 1
elif item == 'arch_kind':
app['runtime_environment'] = obj[item]
if (obj[item] == 'arch_i64' or obj[item] == 'arch_i32_i64' or obj[item] == 'arch_arm_i64' or obj[item] == 'arch_ios'):
if (obj[item] == 'arch_i64' or obj[item] == 'arch_i32_i64' or obj[item] == 'arch_arm_i64' or obj[item] == 'arch_ios' or obj[item] == 'arch_arm'):
app['has64bit'] = 1

# Sometimes Spotlight doesn't properly get the app version, get that manually
Expand Down
4 changes: 2 additions & 2 deletions views/applications_listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@
var sn=$('td:eq(1)', nRow).html();
var link = mr.getClientDetailLink(name, sn, '#tab_applications-tab');
$('td:eq(0)', nRow).html(link);

// Localize Obtained From
var obtained_from=$('td:eq(6)', nRow).html();
obtained_from = obtained_from == 'unknown' ? i18n.t('unknown') :
obtained_from = obtained_from == 'mac_app_store' ? i18n.t('applications.mac_app_store') :
obtained_from = obtained_from == 'apple' ? "Apple":
(obtained_from === 'identified_developer' ? i18n.t('applications.identified_developer') : obtained_from)
$('td:eq(6)', nRow).html(obtained_from)

// Format date
var event = parseInt($('td:eq(7)', nRow).html());
if (event > 0){
Expand Down

0 comments on commit 5acd1a8

Please sign in to comment.