You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updater.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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', '')=='') OC_Appconfig::setValue('core', 'installedat', microtime(true));
  32. $updaterurl='http://apps.owncloud.com/updater.php';
  33. $version=OC_Util::getVersion();
  34. $version['installed']=OC_Appconfig::getValue('core', 'installedat');
  35. $version['updated']=OC_Appconfig::getValue('core', 'lastupdatedat');
  36. $version['updatechannel']='stable';
  37. $version['edition']=OC_Util::getEditionString();
  38. $versionstring=implode('x', $version);
  39. //fetch xml data from updater
  40. $url=$updaterurl.'?version='.$versionstring;
  41. // set a sensible timeout of 10 sec to stay responsive even if the update server is down.
  42. $ctx = stream_context_create(
  43. array(
  44. 'http' => array(
  45. 'timeout' => 10
  46. )
  47. )
  48. );
  49. $xml=@file_get_contents($url, 0, $ctx);
  50. if($xml==false) {
  51. return array();
  52. }
  53. $data=@simplexml_load_string($xml);
  54. $tmp=array();
  55. $tmp['version'] = $data->version;
  56. $tmp['versionstring'] = $data->versionstring;
  57. $tmp['url'] = $data->url;
  58. $tmp['web'] = $data->web;
  59. return $tmp;
  60. }
  61. public static function ShowUpdatingHint() {
  62. $l = OC_L10N::get('lib');
  63. if(OC_Config::getValue('updatechecker', true)==true) {
  64. $data=OC_Updater::check();
  65. if(isset($data['version']) and $data['version']<>'') {
  66. $txt='<span style="color:#AA0000; font-weight:bold;">'.$l->t('%s is available. Get <a href="%s">more information</a>', array($data['versionstring'], $data['web'])).'</span>';
  67. }else{
  68. $txt=$l->t('up to date');
  69. }
  70. }else{
  71. $txt=$l->t('updates check is disabled');
  72. }
  73. return($txt);
  74. }
  75. /**
  76. * do ownCloud update
  77. */
  78. public static function doUpdate() {
  79. //update ownCloud core
  80. //update all apps
  81. //update version in config
  82. }
  83. }