-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,632 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Disable crlf normalization (http://stackoverflow.com/a/10017566). | ||
* -text |
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
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,100 @@ | ||
<?php | ||
|
||
class Migration_machine_add_cpu extends Model | ||
{ | ||
protected $columname = 'cpu'; | ||
|
||
function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->tablename = 'machine'; | ||
} | ||
|
||
public function up() | ||
{ | ||
// Get database handle | ||
$dbh = $this->getdbh(); | ||
|
||
// Wrap in transaction | ||
$dbh->beginTransaction(); | ||
|
||
// Adding a column is simple... | ||
$sql = sprintf('ALTER TABLE %s ADD COLUMN %s VARCHAR(255)', | ||
$this->enquote($this->tablename), $this->enquote($this->columname)); | ||
|
||
$this->exec($sql); | ||
|
||
// so is adding an index... | ||
$idx_name = $this->tablename . '_' . $this->columname; | ||
$sql = sprintf("CREATE INDEX %s ON %s (%s)", | ||
$idx_name, $this->enquote($this->tablename), $this->columname); | ||
|
||
$this->exec($sql); | ||
|
||
$dbh->commit(); | ||
} | ||
|
||
public function down() | ||
{ | ||
// Get database handle | ||
$dbh = $this->getdbh(); | ||
|
||
switch ($this->get_driver()) | ||
{ | ||
case 'sqlite':// ...removing a column in SQLite is hard | ||
|
||
$dbh->beginTransaction(); | ||
|
||
// Create temporary table | ||
$sql = "CREATE TABLE machine_temp ( | ||
id INTEGER PRIMARY KEY, | ||
serial_number VARCHAR(255) UNIQUE, | ||
hostname VARCHAR(255), | ||
machine_model VARCHAR(255), | ||
machine_desc VARCHAR(255), | ||
img_url VARCHAR(255), | ||
current_processor_speed VARCHAR(255), | ||
cpu_arch VARCHAR(255), | ||
oci_server_version VARCHAR(255), | ||
physical_memory INTEGER, | ||
platform_UUID VARCHAR(255), | ||
number_processors INTEGER, | ||
SMC_version_system VARCHAR(255), | ||
boot_rom_version VARCHAR(255), | ||
bus_speed VARCHAR(255), | ||
computer_name VARCHAR(255), | ||
l2_cache VARCHAR(255), | ||
machine_name VARCHAR(255), | ||
packages, VARCHAR(255))"; | ||
$this->exec($sql); | ||
|
||
$sql = "INSERT INTO machine_temp | ||
SELECT id, serial_number, hostname, machine_model, machine_desc, img_url, current_processor_speed, cpu_arch, os_version, physical_memory, platform_UUID, number_processors, SMC_version_system, boot_rom_version, bus_speed, computer_name, l2_cache, machine_name, packages FROM machine"; | ||
$this->exec($sql); | ||
|
||
$sql = "DROP table machine"; | ||
$this->exec($sql); | ||
|
||
$sql = "ALTER TABLE machine_temp RENAME TO machine"; | ||
$this->exec($sql); | ||
|
||
// Add index for old filevault_status column | ||
$idx_name = $this->tablename . '_machine'; | ||
$sql = sprintf("CREATE INDEX %s ON %s (%s)", | ||
$idx_name, $this->enquote($this->tablename), 'machine'); | ||
|
||
$this->exec($sql); | ||
|
||
$dbh->commit(); | ||
|
||
break; | ||
|
||
default: // MySQL (other engines?) | ||
|
||
// MySQL drops the index as well -> check for other engines | ||
$sql = sprintf('ALTER TABLE %s DROP COLUMN %s', | ||
$this->enquote($this->tablename), $this->enquote($this->columname)); | ||
$this->exec($sql); | ||
} | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
class Ard_model extends Model { | ||
|
||
function __construct($serial='') | ||
{ | ||
parent::__construct('id', 'ard'); //primary key, tablename | ||
$this->rs['id'] = 0; | ||
$this->rs['serial_number'] = $serial; $this->rt['serial_number'] = 'VARCHAR(255) UNIQUE'; | ||
$this->rs['Text1'] = ''; | ||
$this->rs['Text2'] = ''; | ||
$this->rs['Text3'] = ''; | ||
$this->rs['Text4'] = ''; | ||
|
||
// Schema version, increment when creating a db migration | ||
$this->schema_version = 0; | ||
|
||
// Add indexes | ||
$this->idx[] = array('Text1'); | ||
$this->idx[] = array('Text2'); | ||
$this->idx[] = array('Text3'); | ||
$this->idx[] = array('Text4'); | ||
|
||
|
||
// Create table if it does not exist | ||
$this->create_table(); | ||
|
||
if ($serial) | ||
{ | ||
$this->retrieve_one('serial_number=?', $serial); | ||
} | ||
|
||
$this->serial = $serial; | ||
|
||
} | ||
|
||
function process($data) | ||
{ | ||
require_once(APP_PATH . 'lib/CFPropertyList/CFPropertyList.php'); | ||
$parser = new CFPropertyList(); | ||
$parser->parse($data); | ||
|
||
$plist = $parser->toArray(); | ||
|
||
foreach(array('Text1', 'Text2', 'Text3', 'Text4') AS $item) | ||
{ | ||
if (isset($plist[$item])) | ||
{ | ||
$this->$item = $plist[$item]; | ||
} | ||
else | ||
{ | ||
$this->$item = ''; | ||
} | ||
} | ||
|
||
$this->save(); | ||
} | ||
} |
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,4 @@ | ||
#!/bin/bash | ||
|
||
# Add ARD Preferences to munkireport | ||
defaults write "${PREFPATH}" ReportItems -dict-add ard_model "/Library/Preferences/com.apple.RemoteDesktop.plist" |
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,18 @@ | ||
Bluetooth module | ||
============== | ||
|
||
Provides Bluetooth status and uses ioreg to report on battery levels. | ||
|
||
Data can be viewed under the Bluetooth tab on the client details page or using the Bluetooth list view | ||
|
||
|
||
* Is Bluetooth on or off | ||
* Battery life remaining for Keyboard | ||
* Battery life remaining for Mouse | ||
* Battery life remaining for Trackpad | ||
|
||
|
||
To do | ||
--- | ||
|
||
* Build a report showing battery levels under 15% |
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,30 @@ | ||
<?php | ||
|
||
/** | ||
* bluetooth status module class | ||
* | ||
* @package munkireport | ||
* @author | ||
**/ | ||
class Bluetooth_controller extends Module_controller | ||
{ | ||
|
||
/*** Protect methods with auth! ****/ | ||
function __construct() | ||
{ | ||
// Store module path | ||
$this->module_path = dirname(__FILE__); | ||
} | ||
|
||
/** | ||
* Default method | ||
* | ||
* @author AvB | ||
**/ | ||
function index() | ||
{ | ||
echo "You've loaded the bluetooth module!"; | ||
} | ||
|
||
|
||
} // END class default_module |
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,65 @@ | ||
<?php | ||
class Bluetooth_model extends Model { | ||
|
||
function __construct($serial='') | ||
{ | ||
parent::__construct('id', 'bluetooth'); //primary key, tablename | ||
$this->rs['id'] = ''; | ||
$this->rs['serial_number'] = $serial; $this->rt['serial_number'] = 'VARCHAR(255) UNIQUE'; | ||
$this->rs['bluetooth_status'] = ''; | ||
$this->rs['keyboard_battery'] = ''; | ||
$this->rs['mouse_battery'] = ''; | ||
$this->rs['trackpad_battery'] = ''; | ||
|
||
// Schema version, increment when creating a db migration | ||
$this->schema_version = 0; | ||
|
||
// Create table if it does not exist | ||
$this->create_table(); | ||
|
||
if ($serial) | ||
$this->retrieve_one('serial_number=?', $serial); | ||
|
||
$this->serial = $serial; | ||
|
||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Process data sent by postflight | ||
* | ||
* @param string data | ||
* | ||
**/ | ||
function process($data) | ||
{ | ||
// Translate network strings to db fields | ||
$translate = array( | ||
'Status = ' => 'bluetooth_status', | ||
'Keyboard = ' => 'keyboard_battery', | ||
'Mouse = ' => 'mouse_battery', | ||
'Trackpad = ' => 'trackpad_battery'); | ||
|
||
//clear any previous data we had | ||
foreach($translate as $search => $field) { | ||
$this->$field = ''; | ||
} | ||
// Parse data | ||
foreach(explode("\n", $data) as $line) { | ||
// Translate standard entries | ||
foreach($translate as $search => $field) { | ||
|
||
if(strpos($line, $search) === 0) { | ||
|
||
$value = substr($line, strlen($search)); | ||
|
||
$this->$field = $value; | ||
break; | ||
} | ||
} | ||
|
||
} //end foreach explode lines | ||
$this->save(); | ||
} | ||
} |
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,50 @@ | ||
#!/bin/sh | ||
|
||
# Battery status check for Apple Wireless Keyboard, Mouse, and Trackpad | ||
# Based on http://www.macosxtips.co.uk/geeklets/system/battery-status-for-apple-wireless-keyboard-mouse-and-trackpad/ | ||
|
||
# Skip manual check | ||
if [ "$1" = 'manualcheck' ]; then | ||
echo 'Manual check: skipping' | ||
exit 0 | ||
fi | ||
|
||
# Create cache dir if it does not exist | ||
DIR=$(dirname $0) | ||
mkdir -p "$DIR/cache" | ||
|
||
bluetoothfile="$DIR/cache/bluetoothinfo.txt" | ||
|
||
# echo "Getting Bluetooth device status" | ||
|
||
# Bluetooth status. Returns '0' for off and '1' for on | ||
Power=`defaults read /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState` | ||
if [ $Power = 0 ]; then | ||
status="Status = Bluetooth is off" | ||
else | ||
status="Status = Bluetooth is on" | ||
fi | ||
|
||
KeyboardPercent=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'` | ||
if [ "${KeyboardPercent}" = "" ]; then | ||
keyboard="Keyboard = Disconnected" | ||
else | ||
keyboard="Keyboard = $KeyboardPercent% battery life remaining" | ||
fi | ||
|
||
MousePercent=`ioreg -c BNBMouseDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'` | ||
if [ "${MousePercent}" = "" ]; then | ||
mouse="Mouse = Disconnected" | ||
else | ||
mouse="Mouse = $MousePercent% battery life remaining" | ||
fi | ||
|
||
TrackpadPercent=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'` | ||
if [ "${TrackpadPercent}" = "" ]; then | ||
trackpad="Trackpad = Disconnected" | ||
else | ||
trackpad="Trackpad = $TrackpadPercent% battery life remaining" | ||
fi | ||
|
||
|
||
echo $status '\n'$keyboard '\n'$mouse '\n'$trackpad > "$bluetoothfile" |
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,25 @@ | ||
#!/bin/bash | ||
|
||
# bluetooth controller | ||
CTL="${BASEURL}index.php?/module/bluetooth/" | ||
|
||
# Get the scripts in the proper directories | ||
${CURL} "${CTL}get_script/bluetooth.sh" -o "${MUNKIPATH}preflight.d/bluetooth.sh" | ||
|
||
# Check exit status of curl | ||
if [ $? = 0 ]; then | ||
# Make executable | ||
chmod a+x "${MUNKIPATH}preflight.d/bluetooth.sh" | ||
|
||
# Set preference to include this file in the preflight check | ||
defaults write "${PREFPATH}" ReportItems -dict-add bluetooth "${MUNKIPATH}preflight.d/cache/bluetoothinfo.txt" | ||
|
||
else | ||
echo "Failed to download all required components!" | ||
rm -f "${MUNKIPATH}preflight.d/bluetooth.sh" | ||
|
||
# Signal that we had an error | ||
ERR=1 | ||
fi | ||
|
||
|
Oops, something went wrong.