Skip to content

Commit f511adb

Browse files
committed
feat: enhance proxy configuration and authentication handling
1 parent 63dc2bd commit f511adb

4 files changed

Lines changed: 33 additions & 21 deletions

File tree

config.toml.example

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,21 @@ users = [
5252

5353
[callrecord]
5454
type = "local"
55-
root = "/tmp/cdr"
55+
root = "/tmp/cdr"
56+
57+
[proxy.trunks.wuhoo]
58+
dest = "sip:123.456.789.00:1234"
59+
60+
[[proxy.routes]]
61+
name = "default"
62+
priority = 1
63+
dest = "wuhoo"
64+
65+
[proxy.routes.match]
66+
"to.user" = "^\\+.*"
67+
68+
[proxy.routes.rewrite]
69+
"to.user" = "+{1}"
70+
"to.host" = "123.456.789.00:1234"
71+
"from.user" = "12345"
72+
"from.host" = "123.456.789.00:1234"

src/proxy/auth.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::sync::Arc;
2-
31
use super::{server::SipServerRef, user::SipUser, ProxyAction, ProxyModule};
42
use crate::config::ProxyConfig;
53
use crate::proxy::server::TransactionCookie;
@@ -15,6 +13,7 @@ use rsip::typed::Authorization;
1513
use rsip::Header;
1614
use rsip::Uri;
1715
use rsipstack::transaction::transaction::Transaction;
16+
use std::sync::Arc;
1817
use tokio_util::sync::CancellationToken;
1918
use tracing::{debug, info};
2019

@@ -189,18 +188,8 @@ impl ProxyModule for AuthModule {
189188
_cookie.set_user(user);
190189
Ok(ProxyAction::Continue)
191190
} else {
192-
// Extract realm from request
193-
let from = if tx.original.method == rsip::Method::Register {
194-
tx.original.to_header()?.uri()?.to_string()
195-
} else {
196-
tx.original.uri.to_string()
197-
};
198-
199-
let realm = if tx.original.method == rsip::Method::Register {
200-
tx.original.to_header()?.uri()?.host().to_string()
201-
} else {
202-
tx.original.uri.host().to_string()
203-
};
191+
let from_uri = tx.original.from_header()?.uri()?;
192+
let realm = from_uri.host().to_string();
204193
let realm = ProxyConfig::normalize_realm(&realm);
205194
// Check which type of authentication was attempted or send both challenges
206195
let has_proxy_auth_header =
@@ -210,7 +199,8 @@ impl ProxyModule for AuthModule {
210199
// Send proxy challenge if proxy auth was attempted
211200
let proxy_auth = self.create_proxy_auth_challenge(&realm)?;
212201
info!(
213-
from,
202+
from = from_uri.to_string(),
203+
realm = realm,
214204
?proxy_auth,
215205
"Proxy authentication failed, sending proxy challenge"
216206
);
@@ -222,7 +212,8 @@ impl ProxyModule for AuthModule {
222212
// Send WWW challenge if WWW auth was attempted
223213
let www_auth = self.create_www_auth_challenge(&realm)?;
224214
info!(
225-
from,
215+
from = from_uri.to_string(),
216+
realm = realm,
226217
?www_auth,
227218
"WWW authentication failed, sending WWW challenge"
228219
);

src/proxy/call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ impl CallModule {
248248
}
249249
// Attempt outbound call
250250
info!(
251-
"Creating outbound call: {} -> {} via {} (should_bridge_media: {}) sdp:\n {:?}",
251+
"Creating outbound call: {} -> {} via {:?} (should_bridge_media: {}) sdp:\n {:?}",
252252
invite_option.caller,
253253
invite_option.callee,
254-
target_location.destination,
254+
invite_option.destination,
255255
should_bridge_media,
256256
outbound_sdp
257257
);

static/phone.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,12 @@ <h3>Logs</h3>
402402
log('Please enter a call target and ensure you are registered');
403403
return;
404404
}
405-
406-
const targetURI = SIP.UserAgent.makeURI(`sip:${target}@${serverInput.value.replace('ws://', '').replace('wss://', '').split('/')[0]}`);
405+
let targetURI = undefined;
406+
if (target.startsWith('sip:')) {
407+
targetURI = SIP.UserAgent.makeURI(target);
408+
} else {
409+
targetURI = SIP.UserAgent.makeURI(`sip:${target}@${serverInput.value.replace('ws://', '').replace('wss://', '').split('/')[0]}`);
410+
}
407411

408412
const inviteOptions = {
409413
sessionDescriptionHandlerOptions: {

0 commit comments

Comments
 (0)