Skip to content

Commit d22238b

Browse files
committed
Check operator more carefully on API
1 parent d12d991 commit d22238b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

application/controllers/Api.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ function qso($dryrun = false) {
224224
$this->load->model('api_model');
225225

226226
$this->load->model('stations');
227+
$this->load->model('club_model');
227228

228229
if (!$this->load->is_loaded('Qra')) {
229230
$this->load->library('Qra');
@@ -252,6 +253,7 @@ function qso($dryrun = false) {
252253

253254
$userid = $this->api_model->key_userid($obj['key']);
254255
$created_by = $this->api_model->key_created_by($obj['key']);
256+
$club_perm = $this->club_model->get_permission_noui($userid,$created_by);
255257

256258
/**
257259
* As the API key user could use it also for clubstations we need to do an additional check here. Only if clubstations are enabled
@@ -260,12 +262,11 @@ function qso($dryrun = false) {
260262
* If the user is not the creator of the API key, it's likely a clubstation. In this case the callsign of the clubstation
261263
* can not be the same as the callsign of the user (operator call provided by the user). If this is the case, we need to use the callsign of the creator of the API key
262264
*/
263-
$real_operator = null;
265+
$real_operator = null; // real_operator is only filled if its a clubstation and the used key is created by an OP. otherwise its null
264266
if ($this->config->item('special_callsign')) {
265267
if ($userid != $created_by) {
266268
$this->load->model('user_model');
267269
$real_operator = $this->user_model->get_by_id($created_by)->row()->user_callsign;
268-
// TODO: It would be possible to check here if operator is allowed to use the clubstation, but this can be added later if needed
269270
} else {
270271
$real_operator = null;
271272
}
@@ -327,6 +328,11 @@ function qso($dryrun = false) {
327328
$record['operator'] = $real_operator;
328329
}
329330

331+
// in case the caller is an OP for a clubstation (real_operator is filled - see above) and the OP only has level 3 or 6 - take the OP from real_operator!
332+
if ($real_operator != null && ((($club_perm ?? 0) == 3) || (($club_perm ?? 0) == 6))) {
333+
$record['operator'] = $real_operator;
334+
}
335+
330336
if ((key_exists('gridsquare',$record)) && (($mygrid ?? '') != '') && (($record['gridsquare'] ?? '') != '') && (!(key_exists('distance',$record)))) {
331337
$record['distance'] = $this->qra->distance($mygrid, $record['gridsquare'], 'K');
332338
}

application/models/Club_model.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,38 @@ function club_authorize($level, $club_id, $user_id = NULL) {
5656
return false;
5757
}
5858

59+
/**
60+
* Get Permissionlevel for User in Club in a real model-way without UI
61+
*
62+
* @param int $club_id
63+
* @param int $user_id
64+
*
65+
* @return int
66+
*/
67+
function get_permission_noui($club_id, $user_id) {
68+
69+
if ($club_id == 0 || !is_numeric($club_id)) {
70+
return 0;
71+
}
72+
73+
if ($user_id == 0 || !is_numeric($user_id)) {
74+
return 0;
75+
}
76+
77+
$binding = [];
78+
$sql = 'SELECT p_level FROM `club_permissions` WHERE user_id = ? AND club_id = ?';
79+
$binding[] = $user_id;
80+
$binding[] = $club_id;
81+
82+
$query = $this->db->query($sql, $binding);
83+
84+
if ($query->num_rows() > 0) {
85+
return $query->row()->p_level;
86+
} else {
87+
return 0;
88+
}
89+
}
90+
5991
/**
6092
* Get Permissionlevel for User in Club
6193
*

0 commit comments

Comments
 (0)