|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright (c) 2013, Marius Cramer, pixcept KG |
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +Redistribution and use in source and binary forms, with or without modification, |
| 8 | +are permitted provided that the following conditions are met: |
| 9 | +
|
| 10 | + * Redistributions of source code must retain the above copyright notice, |
| 11 | + this list of conditions and the following disclaimer. |
| 12 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + this list of conditions and the following disclaimer in the documentation |
| 14 | + and/or other materials provided with the distribution. |
| 15 | + * Neither the name of ISPConfig nor the names of its contributors |
| 16 | + may be used to endorse or promote products derived from this software without |
| 17 | + specific prior written permission. |
| 18 | +
|
| 19 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 20 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 23 | +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 24 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 26 | +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 28 | +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | +*/ |
| 30 | + |
| 31 | +class cronjob_monitor_backup extends cronjob { |
| 32 | + |
| 33 | + // job schedule |
| 34 | + protected $_schedule = '*/5 * * * *'; |
| 35 | + protected $_run_at_new = true; |
| 36 | + |
| 37 | + private $_tools = null; |
| 38 | + |
| 39 | + /* this function is optional if it contains no custom code */ |
| 40 | + public function onPrepare() { |
| 41 | + parent::onPrepare(); |
| 42 | + } |
| 43 | + |
| 44 | + /* this function is optional if it contains no custom code */ |
| 45 | + public function onBeforeRun() { |
| 46 | + return parent::onBeforeRun(); |
| 47 | + } |
| 48 | + |
| 49 | + public function onRunJob() { |
| 50 | + global $app, $conf; |
| 51 | + |
| 52 | + /* used for all monitor cronjobs */ |
| 53 | + $app->load('monitor_tools'); |
| 54 | + $this->_tools = new monitor_tools(); |
| 55 | + /* end global section for monitor cronjobs */ |
| 56 | + |
| 57 | + /* the id of the server as int */ |
| 58 | + $server_id = intval($conf['server_id']); |
| 59 | + |
| 60 | + /** The type of the data */ |
| 61 | + |
| 62 | + |
| 63 | + $type = 'backup_utils'; |
| 64 | + |
| 65 | + $missing_utils = array(); |
| 66 | + $compressors_list = array( |
| 67 | + 'gzip', |
| 68 | + 'gunzip', |
| 69 | + 'zip', |
| 70 | + 'unzip', |
| 71 | + 'pigz', |
| 72 | + 'tar', |
| 73 | + 'bzip2', |
| 74 | + 'bunzip2', |
| 75 | + 'xz', |
| 76 | + 'unxz', |
| 77 | + '7z', |
| 78 | + 'rar', |
| 79 | + ); |
| 80 | + foreach ($compressors_list as $compressor) { |
| 81 | + if (!$app->system->is_installed($compressor)) { |
| 82 | + $missing_utils[] = $compressor; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + $res = array(); |
| 87 | + $res['server_id'] = $server_id; |
| 88 | + $res['type'] = $type; |
| 89 | + $res['data'] = array('missing_utils' => $missing_utils); |
| 90 | + $res['state'] = 'ok'; |
| 91 | + |
| 92 | + /* |
| 93 | + * Insert the data into the database |
| 94 | + */ |
| 95 | + $sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
| 96 | + 'VALUES (?, ?, UNIX_TIMESTAMP(), ?, ?)'; |
| 97 | + $app->dbmaster->query($sql, $res['server_id'], $res['type'], serialize($res['data']), $res['state']); |
| 98 | + |
| 99 | + /* The new data is written, now we can delete the old one */ |
| 100 | + $this->_tools->delOldRecords($res['type'], $res['server_id']); |
| 101 | + |
| 102 | + parent::onRunJob(); |
| 103 | + } |
| 104 | + |
| 105 | + /* this function is optional if it contains no custom code */ |
| 106 | + public function onAfterRun() { |
| 107 | + parent::onAfterRun(); |
| 108 | + } |
| 109 | + |
| 110 | +} |
0 commit comments