-
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
32 changed files
with
911 additions
and
62 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
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 @@ | ||
<?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 |
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,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)); | ||
} | ||
} |
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,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} |
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,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 |
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,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" |
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,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> | ||
|
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
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
Oops, something went wrong.