Can we add a new user to opensips using rest_client? - voip

Can we a new user using opensips rest_client?
If yes then what i have to add to the config file.
If not then is there any other module using which i can communicate to opensips from an external system?

There are several ways to provision data for the OpenSIPS tables:
web GUI (OpenSIPS Control Panel)
HTTP requests (with the pi_http + httpd modules [1])
I can see that 2. seems to suit you best. The involved module is named "auth_db", table "subscriber".
[1] : http://www.opensips.org/html/docs/modules/1.12.x/pi_http.html

You can create a new user directly to the DB. I use a stored procedure (MySQL) similar to below:
CREATE DEFINER=`root`#`%` PROCEDURE `ADD_SUBS`(IN subid VARCHAR(64),INOUT pwd VARCHAR(64))
BEGIN
DECLARE realm , ha1 , ha1b VARCHAR(64) DEFAULT 'your.sip.domain';
DECLARE res INT DEFAULT 0;
SELECT count(id) into res from subscriber where `username` = subid;
if res = 0 then
set ha1 = md5(concat(subid ,':',realm,':',pwd));
set ha1b = md5(concat(subid,'#',realm,':',realm,':',pwd));
INSERT INTO subscriber (`username`,`domain`,`password`,`ha1`,`ha1b`) VALUES (subid, realm, pwd, ha1, ha1b);
end if;

Related

Function made of transaction statement on PostgreSQL

I want to authenticate an user by its nickname (networkId) and before-hand hashed password, with an user public table (recoyx.user) and an user private table (recoyx_private.user). The function is based on browsing this PostGraphile tutorial (PostGraphile combines GraphQL and PostgreSQL).
create function recoyx.authenticate(
network_id text,
password_hash text
) returns recoyx.jwt_token
begin;
set local id to (select (numeric_id) from recoyx.user where user.network_id = $1).numeric_id;
select (numeric_id, password_hash)::recoyx.jwt_token
from recoyx_private.user
where user.numeric_id = id and user.password_hash = $2;
end;
The query runner is giving invalid syntax within this function overall, both at the part like select * from recoyx.table where table.field = value, transaction frames and the id binding. I took the query runner from this example which gives a short
facility for initializing, querying and releasing the query runner for the PostgreSQL database (I got here through this postgraphile module API documentation).
When I eliminate this function from my query, it runs fine. As far as I've just seen the dot is valid, and the local assignment too. So is my syntax really wrong?
Update
Now this is my function:
create function recoyx.authenticate(
network_id text,
password_hash text
) returns recoyx.jwt_token
as
$body$
select (numeric_id, password_hash)::recoyx.jwt_token
from recoyx_private.user
where numeric_id = (select numeric_id from recoyx.user where network_id = $1)
and password_hash = $2;
$body$
language sql
stable;
I'm getting undefined relations, but I'm connecting to the default root role that comes within my PostgreSQL installation (postgres role) as I run the create function query
I've put the project on GitHub. I'm running the query through npm run init-database. See environment-example.json (it specifies the conventional "postgres" role).
As documented in the manual the function body is passed as a string in Postgres (and the tutorial you linked to actually included the necessary as $$ ...$$ - you just didn't copy it). You also forgot to specify the function's language.
set local id is neither a valid variable assignment in PL/pgSQL nor in SQL (which doesn't have variables to begin with).
But you don't really need a variable to do what you want, your function can be implemented as a SQL function:
create function recoyx.authenticate(
network_id text,
password_hash text
) returns recoyx.jwt_token
as
$body$
select (numeric_id, password_hash)::recoyx.jwt_token
from recoyx_private.user
where user.numeric_id = (select numeric_id
from recoyx.user
where network_id = $1)
and user.password_hash = $2;
$body$
language sql
stable;

Lotus Notes NAB - Adding a field

I have a project that I need to put an Internet Address and also add a new field called ShortName for all groups in the Notes NAB.
I am able to put the values and save the document , I tried with a doc.save and a computewithform. This is the Group form.
After the change, people in that group are no longer able to access the application.
Do you have an idea what I am doing wrong ?
User A is in group XYZ.
I added internetaddress xyz.com and a shortname text field xyzmigration
Application A is having an ACL with the group XYZ as editor. When User A tries to open the Application A, he get a not authorize. If I delete both values, User A is able to open the database.
Thanks for your help
$ServerAccess view validates Group documents and omits any Groups that has Shortname field present.
Normunds has the correct answer, but I want to add a suggestion: create a new group instead of modifying the existing group. I.e., if the group is "MyGroup", create a group named "MyGroup_Extended" and set it up with
Shortname = the value that you want
InternetAddress = the value that you want
Members = "MyGroup"
That way, you leave MyGroup untouched, but you still have a modified group document with the additional information added and the same member list.
And another thing: In order to make those groups that you already altered functional again, you should run a simple agent against all of the groups that does this:
FIELD ShortName := #DeleteField;
FIELD InternetAddress := #DeleteField;
After the help of some answers that I got here. I checked the view $ServerAccess. The selection formula is checking for a field Shortname and that is what was causing my problem. I will create another field name and we will be able to use this field instead of ShortName. allfields := #DocFields;
test1 := 0;
test2 := 0;
#For(i:=1; i < #Elements(allfields); i:=i+1; test1 := test1 + #If(#UpperCase(allfields[i]) = "LISTNAME";1;0));
#For(i:=1; i < #Elements(allfields); i:=i+1; test2:=test2 + #If(#UpperCase(allfields[i]) = "SHORTNAME";1;0));
SELECT (test1 < 2 & test2 = 0 &Type = "Group" & (#IsUnavailable ( GroupType)|GroupType="0" : "2":"3":"4")) & Form="Group" & #IsUnavailable($Conflict)
Thanks for your help.

Azure SQL Error Retrieving data from shard - Login Failed for User

I'm trying to do a cross database query but my error suggest's that I can't even connect to my external data source.
My exact error message is the following:
Error retrieving data from shard [DataSource=xxxxxxxxxxxxxxxxxx Database=CRDMPointOfSale_Configuration]. The underlying error message received was: 'Login failed for user 'CRDMAdmin'.'.
Below is my 'Create Database Scoped Credential'.
CREATE DATABASE SCOPED CREDENTIAL CRDMCred
WITH IDENTITY = 'CRDMAdmin',
SECRET = 'xxxxxxxxxx';
GO
Below is my 'Create Extenal Data Source'.
CREATE EXTERNAL DATA SOURCE CRDM_Configuration
WITH (
TYPE=RDBMS,
LOCATION='xxxxxxxxxxxxxxxxxxxxx',
DATABASE_NAME='CRDMPointOfSale_Configuration',
CREDENTIAL = CRDMCred
);
Below you can see my execute remote statement is within a stored procedure. Which I've seen elsewhere online.
CREATE PROCEDURE [admin].[InsertThreadProcessingDataIntoLoadTable]
(
#ThreadID VARCHAR(100)
, #DataLoadSchemaID INT OUTPUT
, #DateFrom CHAR(8) OUTPUT
, #DateTo CHAR(8) OUTPUT
, #DatabaseName VARCHAR(100)
)
AS BEGIN
SET NOCOUNT ON
DECLARE #IsBatchLoad BIT
SET #IsBatchLoad = CASE 'NO' WHEN 'YES' THEN 1 ELSE 0 END
Exec sp_execute_remote #data_source_name = N'CRDM_Configuration',
#stmt = N'SELECT #DateFrom = CONVERT(CHAR(8),FromDate,112), #DateTo = CONVERT(CHAR(8),DATEADD(DAY,1,ToDate),112)
FROM [admin].[GetFromAndToDatesForDatabase] (#DatabaseName, #IsBatchLoad,NULL)',
#params = N'#DatabaseName VARCHAR(100), #IsBatchLoad BIT',
#DatabaseName = 'CRDMPointOfSale', #IsBatchLoad = 1;
END
As you can see above the execute remote contains a SELECT statement, the FROM is the result of a function being called ([admin].[GetFromAndToDatesForDatabase]) that is from a different database which is why i have a 'Exec sp_execute_remote' wrapped around.
Should I be specifying parameters when not directly calling a SP? Also what am i doing wrong?

CRM 2011: Special permissions missing for Users

We have created a bunch of users in CRM 2011 using the SDK. However, we added their Security Role records through the database.
Everything seems to work fine, until these users started to save their own User Dashboards and Advanced Finds.
The users could create their own User Dashboards. However, once they created them, they could not see them. They were not in their list of Dashboards - only the System Dashboards where there.
There were no errors in the event viewer or even the trace logs.
I used SQL Profiler to see what it was doing and I discovered it was checking the PrincipalEntityMap table for principals that had an objecttypecode of 1031 - which is the User Dashboard (called UserForm).
How do these records get created?
I can write a SQL script to populate the database with these missing records.
What I would like to know is why they are missing? Any ideas?
Where do the records for PrincipalEntityMap come from?
Because we created the UserRole (i.e. User Security Role) records through the database and not through the SDK - we missed some POA (Principal Object Access) related records.
There are a number of stored procedures that can be called to re-initialise these records.
We have written a script to reset these records for all users:
-- This will create PrincipalEntityMap for users - if they are not there:
INSERT INTO PrincipalEntityMap (ObjectTypeCode, PrincipalId, PrincipalEntityMapId)
SELECT 1031, sup.PrincipalId, NEWID()
FROM SystemUserPrincipals sup
INNER JOIN SystemUser su ON su.SystemUserId = sup.SystemUserId
WHERE
(sup.PrincipalId = su.SystemUserId) AND
(sup.PrincipalId NOT IN
(
SELECT pem.PrincipalId
FROM PrincipalEntityMap pem
WHERE pem.ObjectTypeCode = 1031
)
)
DECLARE #PrincipalTable TABLE (PrincipalID uniqueidentifier)
DECLARE #CurrentPrincipalID uniqueidentifier
DECLARE #UserIds VARCHAR(60)
DECLARE #Type INT
BEGIN TRANSACTION ResetPrincipalEntitiyMap
BEGIN
SET #Type = 8
INSERT INTO #PrincipalTable (PrincipalID)
SELECT sup.PrincipalId
FROM SystemUserPrincipals sup WITH (NOLOCK)
INNER JOIN SystemUser su WITH (NOLOCK) ON sup.SystemUserId = su.SystemUserId AND sup.PrincipalId = su.SystemUserId
WHILE EXISTS (SELECT PrincipalID FROM #PrincipalTable)
BEGIN
SELECT TOP 1 #CurrentPrincipalID = PrincipalID
FROM #PrincipalTable
ORDER BY PrincipalID ASC
EXEC p_PrincipalEntityMapReinit #CurrentPrincipalID, #Type
EXEC p_PrincipalAttributeAccessMapReinit #CurrentPrincipalID, #Type
SET #UserIds = cast(#CurrentPrincipalID AS VARCHAR(50))
EXEC p_SystemUserBuEntityMapReinit #UserIds
DELETE FROM #PrincipalTable WHERE PrincipalID = #CurrentPrincipalID
END
END
COMMIT TRANSACTION ResetPrincipalEntitiyMap
Please Note: Always perform inserts/updates/deletes of Security
Related entities (User, UserRole, Team, TeamRole, etc.) through the
SDK - rather than the database. The SDK does some weird stuff in the
background that will be missed if you use SQL.
While trying to resolve the common/constant problem with exchange server side sync on CRM 2013 (error code E-Mail-Server: Crm.80044151 when sync of contacts, tasks and appoitments is enabled), we've also tried to reinit the principal-tables using your script.
For CRM2013/15, it had to be modified slightly, because the signature of SP p_PrincipalEntityMapReinit has changed.
Here's the updated TSQL - maybe it helps someone else (in our case, it didn't :( ):
DECLARE #PrincipalTable dbo.EntityIdCollection
DECLARE #CurrentPrincipalID uniqueidentifier
DECLARE #UserIds VARCHAR(60)
DECLARE #Type INT
BEGIN TRANSACTION ResetPrincipalEntitiyMap
BEGIN
SET #Type = 8
INSERT INTO #PrincipalTable (id)
SELECT sup.PrincipalId
FROM SystemUserPrincipals sup WITH (NOLOCK)
INNER JOIN SystemUser su WITH (NOLOCK) ON sup.SystemUserId = su.SystemUserId AND sup.PrincipalId = su.SystemUserId
EXEC p_PrincipalEntityMapReinit #PrincipalTable, #Type
WHILE EXISTS (SELECT id FROM #PrincipalTable)
BEGIN
SELECT TOP 1 #CurrentPrincipalID = id
FROM #PrincipalTable
ORDER BY id ASC
EXEC p_PrincipalAttributeAccessMapReinit #CurrentPrincipalID, #Type, 1
SET #UserIds = cast(#CurrentPrincipalID AS VARCHAR(50))
EXEC p_SystemUserBuEntityMapReinit #UserIds
DELETE FROM #PrincipalTable WHERE id = #CurrentPrincipalID
END
END
COMMIT TRANSACTION ResetPrincipalEntitiyMap

XPages #DbLookup returning undefined when looking to another server/database

I am trying to perform an #DbLookup to another server/database and continually receive an "undefined" return message. The database exists, the view name is correct, the key is correct, as well as the column I am trying to return. I have reader access to the database.
I have tried all these combinations for the server/file path, but none seem to work:
var dbName = new Array(session.getServerName(), "my/folder/thisdb.nsf");
var dbName = session.getServerName() + "!!" + my\\folder\\thisdb.nsf;
var dbName = "CN=Server/OU=Name/O=This" + "!!" + my\\folder\\thisdb.nsf;
var dbName = [#DbName([0]), "my/folder/thisdb.nsf"];
I have found this post and tried most of the combinations:
http://www.c-lutions.com/c-lutions/mcblog.nsf/dx/08242012095124AMJMMJ69.htm
Are there any other combinations I can try?
Thanks!
Is your folder's name my folder with a space in it? This could be the challenge. I would suggest to ease your pain....
Create one XPage in your target database, have one computed field on it with #DbName() as formula and see what is coming back. Besides that, your formulas have some issues (comments below the entries):
var dbName = new Array(session.getServerName(), "my/folder/thisdb.nsf");
looks OK unless your folder isn't a subfolder of my. Folders need to be relative to the data directory.
var dbName = session.getServerName() + "!!" + my\\folder\\thisdb.nsf;
dbName must be an array, this one isn't. Also there are no quotes around the file name
var dbName = "CN=Server/OU=Name/O=This" + "!!" + my\\folder\\thisdb.nsf;
same here: must be an array, quote is missing. It is confusing since the data source syntax uses the (CN) format of this: #Name("[CN]";#Subset(#DbName();1)+"!!....
var dbName = [#DbName([0]), "my/folder/thisdb.nsf"];
almost there. #DbName() doesn't take a parameter, so you would write:var dbName = [#DbName()[0], "my/folder/thisdb.nsf"]; or use var dbName = [#Subset(#DbName(),1), "my/folder/thisdb.nsf"];
You also can check great samples to play with.
Make sure the second server is in a trusted server group that is trusted by the first server. For security reasons XPages (and LotusScript) running on any server is unable to access the contents of databases if they are not in the same trusted server group.

Resources