diff --git a/WHATSNEW.md b/WHATSNEW.md index c197b0dcdb16f4ce1ac716d5cdd62328de6bc772..fee85be12ff60740974dfbb91aa25161e88a6851 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -6,6 +6,7 @@ osTicket v1.9.11 * Log to syslog on php mail() error (#2128) * Full path of help topics shown in filter management (3d98dff) * Auto rebuild the search index if %_search table is dropped (#2250) + * New version available message in system information (0cca608) ### Improvements * Fix appearance of ` <div>` in user names (*regression in v1.9.9*) (be2f138) diff --git a/bootstrap.php b/bootstrap.php index 145918c87800867cfa3ce557e67eaf755419f32f..55848778c4670d48a6c8f91fbb7ec24cf907cf29 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -304,6 +304,7 @@ define('I18N_DIR', INCLUDE_DIR.'i18n/'); #Current version && schema signature (Changes from version to version) define('THIS_VERSION','1.8-git'); //Shown on admin panel define('GIT_VERSION','$git'); +define('MAJOR_VERSION', '1.9'); //Path separator if(!defined('PATH_SEPARATOR')){ if(strpos($_ENV['OS'],'Win')!==false || !strcasecmp(substr(PHP_OS, 0, 3),'WIN')) diff --git a/include/class.osticket.php b/include/class.osticket.php index d7e8f3d98a4386762d0071294f6dfb982f4a070e..44a354ed06072e48d9ba90939ba9713c7f8e6595 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -361,6 +361,75 @@ class osTicket { return null; } + /** + * Fetch the current version(s) of osTicket softwares via DNS. The + * constants of MAJOR_VERSION, THIS_VERSION, and GIT_VERSION will be + * consulted to arrive at the most relevant version code for the latest + * release. + * + * Parameters: + * $product - (string|default:'core') the product to fetch versions for + * $major - (string|optional) optional major version to compare. This is + * useful if more than one version is available. Only versions + * specifying this major version ('m') are considered as version + * candidates. + * + * Dns: + * The DNS zone will have TXT records for the product will be published + * in this format: + * + * "v=1; m=1.9; V=1.9.11; c=deadbeef" + * + * Where the string is a semicolon-separated string of key/value pairs + * with the following meanings: + * + * --+-------------------------- + * v | DNS record format version + * + * For v=1, this is the meaning of the other keys + * --+------------------------------------------- + * m | (optional) major product version + * V | Full product version (usually a git tag) + * c | Git commit id of the release tag + * s | Schema signature of the version, which might help detect + * | required migration + * + * Returns: + * (string|bool|null) + * - 'v1.9.11' or 'deadbeef' if release tag or git commit id seems to + * be most appropriate based on the value of GIT_VERSION + * - null if the $major version is no longer supported + * - false if no information is available in DNS + */ + function getLatestVersion($product='core', $major=null) { + $records = dns_get_record($product.'.updates.osticket.com', DNS_TXT); + if (!$records) + return false; + + $versions = array(); + foreach ($records as $r) { + $txt = $r['txt']; + $info = array(); + foreach (explode(';', $r['txt']) as $kv) { + list($k, $v) = explode('=', $kv); + if (!($k = trim($k))) + continue; + $info[$k] = trim($v); + } + $versions[] = $info; + } + foreach ($versions as $info) { + switch ($info['v']) { + case '1': + if ($major && $info['m'] && $info['m'] != $major) + continue; + if ($product == 'core' && GIT_VERSION == '$git') + return $info['c']; + return $info['V']; + } + } + } + static function get_root_path($dir) { /* If run from the commandline, DOCUMENT_ROOT will not be set. It is diff --git a/include/class.plugin.php b/include/class.plugin.php index 240fbbc02559c7688181edbda0bc3c1c9e49b4c6..dd9b5bceb1d0d7cb71104766654296c0e01c6d80 100644 --- a/include/class.plugin.php +++ b/include/class.plugin.php @@ -532,27 +532,19 @@ abstract class Plugin { return self::VERIFY_ERROR; } - require_once(PEAR_DIR.'Net/DNS2.php'); $P = new Phar($phar); $sig = $P->getSignature(); $info = array(); - try { - $q = new Net_DNS2_Resolver(); - $r = $q->query(strtolower($sig['hash']) . '.' . self::$verify_domain, 'TXT'); - foreach ($r->answer as $rec) { - foreach ($rec->text as $txt) { - foreach (explode(';', $txt) as $kv) { - list($k, $v) = explode('=', trim($kv)); - $info[$k] = trim($v); - } - if ($info['v'] && $info['s']) - break; + if ($r = dns_get_record($sig['hash'].'.'.self::$verify_domain, DNS_TXT)) { + foreach ($r as $rec) { + foreach (explode(';', $rec['txt']) as $kv) { + list($k, $v) = explode('=', trim($kv)); + $info[$k] = trim($v); } + if ($info['v'] && $info['s']) + break; } } - catch (Net_DNS2_Exception $e) { - // TODO: Differenciate NXDOMAIN and DNS failure - } if (is_array($info) && isset($info['v'])) { switch ($info['v']) { diff --git a/include/staff/system.inc.php b/include/staff/system.inc.php index 1445f25474e541c5354da7bffaf0f75e57a99010..144b9a74ab6739ab4396e7ad603ef75eff3fd918 100644 --- a/include/staff/system.inc.php +++ b/include/staff/system.inc.php @@ -49,7 +49,35 @@ $extensions = array( <tbody> <tr><td><?php echo __('osTicket Version'); ?></td> <td><span class="ltr"><?php - echo sprintf("%s (%s)", THIS_VERSION, trim($commit)); ?></span></td></tr> + echo sprintf("%s (%s)", THIS_VERSION, trim($commit)); ?></span> +<?php +$lv = $ost->getLatestVersion('core', MAJOR_VERSION); +$tv = THIS_VERSION; +$gv = GIT_VERSION == '$git' ? substr(@`git rev-parse HEAD`, 0, 7) : false ?: GIT_VERSION; +if ($lv && $tv[0] == 'v' ? version_compare(THIS_VERSION, $lv, '>=') : $lv == $gv) { ?> + — <span style="color:green"><i class="icon-check"></i> <?php echo __('Up to date'); ?></span> +<?php +} +else { + // Report current version (v1.9.x ?: deadbeef ?: $git) + $cv = $tv[0] == 'v' ? $tv : $gv; +?> + <a class="green button action-button pull-right" + href="http://osticket.com/download?cv=<?php echo $cv; ?>"><i class="icon-rocket"></i> + <?php echo __('Upgrade'); ?></a> +<?php if ($lv) { ?> + <strong> — <?php echo str_replace( + '%s', $lv, __("%s is available") + ); ?></strong> +<?php } +} +if (!$lv) { ?> + <strong> — <?php echo __('This osTicket version is no longer supported. Please consider upgrading'); + ?></strong> +<?php +} +?> + </td></tr> <tr><td><?php echo __('Web Server Software'); ?></td> <td><span class="ltr"><?php echo $_SERVER['SERVER_SOFTWARE']; ?></span></td></tr> <tr><td><?php echo __('MySQL Version'); ?></td> diff --git a/setup/cli/modules/package.php b/setup/cli/modules/package.php index 77a86a9446382cd010b9972bcf6e854ee9557367..0374f27d6f6831bc868fc9f0aa2e743b2260412a 100644 --- a/setup/cli/modules/package.php +++ b/setup/cli/modules/package.php @@ -20,6 +20,10 @@ class Packager extends Deployment { 'action'=>'store_true', 'default'=>false, 'help'=>'Skip regression testing (NOT RECOMMENDED)', ), + 'version' => array('', '--dns', + 'action'=>'store_true', 'default'=>false, + 'help'=>'Print current version tag for DNS' + ), ); var $arguments = array(); @@ -30,6 +34,9 @@ class Packager extends Deployment { } function run($args, $options) { + if ($options['dns']) + return $this->print_dns(); + // Set some forced args and options $temp = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $stage_path = $temp . 'osticket' @@ -87,6 +94,15 @@ class Packager extends Deployment { return (require "$root/setup/test/run-tests.php"); } + function print_dns() { + $streams = DatabaseMigrater::getUpgradeStreams(INCLUDE_DIR.'upgrader/streams/'); + $this->stdout->write(sprintf( + '"v=1; m=%s; V=%s; c=%s; s=%s"', + MAJOR_VERSION, trim(`git describe`), substr(`git rev-parse HEAD`, 0, 7), + substr($streams['core'], 0, 8) + )); + } + function packageZip($name, $path) { $zip = new ZipArchive(); if (!$zip->open($name, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true)