From ac8c81028bfccc0e7b1ebfaf7ab38a3dba04a00b Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Mon, 26 Sep 2022 16:58:42 +0200 Subject: [PATCH 01/92] Moving to Eloquent --- kandji_model.php | 83 +++++++++++--------------------------------- kandji_processor.php | 27 ++++++++++++++ 2 files changed, 47 insertions(+), 63 deletions(-) create mode 100644 kandji_processor.php diff --git a/kandji_model.php b/kandji_model.php index 36cadbc..b34f09c 100755 --- a/kandji_model.php +++ b/kandji_model.php @@ -1,68 +1,25 @@ rs['id'] = ''; - $this->rs['serial_number'] = $serial; - $this->rs['kandji_id'] = 0; - $this->rs['name'] = ''; - $this->rs['kandji_agent_version'] = ''; - $this->rs['asset_tag'] = ''; - $this->rs['last_check_in'] = 0; - $this->rs['last_enrollment'] = 0; - $this->rs['first_enrollment'] = 0; - $this->rs['blueprint_id'] = ''; - $this->rs['blueprint_name'] = ''; - $this->rs['realname'] = ''; - $this->rs['email_address'] = ''; - +use munkireport\models\MRModel as Eloquent; - if ($serial) { - $this->retrieve_record($serial); - } - - $this->serial_number = $serial; - - $this->module_dir = dirname(__FILE__); - - // Add local config - configAppendFile(__DIR__ . '/config.php'); - } +class Kandji_new_model extends Eloquent +{ + protected $table = 'kandji_new'; - /** - * Get Kandji data - * - * @return void - * @author jc0b - **/ - public function run_kandji_stats() - { - // Check if we should enable Kandji lookup - if (conf('kandji_enable')) { - // Load Kandji helper - require_once($this->module_dir.'/lib/kandji_helper.php'); - $kandji_helper = new munkireport\module\kandji\kandji_helper; - $kandji_helper->pull_kandji_data($this); - // ^^ Comment and uncomment to turn off and on - } - - return $this; - } - - /** - * Process method, is called by the client - * - * @return void - * @author jc0b - **/ - public function process() - { - $this->run_kandji_stats(); - } + protected $hidden = ['id', 'serial_number']; + + protected $fillable = [ + 'serial_number', + 'kandji_id', + 'name', + 'kandji_agent_version', + 'asset_tag', + 'last_check_in', + 'last_enrollment', + 'first_enrollment', + 'blueprint_id', + 'blueprint_name', + 'realname', + 'email_address', + ]; } diff --git a/kandji_processor.php b/kandji_processor.php new file mode 100644 index 0000000..43cec10 --- /dev/null +++ b/kandji_processor.php @@ -0,0 +1,27 @@ + $this->serial_number]; + $module_dir = dirname(__FILE__); + // Check if we should enable Kandji lookup + if (conf('kandji_enable')) { + // Load Kandji helper + require_once($module_dir.'/lib/kandji_helper.php'); + $kandji_helper = new munkireport\module\kandji\kandji_helper; + $kandji_helper->pull_kandji_data($modelData); + // ^^ Comment and uncomment to turn off and on + } + + Kandji_model::updateOrCreate( + ['serial_number' => $this->serial_number], $modelData + ); + + return $this; + } +} \ No newline at end of file From 6637af730a4f5fbc7f4f8c2f863edbb06918d233 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:39:42 +0200 Subject: [PATCH 02/92] Removed references to kandji_new --- kandji_model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kandji_model.php b/kandji_model.php index b34f09c..4b755c3 100755 --- a/kandji_model.php +++ b/kandji_model.php @@ -2,9 +2,9 @@ use munkireport\models\MRModel as Eloquent; -class Kandji_new_model extends Eloquent +class Kandji_model extends Eloquent { - protected $table = 'kandji_new'; + protected $table = 'kandji'; protected $hidden = ['id', 'serial_number']; From d287e702733afeba9509327cdc54e6ae7bd7aee4 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:44:50 +0200 Subject: [PATCH 03/92] Testing last_checkin --- kandji_controller.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index c963a6f..045acba 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -62,18 +62,26 @@ public function get_last_checkin() $week = $currentdate - 604800; $month = $currentdate - 2592000; - $sql = "SELECT COUNT( CASE WHEN ".$month." >= last_check_in THEN 1 END) AS red, - COUNT( CASE WHEN ".$week." >= last_check_in AND last_check_in > ".$month." THEN 1 END) AS yellow, - COUNT( CASE WHEN last_check_in > ".$week." AND last_check_in > 0 THEN 1 END) AS green + $sql = Kandji_model::selectRaw("COUNT( CASE WHEN $month >= last_check_in THEN 1 END) AS red, + COUNT( CASE WHEN $week. >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, + COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green FROM kandji - LEFT JOIN reportdata USING (serial_number) - ".get_machine_group_filter(); - - $queryobj = new Kandji_model(); - foreach($queryobj->query($sql)[0] as $label => $value){ - $out[] = ['label' => $label, 'count' => $value]; - } - jsonView($out); + LEFT JOIN reportdata USING (serial_number)") + ->filter(); + // $sql = "SELECT COUNT( CASE WHEN ".$month." >= last_check_in THEN 1 END) AS red, + // COUNT( CASE WHEN ".$week." >= last_check_in AND last_check_in > ".$month." THEN 1 END) AS yellow, + // COUNT( CASE WHEN last_check_in > ".$week." AND last_check_in > 0 THEN 1 END) AS green + // FROM kandji + // LEFT JOIN reportdata USING (serial_number) + // ".get_machine_group_filter(); + + $obj = new View(); + $obj->view('json', array('msg' => $sql)); + // $queryobj = new Kandji_model(); + // foreach($queryobj->query($sql)[0] as $label => $value){ + // $out[] = ['label' => $label, 'count' => $value]; + // } + // jsonView($out); } /** From 7a81407e24a80180e4a963829c1ea0d6ad099729 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:45:29 +0200 Subject: [PATCH 04/92] Testing last_checkin --- kandji_controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kandji_controller.php b/kandji_controller.php index 045acba..8d5ac55 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -68,6 +68,7 @@ public function get_last_checkin() FROM kandji LEFT JOIN reportdata USING (serial_number)") ->filter(); + ->first(); // $sql = "SELECT COUNT( CASE WHEN ".$month." >= last_check_in THEN 1 END) AS red, // COUNT( CASE WHEN ".$week." >= last_check_in AND last_check_in > ".$month." THEN 1 END) AS yellow, // COUNT( CASE WHEN last_check_in > ".$week." AND last_check_in > 0 THEN 1 END) AS green From 52227deafa9dffa8e4408fa95b1093f2d7d7bab2 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:45:45 +0200 Subject: [PATCH 05/92] Testing last_checkin --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 8d5ac55..1beffe0 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -67,7 +67,7 @@ public function get_last_checkin() COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green FROM kandji LEFT JOIN reportdata USING (serial_number)") - ->filter(); + ->filter() ->first(); // $sql = "SELECT COUNT( CASE WHEN ".$month." >= last_check_in THEN 1 END) AS red, // COUNT( CASE WHEN ".$week." >= last_check_in AND last_check_in > ".$month." THEN 1 END) AS yellow, From 1df8f0fecabf3e54ac1cb90f98d1edda6047ac48 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:46:18 +0200 Subject: [PATCH 06/92] Testing last_checkin --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 1beffe0..57419f0 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -63,7 +63,7 @@ public function get_last_checkin() $month = $currentdate - 2592000; $sql = Kandji_model::selectRaw("COUNT( CASE WHEN $month >= last_check_in THEN 1 END) AS red, - COUNT( CASE WHEN $week. >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, + COUNT( CASE WHEN $week >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green FROM kandji LEFT JOIN reportdata USING (serial_number)") From 802e345eb4e4d699908a11255d5c09e2fd01bf35 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:56:41 +0200 Subject: [PATCH 07/92] Testing last_checkin --- kandji_controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 57419f0..f05de5f 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -62,6 +62,7 @@ public function get_last_checkin() $week = $currentdate - 604800; $month = $currentdate - 2592000; + $checkin_data = Kandji_model::selectRaw("SUM(CASE WHEN last_check_in <= $month THEN 1 END) AS red, SUM(CASE WHEN last_check_in <= $week AND last_check_in > $month THEN 1 END) AS yellow, SUM(CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green")->filter()->first(); $sql = Kandji_model::selectRaw("COUNT( CASE WHEN $month >= last_check_in THEN 1 END) AS red, COUNT( CASE WHEN $week >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green @@ -77,7 +78,7 @@ public function get_last_checkin() // ".get_machine_group_filter(); $obj = new View(); - $obj->view('json', array('msg' => $sql)); + $obj->view('json', array('msg' => $checkin_data)); // $queryobj = new Kandji_model(); // foreach($queryobj->query($sql)[0] as $label => $value){ // $out[] = ['label' => $label, 'count' => $value]; From 23833f38cf7b5b583e32efc4c7491c5e619f99fc Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 14:57:24 +0200 Subject: [PATCH 08/92] Testing last_checkin --- kandji_controller.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index f05de5f..1085a2c 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -63,13 +63,13 @@ public function get_last_checkin() $month = $currentdate - 2592000; $checkin_data = Kandji_model::selectRaw("SUM(CASE WHEN last_check_in <= $month THEN 1 END) AS red, SUM(CASE WHEN last_check_in <= $week AND last_check_in > $month THEN 1 END) AS yellow, SUM(CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green")->filter()->first(); - $sql = Kandji_model::selectRaw("COUNT( CASE WHEN $month >= last_check_in THEN 1 END) AS red, - COUNT( CASE WHEN $week >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, - COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green - FROM kandji - LEFT JOIN reportdata USING (serial_number)") - ->filter() - ->first(); + // $sql = Kandji_model::selectRaw("COUNT( CASE WHEN $month >= last_check_in THEN 1 END) AS red, + // COUNT( CASE WHEN $week >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, + // COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green + // FROM kandji + // LEFT JOIN reportdata USING (serial_number)") + // ->filter() + // ->first(); // $sql = "SELECT COUNT( CASE WHEN ".$month." >= last_check_in THEN 1 END) AS red, // COUNT( CASE WHEN ".$week." >= last_check_in AND last_check_in > ".$month." THEN 1 END) AS yellow, // COUNT( CASE WHEN last_check_in > ".$week." AND last_check_in > 0 THEN 1 END) AS green From 4fe366dac5ff1e8cac282e98933f26cad8669571 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:01:01 +0200 Subject: [PATCH 09/92] Testing last_checkin --- kandji_controller.php | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 1085a2c..134b844 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -58,32 +58,18 @@ public function get_kandji_version() **/ public function get_last_checkin() { - $currentdate = date_timestamp_get(date_create()); - $week = $currentdate - 604800; - $month = $currentdate - 2592000; - - $checkin_data = Kandji_model::selectRaw("SUM(CASE WHEN last_check_in <= $month THEN 1 END) AS red, SUM(CASE WHEN last_check_in <= $week AND last_check_in > $month THEN 1 END) AS yellow, SUM(CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green")->filter()->first(); - // $sql = Kandji_model::selectRaw("COUNT( CASE WHEN $month >= last_check_in THEN 1 END) AS red, - // COUNT( CASE WHEN $week >= last_check_in AND last_check_in > $month THEN 1 END) AS yellow, - // COUNT( CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END) AS green - // FROM kandji - // LEFT JOIN reportdata USING (serial_number)") - // ->filter() - // ->first(); - // $sql = "SELECT COUNT( CASE WHEN ".$month." >= last_check_in THEN 1 END) AS red, - // COUNT( CASE WHEN ".$week." >= last_check_in AND last_check_in > ".$month." THEN 1 END) AS yellow, - // COUNT( CASE WHEN last_check_in > ".$week." AND last_check_in > 0 THEN 1 END) AS green - // FROM kandji - // LEFT JOIN reportdata USING (serial_number) - // ".get_machine_group_filter(); + $currentdate = date_timestamp_get(date_create()); + $week = $currentdate - 604800; + $month = $currentdate - 2592000; + + $checkin_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN last_check_in <= $month THEN 1 END), 0) AS red, + COALESCE(SUM(CASE WHEN last_check_in <= $week AND last_check_in > $month THEN 1 END), 0) AS yellow, + COALESCE(SUM(CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END), 0) AS green") + ->filter() + ->first(); $obj = new View(); $obj->view('json', array('msg' => $checkin_data)); - // $queryobj = new Kandji_model(); - // foreach($queryobj->query($sql)[0] as $label => $value){ - // $out[] = ['label' => $label, 'count' => $value]; - // } - // jsonView($out); } /** From 1180b664d2fca1002febbd2a3780f6ede63b15ff Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:03:34 +0200 Subject: [PATCH 10/92] Testing last_checkin --- kandji_controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 134b844..102534f 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -66,7 +66,8 @@ public function get_last_checkin() COALESCE(SUM(CASE WHEN last_check_in <= $week AND last_check_in > $month THEN 1 END), 0) AS yellow, COALESCE(SUM(CASE WHEN last_check_in > $week AND last_check_in > 0 THEN 1 END), 0) AS green") ->filter() - ->first(); + ->first() + ->toLabelCount(); $obj = new View(); $obj->view('json', array('msg' => $checkin_data)); From 539a4f620dc5a3832775ad9ceb9a4d17c33a09c1 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:07:48 +0200 Subject: [PATCH 11/92] Testing kandji_version --- kandji_controller.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 102534f..9ec78ab 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -38,16 +38,20 @@ public function admin() * @author tuxudo **/ public function get_kandji_version() - { - $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version - FROM kandji - LEFT JOIN reportdata USING (serial_number) - ".get_machine_group_filter()." - GROUP BY kandji_agent_version - ORDER BY count DESC"; + { + $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter(); + // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version + // FROM kandji + // LEFT JOIN reportdata USING (serial_number) + // ".get_machine_group_filter()." + // GROUP BY kandji_agent_version + // ORDER BY count DESC"; + + // $queryobj = new Kandji_model; + // jsonView($queryobj->query($sql)); - $queryobj = new Kandji_model; - jsonView($queryobj->query($sql)); + $obj = new View(); + $obj->view('json', array('msg' => $kandji_version_data)); } From 53c1a9d6ea5b0e0d4bca949c5e37008c13130454 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:16:48 +0200 Subject: [PATCH 12/92] Testing kandji_version --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 9ec78ab..2bf241b 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -39,7 +39,7 @@ public function admin() **/ public function get_kandji_version() { - $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter(); + $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version // FROM kandji // LEFT JOIN reportdata USING (serial_number) From 832e1a57bf0bd372eee66d5cdc96c7417c01820e Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:27:16 +0200 Subject: [PATCH 13/92] Testing kandji_version --- kandji_controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 2bf241b..8ed520e 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -39,7 +39,8 @@ public function admin() **/ public function get_kandji_version() { - $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); + // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); + $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version"); // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version // FROM kandji // LEFT JOIN reportdata USING (serial_number) From a7a79ab1a00bf425b562fad2245a2afeb819aabd Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:27:52 +0200 Subject: [PATCH 14/92] Testing kandji_version --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 8ed520e..a623ff9 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -40,7 +40,7 @@ public function admin() public function get_kandji_version() { // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); - $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version"); + $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version"); // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version // FROM kandji // LEFT JOIN reportdata USING (serial_number) From 3967b65ee4087f42419ae47f9bff2a4c9aed085a Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:29:34 +0200 Subject: [PATCH 15/92] Testing kandji_version --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index a623ff9..12017b7 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -40,7 +40,7 @@ public function admin() public function get_kandji_version() { // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); - $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version"); + $kandji_version_data = Kandji_model::selectRaw("(COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count), kandji_agent_version"); // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version // FROM kandji // LEFT JOIN reportdata USING (serial_number) From 54f62fa78a513125d185225e5f11f559f3413a01 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:31:14 +0200 Subject: [PATCH 16/92] Testing kandji_version --- kandji_controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 12017b7..2d599e2 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -40,7 +40,7 @@ public function admin() public function get_kandji_version() { // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); - $kandji_version_data = Kandji_model::selectRaw("(COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count), kandji_agent_version"); + $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version"); // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version // FROM kandji // LEFT JOIN reportdata USING (serial_number) @@ -50,7 +50,7 @@ public function get_kandji_version() // $queryobj = new Kandji_model; // jsonView($queryobj->query($sql)); - + echo $kandji_version_data $obj = new View(); $obj->view('json', array('msg' => $kandji_version_data)); } From 314864bea55c8be1438225324515549e3f57dffd Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:34:37 +0200 Subject: [PATCH 17/92] Testing kandji_version --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 2d599e2..173d81f 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -40,7 +40,7 @@ public function admin() public function get_kandji_version() { // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); - $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version"); + $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc')->get()->toArray(); // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version // FROM kandji // LEFT JOIN reportdata USING (serial_number) From c4f648277a904438af2665e656b80154ccea8022 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:35:06 +0200 Subject: [PATCH 18/92] Testing kandji_version --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 173d81f..8352054 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -50,7 +50,7 @@ public function get_kandji_version() // $queryobj = new Kandji_model; // jsonView($queryobj->query($sql)); - echo $kandji_version_data + echo $kandji_version_data; $obj = new View(); $obj->view('json', array('msg' => $kandji_version_data)); } From 7eb97f69c297e30f21d7a0f90f321eb35b57da6f Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 15:35:42 +0200 Subject: [PATCH 19/92] Testing kandji_version --- kandji_controller.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 8352054..4c13416 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -41,16 +41,6 @@ public function get_kandji_version() { // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc')->get()->toArray(); - // $sql = "SELECT COUNT(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END) AS count, kandji_agent_version - // FROM kandji - // LEFT JOIN reportdata USING (serial_number) - // ".get_machine_group_filter()." - // GROUP BY kandji_agent_version - // ORDER BY count DESC"; - - // $queryobj = new Kandji_model; - // jsonView($queryobj->query($sql)); - echo $kandji_version_data; $obj = new View(); $obj->view('json', array('msg' => $kandji_version_data)); } From 249aa439c7456dc074b0d1a193e984d8c4a8b864 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:38:21 +0200 Subject: [PATCH 20/92] Messing with the processor and controller --- kandji_controller.php | 56 +++++++++++++++++++++++++++++++------------ kandji_processor.php | 2 +- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 4c13416..c5d757a 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -6,6 +6,9 @@ * @package munkireport * @author jc0b **/ + +use munkireport\module\kandji\kandji_processor as Kandji_processor; + class kandji_controller extends Module_controller { public function __construct() @@ -35,11 +38,10 @@ public function admin() * Get Kandji version for widget * * @return void - * @author tuxudo + * @author jc0b **/ public function get_kandji_version() - { - // $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version <> '' AND kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc'); + { $kandji_version_data = Kandji_model::selectRaw("COALESCE(SUM(CASE WHEN kandji_agent_version IS NOT NULL THEN 1 END), 0) AS count, kandji_agent_version")->filter()->groupBy('kandji_agent_version')->orderBy('count', 'desc')->get()->toArray(); $obj = new View(); $obj->view('json', array('msg' => $kandji_version_data)); @@ -49,7 +51,7 @@ public function get_kandji_version() /** * REST API for retrieving last checkin data for widget * - * @author tuxudo + * @author jc0b **/ public function get_last_checkin() { @@ -81,24 +83,27 @@ public function pull_all_kandji_data($incoming_serial = '') // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ // Get all the serial numbers in an object - $machine = new Kandji_model(); - $filter = get_machine_group_filter(); + // $machine = new Kandji_model(); + // $filter = get_machine_group_filter(); - $sql = "SELECT machine.serial_number - FROM machine - LEFT JOIN reportdata USING (serial_number) - $filter"; + $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number FROM machine")->filter(); + // $sql = "SELECT machine.serial_number + // FROM machine + // LEFT JOIN reportdata USING (serial_number) + // $filter"; // Loop through each serial number for processing $out = array(); - foreach ($machine->query($sql) as $serialobj) { + foreach ($out as $serialobj) { $out[] = $serialobj->serial_number; } - jsonView($out); + $obj = new View(); + $obj->view('json', array('msg' => $out)); } else { - $kandji = new Kandji_model($incoming_serial); - $kandji_status = $kandji->run_kandji_stats(); + $kandji = new Kandji_model(); + $kandji->serial_number = $incoming_serial + $kandji_status = run_kandji_stats($kandji); // Check if machine exists in Kandji if ($kandji_status->rs['kandji_id'] == 0 ){ @@ -106,8 +111,29 @@ public function pull_all_kandji_data($incoming_serial = '') } else { $out = array("serial"=>$incoming_serial,"status"=>"Machine processed"); } - jsonView($out); + $obj = new View(); + $obj->view('json', array('msg' => $out)); + } + } + + /** + * Get Kandji data + * + * @return void + * @author jc0b + **/ + function run_kandji_stats($kandji_model) + { + // Check if we should enable Kandji lookup + if (conf('kandji_enable')) { + // Load Kandji helper + require_once($this->module_dir.'/lib/kandji_helper.php'); + $kandji_helper = new munkireport\module\kandji\kandji_helper; + $kandji_helper->pull_kandji_data($kandji_model); + // ^^ Comment and uncomment to turn off and on } + + return $this; } /** diff --git a/kandji_processor.php b/kandji_processor.php index 43cec10..b80753a 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -2,7 +2,7 @@ use munkireport\processors\Processor; -class Kandji_new_processor extends Processor +class Kandji_processor extends Processor { public function run($data) { From 875e4dfcdef69777b70ee686a9d0100d3c2a843b Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:39:39 +0200 Subject: [PATCH 21/92] Fix missing semicolon --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index c5d757a..64d4cc7 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -102,7 +102,7 @@ public function pull_all_kandji_data($incoming_serial = '') } else { $kandji = new Kandji_model(); - $kandji->serial_number = $incoming_serial + $kandji->serial_number = $incoming_serial; $kandji_status = run_kandji_stats($kandji); // Check if machine exists in Kandji From 45d2c1ca34278864b42a2251f85ae0db7d2bb5d6 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:40:08 +0200 Subject: [PATCH 22/92] Add proper call to function --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 64d4cc7..6fd7bfb 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -103,7 +103,7 @@ public function pull_all_kandji_data($incoming_serial = '') $kandji = new Kandji_model(); $kandji->serial_number = $incoming_serial; - $kandji_status = run_kandji_stats($kandji); + $kandji_status = $this->run_kandji_stats($kandji); // Check if machine exists in Kandji if ($kandji_status->rs['kandji_id'] == 0 ){ From 074572c1556ab8432a009a455269f910f30e358b Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:41:22 +0200 Subject: [PATCH 23/92] Fix reference to controller file --- kandji_controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kandji_controller.php b/kandji_controller.php index 6fd7bfb..4c2917a 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -124,6 +124,7 @@ public function pull_all_kandji_data($incoming_serial = '') **/ function run_kandji_stats($kandji_model) { + $module_dir = dirname(__FILE__); // Check if we should enable Kandji lookup if (conf('kandji_enable')) { // Load Kandji helper From 0ee8e8b70716b6cd5f461e765fbe8acb50134525 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:41:51 +0200 Subject: [PATCH 24/92] Fix reference to controller file --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 4c2917a..9b2ee56 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -128,7 +128,7 @@ function run_kandji_stats($kandji_model) // Check if we should enable Kandji lookup if (conf('kandji_enable')) { // Load Kandji helper - require_once($this->module_dir.'/lib/kandji_helper.php'); + require_once($module_dir.'/lib/kandji_helper.php'); $kandji_helper = new munkireport\module\kandji\kandji_helper; $kandji_helper->pull_kandji_data($kandji_model); // ^^ Comment and uncomment to turn off and on From 5417843b6647248e55673e937686f8621c942d09 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:44:24 +0200 Subject: [PATCH 25/92] Fix manual write to db --- lib/kandji_helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index d7ff712..f2b4fc5 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -51,7 +51,9 @@ public function pull_kandji_data(&$Kandji_model) $Kandji_model->email_address = $json[0]->user->email; // Save the data, Protecc the data - $Kandji_model->save(); + Kandji_model::updateOrCreate( + ['serial_number' => $this->serial_number], $Kandji_model + ); $error = 'Kandji data processed'; return $error; } From dcdd03a7a0b298a7167e1688d88faf756d132696 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:46:23 +0200 Subject: [PATCH 26/92] Added reference to Kandji_model --- lib/kandji_helper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index f2b4fc5..c74fda8 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -2,6 +2,8 @@ namespace munkireport\module\kandji; +use munkireport\module\kandji\kandji_model as Kandji_model; + class Kandji_helper { /** From 409f274b4c1d9a3916d5b882368c63c6412a938a Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:49:35 +0200 Subject: [PATCH 27/92] Removing ambiguity around imports of kandji model --- kandji_processor.php | 4 ---- lib/kandji_helper.php | 32 ++++++++++++++++---------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/kandji_processor.php b/kandji_processor.php index b80753a..46d146c 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -18,10 +18,6 @@ public function run($data) // ^^ Comment and uncomment to turn off and on } - Kandji_model::updateOrCreate( - ['serial_number' => $this->serial_number], $modelData - ); - return $this; } } \ No newline at end of file diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index c74fda8..c5629a5 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -2,16 +2,16 @@ namespace munkireport\module\kandji; -use munkireport\module\kandji\kandji_model as Kandji_model; +use munkireport\module\kandji\Kandji_model; class Kandji_helper { /** * - * @param object Kandji model instance + * @param object Kandji machine instance * @author jc0b **/ - public function pull_kandji_data(&$Kandji_model) + public function pull_kandji_data($Kandji_machine) { // Error message $error = ''; @@ -20,7 +20,7 @@ public function pull_kandji_data(&$Kandji_model) $kandji_api_endpoint = rtrim(conf('kandji_api_endpoint'), '/'); // Get computer data from Kandji - $url = "{$kandji_api_endpoint}/api/v1/devices/?serial_number={$Kandji_model->serial_number}"; + $url = "{$kandji_api_endpoint}/api/v1/devices/?serial_number={$Kandji_machine->serial_number}"; $kandji_computer_result = $this->send_kandji_query($url); if(! $kandji_computer_result){ @@ -38,23 +38,23 @@ public function pull_kandji_data(&$Kandji_model) // Transpose Kandji API output into Kandji model // General section - $Kandji_model->kandji_id = $json[0]->device_id; - $Kandji_model->name = $json[0]->device_name; - $Kandji_model->kandji_agent_version = $json[0]->agent_version; - $Kandji_model->asset_tag = $json[0]->asset_tag; - $Kandji_model->blueprint_id = $json[0]->blueprint_id; - $Kandji_model->blueprint_name = $json[0]->blueprint_name; - $Kandji_model->last_check_in = $this->convert_time_to_epoch($json[0]->last_check_in); - $Kandji_model->last_enrollment = $this->convert_time_to_epoch($json[0]->last_enrollment); - $Kandji_model->first_enrollment = $this->convert_time_to_epoch($json[0]->first_enrollment); + $Kandji_machine->kandji_id = $json[0]->device_id; + $Kandji_machine->name = $json[0]->device_name; + $Kandji_machine->kandji_agent_version = $json[0]->agent_version; + $Kandji_machine->asset_tag = $json[0]->asset_tag; + $Kandji_machine->blueprint_id = $json[0]->blueprint_id; + $Kandji_machine->blueprint_name = $json[0]->blueprint_name; + $Kandji_machine->last_check_in = $this->convert_time_to_epoch($json[0]->last_check_in); + $Kandji_machine->last_enrollment = $this->convert_time_to_epoch($json[0]->last_enrollment); + $Kandji_machine->first_enrollment = $this->convert_time_to_epoch($json[0]->first_enrollment); // Location section - $Kandji_model->realname = $json[0]->user->name; - $Kandji_model->email_address = $json[0]->user->email; + $Kandji_machine->realname = $json[0]->user->name; + $Kandji_machine->email_address = $json[0]->user->email; // Save the data, Protecc the data Kandji_model::updateOrCreate( - ['serial_number' => $this->serial_number], $Kandji_model + ['serial_number' => $this->serial_number], $Kandji_machine ); $error = 'Kandji data processed'; return $error; From 7f747e41edea51bb12ce4462564631206448390e Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:52:03 +0200 Subject: [PATCH 28/92] debugging --- lib/kandji_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index c5629a5..19d4d45 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -2,7 +2,7 @@ namespace munkireport\module\kandji; -use munkireport\module\kandji\Kandji_model; +use Kandji_model; class Kandji_helper { From 04d76816cdc2be57fda1dea8d618c065569bf4e3 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:56:17 +0200 Subject: [PATCH 29/92] debugging --- lib/kandji_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index 19d4d45..5989ad6 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -54,7 +54,7 @@ public function pull_kandji_data($Kandji_machine) // Save the data, Protecc the data Kandji_model::updateOrCreate( - ['serial_number' => $this->serial_number], $Kandji_machine + ['serial_number' => $Kandji_machine->serial_number], $Kandji_machine ); $error = 'Kandji data processed'; return $error; From 49a8125e0c84ea07bc145541e46f848e28c39fc6 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:58:00 +0200 Subject: [PATCH 30/92] Add array instead of obj --- lib/kandji_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index 5989ad6..f3cb76d 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -54,7 +54,7 @@ public function pull_kandji_data($Kandji_machine) // Save the data, Protecc the data Kandji_model::updateOrCreate( - ['serial_number' => $Kandji_machine->serial_number], $Kandji_machine + ['serial_number' => $Kandji_machine->serial_number], [$Kandji_machine] ); $error = 'Kandji data processed'; return $error; From 1941a6757510b46dd9e01ea1f0d03d73c50e7d22 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:58:58 +0200 Subject: [PATCH 31/92] Remove rs --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 9b2ee56..a1dd6da 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -106,7 +106,7 @@ public function pull_all_kandji_data($incoming_serial = '') $kandji_status = $this->run_kandji_stats($kandji); // Check if machine exists in Kandji - if ($kandji_status->rs['kandji_id'] == 0 ){ + if ($kandji_status->['kandji_id'] == 0 ){ $out = array("serial"=>$incoming_serial,"status"=>"Machine not found in Kandji!"); } else { $out = array("serial"=>$incoming_serial,"status"=>"Machine processed"); From 9c9aa3a79dca67eb47dabe2cc65332aa917feaec Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 17:59:27 +0200 Subject: [PATCH 32/92] Remove rs --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index a1dd6da..0b88b61 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -106,7 +106,7 @@ public function pull_all_kandji_data($incoming_serial = '') $kandji_status = $this->run_kandji_stats($kandji); // Check if machine exists in Kandji - if ($kandji_status->['kandji_id'] == 0 ){ + if ($kandji_status->kandji_id == 0 ){ $out = array("serial"=>$incoming_serial,"status"=>"Machine not found in Kandji!"); } else { $out = array("serial"=>$incoming_serial,"status"=>"Machine processed"); From 2fa894defc1fc1a0ae2399a42a9c49a3c4bad6ba Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:02:42 +0200 Subject: [PATCH 33/92] Reference kandji object model for updating --- kandji_controller.php | 3 ++- lib/kandji_helper.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 0b88b61..5cc16a3 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -103,6 +103,7 @@ public function pull_all_kandji_data($incoming_serial = '') $kandji = new Kandji_model(); $kandji->serial_number = $incoming_serial; + $kandji->kandji_id = 0; $kandji_status = $this->run_kandji_stats($kandji); // Check if machine exists in Kandji @@ -122,7 +123,7 @@ public function pull_all_kandji_data($incoming_serial = '') * @return void * @author jc0b **/ - function run_kandji_stats($kandji_model) + function run_kandji_stats(&$kandji_model) { $module_dir = dirname(__FILE__); // Check if we should enable Kandji lookup diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index f3cb76d..694f488 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -11,7 +11,7 @@ class Kandji_helper * @param object Kandji machine instance * @author jc0b **/ - public function pull_kandji_data($Kandji_machine) + public function pull_kandji_data(&$Kandji_machine) { // Error message $error = ''; From 4fdba83ae434b32b81f0aa305b7d2f1aa8c197c8 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:03:22 +0200 Subject: [PATCH 34/92] Reference kandji object model for updating --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 5cc16a3..7baa36e 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -107,7 +107,7 @@ public function pull_all_kandji_data($incoming_serial = '') $kandji_status = $this->run_kandji_stats($kandji); // Check if machine exists in Kandji - if ($kandji_status->kandji_id == 0 ){ + if ($kandji->kandji_id == 0 ){ $out = array("serial"=>$incoming_serial,"status"=>"Machine not found in Kandji!"); } else { $out = array("serial"=>$incoming_serial,"status"=>"Machine processed"); From 61a75bcff166f7d323a4335e75742a847afa5cb5 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:09:33 +0200 Subject: [PATCH 35/92] Fix pulling machine data for tab --- kandji_controller.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 7baa36e..6c32890 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -147,8 +147,9 @@ function run_kandji_stats(&$kandji_model) public function recheck_kandji($serial = '') { if (authorized_for_serial($serial)) { - $kandji = new Kandji_model($serial); - $kandji->run_kandji_stats(); + $kandji = new Kandji_model(); + $kandji->serial_number = $incoming_serial; + $this->run_kandji_stats($kandji); } redirect("clients/detail/$serial#tab_kandji-tab"); @@ -160,8 +161,9 @@ public function recheck_kandji($serial = '') * @param string $serial serial number **/ public function get_data($serial_number = '') - { - $kandji = new Kandji_model($serial_number); - jsonView($kandji->rs); + { + $machinedata = Kandji_model::selectRaw("SELECT $serial_number"); + $obj = new View(); + $obj->view('json', array('msg' => $machinedata)); } } // End class kandji_module From 382286eb7d504656b3b304ca8569d07cae14352f Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:10:22 +0200 Subject: [PATCH 36/92] Output to array --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 6c32890..ac6251a 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -162,7 +162,7 @@ public function recheck_kandji($serial = '') **/ public function get_data($serial_number = '') { - $machinedata = Kandji_model::selectRaw("SELECT $serial_number"); + $machinedata = Kandji_model::selectRaw("SELECT $serial_number")->toArray(); $obj = new View(); $obj->view('json', array('msg' => $machinedata)); } From 20eed9f37d26e521b06616ba77cdaf8712d102f6 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:14:40 +0200 Subject: [PATCH 37/92] Hopefully fix get_data --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index ac6251a..73d68f8 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -162,7 +162,7 @@ public function recheck_kandji($serial = '') **/ public function get_data($serial_number = '') { - $machinedata = Kandji_model::selectRaw("SELECT $serial_number")->toArray(); + $machinedata = Kandji_model::select("*")->where("serial_number", $serial_number)->filter()->get()->toArray(); $obj = new View(); $obj->view('json', array('msg' => $machinedata)); } From 412e8b8f04d2dec337ff1bf057f734d79d479dd1 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:15:29 +0200 Subject: [PATCH 38/92] Hopefully fix get_data --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 73d68f8..126916d 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -162,7 +162,7 @@ public function recheck_kandji($serial = '') **/ public function get_data($serial_number = '') { - $machinedata = Kandji_model::select("*")->where("serial_number", $serial_number)->filter()->get()->toArray(); + $machinedata = Kandji_model::select("*")->where("kandji.serial_number", $serial_number)->filter()->get()->toArray(); $obj = new View(); $obj->view('json', array('msg' => $machinedata)); } From f286b4f62def570cad824274410c7bb96714bcb9 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:16:56 +0200 Subject: [PATCH 39/92] not toArray --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 126916d..fc8842c 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -162,7 +162,7 @@ public function recheck_kandji($serial = '') **/ public function get_data($serial_number = '') { - $machinedata = Kandji_model::select("*")->where("kandji.serial_number", $serial_number)->filter()->get()->toArray(); + $machinedata = Kandji_model::select("*")->where("kandji.serial_number", $serial_number)->filter()->get(); $obj = new View(); $obj->view('json', array('msg' => $machinedata)); } From 2c43f4a2306d8a01bcf6b391b15d0ef59e7b4ebc Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:17:28 +0200 Subject: [PATCH 40/92] not toArray --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index fc8842c..7c45c5e 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -164,6 +164,6 @@ public function get_data($serial_number = '') { $machinedata = Kandji_model::select("*")->where("kandji.serial_number", $serial_number)->filter()->get(); $obj = new View(); - $obj->view('json', array('msg' => $machinedata)); + $obj->view('json', array('msg' => $machinedata[0])); } } // End class kandji_module From 3fe5c754c69cfd66e06ab4f81590e7a9d15b655f Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:19:29 +0200 Subject: [PATCH 41/92] limit get_data to kandji table --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 7c45c5e..9320869 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -162,7 +162,7 @@ public function recheck_kandji($serial = '') **/ public function get_data($serial_number = '') { - $machinedata = Kandji_model::select("*")->where("kandji.serial_number", $serial_number)->filter()->get(); + $machinedata = Kandji_model::select("kandji.*")->where("kandji.serial_number", $serial_number)->filter()->get(); $obj = new View(); $obj->view('json', array('msg' => $machinedata[0])); } From efa25130b58b989b4163054aa29ac9d2f335f812 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:21:19 +0200 Subject: [PATCH 42/92] Fix recheck --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 9320869..7ec9109 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -148,7 +148,7 @@ public function recheck_kandji($serial = '') { if (authorized_for_serial($serial)) { $kandji = new Kandji_model(); - $kandji->serial_number = $incoming_serial; + $kandji->serial_number = $serial; $this->run_kandji_stats($kandji); } From 22d8d97fc264b1ade24b6214f4b186cc264912c6 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:23:44 +0200 Subject: [PATCH 43/92] Fix pull_all_kandji_data --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 7ec9109..76615b5 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -94,7 +94,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Loop through each serial number for processing $out = array(); - foreach ($out as $serialobj) { + foreach ($machinedata as $serialobj) { $out[] = $serialobj->serial_number; } $obj = new View(); From 9165740634ae145da166822dfe2dc2c308456a23 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:24:45 +0200 Subject: [PATCH 44/92] Fix pull_all_kandji_data --- kandji_controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 76615b5..c2a58e0 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -86,7 +86,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number FROM machine")->filter(); + $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number FROM machine")->filter()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) @@ -98,7 +98,7 @@ public function pull_all_kandji_data($incoming_serial = '') $out[] = $serialobj->serial_number; } $obj = new View(); - $obj->view('json', array('msg' => $out)); + $obj->view('json', array('msg' => $machinedata)); } else { $kandji = new Kandji_model(); From ea926653582df3aadb907114aa0fd137d52a045e Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:25:20 +0200 Subject: [PATCH 45/92] Fix pull_all_kandji_data --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index c2a58e0..78f18df 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -86,7 +86,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number FROM machine")->filter()->toArray(); + $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number FROM machine")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 1788384454a4ebaa130b44e1c691f9c057fb536c Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:26:02 +0200 Subject: [PATCH 46/92] Fix pull_all_kandji_data --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 78f18df..52bb555 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -86,7 +86,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number FROM machine")->filter()->get()->toArray(); + $machinedata = Kandji_model::select("SELECT machine.serial_number FROM machine")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 72a3a7fe8260b25447e9699b37bec13ff676e302 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 30 Sep 2022 18:30:15 +0200 Subject: [PATCH 47/92] Fix querying machine module --- kandji_controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 52bb555..3bdf43b 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -8,6 +8,7 @@ **/ use munkireport\module\kandji\kandji_processor as Kandji_processor; +use munkireport\module\machine\machine_model as Machine_model; class kandji_controller extends Module_controller { @@ -86,7 +87,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::select("SELECT machine.serial_number FROM machine")->filter()->get()->toArray(); + $machinedata = Machine_model::select("SELECT serial_number")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From af69f542947c5e95ec1bb64c4a79f50dc279c7de Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Mon, 3 Oct 2022 14:48:31 +0200 Subject: [PATCH 48/92] Moved to collect some local data --- kandji_controller.php | 2 +- kandji_processor.php | 1 + scripts/install.sh | 8 ++++---- scripts/kandji | 21 --------------------- scripts/kandji.py | 43 +++++++++++++++++++++++++++++++++++++++++++ scripts/uninstall.sh | 4 ++-- 6 files changed, 51 insertions(+), 28 deletions(-) delete mode 100755 scripts/kandji create mode 100644 scripts/kandji.py diff --git a/kandji_controller.php b/kandji_controller.php index 3bdf43b..5e5180d 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -7,7 +7,7 @@ * @author jc0b **/ -use munkireport\module\kandji\kandji_processor as Kandji_processor; +// use munkireport\module\kandji\kandji_processor as Kandji_processor; use munkireport\module\machine\machine_model as Machine_model; class kandji_controller extends Module_controller diff --git a/kandji_processor.php b/kandji_processor.php index 46d146c..2b9c7fc 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -6,6 +6,7 @@ class Kandji_processor extends Processor { public function run($data) { + echo $data; configAppendFile(__DIR__ . '/config.php'); $modelData = ['serial_number' => $this->serial_number]; $module_dir = dirname(__FILE__); diff --git a/scripts/install.sh b/scripts/install.sh index 42f8019..e0614fb 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -4,19 +4,19 @@ CTL="${BASEURL}index.php?/module/kandji/" # Get the scripts in the proper directories -"${CURL[@]}" "${CTL}get_script/kandji" -o "${MUNKIPATH}preflight.d/kandji" +"${CURL[@]}" "${CTL}get_script/kandji.py" -o "${MUNKIPATH}preflight.d/kandji.py" # Check exit status of curl if [ $? = 0 ]; then # Make executable - chmod a+x "${MUNKIPATH}preflight.d/kandji" + chmod a+x "${MUNKIPATH}preflight.d/kandji.py" # Set preference to include this file in the preflight check - setreportpref "kandji" "${CACHEPATH}kandji.txt" + setreportpref "kandji" "${CACHEPATH}kandji.plist" else echo "Failed to download all required components!" - rm -f "${MUNKIPATH}preflight.d/kandji" + rm -f "${MUNKIPATH}preflight.d/kandji.py" # Signal that we had an error ERR=1 diff --git a/scripts/kandji b/scripts/kandji deleted file mode 100755 index 4d618fc..0000000 --- a/scripts/kandji +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# Trigger MunkiReport server to do a lookup from Kandji - -# Check if Kandji binary is installed -if [ ! -e "/usr/local/bin/kandji" ] && [ ! -e "/Library/Kandji/Kandji Agent.app/Contents/MacOS/kandji-cli" ]; then - echo "The Kandji binary doesn't appear to be installed. Is it enrolled?" - exit 0 -fi - -# Get preference for Kandji checks, if exists -CHECK=$(defaults read /Library/Preferences/MunkiReport KandjiCheck 2>/dev/null) - -# If set to 0, disable automatic Kandji lookups for this machine -if [[ ${CHECK} == "0" ]] ; then - echo "Kandji lookups for this machine are disabled." - exit 0 -else - # Store date in file to trigger Kandji lookup - DIR=$(dirname $0) - date > "$DIR/cache/kandji.txt" -fi diff --git a/scripts/kandji.py b/scripts/kandji.py new file mode 100644 index 0000000..6a7cba3 --- /dev/null +++ b/scripts/kandji.py @@ -0,0 +1,43 @@ +#!/usr/local/munkireport/munkireport-python2 + +import subprocess, re +import os +import sys +import json +import time + +sys.path.insert(0, '/usr/local/munki') +sys.path.insert(0, '/usr/local/munkireport') + +from munkilib import FoundationPlist +from Foundation import CFPreferencesCopyAppValue + +def get_local_kandji_prefs(): + result = dict() + result['blueprint_name'] = CFPreferencesCopyAppValue('AgentVersion', 'io.kandji.Kandji') + result['kandji_agent_version'] = CFPreferencesCopyAppValue('Blueprint', 'io.kandji.Kandji') + result['kandji_id'] = CFPreferencesCopyAppValue('ComputerURL', 'io.kandji.Kandji').split('/')[-1] + +def kandji_report_enabled(): + return CFPreferencesCopyAppValue('KandjiCheck', 'MunkiReport') + +def main(): + """Main""" + + # Set the encoding + reload(sys) + sys.setdefaultencoding('utf8') + + # Get results + if kandji_report_enabled(): + result = get_local_kandji_prefs() + else: + result = dict() + + # Write results to cache + cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__)) + output_plist = os.path.join(cachedir, 'kandji.plist') + FoundationPlist.writePlist(result, output_plist) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 409683b..f5d6fd1 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -1,7 +1,7 @@ #!/bin/bash # Remove kandji script -rm -f "${MUNKIPATH}preflight.d/kandji" +rm -f "${MUNKIPATH}preflight.d/kandji.py" # Remove kandji.txt file -rm -f "${CACHEPATH}kandji.txt" +rm -f "${CACHEPATH}kandji.plist" From 79714698bec08e69da56f466ec4a883deea9a2cd Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 16:59:08 +0200 Subject: [PATCH 49/92] Return result --- scripts/kandji.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/kandji.py b/scripts/kandji.py index 6a7cba3..3b4585b 100644 --- a/scripts/kandji.py +++ b/scripts/kandji.py @@ -17,6 +17,7 @@ def get_local_kandji_prefs(): result['blueprint_name'] = CFPreferencesCopyAppValue('AgentVersion', 'io.kandji.Kandji') result['kandji_agent_version'] = CFPreferencesCopyAppValue('Blueprint', 'io.kandji.Kandji') result['kandji_id'] = CFPreferencesCopyAppValue('ComputerURL', 'io.kandji.Kandji').split('/')[-1] + return result def kandji_report_enabled(): return CFPreferencesCopyAppValue('KandjiCheck', 'MunkiReport') From 78fb52564b9fe177977a0937f6cfcc156f2b65e6 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:10:17 +0200 Subject: [PATCH 50/92] Fix processor --- kandji_processor.php | 15 +++++++++++---- lib/kandji_helper.php | 1 - 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kandji_processor.php b/kandji_processor.php index 2b9c7fc..636e9bf 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -4,18 +4,25 @@ class Kandji_processor extends Processor { - public function run($data) + public function run($plist) { - echo $data; + if ( ! $plist){ + throw new Exception("Error Processing Request: No property list found", 1); + } + echo $plist; configAppendFile(__DIR__ . '/config.php'); - $modelData = ['serial_number' => $this->serial_number]; $module_dir = dirname(__FILE__); // Check if we should enable Kandji lookup + + $parser = new CFPropertyList(); + $parser->parse($plist, CFPropertyList::FORMAT_XML); + $mylist = $parser->toArray(); + if (conf('kandji_enable')) { // Load Kandji helper require_once($module_dir.'/lib/kandji_helper.php'); $kandji_helper = new munkireport\module\kandji\kandji_helper; - $kandji_helper->pull_kandji_data($modelData); + $kandji_helper->pull_kandji_data($mylist); // ^^ Comment and uncomment to turn off and on } diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index 694f488..88f8661 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -40,7 +40,6 @@ public function pull_kandji_data(&$Kandji_machine) // General section $Kandji_machine->kandji_id = $json[0]->device_id; $Kandji_machine->name = $json[0]->device_name; - $Kandji_machine->kandji_agent_version = $json[0]->agent_version; $Kandji_machine->asset_tag = $json[0]->asset_tag; $Kandji_machine->blueprint_id = $json[0]->blueprint_id; $Kandji_machine->blueprint_name = $json[0]->blueprint_name; From e3f945ec5a3ffce6fd07909b6d43e5fb64ffcaa0 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:15:51 +0200 Subject: [PATCH 51/92] Testing processor --- kandji_processor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kandji_processor.php b/kandji_processor.php index 636e9bf..5e4e677 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -6,9 +6,9 @@ class Kandji_processor extends Processor { public function run($plist) { - if ( ! $plist){ - throw new Exception("Error Processing Request: No property list found", 1); - } + // if ( ! $plist){ + // throw new Exception("Error Processing Request: No property list found", 1); + // } echo $plist; configAppendFile(__DIR__ . '/config.php'); $module_dir = dirname(__FILE__); From 57946c1f8b1f2cbb38b3a737eee2e30203beaef3 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:23:56 +0200 Subject: [PATCH 52/92] Swap variable assignment around --- scripts/kandji.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/kandji.py b/scripts/kandji.py index 3b4585b..d092ce0 100644 --- a/scripts/kandji.py +++ b/scripts/kandji.py @@ -14,8 +14,8 @@ def get_local_kandji_prefs(): result = dict() - result['blueprint_name'] = CFPreferencesCopyAppValue('AgentVersion', 'io.kandji.Kandji') - result['kandji_agent_version'] = CFPreferencesCopyAppValue('Blueprint', 'io.kandji.Kandji') + result['kandji_agent_version'] = CFPreferencesCopyAppValue('AgentVersion', 'io.kandji.Kandji') + result['blueprint_name'] = CFPreferencesCopyAppValue('Blueprint', 'io.kandji.Kandji') result['kandji_id'] = CFPreferencesCopyAppValue('ComputerURL', 'io.kandji.Kandji').split('/')[-1] return result From 760cd2faad301772c0996e0fc43b36879a4cc8a3 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:39:55 +0200 Subject: [PATCH 53/92] Add CFPropertyList --- kandji_processor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kandji_processor.php b/kandji_processor.php index 5e4e677..b30d5fe 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -1,5 +1,6 @@ Date: Tue, 4 Oct 2022 17:43:24 +0200 Subject: [PATCH 54/92] Switch to plistlib --- scripts/kandji.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/kandji.py b/scripts/kandji.py index d092ce0..2be700c 100644 --- a/scripts/kandji.py +++ b/scripts/kandji.py @@ -3,13 +3,13 @@ import subprocess, re import os import sys +import plistlib import json import time sys.path.insert(0, '/usr/local/munki') sys.path.insert(0, '/usr/local/munkireport') -from munkilib import FoundationPlist from Foundation import CFPreferencesCopyAppValue def get_local_kandji_prefs(): @@ -38,7 +38,7 @@ def main(): # Write results to cache cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__)) output_plist = os.path.join(cachedir, 'kandji.plist') - FoundationPlist.writePlist(result, output_plist) + plistlib.writePlist(result, output_plist) if __name__ == "__main__": main() \ No newline at end of file From b5df4b61a27b46e3cea8834e11f2d29226520f2d Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:45:51 +0200 Subject: [PATCH 55/92] Create model from plist in processor --- kandji_processor.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kandji_processor.php b/kandji_processor.php index b30d5fe..6631a3d 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -19,11 +19,15 @@ public function run($plist) $parser->parse($plist, CFPropertyList::FORMAT_XML); $mylist = $parser->toArray(); + $model = Kandji_model::firstOrNew(['serial_number' => $this->serial_number]); + + $model->fill($mylist); + if (conf('kandji_enable')) { // Load Kandji helper require_once($module_dir.'/lib/kandji_helper.php'); $kandji_helper = new munkireport\module\kandji\kandji_helper; - $kandji_helper->pull_kandji_data($mylist); + $kandji_helper->pull_kandji_data($model); // ^^ Comment and uncomment to turn off and on } From b6fd018a9139eb8b39c22a61b82cc83b213a140c Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:52:55 +0200 Subject: [PATCH 56/92] Controller fix --- kandji_controller.php | 2 +- kandji_processor.php | 9 ++++----- lib/kandji_helper.php | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 5e5180d..71dfc58 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -87,7 +87,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Machine_model::select("SELECT serial_number")->filter()->get()->toArray(); + $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) diff --git a/kandji_processor.php b/kandji_processor.php index 6631a3d..6304782 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -7,13 +7,11 @@ class Kandji_processor extends Processor { public function run($plist) { - // if ( ! $plist){ - // throw new Exception("Error Processing Request: No property list found", 1); - // } - echo $plist; + if ( ! $plist){ + throw new Exception("Error Processing Request: No property list found", 1); + } configAppendFile(__DIR__ . '/config.php'); $module_dir = dirname(__FILE__); - // Check if we should enable Kandji lookup $parser = new CFPropertyList(); $parser->parse($plist, CFPropertyList::FORMAT_XML); @@ -23,6 +21,7 @@ public function run($plist) $model->fill($mylist); + // Check if we should enable Kandji lookup if (conf('kandji_enable')) { // Load Kandji helper require_once($module_dir.'/lib/kandji_helper.php'); diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index 88f8661..02071a8 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -38,7 +38,6 @@ public function pull_kandji_data(&$Kandji_machine) // Transpose Kandji API output into Kandji model // General section - $Kandji_machine->kandji_id = $json[0]->device_id; $Kandji_machine->name = $json[0]->device_name; $Kandji_machine->asset_tag = $json[0]->asset_tag; $Kandji_machine->blueprint_id = $json[0]->blueprint_id; From f51187ac7c99735f00b54ae45daa615d00076b0c Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:53:32 +0200 Subject: [PATCH 57/92] Controller fix --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 71dfc58..fff64ce 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -87,7 +87,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::selectRaw("SELECT machine.serial_number")->filter()->get()->toArray(); + $machinedata = Kandji_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 9f1f500ed4ab8917679debc0933e47c0a82f5618 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 17:54:33 +0200 Subject: [PATCH 58/92] Controller fix --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index fff64ce..c601db3 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -87,7 +87,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); + $machinedata = Kandji_model::selectRaw("machine.serial_number FROM machine")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From f8f3de4e50f78c5e7d20e33e1c870eb791239bc8 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 18:01:16 +0200 Subject: [PATCH 59/92] Trying something with controller --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index c601db3..80a3409 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -87,7 +87,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Kandji_model::selectRaw("machine.serial_number FROM machine")->filter()->get()->toArray(); + $machinedata = \DB::table('machine')->selectRaw("serial_number")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 34177ce56ce4198986bc17dc42f5874a3c5f368e Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Tue, 4 Oct 2022 18:04:10 +0200 Subject: [PATCH 60/92] Trying something with controller --- kandji_controller.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 80a3409..bfca300 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -10,6 +10,9 @@ // use munkireport\module\kandji\kandji_processor as Kandji_processor; use munkireport\module\machine\machine_model as Machine_model; +use Illuminate\Support\Facades\DB; + + class kandji_controller extends Module_controller { public function __construct() @@ -87,7 +90,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = \DB::table('machine')->selectRaw("serial_number")->filter()->get()->toArray(); + $machinedata = DB::table('machine')->selectRaw("serial_number")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 16a629e176983dab801d20f48f677eea5f8e7295 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 14:53:05 +0200 Subject: [PATCH 61/92] Attempting to get machine info --- kandji_controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index bfca300..9076091 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -8,7 +8,7 @@ **/ // use munkireport\module\kandji\kandji_processor as Kandji_processor; -use munkireport\module\machine\machine_model as Machine_model; +use munkireport\models\MRModel as Eloquent; use Illuminate\Support\Facades\DB; @@ -90,7 +90,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = DB::table('machine')->selectRaw("serial_number")->filter()->get()->toArray(); + $machinedata = Eloquent::table('machine')->selectRaw("serial_number")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 77f25d60cf4c50967d015e9d97334f87a1ce52a5 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 14:55:09 +0200 Subject: [PATCH 62/92] Attempting to get machine info --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 9076091..33419e7 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -90,7 +90,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Eloquent::table('machine')->selectRaw("serial_number")->filter()->get()->toArray(); + $machinedata = Eloquent::selectRaw("serial_number FROM machine")->filter()->get()->toArray(); // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From da6d7bd7d3ddb23f67a9c138d628209160d49a4e Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 14:56:41 +0200 Subject: [PATCH 63/92] Attempting to get machine info --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 33419e7..3ff4a0d 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -8,7 +8,7 @@ **/ // use munkireport\module\kandji\kandji_processor as Kandji_processor; -use munkireport\models\MRModel as Eloquent; +use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Support\Facades\DB; From e46bd994367fd1eccaa54a64d9dc03b0960a5280 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 14:59:59 +0200 Subject: [PATCH 64/92] Attempting to get machine info --- kandji_controller.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 3ff4a0d..3e95a4f 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -6,13 +6,18 @@ * @package munkireport * @author jc0b **/ - +use munkireport\module\machine\Machine_model; // use munkireport\module\kandji\kandji_processor as Kandji_processor; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Support\Facades\DB; +class Temp_machine_model extends Eloquent +{ + protected $table = 'machine'; +} + class kandji_controller extends Module_controller { public function __construct() @@ -90,7 +95,10 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Eloquent::selectRaw("serial_number FROM machine")->filter()->get()->toArray(); + $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); + + $machinedata2 = Temp_machine_model::selectRaw("serial_number")->filter()->get()->toArray(); + echo $machinedata2; // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From bce11bb0f9510e627922c1555a9c2a52f8d59b86 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:00:35 +0200 Subject: [PATCH 65/92] Attempting to get machine info --- kandji_controller.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 3e95a4f..f62f840 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -6,7 +6,7 @@ * @package munkireport * @author jc0b **/ -use munkireport\module\machine\Machine_model; +// use munkireport\module\machine\Machine_model; // use munkireport\module\kandji\kandji_processor as Kandji_processor; use Illuminate\Database\Eloquent\Model as Eloquent; @@ -95,9 +95,9 @@ public function pull_all_kandji_data($incoming_serial = '') // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); - $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); + // $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); - $machinedata2 = Temp_machine_model::selectRaw("serial_number")->filter()->get()->toArray(); + $machinedata = Temp_machine_model::selectRaw("serial_number")->filter()->get()->toArray(); echo $machinedata2; // $sql = "SELECT machine.serial_number // FROM machine From 116eaf892a65d30dbec458720914e21b2b506f42 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:01:45 +0200 Subject: [PATCH 66/92] Attempting to get machine info --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index f62f840..de3dac1 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -8,7 +8,7 @@ **/ // use munkireport\module\machine\Machine_model; // use munkireport\module\kandji\kandji_processor as Kandji_processor; -use Illuminate\Database\Eloquent\Model as Eloquent; +use munkireport\models\MRModel as Eloquent; use Illuminate\Support\Facades\DB; From 82da4e331d0ee7e73f44071f19ae2d8f13c28b4d Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:02:20 +0200 Subject: [PATCH 67/92] Attempting to get machine info --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index de3dac1..e737192 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -97,7 +97,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); - $machinedata = Temp_machine_model::selectRaw("serial_number")->filter()->get()->toArray(); + $machinedata = Temp_machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); echo $machinedata2; // $sql = "SELECT machine.serial_number // FROM machine From e6d570605248710bb39ddaefffc88b69f6c387d2 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:02:43 +0200 Subject: [PATCH 68/92] Attempting to get machine info --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index e737192..1327e87 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -98,7 +98,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); $machinedata = Temp_machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); - echo $machinedata2; + echo $machinedata; // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From 451437a1dc48257228503d727089cfe5a36c6f10 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:03:09 +0200 Subject: [PATCH 69/92] Attempting to get machine info --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 1327e87..7ece24d 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -98,7 +98,7 @@ public function pull_all_kandji_data($incoming_serial = '') // $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); $machinedata = Temp_machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); - echo $machinedata; + // echo $machinedata; // $sql = "SELECT machine.serial_number // FROM machine // LEFT JOIN reportdata USING (serial_number) From ae70926338e341dd0b83017dd187ba33fb4b078f Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:03:53 +0200 Subject: [PATCH 70/92] Troubleshooting --- kandji_controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kandji_controller.php b/kandji_controller.php index 7ece24d..ae82a42 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -107,6 +107,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Loop through each serial number for processing $out = array(); foreach ($machinedata as $serialobj) { + echo $serialobj $out[] = $serialobj->serial_number; } $obj = new View(); From ee977de8c91d583b3b96e28ad4ee67cad4e7fd74 Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:04:14 +0200 Subject: [PATCH 71/92] Troubleshooting --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index ae82a42..5cb8496 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -107,7 +107,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Loop through each serial number for processing $out = array(); foreach ($machinedata as $serialobj) { - echo $serialobj + echo $serialobj; $out[] = $serialobj->serial_number; } $obj = new View(); From ba44df0c6dc79a9ee5dca138973bf5f2c945bf6c Mon Sep 17 00:00:00 2001 From: Jacob Burley Date: Fri, 7 Oct 2022 15:05:46 +0200 Subject: [PATCH 72/92] Troubleshooting --- kandji_controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kandji_controller.php b/kandji_controller.php index 5cb8496..9beebde 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -91,6 +91,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ + echo __NAMESPACE__; // Get all the serial numbers in an object // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); From 1b719782d6062d1129f9d0b7955692ee1c66b193 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:31:40 +0100 Subject: [PATCH 73/92] Use Temp machine model --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 9beebde..464d29a 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -91,7 +91,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ - echo __NAMESPACE__; + require_once('/var/www/munkireport/vendor/munkireport/machine/machine_model.php'); // Get all the serial numbers in an object // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); From fb6d217d172c3885ed58ea4ad6ac72bd613480cd Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:36:25 +0100 Subject: [PATCH 74/92] Fix import --- kandji_controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 464d29a..3091e63 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -91,14 +91,14 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ - require_once('/var/www/munkireport/vendor/munkireport/machine/machine_model.php'); + require_once('/data/munkireport/vendor/munkireport/machine/machine_model.php'); // Get all the serial numbers in an object // $machine = new Kandji_model(); // $filter = get_machine_group_filter(); // $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); - $machinedata = Temp_machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); + $machinedata = Machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); // echo $machinedata; // $sql = "SELECT machine.serial_number // FROM machine From 5e0588630df25cc344a469e37c24358fe2918866 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:39:15 +0100 Subject: [PATCH 75/92] debugging --- kandji_controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kandji_controller.php b/kandji_controller.php index 3091e63..f3b7dbc 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -107,6 +107,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Loop through each serial number for processing $out = array(); + echo $machinedata foreach ($machinedata as $serialobj) { echo $serialobj; $out[] = $serialobj->serial_number; From 88fc0cf5ae9b59c78593611c933378c7087ff96b Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:39:47 +0100 Subject: [PATCH 76/92] debugging --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index f3b7dbc..7df2ca7 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -107,7 +107,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Loop through each serial number for processing $out = array(); - echo $machinedata + echo $machinedata; foreach ($machinedata as $serialobj) { echo $serialobj; $out[] = $serialobj->serial_number; From 5f456e0fff12fd3e2164a9f7f7cdac0229c6845b Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:43:53 +0100 Subject: [PATCH 77/92] debugging --- kandji_controller.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index 7df2ca7..bac5a45 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -107,13 +107,11 @@ public function pull_all_kandji_data($incoming_serial = '') // Loop through each serial number for processing $out = array(); - echo $machinedata; foreach ($machinedata as $serialobj) { - echo $serialobj; - $out[] = $serialobj->serial_number; + $out[] = $serialobj['serial_number']; } $obj = new View(); - $obj->view('json', array('msg' => $machinedata)); + $obj->view('json', array('msg' => $out)); } else { $kandji = new Kandji_model(); From 0324b8942d106d20c267d0813d1160b35e48ee1b Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:50:45 +0100 Subject: [PATCH 78/92] Relative paths --- kandji_controller.php | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/kandji_controller.php b/kandji_controller.php index bac5a45..8118f7d 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -6,18 +6,10 @@ * @package munkireport * @author jc0b **/ -// use munkireport\module\machine\Machine_model; -// use munkireport\module\kandji\kandji_processor as Kandji_processor; use munkireport\models\MRModel as Eloquent; use Illuminate\Support\Facades\DB; - -class Temp_machine_model extends Eloquent -{ - protected $table = 'machine'; -} - class kandji_controller extends Module_controller { public function __construct() @@ -91,20 +83,10 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ - require_once('/data/munkireport/vendor/munkireport/machine/machine_model.php'); + require_once(__DIR__.'../vendor/munkireport/machine/machine_model.php'); // Get all the serial numbers in an object - // $machine = new Kandji_model(); - // $filter = get_machine_group_filter(); - - // $machinedata = Machine_model::selectRaw("serial_number")->filter()->get()->toArray(); $machinedata = Machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); - // echo $machinedata; - // $sql = "SELECT machine.serial_number - // FROM machine - // LEFT JOIN reportdata USING (serial_number) - // $filter"; - // Loop through each serial number for processing $out = array(); foreach ($machinedata as $serialobj) { From 4c9f5b4c37ab75d1a6de780df1baffef3c0d7e8f Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:54:50 +0100 Subject: [PATCH 79/92] Relative paths --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 8118f7d..46b341f 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -83,7 +83,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ - require_once(__DIR__.'../vendor/munkireport/machine/machine_model.php'); + require_once(APP_ROOT.'../vendor/munkireport/machine/machine_model.php'); // Get all the serial numbers in an object $machinedata = Machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); From 31119a006648ef220c84a66d7472b5e8c54ff9c2 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 09:55:10 +0100 Subject: [PATCH 80/92] Relative paths --- kandji_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kandji_controller.php b/kandji_controller.php index 46b341f..41ab496 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -83,7 +83,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ - require_once(APP_ROOT.'../vendor/munkireport/machine/machine_model.php'); + require_once(APP_ROOT.'vendor/munkireport/machine/machine_model.php'); // Get all the serial numbers in an object $machinedata = Machine_model::selectRaw("machine.serial_number")->filter()->get()->toArray(); From b5f31c99de8973048f52e59ebfe8aa562eea17bb Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 10:47:06 +0100 Subject: [PATCH 81/92] Added structure to monitor Passport --- kandji_controller.php | 1 + kandji_model.php | 2 ++ kandji_processor.php | 7 +++++ locales/en.json | 6 ++-- migrations/2022_08_26_000001_kandji.php | 3 ++ scripts/kandji.py | 37 +++++++++++++++++++++---- views/kandji_listing.php | 1 + 7 files changed, 49 insertions(+), 8 deletions(-) mode change 100644 => 100755 scripts/kandji.py diff --git a/kandji_controller.php b/kandji_controller.php index 41ab496..af4f044 100755 --- a/kandji_controller.php +++ b/kandji_controller.php @@ -83,6 +83,7 @@ public function pull_all_kandji_data($incoming_serial = '') // Returns either a list of all serial numbers in MunkiReport OR // a JSON of what serial number was just ran with the status of the run if ( $incoming_serial == ''){ + // APP_ROOT is set in index.php require_once(APP_ROOT.'vendor/munkireport/machine/machine_model.php'); // Get all the serial numbers in an object diff --git a/kandji_model.php b/kandji_model.php index 4b755c3..dc6cbc2 100755 --- a/kandji_model.php +++ b/kandji_model.php @@ -21,5 +21,7 @@ class Kandji_model extends Eloquent 'blueprint_name', 'realname', 'email_address', + 'passport_enabled', + 'passport_users', ]; } diff --git a/kandji_processor.php b/kandji_processor.php index 6304782..b6ed421 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -1,5 +1,12 @@ text('blueprint_name')->nullable(); $table->text('realname')->nullable(); $table->string('email_address')->nullable(); + $table->string('passport_enabled')->nullable(); + $table->string('passport_users')->nullable(); }); // Make the indexes @@ -35,6 +37,7 @@ public function up() $table->index('kandji_agent_version'); $table->index('blueprint_id'); $table->index('email_address'); + $table->index('passport_enabled'); }); } diff --git a/scripts/kandji.py b/scripts/kandji.py old mode 100644 new mode 100755 index 2be700c..13daf8c --- a/scripts/kandji.py +++ b/scripts/kandji.py @@ -19,8 +19,32 @@ def get_local_kandji_prefs(): result['kandji_id'] = CFPreferencesCopyAppValue('ComputerURL', 'io.kandji.Kandji').split('/')[-1] return result -def kandji_report_enabled(): - return CFPreferencesCopyAppValue('KandjiCheck', 'MunkiReport') +def get_users_info(): + + # Get all users info as plist + cmd = ['/usr/bin/dscl', '-plist', '.', '-readall', '/Users'] + proc = subprocess.Popen(cmd, shell=False, bufsize=-1, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (output, unused_error) = proc.communicate() + + try: + try: + return plistlib.readPlistFromString(output) + except AttributeError as e: + return plistlib.loads(output) + except Exception: + return {} + +def get_passport_info(): + out = [] + all_users = get_users_info() + for user in all_users: + if 'dsAttrTypeNative:io.kandji.KandjiLogin.LinkedAccount' in list(user.keys()): + kandji_linked_account = user['dsAttrTypeNative:io.kandji.KandjiLogin.LinkedAccount'][0] + user_shortname = user['dsAttrTypeStandard:RecordName'][0] + out.append('%s: %s' % (user_shortname, kandji_linked_account)) + return out def main(): """Main""" @@ -30,10 +54,11 @@ def main(): sys.setdefaultencoding('utf8') # Get results - if kandji_report_enabled(): - result = get_local_kandji_prefs() - else: - result = dict() + result = get_local_kandji_prefs() + passport_users = get_passport_info() + if len(passport_users) > 0: + result['passport_enabled'] = True + result['passport_users'] = passport_users # Write results to cache cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__)) diff --git a/views/kandji_listing.php b/views/kandji_listing.php index d55a3ed..fa8b615 100755 --- a/views/kandji_listing.php +++ b/views/kandji_listing.php @@ -18,6 +18,7 @@ + From 54d046a9d301f29bb90f5f3935c7055dfbba693f Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 10:49:26 +0100 Subject: [PATCH 82/92] Added new migration --- migrations/2022_08_26_000001_kandji.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/migrations/2022_08_26_000001_kandji.php b/migrations/2022_08_26_000001_kandji.php index fff8e61..e8d3047 100755 --- a/migrations/2022_08_26_000001_kandji.php +++ b/migrations/2022_08_26_000001_kandji.php @@ -24,8 +24,6 @@ public function up() $table->text('blueprint_name')->nullable(); $table->text('realname')->nullable(); $table->string('email_address')->nullable(); - $table->string('passport_enabled')->nullable(); - $table->string('passport_users')->nullable(); }); // Make the indexes @@ -37,7 +35,6 @@ public function up() $table->index('kandji_agent_version'); $table->index('blueprint_id'); $table->index('email_address'); - $table->index('passport_enabled'); }); } @@ -46,4 +43,4 @@ public function down() $capsule = new Capsule(); $capsule::schema()->dropIfExists($this->tableName); } -} +} \ No newline at end of file From 7e1f045b52e06957c75448e91372fbd2b2d27c6c Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 10:51:26 +0100 Subject: [PATCH 83/92] Renamed migration file --- .../2023_02_07_000002_kandji_add_passport.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 migrations/2023_02_07_000002_kandji_add_passport.php diff --git a/migrations/2023_02_07_000002_kandji_add_passport.php b/migrations/2023_02_07_000002_kandji_add_passport.php new file mode 100755 index 0000000..fff8e61 --- /dev/null +++ b/migrations/2023_02_07_000002_kandji_add_passport.php @@ -0,0 +1,49 @@ +create($this->tableName, function (Blueprint $table) { + $table->increments('id'); + $table->string('serial_number')->unique(); + $table->string('kandji_id'); + $table->string('name')->nullable(); + $table->string('kandji_agent_version')->nullable(); + $table->text('asset_tag')->nullable(); + $table->bigInteger('last_check_in')->nullable(); + $table->bigInteger('last_enrollment')->nullable(); + $table->bigInteger('first_enrollment')->nullable(); + $table->string('blueprint_id')->nullable(); + $table->text('blueprint_name')->nullable(); + $table->text('realname')->nullable(); + $table->string('email_address')->nullable(); + $table->string('passport_enabled')->nullable(); + $table->string('passport_users')->nullable(); + }); + + // Make the indexes + $capsule::schema()->table($this->tableName, function (Blueprint $table) { + $table->index('id'); + $table->index('serial_number'); + $table->index('kandji_id'); + $table->index('name'); + $table->index('kandji_agent_version'); + $table->index('blueprint_id'); + $table->index('email_address'); + $table->index('passport_enabled'); + }); + } + + public function down() + { + $capsule = new Capsule(); + $capsule::schema()->dropIfExists($this->tableName); + } +} From d12d51143c28eeb875957eb620edba26115facbf Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 10:57:10 +0100 Subject: [PATCH 84/92] Updated migration file --- ...sport.php => 2023_02_07_000002_kandji.php} | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) rename migrations/{2023_02_07_000002_kandji_add_passport.php => 2023_02_07_000002_kandji.php} (57%) diff --git a/migrations/2023_02_07_000002_kandji_add_passport.php b/migrations/2023_02_07_000002_kandji.php similarity index 57% rename from migrations/2023_02_07_000002_kandji_add_passport.php rename to migrations/2023_02_07_000002_kandji.php index fff8e61..f50053c 100755 --- a/migrations/2023_02_07_000002_kandji_add_passport.php +++ b/migrations/2023_02_07_000002_kandji.php @@ -6,10 +6,24 @@ class Kandji extends Migration { private $tableName = 'kandji'; + private $tableNameV2 = 'kandji_orig'; public function up() { $capsule = new Capsule(); + + $migrateData = false; + + if ($capsule::schema()->hasTable($this->tableNameV2)) { + // Migration already failed before, but didnt finish + throw new Exception("previous failed migration exists"); + } + + if ($capsule::schema()->hasTable($this->tableName)) { + $capsule::schema()->rename($this->tableName, $this->tableNameV2); + $migrateData = true; + } + $capsule::schema()->create($this->tableName, function (Blueprint $table) { $table->increments('id'); $table->string('serial_number')->unique(); @@ -27,6 +41,30 @@ public function up() $table->string('passport_enabled')->nullable(); $table->string('passport_users')->nullable(); }); + + if ($migrateData) { + $capsule::unprepared("INSERT INTO + $this->tableName + SELECT + id, + serial_number, + kandji_id, + name, + kandji_agent_version, + asset_tag, + last_check_in, + last_enrollment, + first_enrollment, + blueprint_id, + blueprint_name, + realname, + email_address, + passport_enabled, + passport_users + FROM + $this->tableNameV2"); + $capsule::schema()->drop($this->tableNameV2); + } // Make the indexes $capsule::schema()->table($this->tableName, function (Blueprint $table) { @@ -45,5 +83,8 @@ public function down() { $capsule = new Capsule(); $capsule::schema()->dropIfExists($this->tableName); + if ($capsule::schema()->hasTable($this->tableNameV2)) { + $capsule::schema()->rename($this->tableNameV2, $this->tableName); + } } } From ec0039783bdd79123aa59cd5aa4bf1acd5e433c2 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 10:58:21 +0100 Subject: [PATCH 85/92] Updated migration file --- migrations/2023_02_07_000002_kandji.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/migrations/2023_02_07_000002_kandji.php b/migrations/2023_02_07_000002_kandji.php index f50053c..9a44c01 100755 --- a/migrations/2023_02_07_000002_kandji.php +++ b/migrations/2023_02_07_000002_kandji.php @@ -58,9 +58,7 @@ public function up() blueprint_id, blueprint_name, realname, - email_address, - passport_enabled, - passport_users + email_address FROM $this->tableNameV2"); $capsule::schema()->drop($this->tableNameV2); From 8c5b2525a5df852bfccad8641f9d537cbf131b1e Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 11:06:06 +0100 Subject: [PATCH 86/92] Fix migration again --- migrations/2023_02_07_000002_kandji.php | 67 ++----------------------- 1 file changed, 4 insertions(+), 63 deletions(-) diff --git a/migrations/2023_02_07_000002_kandji.php b/migrations/2023_02_07_000002_kandji.php index 9a44c01..e033ed4 100755 --- a/migrations/2023_02_07_000002_kandji.php +++ b/migrations/2023_02_07_000002_kandji.php @@ -6,73 +6,14 @@ class Kandji extends Migration { private $tableName = 'kandji'; - private $tableNameV2 = 'kandji_orig'; public function up() { $capsule = new Capsule(); - - $migrateData = false; - - if ($capsule::schema()->hasTable($this->tableNameV2)) { - // Migration already failed before, but didnt finish - throw new Exception("previous failed migration exists"); - } - - if ($capsule::schema()->hasTable($this->tableName)) { - $capsule::schema()->rename($this->tableName, $this->tableNameV2); - $migrateData = true; - } - - $capsule::schema()->create($this->tableName, function (Blueprint $table) { - $table->increments('id'); - $table->string('serial_number')->unique(); - $table->string('kandji_id'); - $table->string('name')->nullable(); - $table->string('kandji_agent_version')->nullable(); - $table->text('asset_tag')->nullable(); - $table->bigInteger('last_check_in')->nullable(); - $table->bigInteger('last_enrollment')->nullable(); - $table->bigInteger('first_enrollment')->nullable(); - $table->string('blueprint_id')->nullable(); - $table->text('blueprint_name')->nullable(); - $table->text('realname')->nullable(); - $table->string('email_address')->nullable(); + $capsule::schema()->table($this->tableName, function (Blueprint $table) { $table->string('passport_enabled')->nullable(); $table->string('passport_users')->nullable(); - }); - if ($migrateData) { - $capsule::unprepared("INSERT INTO - $this->tableName - SELECT - id, - serial_number, - kandji_id, - name, - kandji_agent_version, - asset_tag, - last_check_in, - last_enrollment, - first_enrollment, - blueprint_id, - blueprint_name, - realname, - email_address - FROM - $this->tableNameV2"); - $capsule::schema()->drop($this->tableNameV2); - } - - // Make the indexes - $capsule::schema()->table($this->tableName, function (Blueprint $table) { - $table->index('id'); - $table->index('serial_number'); - $table->index('kandji_id'); - $table->index('name'); - $table->index('kandji_agent_version'); - $table->index('blueprint_id'); - $table->index('email_address'); $table->index('passport_enabled'); }); } @@ -80,9 +21,9 @@ public function up() public function down() { $capsule = new Capsule(); - $capsule::schema()->dropIfExists($this->tableName); - if ($capsule::schema()->hasTable($this->tableNameV2)) { - $capsule::schema()->rename($this->tableNameV2, $this->tableName); + $capsule::schema()->table($this->tableName) { + $table->dropColumn('passport_enabled'); + $table->dropColumn('passport_users'); } } } From 4689da4106b5865c7e34ea66d2edcd1886fbdf70 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 11:07:10 +0100 Subject: [PATCH 87/92] Fix migration syntax --- migrations/2023_02_07_000002_kandji.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/2023_02_07_000002_kandji.php b/migrations/2023_02_07_000002_kandji.php index e033ed4..cca07ac 100755 --- a/migrations/2023_02_07_000002_kandji.php +++ b/migrations/2023_02_07_000002_kandji.php @@ -21,7 +21,7 @@ public function up() public function down() { $capsule = new Capsule(); - $capsule::schema()->table($this->tableName) { + $capsule::schema()->table($this->tableName), function (Blueprint $table) { $table->dropColumn('passport_enabled'); $table->dropColumn('passport_users'); } From c377bafcbcae51e17de510b16bc6c1ac17d7c90e Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 11:07:56 +0100 Subject: [PATCH 88/92] Fix migration syntax --- migrations/2023_02_07_000002_kandji.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/2023_02_07_000002_kandji.php b/migrations/2023_02_07_000002_kandji.php index cca07ac..c6112a9 100755 --- a/migrations/2023_02_07_000002_kandji.php +++ b/migrations/2023_02_07_000002_kandji.php @@ -21,9 +21,9 @@ public function up() public function down() { $capsule = new Capsule(); - $capsule::schema()->table($this->tableName), function (Blueprint $table) { + $capsule::schema()->table($this->tableName, function (Blueprint $table) { $table->dropColumn('passport_enabled'); $table->dropColumn('passport_users'); - } + }); } } From 3560ac90b9ac97e7c0115b1a7c9cfd95078a6393 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 11:08:58 +0100 Subject: [PATCH 89/92] Fix incorrect date formatting --- views/kandji_listing.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/kandji_listing.php b/views/kandji_listing.php index fa8b615..ff673c4 100755 --- a/views/kandji_listing.php +++ b/views/kandji_listing.php @@ -81,8 +81,8 @@ $('td:eq(4)', nRow).html(''+moment(date).fromNow()+''); // Format last_enrollment timestamp - var date = parseInt($('td:eq(5)', nRow).html())*1000; - $('td:eq(5)', nRow).html(''+moment(date).fromNow()+''); + var date = parseInt($('td:eq(6)', nRow).html())*1000; + $('td:eq(6)', nRow).html(''+moment(date).fromNow()+''); } }); }); From d71f3f77f0e13d23486113258ef1703a8c05844e Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 11:44:10 +0100 Subject: [PATCH 90/92] Align how this works more with how machine works --- kandji_processor.php | 29 +++++++++++++++++++++++++---- lib/kandji_helper.php | 21 +-------------------- scripts/kandji.py | 4 +++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/kandji_processor.php b/kandji_processor.php index b6ed421..edc099b 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -24,7 +24,14 @@ public function run($plist) $parser->parse($plist, CFPropertyList::FORMAT_XML); $mylist = $parser->toArray(); - $model = Kandji_model::firstOrNew(['serial_number' => $this->serial_number]); + // Retrieve Kandji MR record (if existing) + try { + $model = Kandji_model::select() + ->where('serial_number', $this->serial_number) + ->firstOrFail(); + } catch (\Throwable $th) { + $model = new Kandji_model(); + } $model->fill($mylist); @@ -33,10 +40,24 @@ public function run($plist) // Load Kandji helper require_once($module_dir.'/lib/kandji_helper.php'); $kandji_helper = new munkireport\module\kandji\kandji_helper; - $kandji_helper->pull_kandji_data($model); - // ^^ Comment and uncomment to turn off and on + $json = $kandji_helper->pull_kandji_data($model); + + // Transpose Kandji API output into Kandji model + // General section + $mylist['name'] = $json[0]->device_name; + $mylist['asset_tag'] = $json[0]->asset_tag; + $mylist['blueprint_id'] = $json[0]->blueprint_id; + $mylist['blueprint_name'] = $json[0]->blueprint_name; + $mylist['last_check_in'] = $kandji_helper->convert_time_to_epoch($json[0]->last_check_in); + $mylist['last_enrollment'] = $kandji_helper->convert_time_to_epoch($json[0]->last_enrollment); + $mylist['first_enrollment'] = $kandji_helper->convert_time_to_epoch($json[0]->first_enrollment); + + // Location section + $mylist['realname'] = $json[0]->user->name; + $mylist['email_address'] = $json[0]->user->email; + } - return $this; + $model->fill($mylist)->save(); } } \ No newline at end of file diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index 02071a8..29912b4 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -36,26 +36,7 @@ public function pull_kandji_data(&$Kandji_machine) return $error; } - // Transpose Kandji API output into Kandji model - // General section - $Kandji_machine->name = $json[0]->device_name; - $Kandji_machine->asset_tag = $json[0]->asset_tag; - $Kandji_machine->blueprint_id = $json[0]->blueprint_id; - $Kandji_machine->blueprint_name = $json[0]->blueprint_name; - $Kandji_machine->last_check_in = $this->convert_time_to_epoch($json[0]->last_check_in); - $Kandji_machine->last_enrollment = $this->convert_time_to_epoch($json[0]->last_enrollment); - $Kandji_machine->first_enrollment = $this->convert_time_to_epoch($json[0]->first_enrollment); - - // Location section - $Kandji_machine->realname = $json[0]->user->name; - $Kandji_machine->email_address = $json[0]->user->email; - - // Save the data, Protecc the data - Kandji_model::updateOrCreate( - ['serial_number' => $Kandji_machine->serial_number], [$Kandji_machine] - ); - $error = 'Kandji data processed'; - return $error; + return $json; } /** diff --git a/scripts/kandji.py b/scripts/kandji.py index 13daf8c..392d7e0 100755 --- a/scripts/kandji.py +++ b/scripts/kandji.py @@ -44,7 +44,9 @@ def get_passport_info(): kandji_linked_account = user['dsAttrTypeNative:io.kandji.KandjiLogin.LinkedAccount'][0] user_shortname = user['dsAttrTypeStandard:RecordName'][0] out.append('%s: %s' % (user_shortname, kandji_linked_account)) - return out + if len(out) > 0: + return ', '.join(out) + return [] def main(): """Main""" From eba873032701e9bb047a6b13e47c094d1ee70eb7 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 15:04:40 +0100 Subject: [PATCH 91/92] Fixed processor, script modifications --- kandji_processor.php | 25 ++++++++++++++++++------- lib/kandji_helper.php | 14 -------------- scripts/kandji.py | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/kandji_processor.php b/kandji_processor.php index edc099b..39abeec 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -23,7 +23,7 @@ public function run($plist) $parser = new CFPropertyList(); $parser->parse($plist, CFPropertyList::FORMAT_XML); $mylist = $parser->toArray(); - + echo "Parsed plist"; // Retrieve Kandji MR record (if existing) try { $model = Kandji_model::select() @@ -33,8 +33,6 @@ public function run($plist) $model = new Kandji_model(); } - $model->fill($mylist); - // Check if we should enable Kandji lookup if (conf('kandji_enable')) { // Load Kandji helper @@ -48,9 +46,9 @@ public function run($plist) $mylist['asset_tag'] = $json[0]->asset_tag; $mylist['blueprint_id'] = $json[0]->blueprint_id; $mylist['blueprint_name'] = $json[0]->blueprint_name; - $mylist['last_check_in'] = $kandji_helper->convert_time_to_epoch($json[0]->last_check_in); - $mylist['last_enrollment'] = $kandji_helper->convert_time_to_epoch($json[0]->last_enrollment); - $mylist['first_enrollment'] = $kandji_helper->convert_time_to_epoch($json[0]->first_enrollment); + $mylist['last_check_in'] = $this->convert_time_to_epoch($json[0]->last_check_in); + $mylist['last_enrollment'] = $this->convert_time_to_epoch($json[0]->last_enrollment); + $mylist['first_enrollment'] = $this->convert_time_to_epoch($json[0]->first_enrollment); // Location section $mylist['realname'] = $json[0]->user->name; @@ -60,4 +58,17 @@ public function run($plist) $model->fill($mylist)->save(); } -} \ No newline at end of file + + /** + * Convert Kandji timestamps to epochs + * + * @return Unix epoch + * @author jc0b + * + **/ + private function convert_time_to_epoch($date) + { + $dt = new \DateTime($date); + return $dt->getTimestamp(); + } +} diff --git a/lib/kandji_helper.php b/lib/kandji_helper.php index 29912b4..4da8173 100755 --- a/lib/kandji_helper.php +++ b/lib/kandji_helper.php @@ -69,18 +69,4 @@ public function send_kandji_query($url) return $return; } - - - /** - * Convert Kandji timestamps to epochs - * - * @return Unix epoch - * @author jc0b - * - **/ - private function convert_time_to_epoch($date) - { - $dt = new \DateTime($date); - return $dt->getTimestamp(); - } } \ No newline at end of file diff --git a/scripts/kandji.py b/scripts/kandji.py index 392d7e0..0f48527 100755 --- a/scripts/kandji.py +++ b/scripts/kandji.py @@ -59,7 +59,7 @@ def main(): result = get_local_kandji_prefs() passport_users = get_passport_info() if len(passport_users) > 0: - result['passport_enabled'] = True + result['passport_enabled'] = "True" result['passport_users'] = passport_users # Write results to cache From ae6651f83554911055bdc551708b519deb9e9b26 Mon Sep 17 00:00:00 2001 From: jc0b Date: Tue, 7 Feb 2023 15:08:12 +0100 Subject: [PATCH 92/92] Cleaned up, updated installer to remove old versions of module --- kandji_processor.php | 1 - scripts/install.sh | 6 +++++- scripts/uninstall.sh | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kandji_processor.php b/kandji_processor.php index 39abeec..6acfc1c 100644 --- a/kandji_processor.php +++ b/kandji_processor.php @@ -23,7 +23,6 @@ public function run($plist) $parser = new CFPropertyList(); $parser->parse($plist, CFPropertyList::FORMAT_XML); $mylist = $parser->toArray(); - echo "Parsed plist"; // Retrieve Kandji MR record (if existing) try { $model = Kandji_model::select() diff --git a/scripts/install.sh b/scripts/install.sh index e0614fb..66e09a3 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -22,4 +22,8 @@ else ERR=1 fi - +# delete old Kandji module things +rm -f "${CACHEPATH}kandji.txt" +rm -f "${MUNKIPATH}preflight.d/kandji" +rm -f "${MUNKIPATH}scripts/kandji" +rm -f "${MUNKIPATH}postflight.d/kandji" diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index f5d6fd1..7930d6f 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -3,5 +3,5 @@ # Remove kandji script rm -f "${MUNKIPATH}preflight.d/kandji.py" -# Remove kandji.txt file +# Remove kandji.plist file rm -f "${CACHEPATH}kandji.plist"