Skip to content

Commit

Permalink
Merge branch 'wip'
Browse files Browse the repository at this point in the history
  • Loading branch information
bochoven committed Nov 29, 2016
2 parents 5a341f6 + 71da4ce commit 0a2d8f5
Show file tree
Hide file tree
Showing 32 changed files with 911 additions and 62 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.10.1.2197';
$GLOBALS['version'] = '2.11.0.2288';

// Return version without commit count
function get_version()
Expand Down
22 changes: 14 additions & 8 deletions app/helpers/warranty_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,26 @@ function model_description_lookup($serial)
if (strpos($serial, 'VMWV') === 0) {
return 'VMware virtual machine';
}
$snippet = substr($serial, 8);
$url = sprintf('http://support-sp.apple.com/sp/product?cc=%s&lang=en_US', $snippet);


$url = sprintf('https://km.support.apple.com/kb/index?page=categorydata&serialnumber=%s', $serial);
$result = get_url($url);

if ($result === false) {
return 'model_lookup_failed';
}

if (preg_match('#<configCode>(.*)</configCode>#', $result, $matches)) {
return($matches[1]);

try {
$categorydata = json_decode($result);
if(isset($categorydata->name)){
return $categorydata->name;
}
else{
return 'unknown_model';
}
} catch (Exception $e) {
return 'model_lookup_failed';
}

return 'unknown_model';

}

/**
Expand Down
50 changes: 50 additions & 0 deletions app/modules/backup2go/backup2go_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* backup2go class
*
* @package munkireport
* @author
**/
class backup2go_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 backup2go module!";
}


/**
* Get stats
*
* @return void
* @author
**/
function get_stats($hours = 24)
{
$obj = new View();

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

$model = new Backup2go_Model;
$obj->view('json', array('msg' => $model->get_stats($hours)));
}

} // END class default_module
86 changes: 86 additions & 0 deletions app/modules/backup2go/backup2go_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
class backup2go_model extends Model {

protected $restricted;

/**
* function: __construct
* initialise module
**/
function __construct($serial='')
{
parent::__construct('id', 'backup2go'); //primary key, tablename

//initialise tables
$this->rs['id'] = 0;
$this->rs['serial_number'] = $serial; $this->rt['serial_number'] = 'VARCHAR(255) UNIQUE';
$this->rs['backupdate'] = '';

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

// id is serial number
$this->idx[] = array('serial_number');

// Create table if it does not exist
$this->create_table();

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

$this->serial = $serial;
}


/**
* function: process($data)
* data sends by postflight
* processes the data returned in the postflight
**/
function process($data)
{
//init variables
$column = "backupdate";
$last = "";

//check if data is empty
if($data != ""){
$arr_data = explode("\n", $data);

//loop over the lines, but we only need the last line (cause values append at the end)
foreach($arr_data as $line){
if($line != ""){
$last = $line;
}
}

//save last date
$this->$column = $last;
$this->save();
}
}

/**
* function: get_stats
* this script is used for the widget in the report page
* it returns label classes and values for the widget
**/
function get_stats($hours)
{
$now = time();
$today = $now - 3600 * 24;
$two_weeks_ago = $now - 3600 * 24 * 14;
$month_ago = $now - 3600 * 24 * 28;
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN backupdate > '$two_weeks_ago' THEN 1 END) AS b2g_ok,
COUNT(CASE WHEN backupdate > '$month_ago' AND backupdate < '$two_weeks_ago' THEN 1 END) AS b2g_warning,
COUNT(CASE WHEN backupdate < '$month_ago' THEN 1 END) AS b2g_danger
FROM backup2go
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
return current($this->query($sql));
}
}
20 changes: 20 additions & 0 deletions app/modules/backup2go/scripts/backup2go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Script to collect data
# and put the data into outputfile

CWD=$(dirname $0)
CACHEDIR="$CWD/cache/"
OUTPUT_FILE="${CACHEDIR}backup2go.txt"
SEPARATOR=' = '

# Skip manual check
if [ "$1" = 'manualcheck' ]; then
echo 'Manual check: skipping'
exit 0
fi

# Create cache dir if it does not exist
mkdir -p "${CACHEDIR}"

/usr/local/aw/bin/nsdchat -c Server 10001 lastend > ${OUTPUT_FILE}
24 changes: 24 additions & 0 deletions app/modules/backup2go/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
MODULE_NAME="backup2go"

# backup2go controller
CTL="${BASEURL}index.php?/module/backup2go/"

# Get the scripts in the proper directories
${CURL} "${CTL}get_script/backup2go.sh" -o "${MUNKIPATH}preflight.d/backup2go.sh"

# Check exit status of curl
if [ $? = 0 ]; then
# Make executable
chmod a+x "${MUNKIPATH}preflight.d/backup2go.sh"

# Set preference to include this file in the preflight check
setreportpref "backup2go" "${CACHEPATH}backup2go.txt"

else
echo "Failed to download all required components!"
rm -f "${MUNKIPATH}preflight.d/backup2go.sh"

# Signal that we had an error
ERR=1
fi
7 changes: 7 additions & 0 deletions app/modules/backup2go/scripts/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Remove backup2go script
rm -f "${MUNKIPATH}preflight.d/backup2go.sh"

# Remove backup2go.txt file
rm -f "${MUNKIPATH}preflight.d/cache/backup2go.txt"
48 changes: 48 additions & 0 deletions app/modules/backup2go/views/backup2go_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="col-lg-4 col-md-6">
<div class="panel panel-default">
<div class="panel-heading" data-container="body">
<h3 class="panel-title"><i class="fa fa-clock-o"></i> <span data-i18n="backup2go.widget.title"></span></h3>
</div>

<div class="list-group scroll-box">
<a id="b2g-b2g_ok" href="<?=url('/show/listing/backup2go')?>" class="list-group-item list-group-item-success hide">
<span class="badge">0</span>
<span data-i18n="widget.timemachine.b2g_ok"></span>
</a>
<a id="b2g-b2g_warning" href="<?=url('/show/listing/backup2go')?>" class="list-group-item list-group-item-warning hide">
<span class="badge">0</span>
<span data-i18n="widget.timemachine.b2g_warning"></span>
</a>
<a id="b2g-b2g_danger" href="<?=url('/show/listing/backup2go')?>" class="list-group-item list-group-item-danger hide">
<span class="badge">0</span>
<span data-i18n="widget.timemachine.b2g_danger"></span>
</a>
<span id="b2g-nodata" data-i18n="no_clients" class="list-group-item"></span>
</div>
</div>
</div>

<script>
$(document).on('appReady appUpdate', function(e, lang) {

$.getJSON( appUrl + '/module/backup2go/get_stats', function( data ) {
// Show no clients span
$('#b2g-nodata').removeClass('hide');

//load colour classes into list
$.each(data, function(prop, val){
if(val > 0){
$('#b2g-' + prop).removeClass('hide');
$('#b2g-' + prop + ' > .badge').text(val);

// Hide no clients span
$('#b2g-nodata').addClass('hide');
}
else {
$('#b2g-' + prop).addClass('hide');
}
});
});
});
</script>

5 changes: 3 additions & 2 deletions app/modules/deploystudio/lib/deploystudio_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public function pull_deploystudio_data(&$deploystudio_model)
{
// Error message
$error = '';

$deploystudio_server = conf('deploystudio_server');

# Trim off any slashes on the right (DeployStudio does not handle double slashes well)
$deploystudio_server = rtrim(conf('deploystudio_server'), '/');

// Get computer data from DeployStudio
$url = "{$deploystudio_server}/computers/get/entry?id={$deploystudio_model->serial_number}";
Expand Down
4 changes: 2 additions & 2 deletions app/modules/disk_report/scripts/disk_info
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def DiskReport():
if getattr(disk, 'Partitions', None):
for partition in disk.Partitions:

if partition.Content == 'Apple_HFS':
if partition.Content == 'Apple_HFS' and partition.get('MountPoint'):
diskInfo = filteredDiskInfo(partition.DeviceIdentifier)
if diskInfo['BusProtocol'] == 'Disk Image':
# Skip Disk Images
Expand Down Expand Up @@ -190,7 +190,7 @@ def DiskReport():
volumeList.append(diskInfo)

else:
if disk.Content == 'Apple_HFS':
if disk.Content == 'Apple_HFS' and disk.get('MountPoint'):
diskInfo = filteredDiskInfo(disk.DeviceIdentifier)

if diskInfo['BusProtocol'] == 'Disk Image':
Expand Down
5 changes: 1 addition & 4 deletions app/modules/managedinstalls/scripts/managedinstalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
DEBUG = False
MANAGED_INSTALL_REPORT = '/Library/Managed Installs/ManagedInstallReport.plist'

# Skip manual check
# Don't skip manual check
if len(sys.argv) > 1:
if sys.argv[1] == 'manualcheck':
print 'Manual check: skipping'
exit(0)
if sys.argv[1] == 'debug':
print '**** DEBUGGING ENABLED ****'
DEBUG = True
Expand Down
13 changes: 3 additions & 10 deletions app/modules/managedinstalls/views/pkg_stats.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php $this->view('partials/head', array('scripts' => array("clients/client_list.js"))); ?>

<?php //Initialize models needed for the table
new Machine_model;
new Reportdata_model;
new Munkireport_model;
new munkiinfo_model;
?>

<div class="container">

<div class="row">
Expand Down Expand Up @@ -48,9 +41,9 @@
$.each(data, function(index, val){
if(val.name){
var displayname = (val.display_name || val.name),
installed = val.installed || 0,
pending = val.pending_install || 0,
failed = val.install_failed || 0,
installed = +val.installed || 0,
pending = +val.pending_install || 0,
failed = +val.install_failed || 0,
total = installed + pending + failed,
pct = total ? Math.round((total - pending - failed)/total * 100) : 0;
dataSet.push([
Expand Down
8 changes: 3 additions & 5 deletions app/modules/munkireport/scripts/munkireport.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/python
"""
Filter the result of /Library/Managed Installs/MANAGED_INSTALL_REPORT.plist
to only the parts that represent the installed items
to these items: 'EndTime', 'StartTime', 'ManifestName', 'ManagedInstallVersion'
'Errors', 'Warnings', 'RunType'
"""

import plistlib
Expand All @@ -11,11 +12,8 @@
DEBUG = False
MANAGED_INSTALL_REPORT = '/Library/Managed Installs/ManagedInstallReport.plist'

# Skip manual check
# Don't skip manual check
if len(sys.argv) > 1:
if sys.argv[1] == 'manualcheck':
print 'Manual check: skipping'
exit(0)
if sys.argv[1] == 'debug':
print '**** DEBUGGING ENABLED ****'
DEBUG = True
Expand Down
2 changes: 1 addition & 1 deletion app/modules/printer/scripts/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
if printer.get('uri'):
result += 'Name: ' + printer['_name'] + '\n'
result += 'PPD: ' + printer['ppd'] + '\n'
result += 'Driver Version: ' + printer['ppdfileversion'] + '\n'
result += 'Driver Version: ' + printer.get('ppdfileversion', '') + '\n'
result += 'URL: ' + printer['uri'] + '\n'
result += 'Default Set: ' + printer['default'] + '\n'
result += 'Printer Status: ' + printer['status'] + '\n'
Expand Down
Loading

0 comments on commit 0a2d8f5

Please sign in to comment.