updater.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Class that handels autoupdating of ownCloud
  24. */
  25. class OC_Updater{
  26. /**
  27. * Check if a new version is available
  28. */
  29. public static function check() {
  30. OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
  31. if(OC_Appconfig::getValue('core', 'installedat', '')=='') {
  32. OC_Appconfig::setValue('core', 'installedat', microtime(true));
  33. }
  34. $updaterurl='http://apps.owncloud.com/updater.php';
  35. $version=OC_Util::getVersion();
  36. $version['installed']=OC_Appconfig::getValue('core', 'installedat');
  37. $version['updated']=OC_Appconfig::getValue('core', 'lastupdatedat');
  38. $version['updatechannel']='stable';
  39. $version['edition']=OC_Util::getEditionString();
  40. $versionstring=implode('x', $version);
  41. //fetch xml data from updater
  42. $url=$updaterurl.'?version='.$versionstring;
  43. // set a sensible timeout of 10 sec to stay responsive even if the update server is down.
  44. $ctx = stream_context_create(
  45. array(
  46. 'http' => array(
  47. 'timeout' => 10
  48. )
  49. )
  50. );
  51. $xml=@file_get_contents($url, 0, $ctx);
  52. if($xml==false) {
  53. return array();
  54. }
  55. $data=@simplexml_load_string($xml);
  56. $tmp=array();
  57. $tmp['version'] = $data->version;
  58. $tmp['versionstring'] = $data->versionstring;
  59. $tmp['url'] = $data->url;
  60. $tmp['web'] = $data->web;
  61. return $tmp;
  62. }
  63. public static function ShowUpdatingHint() {
  64. $l = OC_L10N::get('lib');
  65. if(OC_Config::getValue('updatechecker', true)==true) {
  66. $data=OC_Updater::check();
  67. if(isset($data['version']) and $data['version']<>'') {
  68. $txt='<span style="color:#AA0000; font-weight:bold;">'
  69. .$l->t('%s is available. Get <a href="%s">more information</a>',
  70. array($data['versionstring'], $data['web'])).'</span>';
  71. }else{
  72. $txt=$l->t('up to date');
  73. }
  74. }else{
  75. $txt=$l->t('updates check is disabled');
  76. }
  77. return($txt);
  78. }
  79. /**
  80. * do ownCloud update
  81. */
  82. public static function doUpdate() {
  83. //update ownCloud core
  84. //update all apps
  85. //update version in config
  86. }
  87. }