Add SuperAdmin SMS probe command and per-version enable-remote helper.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\SmsBilling\SuperAdminSmsClient;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Smoke-test SuperAdmin SMS remote for this sold version.
|
||||
*
|
||||
* php artisan sms:superadmin-probe
|
||||
*/
|
||||
class SmsSuperAdminProbeCommand extends Command
|
||||
{
|
||||
protected $signature = 'sms:superadmin-probe';
|
||||
|
||||
protected $description = 'Probe SuperAdmin SMS remote (enabled flag, domain, balance/overview)';
|
||||
|
||||
public function handle(SuperAdminSmsClient $client): int
|
||||
{
|
||||
$base = (string) config('services.superadmin.sms_base_url', '');
|
||||
$domain = (string) config('services.superadmin.sms_domain', '');
|
||||
$appUrl = (string) config('app.url', '');
|
||||
$secretSet = trim((string) config('services.superadmin.sms_shared_secret', '')) !== '';
|
||||
$tokenSet = trim((string) config('services.superadmin.remote_token', '')) !== '';
|
||||
|
||||
$this->table(
|
||||
['key', 'value'],
|
||||
[
|
||||
['enabled', $client->enabled() ? 'yes' : 'no'],
|
||||
['sms_base_url', $base !== '' ? $base : '(empty)'],
|
||||
['sms_domain_override', $domain !== '' ? $domain : '(empty → APP_URL host)'],
|
||||
['app_url', $appUrl !== '' ? $appUrl : '(empty)'],
|
||||
['shared_secret_set', $secretSet ? 'yes' : 'no'],
|
||||
['remote_token_set', $tokenSet ? 'yes' : 'no'],
|
||||
]
|
||||
);
|
||||
|
||||
if (!$client->enabled()) {
|
||||
$this->error('SuperAdmin SMS remote is disabled. Set SUPERADMIN_SMS_BASE_URL and secret/token.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$balance = $client->balance();
|
||||
if ($balance === null) {
|
||||
$this->error('balance request failed (auth/domain/network). Check SUPERADMIN_SMS_DOMAIN vs SuperAdmin tenant.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('SuperAdmin SMS remote OK');
|
||||
$this->line(json_encode([
|
||||
'balance' => $balance['balance'] ?? $balance['balanceRials'] ?? null,
|
||||
'price_per_part' => $balance['price_per_part'] ?? $balance['pricePerPartRials'] ?? null,
|
||||
'is_blocked' => $balance['is_blocked'] ?? $balance['isBlocked'] ?? null,
|
||||
'source' => $balance['source'] ?? null,
|
||||
'raw_keys' => array_keys($balance),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run on the Khanegi install for ONE sold version (its own .env).
|
||||
# Never point multiple installs on the same server at the same SUPERADMIN_SMS_DOMAIN.
|
||||
#
|
||||
# Usage:
|
||||
# ./khanegi-sms-enable-remote.sh /path/to/khanegi/server DOMAIN SHARED_SECRET
|
||||
#
|
||||
# Example:
|
||||
# ./khanegi-sms-enable-remote.sh /var/www/customer/server example.ir 'secret-from-sa'
|
||||
set -euo pipefail
|
||||
|
||||
INSTALL_SERVER_DIR="${1:-}"
|
||||
DOMAIN="${2:-}"
|
||||
SHARED_SECRET="${3:-}"
|
||||
BASE_URL="${SUPERADMIN_SMS_BASE_URL:-https://adm.montzar.ir/api/remote/sms}"
|
||||
|
||||
if [[ -z "$INSTALL_SERVER_DIR" || -z "$DOMAIN" || -z "$SHARED_SECRET" ]]; then
|
||||
echo "Usage: $0 /path/to/khanegi/server DOMAIN SHARED_SECRET" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ENV_FILE="$INSTALL_SERVER_DIR/.env"
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Missing .env: $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
backup="$ENV_FILE.bak.sms-sync.$(date +%Y%m%d%H%M%S)"
|
||||
cp "$ENV_FILE" "$backup"
|
||||
echo "Backup: $backup"
|
||||
|
||||
# Remove previous SuperAdmin SMS keys (keep other env intact)
|
||||
tmp="$(mktemp)"
|
||||
grep -vE '^(SUPERADMIN_SMS_BASE_URL|SUPERADMIN_SMS_SHARED_SECRET|SUPERADMIN_SMS_DOMAIN|SUPERADMIN_REMOTE_TOKEN)=' "$ENV_FILE" > "$tmp" || true
|
||||
mv "$tmp" "$ENV_FILE"
|
||||
|
||||
{
|
||||
echo ""
|
||||
echo "# SuperAdmin SMS sync — per sold version (domain=$DOMAIN)"
|
||||
echo "SUPERADMIN_SMS_BASE_URL=$BASE_URL"
|
||||
echo "SUPERADMIN_SMS_SHARED_SECRET=$SHARED_SECRET"
|
||||
echo "SUPERADMIN_SMS_DOMAIN=$DOMAIN"
|
||||
} >> "$ENV_FILE"
|
||||
|
||||
cd "$INSTALL_SERVER_DIR"
|
||||
php artisan config:clear
|
||||
php artisan config:cache || true
|
||||
|
||||
if php artisan list --raw 2>/dev/null | grep -q '^sms:superadmin-probe'; then
|
||||
php artisan sms:superadmin-probe
|
||||
else
|
||||
echo "Env written. Deploy code with sms:superadmin-probe, then run: php artisan sms:superadmin-probe"
|
||||
fi
|
||||
|
||||
echo "OK: remote enabled for domain=$DOMAIN in $ENV_FILE"
|
||||
Reference in New Issue
Block a user