]> git.defcon.no Git - hermes/blob - api/lib/common_functions.php
adding provision URL as part of server-data in SQL
[hermes] / api / lib / common_functions.php
1 <?php
2 require_once('config.php');
3 require_once('lib/common_functions.php');
4 require_once('lib/db_functions.php');
5 require_once('lib/check_email.php');
6
7 $config = get_config();
8
9 function is_kamailio_domain ( $domain )
10 {
11 global $config;
12 $query = sprintf("SELECT id FROM %s WHERE domain = '%s'",
13 $config['kamailio_domain_table'],
14 sql_clean( $domain )
15 );
16 $domain = sql_dbquery_single( $config['kamailio_db'], $query );
17 if ( !$domain ) return false;
18 return $domain['id'];
19
20 }
21
22 function get_servers( $domain )
23 {
24 global $config;
25 $query = sprintf("SELECT registrar, r_port, proxy, p_port, prov_url FROM %s WHERE domain = '%s'",
26 $config['provision_servers_table'],
27 sql_clean( $domain ));
28 $servers = sql_dbquery_single( $config['provision_db'], $query );
29 return $servers;
30 }
31
32 function verify_sipadress( $address ) //TODO: Improve/expand on the test!
33 {
34 return check_email_address($address); // A SIP address follows the requirements for email addresses...
35 // Except that it permits the use of :portnumber notation!
36 // TODO: Fix this so it allows :NNNN syntax for portnumbers...
37 }
38
39 function split_sipaddress ( $address )
40 {
41 if ( !verify_sipadress( $address ) ) return null;
42 $data = split('@', $address);
43 if ( count( $data ) != 2 ) return null;
44 return $data;
45 }
46
47 function clean_mac ( $input )
48 {
49 $mac = strtolower( preg_replace('/:/', '', $input) );
50 if ( ! preg_match( '/^[a-f0-9]{1,}$/', $mac ) ) return null;
51 if (strlen( $mac ) != 12 ) return null;
52 return $mac;
53 }
54 ?>