Skip to content

Commit

Permalink
Merge branch 'wip'
Browse files Browse the repository at this point in the history
  • Loading branch information
bochoven committed Jun 30, 2014
2 parents 352fc3d + bb7aa88 commit 3173113
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 147 deletions.
2 changes: 1 addition & 1 deletion app/helpers/site_helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// Munkireport version (last number is number of commits)
$GLOBALS['version'] = '2.0.9.779';
$GLOBALS['version'] = '2.0.10.812';

// Return version without commit count
function get_version()
Expand Down
77 changes: 77 additions & 0 deletions app/migrations/reportdata_model/002_reportdata_add_uptime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

// Add uptime field

class Migration_reportdata_add_uptime extends Model
{
protected $columname = 'uptime';

function __construct()
{
parent::__construct();
$this->tablename = 'reportdata';
}

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 INTEGER DEFAULT 0',
$this->enquote($this->tablename), $this->enquote($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 %s_temp (
id INTEGER PRIMARY KEY,
serial_number VARCHAR(255) UNIQUE,
console_user VARCHAR(255),
long_username VARCHAR(255),
remote_ip VARCHAR(255),
reg_timestamp INTEGER,
timestamp INTEGER)";
$this->exec(sprintf($sql, $this->tablename));

$sql = "INSERT INTO %s_temp
SELECT id, serial_number, console_user, long_username, remote_ip, reg_timestamp, timestamp
FROM %s";
$this->exec(sprintf($sql, $this->tablename, $this->tablename));

$sql = "DROP table %s";
$this->exec(sprintf($sql, $this->tablename));

$sql = "ALTER TABLE %s_temp RENAME TO %s";
$this->exec(sprintf($sql, $this->tablename, $this->tablename));

$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);
}
}
}
10 changes: 3 additions & 7 deletions app/modules/bluetooth/scripts/bluetooth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ 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
# Bluetooth status.
Power=`system_profiler SPBluetoothDataType | grep 'Bluetooth Power' | awk '{print tolower($3)}'`
status="Status = Bluetooth is $Power"

KeyboardPercent=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`
if [ "${KeyboardPercent}" = "" ]; then
Expand Down
18 changes: 12 additions & 6 deletions app/modules/displays_info/scripts/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,21 @@
#loop within each display
for display in vga['spdisplays_ndrvs']:

#Serial and Type sections
#Type section
try:
if display.get('spdisplays_display-serial-number', None):
result += 'Type = External'
elif display['_spdisplays_display-vendor-id'] == "610":
result += 'Type = Internal'
else:
result += 'Type = External'
except KeyError as error: #this catches the error for 10.6 where there is no vendor for built-in displays
result += 'Type = Internal'

#Serial section
if display.get('spdisplays_display-serial-number', None):
result += 'Type = External'
result += '\nSerial = ' + str(display['spdisplays_display-serial-number'])
elif display['_spdisplays_display-vendor-id'] != "610":
result += 'Type = External'
result += '\nSerial = n/a'
else:
result += 'Type = Internal'
result += '\nSerial = n/a'

try:
Expand Down
3 changes: 2 additions & 1 deletion app/modules/reportdata/reportdata_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ function __construct($serial='')
$this->rs['console_user'] = '';
$this->rs['long_username'] = '';
$this->rs['remote_ip'] = '';
$this->rs['uptime'] = 0; $this->rt['uptime'] = 'INTEGER DEFAULT 0';// Uptime in seconds
$this->rs['reg_timestamp'] = time(); // Registration date
$this->rs['timestamp'] = time();

// Schema version, increment when creating a db migration
$this->schema_version = 1;
$this->schema_version = 2;


// Create indexes
Expand Down
2 changes: 1 addition & 1 deletion app/views/auth/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<?if(empty($_SERVER['HTTPS'])):?>

<a href="<?=secure_url()?>"><i title="<?=lang('auth_insecure')?>" class="text-danger fa fa-unlock-alt pull-right"></i></a>
- <?=conf('sitename')?><a href="<?=secure_url()?>"><i title="<?=lang('auth_insecure')?>" class="text-danger fa fa-unlock-alt pull-right"></i></a>

<?else:?>

Expand Down
14 changes: 14 additions & 0 deletions app/views/client/client_detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@
document.body.scrollTop=yScroll;
}
})

// Set times
$( "dd time" ).each(function( index ) {
if($(this).hasClass('absolutetime'))
{
seconds = moment().seconds(parseInt($(this).attr('datetime')))
$(this).html(moment(seconds).fromNow(true));
}
else
{
$(this).html(moment($(this).attr('datetime') * 1000).fromNow());
}
$(this).tooltip().css('cursor', 'pointer');
});
});
</script>
</div> <!-- /span 12 -->
Expand Down
11 changes: 0 additions & 11 deletions app/views/client/filevault_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
?>


<!-- Format date -->
<script>
$(document).ready(function() {
$( "dd time" ).each(function( index ) {
$(this).html(moment($(this).attr('datetime') * 1000).fromNow());
$(this).tooltip().css('cursor', 'pointer');
});
});
</script>


<h2>FileVault Escrow</h2>

<table class="table table-striped">
Expand Down
18 changes: 9 additions & 9 deletions app/views/client/machine_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@
<dd><?=$warranty->purchase_date?></dd>
</dl>

<dl class="dl-horizontal">
<dt>Uptime</dt>
<?if($report->uptime > 0):?>
<dd><time class="absolutetime" title="Booted: <?=strftime('%c', $report->timestamp - $report->uptime)?>" datetime="<?=$report->uptime?>"><?=strftime('%x', $report->timestamp - $report->uptime)?></time></dd>
<?else:?>
<dd><?=lang('unavailable')?></dd>
<?endif?>
</dl>

<dl class="dl-horizontal">
<dt>Registration date</dt>
<dd><time title="<?=strftime('%c', $report->reg_timestamp)?>" datetime="<?=$report->reg_timestamp?>"><?=strftime('%x', $report->reg_timestamp)?></time></dd>
<dt>Last checkin</dt>
<dd><time title="<?=strftime('%c', $report->timestamp)?>" datetime="<?=$report->timestamp?>"><?=strftime('%x', $report->timestamp)?></time></dd>
</dl>

<script>
$(document).ready(function() {
$( "dd time" ).each(function( index ) {
$(this).html(moment($(this).attr('datetime') * 1000).fromNow());
$(this).tooltip().css('cursor', 'pointer');
});
});
</script>

</small>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/client/munki_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<script>
$(document).ready(function() {
$( "table time" ).each(function( index ) {
$(this).html(moment($(this).attr('datetime')).fromNow());
$(this).html(moment($(this).attr('datetime'), "YYYY-MM-DD HH:mm:ss Z").fromNow());
});
});
</script>
Expand Down
3 changes: 3 additions & 0 deletions app/views/install/install_script.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
# Create postflight.d
mkdir -p "${MUNKIPATH}postflight.d"

# Create preflight_abort.d
mkdir -p "${MUNKIPATH}preflight_abort.d"

echo "Configuring munkireport"
#### Configure Munkireport ####

Expand Down
26 changes: 25 additions & 1 deletion app/views/listing/displays.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,31 @@
vendor="SMART Technologies"
break;
case "9d1":
vendor="BenQ"
vendor="BenQ"
break;
case "4dd9":
vendor="Sony"
break;
case "472":
vendor="Acer"
break;
case "22f0":
vendor="HP"
break;
case "34ac":
vendor="Mitsubishi"
break;
case "22f0":
vendor="HP"
break;
case "5a63":
vendor="ViewSonic"
break;
case "4c2d":
vendor="Samsung"
break;
case "593a":
vendor="Vizio"
break;
}
$('td:eq(3)', nRow).html(vendor)
Expand Down
59 changes: 13 additions & 46 deletions assets/client_installer/postflight
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def main():
runtype = sys.argv[1]
else:
runtype = 'custom'

# Try to get the munki verbosity level
verbosity = os.environ.get('MUNKI_VERBOSITY_LEVEL')
if (verbosity):
reportcommon.set_verbosity(int(verbosity))
else:
reportcommon.set_verbosity(3)

# Get serial
hardware_info = munkicommon.get_hardware_info()
Expand All @@ -26,6 +33,7 @@ def main():
report_info['console_user'] = "%s" % munkicommon.getconsoleuser()
report_info['runtype'] = runtype
report_info['runstate'] = 'done'
report_info['uptime'] = reportcommon.get_uptime()
report_info_plist = FoundationPlist.writePlistToString(report_info)
items = {'reportdata':{'hash':hashlib.md5(report_info_plist).hexdigest(), \
'data':report_info_plist}}
Expand All @@ -34,59 +42,18 @@ def main():
config_items = reportcommon.pref('ReportItems') or {}

for key, val in config_items.items():
print "Requesting %s" % key
reportcommon.display_detail("Requesting %s" % key)
items[key] = {'path':val}

reportcommon.process(serial, items)

run_postflightd_scripts(runtype)

exit(0)

def run_postflightd_scripts(runtype):
# define path to directory with postflight scripts
scriptdir = os.path.realpath(os.path.dirname(sys.argv[0]))
postflightscriptdir = os.path.join(scriptdir, "postflight.d")

if os.path.exists(postflightscriptdir):
from munkilib import utils
# Get all files in postflight.d
files = os.listdir(postflightscriptdir)

# Sort list
files.sort()
for postflightscript in files:
if postflightscript.startswith('.'):
# Skip files that start with a period
continue
postflightscriptpath = os.path.join(
postflightscriptdir, postflightscript)
if os.path.isdir(postflightscriptpath):
# Skip directories in postflight.d directory
continue
try:
# Attempt to execute script
print 'Running %s' % postflightscript
result, stdout, stderr = utils.runExternalScript(
postflightscriptpath, allow_insecure=False, script_args=[runtype])
if stdout:
print(stdout.encode('UTF-8'))
if stderr:
print('%s Error: %s'
% (postflightscript, stderr))
if result:
print('postflight.d/%s return code: %d'
% (postflightscript, result))
exit(-1)
# Try to run postflight.d
postflightscriptdir = os.path.join(scriptdir, "postflight.d")
reportcommon.rundir(postflightscriptdir, runtype, False)

except utils.ScriptNotFoundError:
pass # Script has disappeared? Well, it is not required, so pass
except utils.RunExternalScriptError, e:
print >> sys.stderr, str(e)
# Skip this script
else:
# /usr/local/munki/postflight.d does not exist
pass
exit(0)

if __name__ == '__main__':
main()
Loading

0 comments on commit 3173113

Please sign in to comment.