2780 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* UpdateNotifier Plugin, which displays update notification from Ubuntu Landscape system
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package PSI_Plugin_UpdateNotifier
|
|
|
7 |
* @author Damien ROTH <iysaak@users.sourceforge.net>
|
|
|
8 |
* @copyright 2009 phpSysInfo
|
|
|
9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
10 |
* @version $Id: class.updatenotifier.inc.php 661 2012-08-27 11:26:39Z namiltd $
|
|
|
11 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
12 |
*/
|
|
|
13 |
class UpdateNotifier extends PSI_Plugin
|
|
|
14 |
{
|
|
|
15 |
/**
|
|
|
16 |
* variable, which holds the content of the command
|
|
|
17 |
* @var array
|
|
|
18 |
*/
|
|
|
19 |
private $_filecontent = array();
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* variable, which holds the result before the xml is generated out of this array
|
|
|
23 |
* @var array
|
|
|
24 |
*/
|
|
|
25 |
private $_result = array();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* read the data into an internal array and also call the parent constructor
|
|
|
29 |
*
|
|
|
30 |
* @param String $enc encoding
|
|
|
31 |
*/
|
|
|
32 |
public function __construct($enc)
|
|
|
33 |
{
|
|
|
34 |
parent::__construct(__CLASS__, $enc);
|
|
|
35 |
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
|
|
|
36 |
case 'command':
|
|
|
37 |
if (defined('PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT') && (PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT === true)) {
|
|
|
38 |
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "--human-readable", $buffer_info);
|
|
|
39 |
} else {
|
|
|
40 |
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "2>&1", $buffer_info);
|
|
|
41 |
}
|
|
|
42 |
break;
|
|
|
43 |
case 'data':
|
|
|
44 |
if (defined('PSI_PLUGIN_UPDATENOTIFIER_FILE') && is_string(PSI_PLUGIN_UPDATENOTIFIER_FILE)) {
|
|
|
45 |
CommonFunctions::rfts(PSI_PLUGIN_UPDATENOTIFIER_FILE, $buffer_info);
|
|
|
46 |
} else {
|
|
|
47 |
CommonFunctions::rfts("/var/lib/update-notifier/updates-available", $buffer_info);
|
|
|
48 |
}
|
|
|
49 |
break;
|
|
|
50 |
default:
|
|
|
51 |
$this->global_error->addConfigError("__construct()", "[updatenotifier] ACCESS");
|
|
|
52 |
break;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
// Remove blank lines
|
|
|
56 |
$this->_filecontent = preg_split("/\r?\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* doing all tasks to get the required informations that the plugin needs
|
|
|
61 |
* result is stored in an internal array
|
|
|
62 |
*
|
|
|
63 |
* @return void
|
|
|
64 |
*/
|
|
|
65 |
public function execute()
|
|
|
66 |
{
|
|
|
67 |
if (empty($this->_filecontent)) {
|
|
|
68 |
return;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
if (defined('PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT') && (PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT === true)) {
|
|
|
72 |
/*
|
|
|
73 |
Ubuntu Landscape format:
|
|
|
74 |
- line 1: packages to update
|
|
|
75 |
- line 2: security packages to update
|
|
|
76 |
*/
|
|
|
77 |
if (count($this->_filecontent) == 2) {
|
|
|
78 |
foreach ($this->_filecontent as $line) {
|
|
|
79 |
list($num, $text) = explode(" ", $line, 2);
|
|
|
80 |
$this->_result[] = $num;
|
|
|
81 |
}
|
|
|
82 |
} else {
|
|
|
83 |
$this->global_error->addWarning("Unable to parse UpdateNotifier file");
|
|
|
84 |
}
|
|
|
85 |
} else {
|
|
|
86 |
/*
|
|
|
87 |
Universal format: A;B
|
|
|
88 |
- A: packages to update
|
|
|
89 |
- B: security packages to update
|
|
|
90 |
*/
|
|
|
91 |
if (count($this->_filecontent) == 1 && strpos($this->_filecontent[0], ";") !== false) {
|
|
|
92 |
$this->_result = explode(";", $this->_filecontent[0]);
|
|
|
93 |
} else {
|
|
|
94 |
$this->global_error->addWarning("Unable to parse UpdateNotifier file");
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* generates the XML content for the plugin
|
|
|
101 |
*
|
|
|
102 |
* @return SimpleXMLElement entire XML content for the plugin
|
|
|
103 |
*/
|
|
|
104 |
public function xml()
|
|
|
105 |
{
|
|
|
106 |
if (!empty($this->_result)) {
|
|
|
107 |
$xmluu = $this->xml->addChild("UpdateNotifier");
|
|
|
108 |
$xmluu->addChild("packages", $this->_result[0]);
|
|
|
109 |
$xmluu->addChild("security", $this->_result[1]);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
return $this->xml->getSimpleXmlElement();
|
|
|
113 |
}
|
|
|
114 |
}
|