This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | //------------------------------------------------------------------------------ |
||
4 | // |
||
5 | // eTraxis - Records tracking web-based system |
||
6 | // Copyright (C) 2005-2010 Artem Rodygin |
||
7 | // |
||
8 | // This program is free software: you can redistribute it and/or modify |
||
9 | // it under the terms of the GNU General Public License as published by |
||
10 | // the Free Software Foundation, either version 3 of the License, or |
||
11 | // (at your option) any later version. |
||
12 | // |
||
13 | // This program 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 General Public License for more details. |
||
17 | // |
||
18 | // You should have received a copy of the GNU General Public License |
||
19 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 | // |
||
21 | //------------------------------------------------------------------------------ |
||
22 | |||
23 | /** |
||
24 | * @package eTraxis |
||
25 | * @ignore |
||
26 | */ |
||
27 | |||
28 | /**#@+ |
||
29 | * Dependency. |
||
30 | */ |
||
31 | require_once('../engine/engine.php'); |
||
32 | require_once('../dbo/projects.php'); |
||
33 | require_once('../dbo/fields.php'); |
||
34 | /**#@-*/ |
||
35 | |||
36 | init_page(LOAD_TAB); |
||
37 | |||
38 | if (get_user_level() != USER_LEVEL_ADMIN) |
||
39 | { |
||
40 | debug_write_log(DEBUG_NOTICE, 'User must have admin rights to be allowed.'); |
||
41 | exit; |
||
42 | } |
||
43 | |||
44 | // check that requested field exists |
||
45 | |||
46 | $id = ustr2int(try_request('id')); |
||
47 | $field = field_find($id); |
||
48 | |||
49 | if (!$field) |
||
50 | { |
||
51 | debug_write_log(DEBUG_NOTICE, 'Field cannot be found.'); |
||
52 | exit; |
||
53 | } |
||
54 | |||
55 | // save changed permissions |
||
56 | |||
57 | if (try_request('submitted') == 'permsform') |
||
58 | { |
||
59 | debug_write_log(DEBUG_NOTICE, 'Data are submitted.'); |
||
60 | |||
61 | $gid = ustr2int(try_request('group', FIELD_ROLE_AUTHOR), MIN_FIELD_ROLE); |
||
62 | $permissions = ustr2int(try_request('permissions', FIELD_RESTRICTED), FIELD_RESTRICTED, FIELD_ALLOW_TO_WRITE); |
||
63 | |||
64 | switch ($gid) |
||
65 | { |
||
66 | case FIELD_ROLE_AUTHOR: |
||
67 | field_author_permission_set($id, $permissions); |
||
68 | break; |
||
69 | |||
70 | case FIELD_ROLE_RESPONSIBLE: |
||
71 | field_responsible_permission_set($id, $permissions); |
||
72 | break; |
||
73 | |||
74 | case FIELD_ROLE_REGISTERED: |
||
75 | field_registered_permission_set($id, $permissions); |
||
76 | break; |
||
77 | |||
78 | default: |
||
79 | |||
80 | field_permission_remove($id, $gid); |
||
81 | |||
82 | if ($permissions == FIELD_ALLOW_TO_READ) |
||
83 | { |
||
84 | field_permission_add($id, $gid, FIELD_ALLOW_TO_READ); |
||
85 | } |
||
86 | elseif ($permissions == FIELD_ALLOW_TO_WRITE) |
||
87 | { |
||
88 | field_permission_add($id, $gid, FIELD_ALLOW_TO_READ); |
||
89 | field_permission_add($id, $gid, FIELD_ALLOW_TO_WRITE); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | exit; |
||
94 | } |
||
95 | else |
||
96 | { |
||
97 | debug_write_log(DEBUG_NOTICE, 'Data are being requested.'); |
||
98 | } |
||
99 | |||
100 | // JS array with permissions |
||
101 | |||
102 | $xml = '<script>' |
||
103 | . 'var permissions = new Array();' |
||
104 | . sprintf('permissions["g%d"] = %d;', FIELD_ROLE_AUTHOR, $field['author_perm']) |
||
105 | . sprintf('permissions["g%d"] = %d;', FIELD_ROLE_RESPONSIBLE, $field['responsible_perm']) |
||
106 | . sprintf('permissions["g%d"] = %d;', FIELD_ROLE_REGISTERED, $field['registered_perm']); |
||
107 | |||
108 | $rs = dal_query('groups/list.sql', $field['project_id'], 'is_global, group_name'); |
||
109 | |||
110 | while (($row = $rs->fetch())) |
||
111 | { |
||
112 | $xml .= sprintf('permissions["g%d"] = 0;', $row['group_id']); |
||
113 | } |
||
114 | |||
115 | $rs = dal_query('fields/fplist.sql', $id); |
||
116 | |||
117 | while (($row = $rs->fetch())) |
||
118 | { |
||
119 | $xml .= sprintf('permissions["g%d"] = %d;', $row['group_id'], $row['perms']); |
||
120 | } |
||
121 | |||
122 | // local JS functions |
||
123 | |||
124 | $resTitle = get_js_resource(RES_PERMISSIONS_ID); |
||
125 | $resMessage = get_js_resource(RES_ALERT_SUCCESSFULLY_SAVED_ID); |
||
126 | $resOK = get_js_resource(RES_OK_ID); |
||
127 | |||
128 | $xml .= <<<JQUERY |
||
129 | |||
130 | function permissionsSuccess () |
||
131 | { |
||
132 | var id = $("#group").val(); |
||
133 | permissions["g"+id] = $("input[name=permissions]:radio:checked").val(); |
||
134 | jqAlert("{$resTitle}", "{$resMessage}", "{$resOK}"); |
||
135 | } |
||
136 | |||
137 | function updatePerms () |
||
138 | { |
||
139 | var id = $("#group").val(); |
||
140 | var perm = permissions["g"+id]; |
||
141 | $("input[name=permissions]:radio[value=" + perm + "]").prop("checked", true); |
||
142 | } |
||
143 | |||
144 | </script> |
||
145 | JQUERY; |
||
146 | |||
147 | // generate left side |
||
148 | |||
149 | $xml .= '<form name="permsform" action="fperms.php?id=' . $id . '" success="permissionsSuccess">' |
||
150 | . '<dual>' |
||
151 | . '<dualleft>' |
||
152 | . '<group title="' . get_html_resource(RES_GROUPS_ID) . '">' |
||
153 | . '<control name="group">' |
||
154 | . '<listbox size="10" action="updatePerms()">' |
||
155 | . '<listitem value="' . FIELD_ROLE_AUTHOR . '">' . sprintf('%s (%s)', get_html_resource(RES_AUTHOR_ID), get_html_resource(RES_ROLE_ID)) . '</listitem>' |
||
156 | . '<listitem value="' . FIELD_ROLE_RESPONSIBLE . '">' . sprintf('%s (%s)', get_html_resource(RES_RESPONSIBLE_ID), get_html_resource(RES_ROLE_ID)) . '</listitem>' |
||
157 | . '<listitem value="' . FIELD_ROLE_REGISTERED . '">' . sprintf('%s (%s)', get_html_resource(RES_REGISTERED_ID), get_html_resource(RES_ROLE_ID)) . '</listitem>'; |
||
158 | |||
159 | $rs = dal_query('groups/list.sql', $field['project_id'], 'is_global, group_name'); |
||
160 | |||
161 | View Code Duplication | while (($row = $rs->fetch())) |
|
0 ignored issues
–
show
|
|||
162 | { |
||
163 | $xml .= '<listitem value="' . $row['group_id'] . '">' |
||
164 | . ustr2html(sprintf('%s (%s)', $row['group_name'], get_html_resource($row['is_global'] ? RES_GLOBAL_ID : RES_LOCAL_ID))) |
||
165 | . '</listitem>'; |
||
166 | } |
||
167 | |||
168 | $xml .= '</listbox>' |
||
169 | . '</control>' |
||
170 | . '</group>' |
||
171 | . '</dualleft>'; |
||
172 | |||
173 | // generate right side |
||
174 | |||
175 | $xml .= '<dualright>' |
||
176 | . '<group title="' . get_html_resource(RES_PERMISSIONS_ID) . '">' |
||
177 | . '<control name="permissions">' |
||
178 | . '<radio value="' . FIELD_RESTRICTED . '">' . get_html_resource(RES_NONE_ID) . '</radio>' |
||
179 | . '<radio value="' . FIELD_ALLOW_TO_READ . '">' . get_html_resource(RES_READ_ONLY_ID) . '</radio>' |
||
180 | . '<radio value="' . FIELD_ALLOW_TO_WRITE . '">' . get_html_resource(RES_READ_AND_WRITE_ID) . '</radio>' |
||
181 | . '</control>' |
||
182 | . '</group>' |
||
183 | . '<button default="true">' . get_html_resource(RES_SAVE_ID) . '</button>' |
||
184 | . '</dualright>' |
||
185 | . '</dual>' |
||
186 | . '</form>'; |
||
187 | |||
188 | $xml .= '<onready>' |
||
189 | . '$("#group :first-child").prop("selected", true);' |
||
190 | . 'updatePerms();' |
||
191 | . '</onready>'; |
||
192 | |||
193 | echo(xml2html($xml)); |
||
194 | |||
195 | ?> |
||
196 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.