ejabberd modules in php - php

I am trying to write a couple of modules / filter for ejabberd.
After successfully implemented external auth in php I was having high hopes, that I will be able to do everything in PHP.
What I am trying to accomplish is the following:
Ejabberd hooks -> Send data to PHP
PHP accessing Ejabberd via shell_exec() / exec() using ejabberdctl
PHP responding to "Hooks".
I found this SO question (How to filter messages in Ejabberd) which almost answered my question, but it misses the part where the data gets passed to PHP.
So my question are:
How I can send the data to php from erlang (ie. the " %% should return modified Packet or atom drop to drop the packet" part from the linked question)
Where I can find some specification / documentation about ejabberd binary protocol?

Filtering messages in the xmpp internal domain with ejabberd is only possible making an erlang module.
You could try a component approach. The component will be in a subdomain and be able to filter messages passing through it. You should use it like a proxy domain where all parties in the chat should talk to. Remember that your component should be a daemon like process listening on the component interface for stanzas. This is not easy in php. I've used an intermediate python script for this.
Depending on your needs you could also use mod_logxml to dump all stanzas in an xml file and read that file with a daemon.
Actually, I ended up rewriting the whole thing in node.

Related

Aurelia + Php Possible/Recommended?

Before this question gets closed, I know the setup above is possible. I just want clarification on some things.
I just started learning Aurelia because I want to convert one of my projects into a web app. My project is built with html+css+JavaScript(jQuery)+ PHP(MySql).
I havent used any sort of framework before.
In the guide, they mention a few ways to setup a web server. I used the http server with node. Now this is where I need some help understanding a few things.
I dont want to use node.js. I want to use PHP on the server. Will that work and how?
When using Apache server, I know any PHP page is sent to the interpreter that renders the final html. I use XAMPP and its apache comes bundled with PHP. Does the http server used by node come with PHP? Is this even a sensible question?
Now I know Aurelia is purely front end. If it used to make single page applications, it uses Ajax. So now I made the following assumption:
Using Aurelia, the user accesses the root page of the app that the web server sends. After that, Aurelia makes various Ajax requests to the server which will use my PHP files to do database query stuff.
Is that right or am I missing something. And can I just use xampp(apache) to host my app instead of server from node?
Aurelia is a framework that, after you export it to any server, does not rely on any back-end software at all. This means that with the help of the http- / fetch-client API, you can just call out to your php script.
I have an example in my github:
https://github.com/rjpvroegop/randyvroegop.nl-made-with-aurelia
Here I use the http-client to post data to my php script wich has a very simple email functionality.
You can see the action inside my view-model in src/pages/contact/index.js.
You can see the PHP script in src/assets/components/contactengine.php.
These work the way they should. Note: you have to change your gulp build if you want your PHP served the way I serve mine, from the dist folder after gulp-watch or gulp-export.
Next to that you can use any back-end functionality you would like, as long as it returns the proper data. This PHP script does that. If you would download my distribution to test this you can simply do the following:
gulp export from your terminal in the root folder
copy everything from the export folder to your PHP webserver.

How to integrate C++ application into PHP website?

I have a c++ application that processes a sentence and responds back to the respective user. I have a website using php that I would like to post data to this application and receive this response. Ideally, the C++ would run on the webserver and not have to be fully loaded each time it is used, but i haven't been able to get a simple 'hello world' (with cgi or c++) to work on the webserver.
What would be the easiest way to integrate a c++ application into a website? Should this work with any webhost?
To Integrate them you can take two approaches.
1) Integrate C++ as a function into PHP with http://www.php-cpp.com
You can create a function, say my_complex_function, that when called in PHP, will execute a C++ code. You can read the site's documentation for information about it.
2) Keep them separate and communicate through HTTP/Pipes/Sockets/Other
You could build a C++ daemon that opens up some kind of communication interface like a Socket, then with PHP you open a socket to it, send the information through the socket, and receive the answer there too.
You can find socket examples for PHP here: http://php.net/manual/en/sockets.examples.php

Using PHP in Node-Webkit

Ive built an AngularJS application over the last several months that utilizes a MySQL database for its data. This data is fetched by Angular making calls to PHP and PHP returns JSON strings etc.
The issue is once this application is running inside node-webkit, none of the php works, so all of the content areas are empty. I assume (though the documentation on this issue is null and so i have no confirmation) this happens because Node-webkit is a client-side application framework and therefor wont run server-side languages like php. Is there a way to expand node webkit to run php and other server side languages?
I have done my best to find an answer to this question before posting, but documentation for this is nonexistent, and all of the information I have found about node-webkit talks about installing node on your server and installing npms for MySQL and having angular make calls to node. This defeats the purpose of the application entirely as it is designed so that the exe/deb/rpm/dmg can run and you can set up a database with any cloud database provider and be ready to go. Not ideal if you have to buy a vps just to run this one thing.
I have to assume this is possible in some way. i refuse to believe that everyone with an nw application hard codes all their data.
Thanks in advance
I know of four methods to accomplish this. Some of which you have preferred not to do but I am going to offer them in the hopes it helps you or someone else.
Look for an NPM that can do this for you. You should be able to do this functionality within node.js. - https://www.npmjs.com/search?q=mysql
You can host your PHP remotely. Using node-remote you can give this server the appropriate access to your NW.js project.
You can code a RESTful PHP application that your JavaScript can pass off information to.
You can use my boilerplate code to run PHP within a NW.js project. It however fires up an express.js web server internally to accomplish this. But the server is restricted to the machine and does not accept outside connections - https://github.com/baconface/php-webkit
1 and 4 both carry a risk in your case. Your project can be reversed engineered to reveal the source code and the connection information can be retrieved rather easy. So this should only be in an application on trusted machines and 2 and 3 are the ideal solutions.

Is it possible to use Apache Thrift on a regular web server?

I already have a web server that I pay for, and I want to expose some services on it using Thrift and PHP.
My question is: can I run a Thrift server using normal PHP that's hosted on the default port (the same way web pages are hosted) instead of having a separate PHP application that runs on some funky obscure port. This way I wouldn't have to change the server configuration (which is something I'm not able to do even if I wanted to).
Thanks
EDIT: maybe I should clarify a bit more. Once I've defined my service using a .thrift file, is it possible to:
Run the thrift code generator
Take the generated code and put it on my webserver
Create an index.php which says (in pseudocode) "create a new instance of the service, and handle incoming requests"?
Okay, well I have figured out the answer on my own!
If you use a TPhpStream on the server side, you are able to serve requests coming in as regular http requests.
Many thanks to Rob Wilkerson https://github.com/robwilkerson/Thrift-Client-Server-Example--PHP-.
I also blogged about how to implement a simple example with PHP and Python at http://willwarren.com/2012/01/24/creating-a-public-api-with-apache-thrift/

CORBA broker / proxy over HTTP or accessible via sockets (for PHP)?

I'm looking at connecting an existing PHP codebase to a remote CORBA service. All actual data is passed via XML so I don't think I need an IDL to PHP mapping for remote invocation. I just need to connect to the CORBA service, transmit to it the XML string, and read the XML response.
After some research on this I found the CORBA4PHP PHP extension which I'm about to try although am having some reservations (last updated in 2009). I also found numerous implementations in Java and Python.
To avoid dealing with a new PHP extension I'm wondering if there exists a CORBA HTTP proxy of sorts in any language that would take care of communicating with the CORBA service. I would HTTP POST to the proxy (or some socket communication), it would relay it to the CORBA service, and relay back to me its response.
Does such a proxy exist?
I don't know of such a service, but perhaps others might know of one. That said, given how simple your IDL is, I would just go ahead and try the CORBA4PHP extension and use that if it works.
If it doesn't work (I've no idea about its quality), it would be really simple to build such a proxy yourself:
Download a free ORB (let's say you get one for Java, say JacORB)
Compile your IDL and build a client to the CORBA service
Add a front-end API to your Java application which your PHP code will use to call it and pass in the string parameter containing your XML (POST sounds reasonable, and there are plenty of ways to implement such a thing in Java)

Categories