updater.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // Look up the cache - it is invalidated all 30 minutes
  31. if((OC_Appconfig::getValue('core', 'lastupdatedat') + 1800) > time()) {
  32. return json_decode(OC_Appconfig::getValue('core', 'lastupdateResult'), true);
  33. }
  34. OC_Appconfig::setValue('core', 'lastupdatedat', time());
  35. if(OC_Appconfig::getValue('core', 'installedat', '')=='') {
  36. OC_Appconfig::setValue('core', 'installedat', microtime(true));
  37. }
  38. $updaterurl='http://apps.owncloud.com/updater.php';
  39. $version=OC_Util::getVersion();
  40. $version['installed']=OC_Appconfig::getValue('core', 'installedat');
  41. $version['updated']=OC_Appconfig::getValue('core', 'lastupdatedat');
  42. $version['updatechannel']='stable';
  43. $version['edition']=OC_Util::getEditionString();
  44. $versionstring=implode('x', $version);
  45. //fetch xml data from updater
  46. $url=$updaterurl.'?version='.$versionstring;
  47. // set a sensible timeout of 10 sec to stay responsive even if the update server is down.
  48. $ctx = stream_context_create(
  49. array(
  50. 'http' => array(
  51. 'timeout' => 10
  52. )
  53. )
  54. );
  55. $xml=@file_get_contents($url, 0, $ctx);
  56. if($xml==false) {
  57. return array();
  58. }
  59. $data=@simplexml_load_string($xml);
  60. $tmp=array();
  61. $tmp['version'] = $data->version;
  62. $tmp['versionstring'] = $data->versionstring;
  63. $tmp['url'] = $data->url;
  64. $tmp['web'] = $data->web;
  65. // Cache the result
  66. OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data));
  67. return $tmp;
  68. }
  69. }