USERBLACKLIST module
Admin Guide
Section titled “Admin Guide”Overview
Section titled “Overview”The userblacklist module allows OpenSIPS to handle blacklists on a per user basis. This information is stored in a database table, which is queried to decide if the number (more exactly, the request URI user) is blacklisted or not.
An additional functionality that this module provides is the ability to handle global blacklists. This lists are loaded on startup into memory, thus providing a better performance then in the userblacklist case. This global blacklists are useful to only allow calls to certain international destinations, i.e. block all not whitelisted numbers. They could also used to prevent the blacklisting of important numbers, as whitelisting is supported too. This is useful for example to prevent the customer from blocking emergency call number or service hotlines.
The module exports two functions, check_blacklist and check_user_blacklist for usage in the config file. Furthermore its provide a FIFO function to reload the global blacklist cache.
Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”The module depends on the following modules (in the other words the listed modules must be loaded before this module):
- database — Any database module
External Libraries or Applications
Section titled “External Libraries or Applications”The following libraries or applications must be installed before running OpenSIPS with this module loaded:
- none
Exported Parameters
Section titled “Exported Parameters”db_url (string)
Section titled “db_url (string)”Url to the database containing the routing data.
Default value is “mysql://opensipsro:opensipsro@localhost/opensips”.
...modparam("userblacklist", "db_url", "dbdriver://username:password@dbhost/dbname")...db_table (string)
Section titled “db_table (string)”Name of the table where the user blacklist data is stored.
Default value is “userblacklist”.
...modparam("userblacklist", "db_table", "userblacklist")...use_domain (integer)
Section titled “use_domain (integer)”If set to non-zero value, the domain column in the userblacklist is used.
Default value is “0”.
...modparam("userblacklist", "use_domain", 0)...Exported Functions
Section titled “Exported Functions”check_user_blacklist (string user, string domain, string number, string table)
Section titled “check_user_blacklist (string user, string domain, string number, string table)”Finds the longest prefix that matches the request URI user (or the number parameter) for the given user and domain name in the database. If a match is found and it is not set to whitelist, false is returned. Otherwise, true is returned. Pseudo-variables or AVPs can be used for the user, domain and number parameters. The number and table variables are optional, the defaults are used if they are ommited. The number parameter can be used to check for example against the from URI user.
...$avp(i:80) = $rU;# rewrite the R-URIif (!check_user_blacklist("$avp(i:80)", "$avp(i:82)")) sl_send_reply("403", "Forbidden"); exit;}...check_blacklist (string table)
Section titled “check_blacklist (string table)”Finds the longest prefix that matches the request URI for the given table. If a match is found and it is not set to whitelist, false is returned. Otherwise, true is returned.
...if (!check_blacklist("global_blacklist"))) sl_send_reply("403", "Forbidden"); exit;}...Exported MI Functions
Section titled “Exported MI Functions”reload_blacklist
Section titled “reload_blacklist”Reload the internal global blacklist cache. This is necessary after the database tables for the global blacklist have been changed.
...opensipsctl fifo reload_blacklist...Installation and Running
Section titled “Installation and Running”Database setup
Section titled “Database setup”Before running OpenSIPS with userblacklist, you have to setup the database table where the module will read the blacklist data. For that, if the table was not created by the installation script or you choose to install everything by yourself you can use the userblacklist-create.sql SQL script in the database directories in the opensips/scripts folder as template. Database and table name can be set with module parameters so they can be changed, but the name of the columns must be as they are in the SQL script. You can also find the complete database documentation on the project webpage, http://www.opensips.org/html/docs/db/db-schema-1.4.x.html.
...+----+-----------+-----------+| id | prefix | whitelist |+----+-----------+-----------+| 1 | | 0 || 2 | 1 | 1 || 3 | 123456 | 0 || 4 | 123455787 | 0 |+----+-----------+-----------+...This table will setup a global blacklist for all numbers, only allowing calls starting with “1”. Numbers that starting with “123456” and “123455787” are also blacklisted, because the longest prefix will be matched.
...+----+----------------+-------------+-----------+-----------+| id | username | domain | prefix | whitelist |+----+----------------+-------------+-----------+-----------+| 23 | 49721123456788 | | 1234 | 0 || 22 | 49721123456788 | | 123456788 | 1 || 21 | 49721123456789 | | 12345 | 0 || 20 | 494675231 | | 499034133 | 1 || 19 | 494675231 | test | 499034132 | 0 || 18 | 494675453 | test.domain | 49901 | 0 || 17 | 494675454 | | 49900 | 0 |+----+----------------+-------------+-----------+-----------+...This table will setup user specific blacklists for certain usernames. For example for user “49721123456788” the prefix “1234” will be not allowed, but the number “123456788” is allowed. Additionally a domain could be specified that is used for username matching if the “use_domain” parameter is set.
Contributors
Section titled “Contributors”By Commit Statistics
Section titled “By Commit Statistics”Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
| # | Name | DevScore | Commits | Lines++ | Lines— |
|---|---|---|---|---|---|
| 1. | Hardy Kahl | 12 | 1 | 1191 | 0 |
| 2. | Stefan Darius (@dariusstefan) | 9 | 5 | 293 | 49 |
| 3. | Henning Westerholt (@henningw) | 9 | 5 | 211 | 79 |
| 4. | Daniel-Constantin Mierla (@miconda) | 8 | 6 | 18 | 13 |
| 5. | Bogdan-Andrei Iancu (@bogdan-iancu) | 7 | 5 | 23 | 25 |
| 6. | Razvan Crainea (@razvancrainea) | 3 | 1 | 2 | 2 |
| 7. | Edson Gellert Schubert | 2 | 1 | 0 | 60 |
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits
(3) ignoring whitespace edits, renamed files and auto-generated files
By Commit Activity
Section titled “By Commit Activity”| # | Name | Commit Activity |
|---|---|---|
| 1. | Stefan Darius (@dariusstefan) | Jun 2026 - Jul 2026 |
| 2. | Razvan Crainea (@razvancrainea) | Jun 2026 - Jun 2026 |
| 3. | Bogdan-Andrei Iancu (@bogdan-iancu) | Feb 2008 - Jul 2008 |
| 4. | Henning Westerholt (@henningw) | Feb 2008 - May 2008 |
| 5. | Daniel-Constantin Mierla (@miconda) | Mar 2008 - Mar 2008 |
| 6. | Edson Gellert Schubert | Feb 2008 - Feb 2008 |
| 7. | Hardy Kahl | Feb 2008 - Feb 2008 |
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Bogdan-Andrei Iancu (@bogdan-iancu), Henning Westerholt (@henningw), Daniel-Constantin Mierla (@miconda), Edson Gellert Schubert, Hardy Kahl.
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0