Files
zoneminder/web/skins/classic/views/_options_api.php
T
Isaac ConnorandClaude Opus 4.8 d248166000 fix: remove the per-user ability to disable the API refs #4908
Disabling the API per user made pages that rely on it (Montage Review and
others) fail silently: the AJAX event queries came back 401
"API disabled for: <user>" and the page just drew empty boxes with no
indication of why.

Rather than keep a foot-gun that makes the UI look broken, drop the per-user
API-disable control entirely:

- AppController no longer rejects an authenticated user because APIEnabled != 1;
  the API is available to any authenticated user.
- Remove the APIEnabled selector from the user edit view and the APIEnabled
  column from the users list and the API options tab. The API options tab keeps
  its token management (New Token, Revoke Token, Revoke All Tokens).
- The user token section no longer hides itself based on APIEnabled.

The Users.APIEnabled column and the model default are left in place so no
database migration is needed; the value is simply no longer consulted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-15 11:58:24 -05:00

96 lines
3.7 KiB
PHP

<?php
//
// ZoneMinder web options view file, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
if (!canView('System')) {
$view = 'error';
return;
}
$canEdit = canEdit('System');
if ((!defined('ZM_OPT_USE_API')) or ZM_OPT_USE_API != '1') {
echo '<div class="errorText">APIs are disabled. To enable, please turn on OPT_USE_API in Options->System</div>';
return;
}
?>
<form name="userForm" method="post" action="?">
<div id="options">
<div class="col button-block">
<button class="float-left" type="submit" name="updateSelected" id="updateSelected"<?php echo $canEdit ? '' : ' disabled="disabled"' ?>><?php echo translate('Update')?></button>
<button class="float-left" type="button" id="btnNewToken"><?php echo translate('New Token')?></button>
<button class="btn-danger float-right" type="submit" name="revokeAllTokens" id="revokeAllTokens"<?php echo $canEdit ? '' : ' disabled="disabled"' ?>><?php echo translate('RevokeAllTokens')?></button>
</div>
<div class="wrapper-scroll-table">
<?php
function revokeAllTokens() {
$minTokenTime = time();
dbQuery('UPDATE `Users` SET `TokenMinExpiry`=?', array($minTokenTime));
echo '<span class="timedSuccessBox">'.translate('AllTokensRevoked').'</span>';
}
function updateSelected() {
if (isset($_REQUEST['tokenUids'])) {
$minTime = time();
foreach ($_REQUEST['tokenUids'] as $markUid) {
dbQuery('UPDATE `Users` SET `TokenMinExpiry`=? WHERE `Id`=?', array($minTime, $markUid));
}
}
echo '<span class="timedSuccessBox">'.translate('Updated').'</span>';
}
// Both actions change every user's tokens, so they need System edit.
// This view only requires System view to render.
if (array_key_exists('revokeAllTokens', $_POST) or array_key_exists('updateSelected', $_POST)) {
if (!$canEdit) {
ZM\Warning('Must have System edit permission to change API access or revoke tokens');
} else {
if (array_key_exists('revokeAllTokens', $_POST)) revokeAllTokens();
if (array_key_exists('updateSelected', $_POST)) updateSelected();
}
}
?>
<input type="hidden" name="view" value="<?php echo $view ?>"/>
<input type="hidden" name="tab" value="<?php echo $tab ?>"/>
<input type="hidden" name="action" value="delete"/>
<table id="contentTable" class="table table-striped">
<thead class="thead-highlight">
<tr>
<th class="colUsername"><?php echo translate('Username') ?></th>
<th class="colMark"><?php echo translate('Revoke Token') ?></th>
</tr>
</thead>
<tbody>
<?php
foreach (ZM\User::find([], ['order'=>'Username']) as $u) {
?>
<tr>
<td class="colUsername"><?php echo validHtmlStr($u->Username()) ?></td>
<td class="colMark"><input type="checkbox" name="tokenUids[]" value="<?php echo $u->Id() ?>"<?php echo $canEdit ? '' : ' disabled="disabled"' ?>/></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</form>