'kamailio_subscriber_table' => 'subscriber',
'kamailio_alias_table' => 'dbaliases',
'kamailio_domain_table' => 'domain',
- 'provision_db' => 'provision',
- 'provision_users_table' => 'users',
- 'provision_phones_table' => 'phones',
- 'provision_servers_table' => 'servers',
+ 'hermes_db' => 'hermes',
+ 'hermes_users_table' => 'users',
+ 'hermes_phones_table' => 'phones',
+ 'hermes_servers_table' => 'servers',
'apikeys_table' => 'apikeys',
'authorizations_table' => 'authorizations',
'sessionkeys_table' => 'sessionkeys',
$query = sprintf("SELECT session, sessid FROM %s WHERE `last` < DATE_SUB( NOW(), INTERVAL %d MINUTE)",
$config['sessionkeys_table'],
$config['sessionkey_lifetime']);
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
while ( $row = @mysql_fetch_row( $result ) )
{
remove_session( $row[0], $row[1] );
$config['sessionkeys_table'],
$config['sessionkey_lifetime']);
- sql_dbexec( $config['provision_db'], $query );
+ sql_dbexec( $config['hermes_db'], $query );
}
function update_authkey ( $session, $authid )
sql_clean($remote),
sql_clean($key),
sql_clean($key));
- if ( ! sql_dbexec( $config['provision_db'], $query ) )
+ if ( ! sql_dbexec( $config['hermes_db'], $query ) )
{
mysql_error();
}
$query = sprintf("DELETE FROM %s WHERE `session` = '%s'",
$config['sessionkeys_table'],
sql_clean($name));
- sql_dbexec( $config['provision_db'], $query );
+ sql_dbexec( $config['hermes_db'], $query );
return false;
}
sql_clean($host),
sql_clean($key));
- if ( ! sql_dbexec( $config['provision_db'], $query ) ) return false;
+ if ( ! sql_dbexec( $config['hermes_db'], $query ) ) return false;
return $key;
}
$query = sprintf("DELETE FROM %s WHERE apikey = '%s'",
$config['apikeys_table'],
sql_clean($key) );
- if ( ! sql_dbexec( $config['provision_db'], $query ) ) return false;
+ if ( ! sql_dbexec( $config['hermes_db'], $query ) ) return false;
return true;
}
$query = sprintf("SELECT host FROM %s WHERE apikey = '%s'",
$config['apikeys_table'],
sql_clean($key) );
- $row = sql_dbquery_single( $config['provision_db'], $query );
+ $row = sql_dbquery_single( $config['hermes_db'], $query );
if (!$row) return false;
$host = $row['host'];
$config['apikeys_table'],
$config['authorizations_table']);
$list = array();
- $result = sql_dbquery( $config['provision_db'], $query);
+ $result = sql_dbquery( $config['hermes_db'], $query);
if ( ! $result ) return $list;
while ( $row = @mysql_fetch_assoc( $result ) )
{
WHERE type = 'user'",
$config['authorizations_table']);
$list = array();
- $result = sql_dbquery( $config['provision_db'], $query);
+ $result = sql_dbquery( $config['hermes_db'], $query);
if ( ! $result ) return $list;
while ( $row = @mysql_fetch_assoc( $result ) )
{
sql_clean($authid),
$type,
$level, $level);
- if ( ! sql_dbexec( $config['provision_db'], $query ) ) return false;
+ if ( ! sql_dbexec( $config['hermes_db'], $query ) ) return false;
return true;
}
$config['authorizations_table'],
sql_clean($authid) );
//print $query . "\n\n";
- if ( ! sql_dbexec( $config['provision_db'], $query ) ) return false;
+ if ( ! sql_dbexec( $config['hermes_db'], $query ) ) return false;
return true;
}
$query = sprintf("SELECT access_level FROM %s WHERE authid = '%s'",
$config['authorizations_table'],
sql_clean($authid) );
- $row = sql_dbquery_single( $config['provision_db'], $query );
+ $row = sql_dbquery_single( $config['hermes_db'], $query );
if (!$row) return false;
$level = $row['access_level'];
return $level;
{
global $config;
$query = sprintf("SELECT registrar, r_port, proxy, p_port, prov_url FROM %s WHERE domain = '%s'",
- $config['provision_servers_table'],
+ $config['hermes_servers_table'],
sql_clean( $domain ));
- $servers = sql_dbquery_single( $config['provision_db'], $query );
+ $servers = sql_dbquery_single( $config['hermes_db'], $query );
return $servers;
}
proxy = '%s', p_port = %d,
prov_url = '%s'
WHERE domain = '%s'",
- $config['provision_servers_table'],
+ $config['hermes_servers_table'],
sql_clean($registrar),
$r_port,
sql_clean($proxy),
$query = sprintf("INSERT INTO %s
(domain, registrar, r_port, proxy, p_port, prov_url)
VALUES ('%s', '%s', %d, '%s', %d, '%s')",
- $config['provision_servers_table'],
+ $config['hermes_servers_table'],
sql_clean($domain),
sql_clean($registrar),
$r_port,
);
}
- return sql_dbexec( $config['provision_db'], $query );
+ return sql_dbexec( $config['hermes_db'], $query );
}
?>
}
$test = "SELECT COUNT(*) FROM " . $config['numbers_table'] . " WHERE number = '" . $number . "'";
- $result = sql_dbquery($config['provision_db'], $test);
+ $result = sql_dbquery($config['hermes_db'], $test);
if ( !$result ) return false;
$row = @mysql_fetch_row($result);
if ( !$row ) return false;
$query = "SELECT number FROM " . $config['numbers_table'] . " ORDER BY RAND()";
if ( $limit && is_numeric( $limit ) )
$query .= " LIMIT " . $limit;
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
if ( !$result ) return null;
if ( @mysql_num_rows($result) < 1 ) return null;
$query .= " LIMIT " . $limit;
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
if ( !$result ) return null;
if ( @mysql_num_rows($result) < 1 ) return null;
if (number_inpool( $number ) ) return false;
$insert = "INSERT INTO " . $config['numbers_table'] . " (number) VALUES ('" . $number . "')";
- return sql_dbexec( $config['provision_db'], $insert);
+ return sql_dbexec( $config['hermes_db'], $insert);
}
function remove_number ( $number )
}
if ( !number_inpool( $number ) ) return false;
$query = "DELETE FROM " . $config['numbers_table'] . " WHERE number = '" . $number . "'";
- return sql_dbexec( $config['provision_db'], $query);
+ return sql_dbexec( $config['hermes_db'], $query);
}
?>
{
global $config;
$query = sprintf("SELECT id FROM %s WHERE username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean( $username ),
sql_clean( $domain )
);
- $user = sql_dbquery_single( $config['provision_db'], $query );
+ $user = sql_dbquery_single( $config['hermes_db'], $query );
if ( ! $user ) return null;
$user_id = $user['id'];
$query = sprintf("SELECT mac FROM %s WHERE user_rel = %d",
- $config['provision_phones_table'],
+ $config['hermes_phones_table'],
$user_id
);
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
if ( !$result ) return null;
if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
function get_phone_users ( $macaddress )
{
global $config;
- $ptbl = $config['provision_phones_table'];
- $utbl = $config['provision_users_table'];
+ $ptbl = $config['hermes_phones_table'];
+ $utbl = $config['hermes_users_table'];
$query = "SELECT ".$ptbl.".mac as mac, CONCAT( ".$utbl.".username, '@', ".$utbl.".domain ) as user
FROM ".$ptbl."
INNER JOIN ".$utbl." ON ".$ptbl.".user_rel = ".$utbl.".id
WHERE ".$ptbl.".mac = '".sql_clean($macaddress ). "'";
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
if ( !$result ) return null;
if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
// OK, so we have the User ID, a valid MAC, and no previous registration
// of that combination. Going to add.
$query = sprintf("INSERT INTO %s ( mac, user_rel ) VALUES ( '%s', %d )",
- $config['provision_phones_table'], $mac, $user_id);
- return sql_dbexec( $config['provision_db'], $query );
+ $config['hermes_phones_table'], $mac, $user_id);
+ return sql_dbexec( $config['hermes_db'], $query );
}
function delete_phone_user( $mac, $username, $domain )
// OK, so we have the User ID, a valid MAC, and no previous registration
// of that combination. Going to remove.
$query = sprintf("DELETE FROM %s WHERE mac = '%s' AND user_rel = %d",
- $config['provision_phones_table'], $mac, $user_id);
- return sql_dbexec( $config['provision_db'], $query );
+ $config['hermes_phones_table'], $mac, $user_id);
+ return sql_dbexec( $config['hermes_db'], $query );
}
function list_phones ( $search = null )
{
global $config;
- $query = sprintf("SELECT mac FROM %s", $config['provision_phones_table']);
+ $query = sprintf("SELECT mac FROM %s", $config['hermes_phones_table']);
if ( $search )
$query .= sprintf(" WHERE mac LIKE '%s%%'", sql_clean($search));
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
if ( !$result ) return null;
if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
{
global $config;
$query = sprintf("SELECT username FROM %s WHERE username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean( $user ),
sql_clean( $domain )
);
- return sql_dbtest_numrows( $config['provision_db'], $query, 1);
+ return sql_dbtest_numrows( $config['hermes_db'], $query, 1);
}
function add_kamailio_subscriber( $username, $domain, $password, $email )
if ( is_provision_user( $username, $password ) ) return false;
$query = sprintf ("INSERT INTO %s ( username, password, displayname, domain, registrar, r_port, proxy, p_port, dialplan, authid, linetext )
VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', %d, '%s', '%s', '%s')",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean($username),
sql_clean($password),
sql_clean($displayname),
sql_clean($authid),
sql_clean($linetext)
);
- if ( ! sql_dbexec( $config['provision_db'], $query ) ) return false;
+ if ( ! sql_dbexec( $config['hermes_db'], $query ) ) return false;
return true;
}
function get_provision_userid ( $username, $domain )
global $config;
$query = sprintf("SELECT id FROM %s WHERE username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean($username),
sql_clean($domain)
);
- $row = sql_dbquery_single( $config['provision_db'], $query );
+ $row = sql_dbquery_single( $config['hermes_db'], $query );
if (!$row) return false;
$user_rowid = $row['id'];
return $user_rowid;
if ( !$user_rowid ) return false;
$query = sprintf( "DELETE FROM %s WHERE id = %d AND username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
$user_rowid,
sql_clean($username),
sql_clean($domain)
);
- if ( sql_dbexec_rows( $config['provision_db'], $query) != 1 ) return false;
+ if ( sql_dbexec_rows( $config['hermes_db'], $query) != 1 ) return false;
return true;
}
return -2;
$query = sprintf("UPDATE %s SET %s = '%s' WHERE username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean($param),
sql_clean($data),
sql_clean($username),
sql_clean($domain)
);
- $res = sql_dbexec_rows( $config['provision_db'], $query);
+ $res = sql_dbexec_rows( $config['hermes_db'], $query);
if ( $res < 0 ) return -2;
if ( $res > 1 ) return -2;
return false;
$query = sprintf("UPDATE %s SET password = '%s' WHERE username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean($password),
sql_clean($username),
sql_clean($domain)
);
- if ( sql_dbexec_rows( $config['provision_db'], $query) != 1 ) return false;
+ if ( sql_dbexec_rows( $config['hermes_db'], $query) != 1 ) return false;
return true;
}
function list_users ( $search = null )
{
global $config;
- $query = sprintf("SELECT CONCAT(username, '@', domain), displayname FROM %s ORDER BY username,domain", $config['provision_users_table'] );
+ $query = sprintf("SELECT CONCAT(username, '@', domain), displayname FROM %s ORDER BY username,domain", $config['hermes_users_table'] );
if ( array_key_exists ( 'search', $_POST ) )
{
$search = $_POST['search']; // TODO: Add some sanitation and input validation!
- $query = sprintf("SELECT CONCAT(username, '@', domain) FROM %s WHERE CONCAT(username, '@', domain) LIKE '%%%s%%' ORDER BY username,domain", $config['provision_users_table'], sql_clean( $search ) );
+ $query = sprintf("SELECT CONCAT(username, '@', domain) FROM %s WHERE CONCAT(username, '@', domain) LIKE '%%%s%%' ORDER BY username,domain", $config['hermes_users_table'], sql_clean( $search ) );
}
- $result = sql_dbquery( $config['provision_db'], $query );
+ $result = sql_dbquery( $config['hermes_db'], $query );
if ( !$result ) return null;
$list = array();
while ( $row = @mysql_fetch_row( $result ) )
$kamailio_data = null;
$query_provision = sprintf ("SELECT id, username, password, displayname, domain, registrar, r_port, proxy, p_port, dialplan, authid, linetext FROM %s WHERE username = '%s' AND domain = '%s'",
- $config['provision_users_table'],
+ $config['hermes_users_table'],
sql_clean($username),
sql_clean($domain));
- $provision_data = sql_dbquery_single( $config['provision_db'] , $query_provision );
+ $provision_data = sql_dbquery_single( $config['hermes_db'] , $query_provision );
if ( ! $provision_data ) return false;
if ( $type == 'local' )
}
else
{
- print json_encode( array ( 'response' => 'ok', 'data' => array (
- 'mac' => $mac, 'username' => $username, 'domain' => $domain) ));
+ print json_encode( array ( 'response' => 'ok', 'mac' => $mac, 'username' => $username, 'domain' => $domain) );
break;
}
break;
}
else
{
- print json_encode( array ( 'response' => 'ok' ));
+ print json_encode( array ( 'response' => 'ok', 'mac' => $mac, 'username' => $username, 'domain' => $domain ));
break;
}
break;
// Now, do funky stuff.
/*
- Test if user exists in both 'kamailio.subscribers' and 'provision.users'
+ Test if user exists in both 'kamailio.subscribers' and 'hermes.users'
* Return 'response' => 'ok', 'type' => 'local', 'user' => complete user object.
- Test if user exists in 'provision.user' only
+ Test if user exists in 'hermes.user' only
* Return 'response' => 'ok', 'type' => 'remote', 'user' => complete user object.
If user does is neither local nor remote
* Return 'response' => 'failed' with 'cause' => 'nonexistant'
email
Verify that domain is local (lookup in the 'kamailio.domain' table.
- Verify that the username is available (nonexistant for domain in kamilio.subscribers (and provision.users?))
+ Verify that the username is available (nonexistant for domain in kamilio.subscribers (and hermes.users?))
* Autocreate password
* Add username, domain, email and created password to the 'kamailio.subscriber' table
- * Get the registrar+port, proxy+port from the 'provision.servers' table.
+ * Get the registrar+port, proxy+port from the 'hermes.servers' table.
* standard dialplan from configuration.
- * Add to the 'provision.users' table:
+ * Add to the 'hermes.users' table:
username -> username
password -> generated password
displayname -> displayname
domain -> domain
- registrar -> provision.servers.registrar
- r_port -> provision.servers.r_port
- proxy -> provision.servers.proxy
- p_port -> provision.servers.p_port
+ registrar -> hermes.servers.registrar
+ r_port -> hermes.servers.r_port
+ proxy -> hermes.servers.proxy
+ p_port -> hermes.servers.p_port
authid -> username
dialplan -> standard dialplan
linetext -> username
linetext
Verify that the domain is not a local kamailio domain (REMOTE user..)
- Verify that the username+domain is not already registered in 'provision.users'.
+ Verify that the username+domain is not already registered in 'hermes.users'.
* If r_port is empty, set to 5060
* If proxy/port is empty, set to registrar/port
* If authid is empty, set to username
* If dialplan is empty, set to standard dialplan
* If linetext is empty, set to username@domain
- * Add to the 'provision.users' table:
+ * Add to the 'hermes.users' table:
username -> username
password -> supplied password
displayname -> displayname
Required parameters should be...
( username & domain ) | user
- * Verify that no associations/relations exist in 'provision.phones'
- * Verify that the user exists in 'provision.users'
- * Remove from 'provision.users'
+ * Verify that no associations/relations exist in 'hermes.phones'
+ * Verify that the user exists in 'hermes.users'
+ * Remove from 'hermes.users'
* Test to see of user exists in 'kamailio.subscriber'.
* Remove from 'kamailio.subscribers'
* Return response' => 'ok', 'type' => 'local'
( username & domain ) | user
password
- * Verify that no associations/relations exist in 'provision.phones'
+ * Verify that no associations/relations exist in 'hermes.phones'
* Verify that the user exists ...
- * Test to see of user exists in 'provision.users'
+ * Test to see of user exists in 'hermes.users'
* Test to see of user exists in 'kamailio.subscriber'.
* If no such user exists, return 'response' => 'failed' with 'cause' => 'nonexistant'
- * Update user passwords in 'provision' and 'kamailio' as appropriate
+ * Update user passwords in 'hermes' and 'kamailio' as appropriate
* On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
*/
if ( array_key_exists('password', $_POST) &&
Required parameters should be...
( username & domain ) | user
- * Verify that no associations/relations exist in 'provision.phones'
+ * Verify that no associations/relations exist in 'hermes.phones'
* Verify that the user exists ...
- * Test to see of user exists in 'provision.users'
+ * Test to see of user exists in 'hermes.users'
* Test to see of user exists in 'kamailio.subscriber'.
* If no such user exists, return 'response' => 'failed' with 'cause' => 'nonexistant'
* Get update parameters, and change as appropriate ;)
a subset matching on the MAC addresses.
Return:
- TODO: Document this.
+ Returns 'list' as a simple array of registered MAC-adresses on success,
+ the list will be limited to addresses matching the search if provided.
+
phone/add
-------------------
are identical to the phone/add node.
Return:
- TODO: Document additional info provided on 'result' = 'ok'
+ Returns 'mac', 'username' and 'domain' on success.
Returns 'failed' with 'cause' = 'invalid' if SIP address is malformed.
Returns 'failed' with 'cause' = 'invalid' if MAC address is malformed.
Returns 'failed' with 'cause' = 'nonexistant' on no such registration.
UNLOCK TABLES;
--
--- Current Database: `provision`
+-- Current Database: `hermes`
--
-USE `provision`;
+USE `hermes`;
--
-- Dumping data for table `number_pool`
SET character_set_client = @saved_cs_client;
--
--- Current Database: `provision`
+-- Current Database: `hermes`
--
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `provision` /*!40100 DEFAULT CHARACTER SET latin1 */;
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `hermes` /*!40100 DEFAULT CHARACTER SET latin1 */;
-USE `provision`;
+USE `hermes`;
--
-- Table structure for table `apikeys`