mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-10-25 17:59:08 +00:00
URI works on android. Shadowsocks doesn't work on iPhone. it's ok - will be fixed.
This commit is contained in:
@@ -5,6 +5,7 @@ use uuid::Uuid;
|
||||
use crate::database::entities::inbound_users::{
|
||||
Entity, Model, ActiveModel, CreateInboundUserDto, UpdateInboundUserDto, Column
|
||||
};
|
||||
use crate::services::uri_generator::ClientConfigData;
|
||||
|
||||
pub struct InboundUsersRepository {
|
||||
db: DatabaseConnection,
|
||||
@@ -129,4 +130,97 @@ impl InboundUsersRepository {
|
||||
let exists = self.find_by_user_and_inbound(user_id, inbound_id).await?;
|
||||
Ok(exists.is_some())
|
||||
}
|
||||
|
||||
/// Get complete client configuration data for URI generation
|
||||
pub async fn get_client_config_data(&self, user_id: Uuid, server_inbound_id: Uuid) -> Result<Option<ClientConfigData>> {
|
||||
use crate::database::entities::{
|
||||
user, server, server_inbound, inbound_template, certificate
|
||||
};
|
||||
|
||||
// Get the inbound_user record first
|
||||
let inbound_user = Entity::find()
|
||||
.filter(Column::UserId.eq(user_id))
|
||||
.filter(Column::ServerInboundId.eq(server_inbound_id))
|
||||
.filter(Column::IsActive.eq(true))
|
||||
.one(&self.db)
|
||||
.await?;
|
||||
|
||||
if let Some(inbound_user) = inbound_user {
|
||||
// Get user info
|
||||
let user_entity = user::Entity::find_by_id(inbound_user.user_id)
|
||||
.one(&self.db)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow::anyhow!("User not found"))?;
|
||||
|
||||
// Get server inbound info
|
||||
let server_inbound_entity = server_inbound::Entity::find_by_id(inbound_user.server_inbound_id)
|
||||
.one(&self.db)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow::anyhow!("Server inbound not found"))?;
|
||||
|
||||
// Get server info
|
||||
let server_entity = server::Entity::find_by_id(server_inbound_entity.server_id)
|
||||
.one(&self.db)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow::anyhow!("Server not found"))?;
|
||||
|
||||
// Get template info
|
||||
let template_entity = inbound_template::Entity::find_by_id(server_inbound_entity.template_id)
|
||||
.one(&self.db)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow::anyhow!("Template not found"))?;
|
||||
|
||||
// Get certificate info (optional)
|
||||
let certificate_domain = if let Some(cert_id) = server_inbound_entity.certificate_id {
|
||||
certificate::Entity::find_by_id(cert_id)
|
||||
.one(&self.db)
|
||||
.await?
|
||||
.map(|cert| cert.domain)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let config = ClientConfigData {
|
||||
user_name: user_entity.name,
|
||||
xray_user_id: inbound_user.xray_user_id,
|
||||
password: inbound_user.password,
|
||||
level: inbound_user.level,
|
||||
hostname: server_entity.hostname,
|
||||
port: server_inbound_entity.port_override.unwrap_or(template_entity.default_port),
|
||||
protocol: template_entity.protocol,
|
||||
stream_settings: template_entity.stream_settings,
|
||||
base_settings: template_entity.base_settings,
|
||||
certificate_domain,
|
||||
requires_tls: template_entity.requires_tls,
|
||||
variable_values: server_inbound_entity.variable_values,
|
||||
server_name: server_entity.name,
|
||||
inbound_tag: server_inbound_entity.tag,
|
||||
};
|
||||
|
||||
Ok(Some(config))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all client configuration data for a user
|
||||
pub async fn get_all_client_configs_for_user(&self, user_id: Uuid) -> Result<Vec<ClientConfigData>> {
|
||||
// Get all active inbound users for this user
|
||||
let inbound_users = Entity::find()
|
||||
.filter(Column::UserId.eq(user_id))
|
||||
.filter(Column::IsActive.eq(true))
|
||||
.all(&self.db)
|
||||
.await?;
|
||||
|
||||
let mut configs = Vec::new();
|
||||
|
||||
for inbound_user in inbound_users {
|
||||
// Get the client config data for each inbound
|
||||
if let Ok(Some(config)) = self.get_client_config_data(user_id, inbound_user.server_inbound_id).await {
|
||||
configs.push(config);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(configs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user