|
| 1 | +<?php |
| 2 | +defined('SCRIPTLOG') || die("Direct access not permitted"); |
| 3 | + |
| 4 | +$api = $this->api ?? []; |
| 5 | +$errors = $this->errors ?? []; |
| 6 | +$status = isset($_GET['status']) ? $_GET['status'] : ""; |
| 7 | +$csrfToken = $this->csrfToken ?? csrf_generate_token('csrfToken'); |
| 8 | +?> |
| 9 | + |
| 10 | +<?php if ($status === 'apiConfigUpdated'): ?> |
| 11 | +<div class="alert alert-success alert-dismissible"> |
| 12 | + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> |
| 13 | + <h4><i class="icon fa fa-check"></i> Success!</h4> |
| 14 | + API settings have been updated successfully. |
| 15 | +</div> |
| 16 | +<?php endif; ?> |
| 17 | + |
| 18 | +<?php if (!empty($errors)): ?> |
| 19 | +<div class="alert alert-danger alert-dismissible"> |
| 20 | + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> |
| 21 | + <h4><i class="icon fa fa-ban"></i> Error!</h4> |
| 22 | + <?php foreach ($errors as $error): ?> |
| 23 | + <p><?= safe_html($error) ?></p> |
| 24 | + <?php endforeach; ?> |
| 25 | +</div> |
| 26 | +<?php endif; ?> |
| 27 | + |
| 28 | +<div class="row"> |
| 29 | + <div class="col-md-12"> |
| 30 | + <div class="box box-primary"> |
| 31 | + <div class="box-header with-border"> |
| 32 | + <h3 class="box-title">RESTful API Settings</h3> |
| 33 | + </div> |
| 34 | + |
| 35 | + <form method="post" action="<?= generate_request('index.php', 'get', ['option-api', 'apiConfig', 0])['link']; ?>"> |
| 36 | + <input type="hidden" name="csrfToken" value="<?= $csrfToken ?>"> |
| 37 | + |
| 38 | + <div class="box-body"> |
| 39 | + <!-- Rate Limiting Toggle --> |
| 40 | + <div class="form-group"> |
| 41 | + <label> |
| 42 | + <input type="checkbox" name="api_rate_limit_enabled" value="1" <?= ($api['api_rate_limit_enabled'] ?? '1') === '1' ? 'checked' : '' ?>> |
| 43 | + Enable Rate Limiting |
| 44 | + </label> |
| 45 | + <p class="help-block">Protect your API from abuse by limiting the number of requests per client.</p> |
| 46 | + </div> |
| 47 | + |
| 48 | + <div class="row"> |
| 49 | + <div class="col-md-6"> |
| 50 | + <!-- Read Rate Limit --> |
| 51 | + <div class="form-group"> |
| 52 | + <label for="api_rate_limit_read">Read Rate Limit (requests per minute)</label> |
| 53 | + <input type="number" id="api_rate_limit_read" name="api_rate_limit_read" |
| 54 | + class="form-control" value="<?= safe_html($api['api_rate_limit_read'] ?? '60') ?>" |
| 55 | + min="1" max="1000"> |
| 56 | + <p class="help-block">Maximum GET requests per client per minute. Default: 60</p> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + |
| 60 | + <div class="col-md-6"> |
| 61 | + <!-- Write Rate Limit --> |
| 62 | + <div class="form-group"> |
| 63 | + <label for="api_rate_limit_write">Write Rate Limit (requests per minute)</label> |
| 64 | + <input type="number" id="api_rate_limit_write" name="api_rate_limit_write" |
| 65 | + class="form-control" value="<?= safe_html($api['api_rate_limit_write'] ?? '20') ?>" |
| 66 | + min="1" max="500"> |
| 67 | + <p class="help-block">Maximum POST/PUT/DELETE/PATCH requests per client per minute. Default: 20</p> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + |
| 72 | + <!-- Info Box --> |
| 73 | + <div class="callout callout-info"> |
| 74 | + <h4>How Rate Limiting Works</h4> |
| 75 | + <p>Rate limits are tracked per client using the following priority:</p> |
| 76 | + <ol> |
| 77 | + <li><strong>API Key</strong> (X-API-Key header)</li> |
| 78 | + <li><strong>Bearer Token</strong> (Authorization header)</li> |
| 79 | + <li><strong>IP Address</strong> (fallback)</li> |
| 80 | + </ol> |
| 81 | + <p>When a client exceeds the rate limit, they receive a <code>429 Too Many Requests</code> response with a <code>Retry-After</code> header.</p> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + |
| 85 | + <div class="box-footer"> |
| 86 | + <button type="submit" name="apiConfigSubmit" class="btn btn-primary"> |
| 87 | + <i class="fa fa-save"></i> Update API Settings |
| 88 | + </button> |
| 89 | + </div> |
| 90 | + </form> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | +</div> |
0 commit comments