Commit graph

2340 commits

Author SHA1 Message Date
Sora39831
c94372a22c fix: address all code review issues for MariaDB support
- Prevent DBPassword from leaking to frontend (json:"-")
- Make migration direction explicit via --direction flag, set dbType only after success
- Use driver-appropriate DROP INDEX IF EXISTS for SQLite vs MariaDB
- Build DSN with mysql.Config.FormatDSN() to prevent injection with special chars
- Close DB before re-initialization in InitDB
- Add migration tests (5 tests using SQLite in-memory DBs)
- Parse JSON once in GetDBConfigFromJSON instead of 7 times
- Use Go binary for dbType in shell script instead of fragile grep
- Add rollback on failure in db_switch_to_sqlite
- Validate DB settings in CheckValid
2026-04-03 09:53:20 +08:00
Sora39831
7f015ad27b fix: address code review issues for MariaDB support
- Close migration DB connections with defer to prevent leaks
- Truncate destination tables before migration to avoid duplicates
- Wrap migration in transaction for atomicity
- Pass DB password via env var instead of CLI args to avoid process list exposure
- Improve error messages for MariaDB export/import with alternatives
- Update package doc to reflect dual DB support
- DRY migration logic with shared migrateAllTables function
2026-04-03 09:39:53 +08:00
Sora39831
cf720b6c5b fix: prevent double-hashing of passwords in fresh DB init 2026-04-03 09:34:17 +08:00
Sora39831
3a9dcd10df feat: add migrate-db subcommand and DB setting CLI flags 2026-04-03 09:33:15 +08:00
Sora39831
f81075fa9e deps: add gorm.io/driver/mysql for MariaDB support 2026-04-03 09:32:55 +08:00
Sora39831
ecc724b787 feat: add database management menu (option 27) to x-ui.sh 2026-04-03 09:31:56 +08:00
Sora39831
d0592a1be8 feat: add DB fields to AllSetting struct for web panel API 2026-04-03 09:30:26 +08:00
Sora39831
8a20cbd5c2 feat: guard GetDb/ImportDB for MariaDB (unsupported SQLite-specific operations) 2026-04-03 09:29:53 +08:00
Sora39831
fd910efec2 feat: add bidirectional SQLite<->MariaDB data migration 2026-04-03 09:29:30 +08:00
Sora39831
2647c2c2ce refactor: update InitDB callers to use new parameterless signature 2026-04-03 09:27:10 +08:00
Sora39831
283892c548 feat: refactor InitDB to be driver-agnostic with SQLite/MariaDB dispatch 2026-04-03 09:26:42 +08:00
Sora39831
e3d1a94d89 feat: add JSON config helpers for DB type and MariaDB settings 2026-04-03 09:24:39 +08:00
Sora39831
5ed8037464 feat: add MariaDB settings to SettingService 2026-04-03 09:24:18 +08:00
Sora39831
82a1b85d45 docs: add MariaDB support design spec
Design for adding MariaDB as alternative database backend with
data migration, x-ui.sh switching UI, and driver-agnostic InitDB.
2026-04-03 09:14:20 +08:00
Sora39831
09f84782b0 test: add unit tests for critical modules and fix flaky redirect middleware
- Add tests for config, database, model, util/common, util/crypto,
  util/random, web/middleware, web/service, and xray packages
- Fix redirect middleware using slice instead of map to guarantee
  deterministic longest-prefix-first matching order
2026-04-03 08:44:51 +08:00
Sora39831
d43f8683b0 feat: enhance user dashboard, set default creds to admin, trim i18n to en/zh only
- install.sh: default username/password to admin on fresh install
- user.go: UpdateFirstUser resets Role to admin, preventing lockout
- user.html: show remaining traffic and last online time
- i18n: remove 11 translation files, keep only en_US and zh_CN
- LanguageManager: trim supportedLanguages to 2 entries, remove simularLangs
2026-04-03 08:13:27 +08:00
Sora39831
463b07db52 feat: add user dashboard with role-based access control
Add a simplified dashboard page for non-admin users showing username,
traffic usage, expiry time, and logout button. Implement role-based
routing so user-role accounts are redirected to their own dashboard
instead of the admin panel. Add getUserInfo API endpoint and i18n
translations across all 13 supported locales.
2026-04-03 03:29:51 +08:00
Sora39831
3045b630f0 fix: use render=explicit and HTMLElement for Turnstile to fix Rocket Loader conflict
- Add ?render=explicit to api.js URL to disable auto-initialization
- Pass HTMLElement (not selector string) to turnstile.render() and turnstile.reset()
- Prevents race condition where Turnstile auto-renders before body DOM is parsed
2026-04-03 03:01:18 +08:00
Sora39831
de6131aeac fix: fix Turnstile widget not rendering behind Cloudflare Rocket Loader
Load Turnstile api.js statically in <head> with data-cfasync="false"
to bypass Rocket Loader interference. Use turnstile.render() API to
manually render widget after site key is fetched, instead of relying
on dynamic script loading and Vue data-bind attributes.
2026-04-03 02:46:20 +08:00
Sora39831
f026afbc17 fix: comment out unused checkEmailsExistForClients to pass staticcheck 2026-04-03 02:12:54 +08:00
Sora39831
a7871a79a5 fix: correct gofmt formatting in inbound.go 2026-04-03 02:04:45 +08:00
Sora39831
90665c92f4 fix: harden registration with rate limiting, input validation, and security fixes
- Add per-IP rate limiter middleware (5 req/min) on /register endpoint
- Validate username (3-64 chars) and password (8-128 chars) with trim
- Use sentinel error ErrUsernameAlreadyExists instead of string matching
- Prevent TurnstileSecretKey exposure via admin settings API (json:"-")
- Skip json:"-" fields in UpdateAllSetting to avoid overwriting secrets
- Add SetTurnstileSecretKey setter for programmatic configuration
- Reuse package-level http.Client in Turnstile verification for connection pooling
- Add io.LimitReader to cap Turnstile response body size
- Log all Turnstile verification error paths for debugging
- Add invalidUsername/invalidPassword i18n keys to all 13 locales
2026-04-03 02:02:25 +08:00
Sora39831
b4047cee54 feat: allow same email across multiple inbounds and auto-add clients on registration
Remove global unique constraint on client_traffics.email, change email
duplication check to per-inbound scope, and automatically register new
users as disabled clients in all existing inbounds within a transaction.
2026-04-03 01:38:31 +08:00
Sora39
756ef6c307
Merge pull request #1 from Sora39831/dev
Dev
2026-04-03 00:41:59 +08:00
Sora39831
87c94cb5b0 fix: make Turnstile widget responsive on narrow screens
Turnstile iframe (~300px min width) overflowed its container on mobile
due to large login card padding and no overflow handling. Reduce mobile
padding, center the widget wrapper, and use compact mode below 480px.
2026-04-03 00:30:55 +08:00
Sora39831
516d24c70a fix: correct gofmt formatting in setting.go 2026-04-03 00:01:07 +08:00
Sora39831
5f83415e95 feat: add user registration with role-based access
- Add Role field to User model (admin/user) with uniqueIndex on Username
- Add POST /register endpoint with optional Cloudflare Turnstile verification
- Add RegisterUser service with bcrypt password hashing and duplicate detection
- Set default admin user role to "admin", new registrations get "user"
- Add turnstileSecretKey setting and GetTurnstileSecretKey getter
- Add i18n keys (userExists, errorRegister) to all 13 translation files
2026-04-02 23:49:30 +08:00
Sora39831
54975d4bd1 Merge branch 'dev' 2026-04-02 22:25:54 +08:00
Sora39831
5729cebb8e fix(setting): merge missing default keys into x-ui.json on load
New fields added after initial install are now automatically merged
into the existing x-ui.json file, so upgrades pick up defaults for
newly added settings without requiring manual intervention.
2026-04-02 22:25:50 +08:00
Sora39831
19fc7fad4c Merge branch 'dev' 2026-04-02 22:14:47 +08:00
Sora39831
26ef0745e7 fix(install): skip credential/cert prompts on non-fresh install
Check x-ui.json or x-ui.db at DB folder path (/etc/x-ui) instead of
only checking x-ui.db at x-ui folder. Existing installs now skip all
username/password/path/port/SSL prompts and preserve saved settings.
2026-04-02 22:14:43 +08:00
Sora39831
b984833563 fix: prerelease JSON parsing for GitHub API 2026-04-02 22:06:59 +08:00
Sora39831
2b7eebd302 fix: correct JSON parsing for prerelease detection in GitHub API response
The GitHub API returns "prerelease": false (with space after colon), but
the grep pattern used "prerelease":false (no space). Also, tag_name and
prerelease are on different lines after tr '{' '\\n', so the piped grep
chain couldn't find both fields. Fixed with grep -B5 to look backwards
from prerelease line to find tag_name.
2026-04-02 22:05:44 +08:00
Sora39831
9cfb747666 merge: add pre-release install/update selection 2026-04-02 21:22:55 +08:00
Sora39831
f6d993c29d feat(update): add pre-release version selection prompt
Replace the single latest-release fetch in update_x-ui() with
get_releases() and select_version() functions that offer users a
choice between the latest stable and latest pre-release version,
matching the pattern already added to install.sh.
2026-04-02 20:56:15 +08:00
Sora39831
3d1d422ae1 feat(install): add pre-release version selection prompt 2026-04-02 20:51:55 +08:00
Sora39831
5103d57879 feat: add registration tab with Cloudflare Turnstile support
Add a register tab on the login page with username, password, confirm
password fields and Cloudflare Turnstile widget. The site key is
configurable via x-ui.json and exposed through a public endpoint.
2026-04-02 20:18:48 +08:00
Sora39831
82d93da36e fix: remove premature x-ui start in ssl_cert_issue to ensure custom port takes effect
The ssl_cert_issue function called systemctl start x-ui after certificate
installation, causing the panel to start before the install flow completed.
Changed install_x-ui final start to restart to guarantee the latest config is used.
2026-04-02 17:37:28 +08:00
Sora39831
e40f73cc1c ci: remove release trigger, auto-create release on tag push
Remove the duplicate release trigger. Now pushing a tag like v*.*.*
automatically creates a prerelease (if not exists) and uploads the
build artifacts via gh CLI, eliminating the duplicate build issue.
2026-04-02 17:20:33 +08:00
Sora39831
2d491e272c ci: disable windows build job to fix invalid workflow file
The build-windows job had an empty matrix platform list (amd64 was
commented out), causing GitHub Actions validation to fail with
"Unexpected value ''" on line 205. Comment out the entire job.
2026-04-02 17:12:38 +08:00
Sora39831
30b27bf091 feat: migrate settings to JSON file, add Cloudflare SSL in installer
- config: add GetSettingPath for JSON-based settings storage
- setting.go: load/save settings from JSON file instead of DB;
  keep xrayTemplateConfig in DB; fix ResetSettings to not clear users
- xray_setting.go: save xray template config to DB directly
- install.sh: add Cloudflare SSL option (wildcard via DNS), allow
  user to input custom credentials on fresh install, fix existing
  install logic to preserve user config
2026-04-02 16:16:52 +08:00
Sora39831
286056ab03 feat: improve uninstall and reset_config behavior
- uninstall: add certificate revocation prompt before removing
- reset_config: fix misleading confirmation text, also reset cert
  config; remove user table deletion from Go ResetSettings
2026-04-02 16:15:07 +08:00
Sora39831
f5c931426d ci: remove docker workflow, simplify release triggers
- Remove docker.yml (no Docker image publishing needed)
- Release workflow now triggers on tag push and release creation
- Only linux-amd64 builds active, other architectures commented out
- Windows build commented out
2026-04-02 10:18:45 +08:00
root
af7ed2a38f chore: update GitHub links to fork repository Sora39831/3x-ui
Replace all MHSanaei/3x-ui references in shell scripts, README files,
HTML, and CI config with Sora39831/3x-ui. Go import paths unchanged
to maintain upstream compatibility.
2026-04-02 09:49:12 +08:00
Yunheng Liu
169b216d7e
perf: replace /dev/urandom | tr with openssl rand to fix CPU spike (#3887)
Some checks failed
Release 3X-UI / Analyze Go code (push) Has been cancelled
Release 3X-UI / build (386) (push) Has been cancelled
Release 3X-UI / build (amd64) (push) Has been cancelled
Release 3X-UI / build (arm64) (push) Has been cancelled
Release 3X-UI / build (armv5) (push) Has been cancelled
Release 3X-UI / build (armv6) (push) Has been cancelled
Release 3X-UI / build (armv7) (push) Has been cancelled
Release 3X-UI / build (s390x) (push) Has been cancelled
Release 3X-UI / Build for Windows (push) Has been cancelled
2026-04-01 13:59:48 +02:00
MHSanaei
7e6d80efa5
Bump Go and dependency versions
Update go toolchain to 1.26.1 and upgrade multiple direct and indirect modules (examples: github.com/gin-contrib/gzip v1.2.6, github.com/gin-contrib/sessions v1.1.0, github.com/go-ldap/ldap/v3 v3.4.13, github.com/goccy/go-json v0.10.6, github.com/pelletier/go-toml/v2 v2.3.0, github.com/shirou/gopsutil/v4 v4.26.3, github.com/xtls/xray-core v1.260327.0, golang.org/x/crypto v0.49.0, google.golang.org/grpc v1.80.0). go.sum updated accordingly to lock the new versions. Routine dependency refresh to pull in fixes and improvements.
2026-04-01 13:47:27 +02:00
kazan417
38d87230d3
Update x-ui.sh (#3947)
Some checks failed
Release 3X-UI / Analyze Go code (push) Has been cancelled
Release 3X-UI / build (386) (push) Has been cancelled
Release 3X-UI / build (amd64) (push) Has been cancelled
Release 3X-UI / build (arm64) (push) Has been cancelled
Release 3X-UI / build (armv5) (push) Has been cancelled
Release 3X-UI / build (armv6) (push) Has been cancelled
Release 3X-UI / build (armv7) (push) Has been cancelled
Release 3X-UI / build (s390x) (push) Has been cancelled
Release 3X-UI / Build for Windows (push) Has been cancelled
looks like now cert management is option 19
2026-03-18 19:45:45 +01:00
MHSanaei
f0f98c7122
Add Go code analyzer workflow
Some checks are pending
Release 3X-UI / Analyze Go code (push) Waiting to run
Release 3X-UI / build (386) (push) Blocked by required conditions
Release 3X-UI / build (amd64) (push) Blocked by required conditions
Release 3X-UI / build (arm64) (push) Blocked by required conditions
Release 3X-UI / build (armv5) (push) Blocked by required conditions
Release 3X-UI / build (armv6) (push) Blocked by required conditions
Release 3X-UI / build (armv7) (push) Blocked by required conditions
Release 3X-UI / build (s390x) (push) Blocked by required conditions
Release 3X-UI / Build for Windows (push) Blocked by required conditions
2026-03-17 23:01:15 +01:00
Abdalrahman
554981d9d3
feat(tgbot): send connection links and qrs on client creation (closes #3320)\n\n- Refactored inline keyboards into getCommonClientButtons to respect DRY\n- Extended SubmitAddClient callback handlers to dispatch individual links and QR codes to the bot chat on success. (#3888) 2026-03-17 22:09:49 +01:00
Nikolay
a08f1c6c13
Update translate.ru_RU.toml (#3889)
Change to plural (geofiles, not geofile)
2026-03-17 21:24:09 +01:00