/
check_version.php
121 lines (101 loc) · 3.6 KB
/
check_version.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
# Mantis - a php based bugtracking system
# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
/**
* @package MantisBT
* @version $Id$
* @copyright Copyright (C) 2000 - 2008 Mantis Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
require_once( 'core.php' );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path . 'version_api.php' );
$f_protocol_version = gpc_get_int( 'protocol_version', -1 );
$f_project_id = gpc_get_int( 'project_id', -1 );
$f_version = gpc_get_string( 'version', '' );
# Make sure that IE can download the attachments under https.
header( 'Pragma: public' );
header( 'Content-Type: text/plain' );
# Protocol Version 1
#
# <operation result>
# <multi line parameters>
#
# operation result: up_to_date | update_available | access_denied | failure
#
# up_to_date has no parameters
#
# update_available Parameters:
# latest version
# changelog link
# version description
#
# Access Denied has no parameters. Issue for case where access is denied or project/version doesn't exist.
#
# Failure:
# error message (e.g. database failure, in maintenance, etc)
$t_latest_supported_protocol = 1;
$t_access_denied_string = VERSION_CHECK_ACCESS_DENIED . "\n";
$t_failure_string = VERSION_CHECK_FAILURE . "\n";
# Make sure protocol version is specified.
if ( $f_protocol_version == -1 ) {
echo $t_failure_string, "protocol version not specified.\n";
die;
}
# Make sure request version is supported.
if ( $f_protocol_version < 1 || $f_protocol_version > $t_latest_supported_protocol ) {
echo $t_failure_string, "protocol version '" . $f_protocol_version . "' not supported.\n";
die;
}
# Make sure project id is specified.
if ( $f_project_id == -1 ) {
echo $t_failure_string, "project id not specified.\n";
die;
}
# Make sure version name is specified.
if ( $f_version == '' ) {
echo $t_failure_string, "version name not specified.\n";
die;
}
# Retrieve configuration
$t_public_projects = config_get( 'check_version_for_public_projects_enabled' );
$t_private_projects = config_get( 'check_version_for_public_projects_enabled' );
# if the feature is disabled for all kinds of projects, then return access denied response.
if ( !$t_public_projects && !$t_private_projects ) {
echo $t_access_denied_string;
die;
}
# if only public projects available, make sure the request is not referring to a public project.
if ( !$t_private_projects ) {
$t_view_state = project_get_field( $f_project_id, 'view_state');
if ( $t_view_state != VS_PUBLIC ) {
echo $t_access_denied_string;
die;
}
}
$t_client_version_id = version_get_id( $f_version, $f_project_id );
if ( $t_client_version_id === false ) {
echo $t_failure_string, "version not found.\n";
die;
}
$t_version = version_get_latest_by_upgrade_tag( $t_client_version_id );
if ( $t_version->id == $t_client_version_id ) {
echo VERSION_CHECK_UP_TO_DATE . "\n";
die;
}
echo VERSION_CHECK_UPDATE_AVAILABLE . "\n";
echo $t_version->version, "\n";
$t_path = config_get( 'path' );
echo $t_path . "changelog_page.php?version=", $t_version->id, "\n";
echo $t_version->description, "\n";