diff --git a/app/Console/Commands/SmsSuperAdminProbeCommand.php b/app/Console/Commands/SmsSuperAdminProbeCommand.php new file mode 100644 index 0000000..886a246 --- /dev/null +++ b/app/Console/Commands/SmsSuperAdminProbeCommand.php @@ -0,0 +1,63 @@ +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; + } +} diff --git a/deploy-khanegi-sms-enable-remote.sh b/deploy-khanegi-sms-enable-remote.sh new file mode 100644 index 0000000..5a67a47 --- /dev/null +++ b/deploy-khanegi-sms-enable-remote.sh @@ -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"