Subversion Repositories oidplus

Rev

Rev 635 | Rev 648 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 635 Rev 647
Line 24... Line 24...
24
        public function init($html=true) {
24
        public function init($html=true) {
25
        }
25
        }
26
 
26
 
27
        public function action($actionID, $params) {
27
        public function action($actionID, $params) {
28
                if ($actionID == 'update_now') {
28
                if ($actionID == 'update_now') {
29
                        @set_time_limit(0); // TODO: what to do if the server does not accept it?
29
                        @set_time_limit(0);
30
 
30
 
31
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
31
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
32
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
32
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
33
                        }
33
                        }
34
 
34
 
35
                        ob_start();
-
 
36
                        $error = "";
35
                        $rev = $params['rev'];
37
                        try {
-
 
38
                                $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
-
 
39
 
36
 
40
                                // We are caching the changed file logs here only in the preview mode.
-
 
41
                                // Reason: We want to avoid that the "update/" page becomes an
37
                        $url = "https://www.oidplus.com/updates/update_".($rev-1)."_to_".($rev).".txt"; // TODO: in consts.ini
42
                                // DoS attack vector if there hasn't been an update for a long time,
-
 
43
                                // and the list is very large.
38
                        $cont = @file_get_contents($url);
44
                                // But we don't want to use cache in the real update, because
-
 
45
                                // otherwise it might break the system if an update is made
-
 
46
                                // while the ViaThinkSoft server is down (because the file list
-
 
47
                                // is cached, and therefore "delete" actions can be made, while
-
 
48
                                // adding/downloading does not work)
-
 
49
                                $svn->use_cache = false;
-
 
50
 
39
 
51
                                if (!$svn->updateWorkingCopy(OIDplus::localpath().'oidplus_version.txt', '/trunk', OIDplus::localpath(), false)) {
40
                        if ($cont === false) throw new OIDplusException(_L("Update could not be downloaded from ViaThinkSoft server. Please try again later."));
52
                                        $error = _L("Some updates failed. Please see details in the update protocol.");
41
                        file_put_contents(OIDplus::localpath().'update.tmp.php', $cont);
53
                                }
42
 
54
                        } catch (Exception $e) {
43
                        # TODO: instead use cURL?
55
                                $error = $e->getMessage();
44
                        // Note: we may not use eval() because script uses die()
56
                        }
-
 
57
                        $cont = ob_get_contents();
45
                        $cont = @file_get_contents(OIDplus::webpath().'update.tmp.php');
58
                        $cont = str_replace(OIDplus::localpath(), '...', $cont);
46
                        if ($cont === false) throw new OIDplusException(_L("Failed to execute update-script. Probably file_get_contents() may not open URLs!"));
59
                        ob_end_clean();
-
 
60
 
47
 
61
                        if ($error != "") {
-
 
62
                                return array("status" => -1, "error" => $error, "content" => $cont);
-
 
63
                        } else {
-
 
64
                                return array("status" => 0, "content" => $cont);
48
                        return array("status" => 0, "content" => $cont);
65
                        }
49
                }
66
                }
50
        }
67
        }
-
 
68
 
51
 
69
        public function gui($id, &$out, &$handled) {
52
        public function gui($id, &$out, &$handled) {
70
                $parts = explode('.',$id,2);
53
                $parts = explode('.',$id,2);
71
                if (!isset($parts[1])) $parts[1] = '';
54
                if (!isset($parts[1])) $parts[1] = '';
72
                if ($parts[0] == 'oidplus:software_update') {
55
                if ($parts[0] == 'oidplus:software_update') {
Line 129... Line 112...
129
                                } else {
112
                                } else {
130
                                        $out['text'] .= '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
113
                                        $out['text'] .= '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
131
 
114
 
132
                                        $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
115
                                        $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
133
 
116
 
-
 
117
                                        // TODO: Completely remove PHP SVN client and instead get log files hard coded from VTS
134
                                        ob_start();
118
                                        ob_start();
135
                                        try {
119
                                        try {
136
                                                $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
120
                                                $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
137
                                                $svn->use_cache = true;
121
                                                $svn->use_cache = true;
138
                                                $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', OIDplus::localpath(), true);
122
                                                $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', OIDplus::localpath(), true);
Line 146... Line 130...
146
                                        $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", $cont);
130
                                        $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", $cont);
147
 
131
 
148
                                        $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>';
132
                                        $out['text'] .= '<pre id="update_infobox">'.$cont.'</pre>';
149
                                }
133
                                }
150
                        } else if ($installType === 'svn-snapshot') {
134
                        } else if ($installType === 'svn-snapshot') {
-
 
135
                                $out['text'] .= '<div id="update_versioninfo">';
-
 
136
 
151
                                $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with oidplus_version.txt file).').'</p>';
137
                                $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with oidplus_version.txt file).').'</p>';
152
 
138
 
153
                                $local_installation = OIDplus::getVersion();
139
                                $local_installation = OIDplus::getVersion();
154
                                try {
140
                                try {
155
                                        $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
141
                                        $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
Line 161... Line 147...
161
                                $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
147
                                $out['text'] .= _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
162
                                $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
148
                                $out['text'] .= _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
163
 
149
 
164
                                if (!$newest_version) {
150
                                if (!$newest_version) {
165
                                        $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
151
                                        $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
-
 
152
                                        $out['text'] .= '</div>';
166
                                }
153
                                }
167
                                else if ($local_installation == $newest_version) {
154
                                else if ($local_installation == $newest_version) {
168
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
155
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
-
 
156
                                        $out['text'] .= '</div>';
169
                                } else {
157
                                } else {
170
                                        $out['text'] .= '<p><font color="red">'.strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! In case the update fails, you can download and extract the complete <a href="https://www.viathinksoft.com/projects/oidplus">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.').'</font></p>';
158
                                        $out['text'] .= '<p><font color="red">'.strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! In case the update fails, you can download and extract the complete <a href="https://www.viathinksoft.com/projects/oidplus">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.').'</font></p>';
171
                                        $out['text'] .= '<form method="POST" action="index.php">';
159
                                        $out['text'] .= '<form method="POST" action="index.php">';
172
 
160
 
173
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus()" value="'._L('Update NOW').'"></p>';
161
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.(substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>';
-
 
162
 
-
 
163
                                        $out['text'] .= '</div>';
174
 
164
 
175
                                        $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
165
                                        $out['text'] .= '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
176
 
166
 
177
                                        ob_start();
167
                                        ob_start();
178
                                        try {
168
                                        try {