-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big change update (Laravel, Python, Passport integration)
- Loading branch information
Showing
12 changed files
with
285 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,27 @@ | ||
<?php | ||
|
||
class Kandji_model extends \Model { | ||
|
||
protected $error = ''; | ||
protected $module_dir; | ||
|
||
public function __construct($serial = '') | ||
{ | ||
parent::__construct('id', 'kandji'); // Primary key, tablename | ||
$this->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_model extends Eloquent | ||
{ | ||
protected $table = 'kandji'; | ||
|
||
/** | ||
* 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', | ||
'passport_enabled', | ||
'passport_users', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/** | ||
* Kandji processor class | ||
* | ||
* @package munkireport | ||
* @author jc0b | ||
**/ | ||
|
||
use CFPropertyList\CFPropertyList; | ||
use munkireport\processors\Processor; | ||
|
||
class Kandji_processor extends Processor | ||
{ | ||
public function run($plist) | ||
{ | ||
if ( ! $plist){ | ||
throw new Exception("Error Processing Request: No property list found", 1); | ||
} | ||
configAppendFile(__DIR__ . '/config.php'); | ||
$module_dir = dirname(__FILE__); | ||
|
||
$parser = new CFPropertyList(); | ||
$parser->parse($plist, CFPropertyList::FORMAT_XML); | ||
$mylist = $parser->toArray(); | ||
// 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(); | ||
} | ||
|
||
// 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; | ||
$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'] = $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; | ||
$mylist['email_address'] = $json[0]->user->email; | ||
|
||
} | ||
|
||
$model->fill($mylist)->save(); | ||
} | ||
|
||
/** | ||
* Convert Kandji timestamps to epochs | ||
* | ||
* @return Unix epoch | ||
* @author jc0b | ||
* | ||
**/ | ||
private function convert_time_to_epoch($date) | ||
{ | ||
$dt = new \DateTime($date); | ||
return $dt->getTimestamp(); | ||
} | ||
} |
Oops, something went wrong.