-
1 Attachment(s)
ACP transfer via PHP
I've attached a zip file that contains three files with PHP code. We use this to transfer control from our Linux scheduling system to the ACP scopes. I've simplified the code from what we use - fewer database calls, a single telescope, etc. - and I might have introduced some problems which I will fix if they exist. <g>
Here's out this plays out:
* The entry file can be anywhere (acp_transfer.php); the other two files have to be co-located (same subnet) as the ACP computer.
* The users clicks on a link and goes to acp_transfer.php. This page evaluates the login request (are they scheduled?, for example) before proceeding.
* acp_transfer.php get user details needed for ACP login from a database, then uses jQuery to POST those details to the ACP admin interface.
* jQuery can't talk directly to an outside IP, so we use a proxy page to handle that. That file is proxy_acp.php. This is also a generally useful technique to be aware of, so I'm including it even though not every setup would require it (as when everything is local).
* There are two jQuery AJAX POST calls: one to create the user, and one to enable the user with specific permissions (in case they already exist and the create fails).
* Following the second POST, the user is transferred to the scope interface with their login data.
* The third file is a simplification of something we set up as a cron job on the co-located server. It terminates a login at a scheduled time. The same principles apply - jQuery is used for POST, proxy is used for interface to ACP admin.
This is somewhat bare bones, and the simplified code has not been tested (I'm on production deadline), but if anyone has to deal with this type of transfer from Linux or Mac to Windows for ACP, it will give you 90% of what you need in terms of technique to get the job done. When I get some time, I'll go over this and verify that it's a completely working sample (e.g., hard-coded variables instead of faux DB calls <g>).
Hope folks find this helpful. It's a bit specialized, but may offer some useful ideas even to someone who is not in our type of situation (needing to integrate across operating systems).
-
Ron --
Wow!!! Thanks so much for contributing this. It may take some time for those of my customers who are professionals to see it as they don't typically participate here very often :-) But if I get a question like that, I'll refer them to your post. Again, I really appreciate it!!!
-
You're welcome. As I said, it's really more of a sketch with ideas than a fully functional sample. But all the hard parts have been worked out, trust me on that. <g>
-
I had to revisit the issue of POSTing to ACP for account changes in order to write a cron job that would log users out at the end of their scheduled time. I have come up with a solution that is completely PHP - no Javascript at all. (this could be done in ASP, Python, or any other language commonly used for building web pages.
The trick? Use fopen to open the ACP admin interface with the POST data, and then capture the response.
Here is the critical function:
function sendPOST($postArray) {
$postData = http_build_query($postArray);
$url = "http://remoteadmin:remotepass@my.web.site/ac/aaccountctrl.asp";
$params = array('http' => array('method' => 'POST','content' => $postData));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
$response = @stream_get_contents($fp);
//Log response, or display to user.
}
The function can be called after setting up the array of POST data:
$postData = array ('op' => $ACP_op, 'nm' => $ACP_name, 'un' => $ACP_username, 'pw' => $ACP_password, 'ci' => $ci, 'wu' => $wu, 'ft' => $ft", 'sx' => $sx, 'ad' => $ad);
sendPOST($postData);
Ron Wodaski
-
Ron --
Thanks a ton for letting me know you found a solution to the logoff problem. I was looking at this before I left for California last week...
-
You're welcome. Of course this could also be done with AJAX, but I wanted to be able to handle it in a context that is effectively a script, not a web page, and thus unable to execute any Javascript.
I don't know what the equivalent to fopen() is in ASP or other languages, but I'm reasonably sure that you can do the same sort of thing in any language. <g> The key to success is getting every byte right in the HTTP request. <g>
-
Right on. In AJAX you use the XmlHttpRequest object and it handles the details fo making and decoding the HTTP request/response. The object name is historical, AJAX doesn't use XML necessarily (JSON more often). It's just that browsers had this from past ideas and it got co-opted for AJAX :-)