Skip to content

Commit

Permalink
Rewrite and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Sep 20, 2024
1 parent d94461b commit 943320a
Show file tree
Hide file tree
Showing 16 changed files with 406 additions and 515 deletions.
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
Homebrew Info module
==============

Gathers and returns information on the client's Homebrew installation. It does not collect information on installed bottles/packages. It can be installed separately from the homebrew module.
Gathers and returns information on the client's Homebrew installation. It does not collect information on installed bottles/packages. It can be installed separately from the `homebrew` module.

Database:
* core_tap_head - varchar(255) - hash of the core tap head
This module requires Homebrew to be installed [https://brew.sh/](https://brew.sh/)

Table Schema
-----
* core_tap_head - varchar(255) - Hash of the core tap head
* core_tap_origin - varchar(255) - URI of the core tap origin
* core_tap_last_commit - varchar(255) - static local time of when brew last checked for updates
* head - varchar(255) - hash of the head
* last_commit - varchar(255) - when brew itself was last updated
* core_tap_last_commit - varchar(255) - Static local time of when brew last checked for updates
* head - varchar(255) - Hash of the head
* last_commit - varchar(255) - When brew itself was last updated
* origin - varchar(255) - Git repo used for origin pulls
* homebrew_bottle_domain - varchar(255) - domain used for making bottles
* homebrew_cellar - varchar(255) - path to cellar
* homebrew_bottle_domain - varchar(255) - Domain used for making bottles
* homebrew_cellar - varchar(255) - Path to cellar
* homebrew_prefix - varchar(255) - Homebrew prefix
* homebrew_repository - varchar(255) - path to Homebrew repository
* homebrew_version - varchar(255) - version of Homebrew currently installed
* homebrew_ruby - varchar(255) - version of Ruby currently used by Homebrew
* command_line_tools - varchar(255) - command line tools version
* cpu - varchar(255) - quick general information about the CPU
* git - varchar(255) - version and path of Git used by brew
* homebrew_repository - varchar(255) - Path to Homebrew repository
* homebrew_version - varchar(255) - Version of Homebrew currently installed
* homebrew_ruby - varchar(255) - Version of Ruby currently used by Homebrew
* command_line_tools - varchar(255) - Command line tools version
* cpu - varchar(255) - Quick general information about the CPU
* git - varchar(255) - Version and path of Git used by brew
* clang - varchar(255) - Clang version
* java - varchar(255) - Java path and version
* perl - varchar(255) - path to perl
* python - varchar(255) - path to Python
* ruby - varchar(255) - path to Ruby
* x11 - varchar(255) - version of X11 installed
* perl - varchar(255) - Path to perl
* python - varchar(255) - Path to Python
* ruby - varchar(255) - Path to Ruby
* x11 - varchar(255) - Version of X11 installed
* xcode - varchar(255) - Xcode version
* macos - varchar(255) - macOS version and type detected by Homebrew
* core_cask_tap - varchar(255) - Cask tap URL
* homebrew_cask_opts - varchar(255) - Homebrew cask options
* homebrew_make_jobs - varchar(255) - Homebrew make jobs count
* rosetta_2 - varchar(255) - Using Rosetta 2

This module requires Homebrew to be installed [https://brew.sh/](https://brew.sh/)

49 changes: 27 additions & 22 deletions homebrew_info_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,45 @@
**/
class Homebrew_info_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
*
**/
function index()
{
echo "You've loaded the homebrew_info module!";
}

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

/**
/**
* Retrieve data in json format
*
**/
public function get_data($serial_number = '')
public function get_tab_data($serial_number = '')
{
// Remove non-serial number characters
$serial_number = preg_replace("/[^A-Za-z0-9_\-]]/", '', $serial_number);

$obj = new View();

if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}

$homebrew_info = new Homebrew_info_model($serial_number);
$obj->view('json', array('msg' => $homebrew_info->rs));
$sql = "SELECT homebrew_version, homebrew_noanalytics_this_run, core_tap_head, core_tap_origin, core_tap_last_commit, core_cask_tap, head, last_commit, origin, homebrew_bottle_domain, homebrew_cellar, homebrew_prefix, homebrew_repository, homebrew_git_config_file, homebrew_ruby, homebrew_cask_opts, homebrew_make_jobs, command_line_tools, cpu, git, clang, curl, java, perl, python, ruby, x11, xcode, macos, rosetta_2
FROM homebrew_info
WHERE serial_number = '$serial_number'";

$queryobj = new Homebrew_info_model();
$homebrew_info_tab = $queryobj->query($sql);
$obj->view('json', array('msg' => current(array('msg' => $homebrew_info_tab[0]))));
}

} // END class Homebrew_info_controller
141 changes: 87 additions & 54 deletions homebrew_info_model.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,68 @@
<?php

use CFPropertyList\CFPropertyList;

class Homebrew_info_model extends \Model {

function __construct($serial='')
{
parent::__construct('id', 'homebrew_info'); //primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial;
$this->rs['core_tap_head'] = '';
$this->rs['core_tap_origin'] = '';
$this->rs['core_tap_last_commit'] = '';
$this->rs['head'] = '';
$this->rs['last_commit'] = '';
$this->rs['origin'] = '';
$this->rs['homebrew_bottle_domain'] = '';
$this->rs['homebrew_cellar'] = '';
$this->rs['homebrew_prefix'] = '';
$this->rs['homebrew_repository'] = '';
$this->rs['homebrew_version'] = '';
$this->rs['homebrew_ruby'] = '';
$this->rs['command_line_tools'] = '';
$this->rs['cpu'] = '';
$this->rs['git'] = '';
$this->rs['clang'] = '';
$this->rs['java'] = '';
$this->rs['perl'] = '';
$this->rs['python'] = '';
$this->rs['ruby'] = '';
$this->rs['x11'] = '';
$this->rs['xcode'] = '';
$this->rs['macos'] = '';
$this->rs['homebrew_git_config_file'] = '';
$this->rs['homebrew_noanalytics_this_run'] = '';
$this->rs['curl'] = '';
function __construct($serial='')
{
parent::__construct('id', 'homebrew_info'); // Primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial;
$this->rs['core_tap_head'] = null;
$this->rs['core_tap_origin'] = null;
$this->rs['core_tap_last_commit'] = null;
$this->rs['head'] = null;
$this->rs['last_commit'] = null;
$this->rs['origin'] = null;
$this->rs['homebrew_bottle_domain'] = null;
$this->rs['homebrew_cellar'] = null;
$this->rs['homebrew_prefix'] = null;
$this->rs['homebrew_repository'] = null;
$this->rs['homebrew_version'] = null;
$this->rs['homebrew_ruby'] = null;
$this->rs['command_line_tools'] = null;
$this->rs['cpu'] = null;
$this->rs['git'] = null;
$this->rs['clang'] = null;
$this->rs['java'] = null;
$this->rs['perl'] = null;
$this->rs['python'] = null;
$this->rs['ruby'] = null;
$this->rs['x11'] = null;
$this->rs['xcode'] = null;
$this->rs['macos'] = null;
$this->rs['homebrew_git_config_file'] = null;
$this->rs['homebrew_noanalytics_this_run'] = null;
$this->rs['curl'] = null;
$this->rs['core_cask_tap'] = null;
$this->rs['homebrew_cask_opts'] = null;
$this->rs['homebrew_make_jobs'] = null;
$this->rs['rosetta_2'] = null;

if ($serial) {
$this->retrieve_record($serial);
}

$this->serial_number = $serial;
}

// ------------------------------------------------------------------------


/**
* Process data sent by postflight
*
* @param string data
* @author tuxudo
**/
function process($json)
{
// Check if data was uploaded
if ( $json ){
$this->serial_number = $serial;
}

// ------------------------------------------------------------------------

/**
* Process data sent by postflight
*
* @param string data
* @author tuxudo
**/
function process($data)
{
// Check if data was uploaded
if (! $data) {
throw new Exception("Error Processing homebrew_info Module Request: No data found", 1);
} else if (substr( $data, 0, 30 ) != '<?xml version="1.0" encoding="' ) { // Else if old style json, process with old json based handler
// Process json into object thingy
$brewinfo = json_decode($json, true);
$brewinfo = json_decode($data, true);

// Translate brew info strings to db fields
$translate = array(
Expand Down Expand Up @@ -88,22 +95,48 @@ function process($json)
);

// Traverse the brew info with translations
foreach ($translate as $search => $field) {
foreach ($translate as $search => $field) {

if (! array_key_exists($search, $brewinfo[0])){
// Skip keys that may not exist and null the value
$this->$field = '';
} else if (! empty($brewinfo[0][$search])) {
$this->$field = null;
} else if (! empty($brewinfo[0][$search])) {
// If key is not empty, save it to the object
$this->$field = $brewinfo[0][$search];
} else if ($brewinfo[0][$search] == "0"){
// Set the value to 0 if it's 0
// Set the value to 0 if it's 0
$this->$field = $brewinfo[0][$search];
} else {
} else {
// Else, null the value
$this->$field = '';
$this->$field = null;
}
}
// Save the info
$this->save();

} else { // Else process with new XML handler

// Process incoming hombrew_info.plist
$parser = new CFPropertyList();
$parser->parse($data, CFPropertyList::FORMAT_XML);
$plist = $parser->toArray();

// Add the serial number to each entry
$plist['serial_number'] = $this->serial_number;

// Delete previous set
$this->deleteWhere('serial_number=?', $this->serial_number);

foreach ($this->rs as $key => $value){
// If key does not exist in $plist, null it
if ( ! array_key_exists($key, $plist) || $plist[$key] == '' && $plist[$key] != '0') {
$this->rs[$key] = null;
// Set the db fields to be the same as those in the plist file
} else {
$this->rs[$key] = $plist[$key];
}
}

// Save the info
$this->save();
}
Expand Down
8 changes: 6 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
"clienttitle": "Homebrew Info",
"core_tap_head": "Core Tap Head",
"core_tap_origin": "Core Tap Origin",
"core_tap_last_commit": "Core Tab Last Commit",
"core_tap_last_commit": "Core Tap Last Commit",
"core_cask_tap": "Core Cask Tap",
"head": "Head",
"last_commit": "Last Commit",
"origin": "Origin",
"homebrew_bottle_domain": "Homebrew Bottle Domain",
"homebrew_cask_opts": "Homebrew Cask Opts",
"homebrew_cellar": "Homebrew Cellar",
"homebrew_make_jobs": "Homebrew Make Jobs",
"homebrew_prefix": "Homebrew Prefix",
"homebrew_repository_short": "Homebrew Repo",
"homebrew_repository": "Homebrew Repository",
"homebrew_version": "Homebrew Version",
"homebrew_ruby": "Homebrew Ruby",
"homebrew_git_config_file": "Homebrew Git Config File",
"homebrew_noanalytics_this_run": "Homebrew Analytics Disabled",
"rosetta_2": "Rosetta 2",
"command_line_tools": "Command Line Tools",
"cpu": "CPU",
"git": "Git",
"curl": "cURL",
"curl": "Curl",
"clang": "Clang",
"java": "Java",
"perl": "Perl",
Expand Down
2 changes: 1 addition & 1 deletion migrations/2017_12_19_193901_homebrew_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function up()
$table->index('curl');
});
}

public function down()
{
$capsule = new Capsule();
Expand Down
31 changes: 31 additions & 0 deletions migrations/2024_09_20_000001_homebrew_info_more.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Capsule\Manager as Capsule;

class HomebrewInfoMore extends Migration
{
private $tableName = 'homebrew_info';

public function up()
{
$capsule = new Capsule();
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->string('core_cask_tap')->nullable();
$table->string('homebrew_cask_opts')->nullable();
$table->string('homebrew_make_jobs')->nullable();
$table->string('rosetta_2')->nullable();
});
}

public function down()
{
$capsule = new Capsule();
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->dropColumn('core_cask_tap');
$table->dropColumn('homebrew_cask_opts');
$table->dropColumn('homebrew_make_jobs');
$table->dropColumn('rosetta_2');
});
}
}
10 changes: 0 additions & 10 deletions provides.php

This file was deleted.

8 changes: 8 additions & 0 deletions provides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
client_tabs:
homebrew_info-tab:
view: homebrew_info_tab
i18n: homebrew_info.clienttitle
listings:
homebrew_info:
view: homebrew_info_listing
i18n: homebrew_info.clienttitle
Loading

0 comments on commit 943320a

Please sign in to comment.