@@ -199,6 +199,69 @@ public function server_get_functions($session_id, $server_id)
199199 }
200200 }
201201
202+ /**
203+ * set record permissions in any table
204+ * @param string session_id
205+ * @param string index_field
206+ * @param string index_value
207+ * @param array permissions
208+ * @author "ispcomm", improved by M. Cramer <m.cramer@pixcept.de>
209+ */
210+ public function update_record_permissions ($ tablename , $ index_field , $ index_value , $ permissions ) {
211+ global $ app ;
212+
213+ if (!$ this ->checkPerm ($ session_id , 'admin_record_permissions ' )) {
214+ $ this ->server ->fault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
215+ return false ;
216+ }
217+
218+ foreach ($ permissions as $ key => $ value ) { // make sure only sys_ fields are updated
219+ switch ($ key ) {
220+ case 'sys_userid ' :
221+ // check if userid is valid
222+ $ check = $ app ->db ->queryOneRecord ('SELECT userid FROM sys_user WHERE userid = ' . $ app ->functions ->intval ($ value ));
223+ if (!$ check || !$ check ['userid ' ]) {
224+ $ this ->server ->fault ('invalid parameters ' , $ value . ' is no valid sys_userid. ' );
225+ return false ;
226+ }
227+ $ permissions [$ key ] = $ app ->functions ->intval ($ value );
228+ break ;
229+ case 'sys_groupid ' :
230+ // check if groupid is valid
231+ $ check = $ app ->db ->queryOneRecord ('SELECT groupid FROM sys_group WHERE groupid = ' . $ app ->functions ->intval ($ value ));
232+ if (!$ check || !$ check ['groupid ' ]) {
233+ $ this ->server ->fault ('invalid parameters ' , $ value . ' is no valid sys_groupid. ' );
234+ return false ;
235+ }
236+ $ permissions [$ key ] = $ app ->functions ->intval ($ value );
237+ break ;
238+ case 'sys_perm_user ' :
239+ case 'sys_perm_group ' :
240+ // check if permissions are valid
241+ $ value = strtolower ($ value );
242+ if (!preg_match ('/^[riud]+$/ ' , $ value )) {
243+ $ this ->server ->fault ('invalid parameters ' , $ value . ' is no valid permission string. ' );
244+ return false ;
245+ }
246+
247+ $ newvalue = '' ;
248+ if (strpos ($ value , 'r ' ) !== false ) $ newvalue .= 'r ' ;
249+ if (strpos ($ value , 'i ' ) !== false ) $ newvalue .= 'i ' ;
250+ if (strpos ($ value , 'u ' ) !== false ) $ newvalue .= 'u ' ;
251+ if (strpos ($ value , 'd ' ) !== false ) $ newvalue .= 'd ' ;
252+ $ permissions [$ key ] = $ newvalue ;
253+ unset($ newvalue );
254+
255+ break ;
256+ default :
257+ $ this ->server ->fault ('invalid parameters ' , 'Only sys_userid, sys_groupid, sys_perm_user and sys_perm_group parameters can be changed with this function. ' );
258+ break ;
259+ }
260+ }
261+
262+ return $ app ->db ->datalogUpdate ( $ tablename , $ permissions , $ index_field , $ index_value ) ;
263+ }
264+
202265 /**
203266 Gets the ISPconfig version of the server
204267 @param int session_id
0 commit comments