PHP Mongodb driver gives "unauthorized" error when running MongoDB->execute() with Mongo 2.4.0 using authentication - mongodb-php

I am having trouble with the following code:
$m = new MongoClient('mongodb://sf:xxxxxx#localhost/sf');
$collections = $m->selectDB("sf")->getCollectionNames();
var_dump($collections); // prints collection names as expected
$collections = $m->selectDB("sf")->execute('function (){ return db.getCollectionNames(); }');
var_dump($collections); // gives error "unauthorized"
This has been reproduced on:
Mongo 2.4.0 , MongoDB PHP driver 1.3.6, PHP Version 5.3.8, Windows 7 32-bit
Mongo 2.4.0 , MongoDB PHP driver 1.3.5, PHP Version 5.3.2, Ubuntu 10.04.4
Any help?

PHP's execute is just a wrapper to call eval which requires admin access to use.
From the documentation:
With authentication enabled, eval will fail during the operation
if you do not have the permission to perform a specified task.
Changed in version 2.4: You must have full admin access to run.

Check your connection string for MongoDB. If it includes the database, try removing it. For example:
mongodb://sf:[pass]#localhost/sf
to
mongodb://sf:[pass]#localhost/
After this is done, select the database after the client is instantiated with authentication. I believe this should allow you to utilize the function. I believe it results in the authentication being done for the admin collection instead of the specified collection, perhaps providing access to this function.

Related

Bigquery to Redshift data transfer using AWS SCT failing?

I am trying to migrate data from Bigquery to Redshift using this article. I followed through and successfully got till "Start the Local Data Migration Task".I had to setup AWS profile to access "Data Migration View(Other)". AWS profile was setup using access key and access secret of an admin user account in AWS.
What am I missing ?However, upon starting the task I keep getting following error:
class com.amazon.dmt.model.FileCredentials cannot be cast to class com.amazon.dmt.model.UserCredentials (com.amazon.dmt.model.FileCredentials and com.amazon.dmt.model.UserCredentials are in unnamed module of loader 'app')
I tried to check AWS documentation and looked around but this error is not listed anywhere. I cannot seem to understand that, why is type casting from FileCredentials to UserCredentials is being done ?
Anyone faced a similar issue or can point me in right direction please ?
Based on my testing, I have determined that this is an issue in the 1.0.670 version of SCT. A request has been submitted to correct the issue. In the meantime, to allow you to continue with your project, please revert to AWS-SCT version 1.0.666 using this link. https://d211wdu1froga6.cloudfront.net/builds/1.0/666/Windows/aws-schema-conversion-tool-1.0.zip
You will have to uninstall SCT and the extractor agent then reinstall and configure the previous version(s) as you did before.

adding basic authentication to Solr 8.6.1

We are having some difficulty when adding basic authentication to Solr 8.6.1. We are following this document, and we have created security.json file, which is successful (since Solr instance will ask userId and password when it starts.) Our difficulty happens when trying to enable the global authentication settings: we did pass the -Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory system property,and we also set the -Dbasicauth=username:password property as follows:
// the following is the last time of our Solr Dockerfile:
CMD ["solr-foreground", "-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory", "-Dbasicauth=username:secret"]
However, the calls to retrieve data from Solr all come back with Error 401 require authentication.
Could someone please kindly let us know what did we miss?
You'll have to set the correct options on the client - not on the server. This is a setting that affects how the client that connects to Solr authenticates.
So when running your application, give the parameter to the java command (or configure it to be the default parameter through ant/maven/gradle/etc.
Setting it on the docker container will not do anything useful.

Ansible API : Custom Module

I would like to use a custom module for which I require "hostname" so that I can initiate SSH connection from the custom module and run commands. So I pass transport = "local" to the Runner object. However, I find no way to obtain "hostname" information in the custom module.
I am using Ansible 1.9.2 using Python API.
A module only has the information available that was explicitly passed to it. What you might be interested in instead is an action plugin, which by (non-exisiting) definition runs local on the control machine and has access to more (all?) data.
You can see some action plugin code here: https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/action
PS: Don't you want to upgrade to Ansible 2 before getting started writing custom modules/plugins? The API changed completely and once you upgrade you have to rewrite you module/plugin.
Okay, silly me. It's exactly the same way in the API too. You can extract hostname using {{ inventory_hostname }}.

Is there a way to bring up a Yii console like 'rails console'?

Is there a way to interact with Yii on the command line with a console like rails console? I'd like to test DB and ActiveRecord calls.
You can install yii-shell. It's made by the Yii team. It works like rails console
EDIT:
Sorry, I worked from the documentation of yii-shell which is - at the time of this writing - but a promise.
This is how you can get a proper REPL working in Yii 2.
First, we would need to get Psysh. You can install it globally to play with it, but I recommend adding the following line to your composer.json
require-dev: {
// ... some other packages ...
"psy/psysh": "0.7.2"
}
Run composer update to get this package installed.
Now we need to add this to a controller. The way to call up the break point from a controller is eval(\Psy\sh());.
Note that this would invoke the console for debugging. So if your app is served with Apache, Nginx, or any other server which is not tied to an interactive console, this is pointless
For this to work, I have served the application using PHP's inbuilt server and Yii's wrapper for it.
In Yii Basic App template...
cd /path/to/application
./yii serve localhost:12345
In any controller, ...say controllers/SiteController.php
public function actionIndex()
{
eval(\Psy\sh()); // <-- debugger point
return $this->render('index');
}
When you access this action via tha URL, it would hang on your browser. If you check back in the console, you would see an interactive shell which should work like rails c. Checkout the Psysh Documentation for more details. To exit this interactive console, type exit; this should return control back to PHP's inbuilt server. Do not exit the interactive console with Ctrl-C as this would close the PHP's inbuilt server also.
In Yii Advanced App template...
Serving the application does not work at the moment since it defaults to serving the contents of console/web which doesn't exist. I have raised an issue with Yii; you can follow along there if it interests you.
However, if you have console controllers, you can do the same thing we did for the basic app. When you run the console command, you should be presented with the same interactive debug console.
1) Install https://github.com/yiisoft/yii2-shell
composer require yiisoft/yii2-shell
2) ./yii shell

3cx make call url for version 12

I am using 3cx version 11 on my machine. On version 11 they provide the api for making up the calls from your client machine to destination. There is no need to configure the devices, we just need to use the following URLto generate the calls:
http://:5000/ivr/PbxAPI.aspx?func=make_call&from=&to=&pin=
where pbx is the ip of the machine which got the 3cx.
Click here! for more info about the api.
As you can see it is mention on their website that this api is not available on version 12.
I need to ask that is there any alternative to generate the calls if some one is using version 12? Because most of the users now are using version 12, and as an admin I need to figure it out that how can I provide this facility to my clients who have installed version 12.
Zain,
Look into this alternative API from VoIPToys.
http://www.voiptoys.com/3cx-http-api-by-voiptoys
It will have similar syntax in a browser:
http://localhost:5505/MakeCall.aspx?ext=100&pin=1234&to=101
Or like this in C#
String url = "http://localhost:5505/MakeCall.aspx?ext=100&pin=1234&to=101";
// Call the API and receive result
using (WebClient client = new WebClient()) {
String result = Encoding.UTF8.GetString(client.DownloadData(url));
}