updateController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. class FreshRSS_update_Controller extends Minz_ActionController {
  3. public function firstAction() {
  4. $current_user = Minz_Session::param('currentUser', '');
  5. if (!$this->view->loginOk && Minz_Configuration::isAdmin($current_user)) {
  6. Minz_Error::error(
  7. 403,
  8. array('error' => array(_t('access_denied')))
  9. );
  10. }
  11. Minz_View::prependTitle(_t('update_system') . ' · ');
  12. }
  13. public function indexAction() {
  14. if (file_exists(UPDATE_FILENAME)) {
  15. // There is an update file to apply!
  16. $this->view->message = array(
  17. 'status' => 'good',
  18. 'title' => _t('ok'),
  19. 'body' => _t('update_can_apply', _url('update', 'apply'))
  20. );
  21. return;
  22. }
  23. }
  24. public function checkAction() {
  25. $this->view->change_view('update', 'index');
  26. if (file_exists(UPDATE_FILENAME)) {
  27. // There is already an update file to apply: we don't need to check
  28. // the webserver!
  29. $this->view->message = array(
  30. 'status' => 'good',
  31. 'title' => _t('ok'),
  32. 'body' => _t('update_can_apply', _url('update', 'apply'))
  33. );
  34. return;
  35. }
  36. $c = curl_init(FRESHRSS_UPDATE_WEBSITE);
  37. curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  38. $result = curl_exec($c);
  39. if (curl_getinfo($c, CURLINFO_HTTP_CODE) == 200) {
  40. $res_array = explode("\n", $result, 2);
  41. $status = $res_array[0];
  42. if (strpos($status, 'UPDATE') === 0) {
  43. $script = $res_array[1];
  44. if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
  45. $this->view->message = array(
  46. 'status' => 'good',
  47. 'title' => _t('ok'),
  48. 'body' => _t('update_can_apply', _url('update', 'apply'))
  49. );
  50. } else {
  51. $this->view->message = array(
  52. 'status' => 'bad',
  53. 'title' => _t('damn'),
  54. 'body' => _t('update_problem')
  55. );
  56. }
  57. } else {
  58. $this->view->message = array(
  59. 'status' => 'bad',
  60. 'title' => _t('damn'),
  61. 'body' => _t('no_update')
  62. );
  63. }
  64. } else {
  65. $this->view->message = array(
  66. 'status' => 'bad',
  67. 'title' => _t('damn'),
  68. 'body' => _t('update_server_not_found', FRESHRSS_UPDATE_WEBSITE)
  69. );
  70. }
  71. curl_close($c);
  72. }
  73. public function applyAction() {
  74. require(UPDATE_FILENAME);
  75. $res = apply_update();
  76. if ($res === true) {
  77. @unlink(UPDATE_FILENAME);
  78. Minz_Session::_param('notification', array(
  79. 'type' => 'good',
  80. 'content' => Minz_Translate::t('update_finished')
  81. ));
  82. Minz_Request::forward(array(), true);
  83. } else {
  84. Minz_Session::_param('notification', array(
  85. 'type' => 'bad',
  86. 'content' => Minz_Translate::t('update_failed', $res)
  87. ));
  88. Minz_Request::forward(array('c' => 'update'), true);
  89. }
  90. }
  91. }