Odoo: How to find Odoo version through XML-RPC API? - version

I'm writing a PHP library for accessing the Odoo XML-RPC API and I need to know the Odoo version of the server I'm talking to - but I can't figure out how to determine the version. Is there a certain model that will tell me or how do I do that?
UPDATE
I thought I have figured it out. The ir.module.module model will give you a list of all the installed modules. Then in the base module you look at the installed_version property. BUT this requires admin access! I need to do this as the regular user that is normally using the API.
But for anyone who has that kind of access this is what you would do. Using ripcord (see example here) you would use this line to retrive just the base module:
$models->execute_kw($db, $username, $password, 'ir.module.module', 'search_read', array(array(array('name', '=', 'base'))) );

You can get the Odoo version even without authentication from the API common endpoint. See documentation on https://www.odoo.com/documentation/12.0/webservices/odoo.html heading ”Logging in” and the first code sample there. You can find the server_version property there.
$common = ripcord::client($url.'/xmlrpc/2/common');
$common->version();

Following code is valid and working fine tested on multiple servers.
$url = 'https://###.###.###.##:8069';
$db = 'demo';
$username = 'user_name';
$password = 'password';
$common = ripcord::client("$url/xmlrpc/2/common");
$models = ripcord::client("$url/xmlrpc/2/object");
$common->version();
$uid = $common->authenticate($db, $username, $password, array());
These examples use the Ripcord library, which provides a simple
XML-RPC API. Ripcord requires that XML-RPC support be enabled in your
PHP installation.
Since calls are performed over HTTPS, it also requires that the
OpenSSL extension be enabled.

Related

Shiro how to secure the data source password

I have been exploring Apache Shiro with Zeppelin and so far has been able to make authentication work with JdbcRealm but one thing that is not going well is giving the data source password as plain text.
Is there a way to avoid that?
My shiro.ini looks like:
[main]
dataSource = org.postgresql.ds.PGPoolingDataSource
dataSource.serverName = localhost
dataSource.databaseName = dp
dataSource.user = dp_test
dataSource.password = Password123
ps = org.apache.shiro.authc.credential.DefaultPasswordService
pm = org.apache.shiro.authc.credential.PasswordMatcher
pm.passwordService = $ps
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealmCredentialsMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
jdbcRealm.dataSource = $dataSource
jdbcRealm.credentialsMatcher = $pm
shiro.loginUrl = /api/login
[roles]
admin = *
[urls]
/** = authc
Is there a way to avoid giving data source password as plain text
dataSource.password = Password123?
Would like to give something like:
$shiro1$SHA-256$500000$YdUEhfDpsx9KLGeyshFegQ==$m+4wcq4bJZo1HqDAGECx50LcEkRZI0zCyq99gtRqZDk=
yes, there is a way, but there will still be a password lying around somewhere due to the nature of shiro needing to know the password.
Why Hashing does not work
You posted
something like: $shiro1$SHA-256[…]
This is a hash, and thus it is not reversible. There is no way shiro could log into the datasource using this String.
Container managed datasources
The best approach I can recommend at this point is to have a container managed resource. A container is referring to a (web) application server in this case, like tomcat, OpenLiberty or Wildfly.
For your use case, try looking into the following:
extend org.apache.shiro.realm.jdbc.JdbcRealm or AuthorizingRealm
Add the JPA API to your module and inject a persistence context like so:
#PersistenceContext
EntityManager entityManager;
Override the methods
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
… to load from your managed datasource instead.
Drawbacks of this approach:
You just delegated datasource login to your container / application server. The server is still facing the same problems. E.g. with OpenLiberty, you will still need to store a master key of an encrypted (not hashed) password somewhere, and thus liberty will do exactly this.
use another configuration source
Instead of using a shiro.ini file, you could also write your own environment loader. You could request the file from an IP-restricted web service or a cryptographic hardware device.
Always a goal: restrict the environment
You should always restrict the environment.
E.g. create a user which can install, but not run your application and who cannot read the logs (called setup-user or so).
Create another user which can start the application, read but not modify configuration files and write logs, called a run-user.
Restrict access to configurations and logs for all other users on that system.
Getting involved
If you have other needs, feel welcome to discuss other solutions on the shiro mailing lists.

CakePHP support for initial configuration / web app installation?

I've got a CakePHP based web app that needs some initial configuration. I'd like to do the equivalent of the mysql source command to set up a bunch of tables / initial rows, then execute a $this->User->save() command to create the root account (I think this needs to be done via code since it'll use the salt value for the local install of CakePHP, which might/should be different than the one on my dev machine), etc, etc.
My hack-y solution is to expose a public method on a controller that does this, direct my browser to it, then set stuff up (via the Configure::load and Configure::dump) so that the route from that URL to the method is removed after the installation is complete.
Does CakePHP provide any support for 'installing' a web app?
Part of my problem is that my attempts at Googling for "CakePHP web app installation" are all overshadowed by the various tutorials (etc) about how to install CakePHP itself. My issue is not installing CakePHP, it's providing an easy and safe way to set up the stuff my web app needs (like SQL database tables, etc) for it's particular needs.
It's called Cake Schemas....
The simplest thing you can do in your development environment is run the following via command line from root:
./app/Console/cake schema dump --write filename.sql
Which gives you a dump of your SQL file then you can edit the sql file directly before using it.
You specifically ask for running $this->User->save(), while learning about Schemas might be a bit complicated, you can accomplish this by running
./app/Console/cake schema generate
Which creates your schema.php, then:
App::uses('User', 'Model');
public function after($event = array()) {
if (isset($event['create'])) {
switch ($event['create']) {
case 'users':
App::uses('ClassRegistry', 'Utility');
$user = ClassRegistry::init('User');
$user->create();
$user->save(
array('User' =>
array(
'username' => 'admin',
'role' => 'admin',
'password' => 'admin'
)));
break;
}
}
}
Which makes a definition as you wish, then when you run:
./app/Console/cake schema create
Your tables get dropped, but remade as per your schema definitions and your model files, and with your specific "after" function
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html

Use Sanitize::clean without Database connection at CakePHP 2.3

I am working over Oracle DataBase and CakePHP 2.3.
As CakePHP doesn't support Oracle (there are no drivers for it), I am using Oracle procedures or php OCI8 functions in my models.
As a result of it, I am working with CakePHP without any effective database link in the eyes of CakePHP framework.
I am trying to use the Sanitize::clean method in order to clean a comment before saving it in the database and I am having troubles as it seems to look in the database for its task.
This is the resulting error:
Database connection "Mysql" is missing, or could not be created.
And this is how I try to sanitize it:
$comment = Sanitize::clean($this->request->data['comment']);
It works perfectly well if i just do this:
$comment = $this->request->data['comment'];
Is it possible somehow to use Sanitize::clean without any configured database at CakePHP 2.3?
Thanks
The function Sanitize::clean() expects 2 arguments, by default when you do not give a second argument CakePHP uses its default values and tries to connect to a DB with the 'default' connection. After a quick glance at the Sanitize Class in the library, it appears that it is the 'escape' option that requires a DB connection. It is called by default to make a string SQL-safe.
So in your case, as you don't need a SQL connection, this request should do the trick:
$comment = Sanitize::clean($this->request->data['comment'], array('escape' => false);
Check the CookBook for more information on the Sanitize class.

CakePHP Cake Bake "database configuration was not found"

I am working on a legacy CakePHP 1.3 app and while I have years of experience with PHP, I am still finding my feet with CakePHP. I am following Chapter 4 'How to use the bakery' in Jamie Munro's Rapid Application Development with CakePHP, however the steps he suggests do not seem to go the way I'd expect them too.
I feel a good way of explaining this is going through the steps involved:
Following the books 'Hello World' example outlined in earlier chapters, I have setup a basic CakePHP app at this location on my machine: /home/public_html/helloworld.local. I can see the 'Hello World' example in a web browser on my local machine when I access: http://helloworld.local/users/add
Chapter 4 suggests that I move to this directory: home/public_html/helloworld.local/cake/console
I then run: ./cake bake
I get prompted to enter the location of the app and I add:
/home/public_html/helloworld.local/app
I then proceed to select defaults for the next few selections and there are no problems until I run into the line:
Your database configuration was not found. Take a moment to create one.
I do not understand this since there is a database file configured in ~/public_html/helloworld.local/app/config/database.php, and when I access the helloworld app outlined earlier (available on my local machine at http://helloworld.local/users/add), there is a database connection successfully established and records can be inserted.
I have also tried re-entering my database details when offered the chance to by cake bake, but end up with the error after succesfully adding the correct details:
Fatal error: Class 'DATABASE_CONFIG' not found in
/home/public_html/helloworld.local/cake/console/libs/tasks/db_config.php
on line 260
But either way, it should have found the existing database connection details, so not sure what is going on.
For using console command like cake bake you have to use your operating system terminal(for linux)/ command prompt(for windows). So you have to do the step mentioned in step 2 and 3 in you console. You can read documentation here to know how to use console commands.
Then, make sure that you have the file home/public_html/helloworld.local/app/config/database.php. I hope you removed .default from its name and rename it to database.php. To link up your database with your cakephp project you have to specify credentials in database.php.
var $default = array('driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'password',
'database' => 'database_name',
'prefix' => ''
);
I don't have a running CakePHP 1.3 installation here at hand, but this is what is happening at that location:
// #link: https://github.com/cakephp/cakephp/blob/1.3/cake/console/libs/tasks/db_config.php#L260
config('database');
$db = new $this->databaseClassName; // i.o.w. $db = new DATABASE_CONFIG;
This line:
config('database');
Does nothing more than including the database.php configuration file, simplified to;
include_once(CONFIGS . $arg . '.php'); // i.o.w. include_once(CONFIGS . 'database.php');
(https://github.com/cakephp/cakephp/blob/1.3/cake/basics.php#L77)
So IMO two problems may cause your error;
app/config/database.php was not found
You can try to check if this outputs the right path:
die(CONFIGS . 'database.php');
There is an error in your app/config/database.php, causing the DATABASE_CONFIG class to be malformed and unable to be initialized
A word of notice
Aparently your running 'bake' for everything including setting up a new database configuration. This may overwrite your
existing database configuration. It is possible to bake only parts of your application (e.g. bake controllers only or models).
The manual on baking in CakePHP 1.3 is located here:
http://book.cakephp.org/1.3/en/The-Manual/Core-Console-Applications/Code-Generation-with-Bake.html
And this
If this is your first CakePHP project, you should realy consider the option to upgrade to CakePHP 2.x CakePHP 1.3 is really outdated and, although it's still able to run fine, I wouldn't invest too much time in 1.3 as a lot of things have changed in CakePHP 2.x. It's probably better to start with CakePHP 2.x then to start with 1.3 and learn things that no longer work in CakePHP 2.
Copy your app/Config folder to app/Console, so the final path would be app/Console/Config. That worked for me.

cake php email helper - internal error

I am trying to send email with cake php email component:
var $components = array('Email');
$email = new CakeEmail();
$email->from(array('me#example.com' => 'My Site'));
$email->to('xxx#gmail.com');
$email->subject('About');
$email->send('My message');
And I always get message: Couldnt send email. Internal error occured.
In error log there is "SocketException".
I am using cakephp 2.0.
How should I configure things to get it work? I don't want to use any smtp servers and so on, I just want to send simple email.
I am using WAMP on my PC.
Uncomment the line: extension=php_openssl.dll in php.ini. This will resolve your Socket problem.
One more thing I want to say is :
You are mixing two thing core library & component both. FYI
EmailComponent is now deprecated. so use core library instead.
for more details check this link http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
Debug the exception.
I bet that you can't open a connection to your mail server. Looks more like it's an error with your mail server setup or the connection to it than with CakePHp.
For an easy mail server setup for windows I recommend you to use XAMPP, it comes with the preconfigured mail server Pegasus, works just easy and fast for me.
This really does look like it's an error with your mail server setup or the connection to it. However, you are confusing the CakeEmail class for the EmailComponent.
Firstly you're not trying to send a email with the emailComponent, you are using the new CakeMail class (new from 2.x).
Thus, this:
var $components = array('Email');
and this:
$email = new CakeEmail();
are two different things. The first loads the EmailComponent, but you're not using it at all. The EmailComponent as of 2.x is deprecated. In your example you're using the CakeEmail Class.
Firstly you should insure that the class is actually loaded:
App::uses('CakeEmail', 'Network/Email');
Then check if you have the configuration file in:
App/Config/email.php
I suppose you're currently using the default configuration option. This means that the default transport is 'Mail' - the PHP mail function. I suppose you're getting a SocketException, because it can't connect to a underlying mail transport agent and because it is trying to do so over a System Socket... (Which I do not think exists in Windows, but I could be wrong. I know for sure that there is something like that in the windows API for inter-process cominucation)
Anyway, using the default email configuration is ok. Read the CakePHP Book's Section on the CakeEmail class.

Resources