Polling printer info from a Windows print server - php

I'm trying to develop a way to pull a list of printers (names and IPs at least), from a Windows print server. I plan to use this info in an external PHP-driven status website, running on a Linux webserver, which talks to the printers individually via SNMP. The SNMP communication is already functional. I just need a way of dynamically generating the list of printers it talks to, instead of hard coding all of the IPs/DNS Hostnames.
The idea here is that I do this entirely without touching or changing the print server(s), printers, or the underlying webserver. The only thing under my control is a shared, non-administrative CPanel account.
My research so far has led me to three potential leads. I have next to no experience with any of them.
1) The PHP printer_list command, which is part of the PECL extension. At the moment our webserver does not have this extension installed, and I'd prefer not to make that request unless I know it will work for my purposes.
2) The lpstat Linux command, part of CUPS. I've tried using it per the man page and it seems to just sit there doing nothing. I don't know if this is because it's expecting a CUPS response which I figure it will not be getting from a Windows server, or if this might be a firewall issue.
3) SMB or WMI queries of some sort. I have no idea how to even begin with these.
I'd like to ask for a recommendation on where to start. This has been a very troubling project to research because 90% of search results are about people wanting to print. Another 8% are about people polling a local system for printer info. The rest are black magic and proprietary enterprise solutions.
Any insights are very much appreciated.
== Matt

I am using WMI effectively to fetch printer information over network using :
Select * FROM Win32_Printer
To begin:
1 - Run wbemtest from run window.
2 - Connect to any machine where you know printers are configured.
3 - There is query option, copy Select * FROM Win32_Printer
4 - Step 4 will return you table, click on Show MOF, it will provide you printer information. Viola, you are done.
5 - I have used C# ManagementObjectSearcher & ManagementObjectCollection and it is pretty straightforward and easy to use.
There are some pros and cons of using WMI. Read it online.

Related

How to set up Plover so Stenography can be broadcast on a LAN in real-time?

A friend of ours is running the Plover software for her closed caption and other reporting work. She is trying to find a way to have this post in real time on a local server for others (Hard of Hearing) to watch in real time (but not allow them to edit) from their tablets or laptops on a LAN.
This would be similar to what Stack Overflow does when editing (but over a LAN rather than on the same machine). I type in an edit box, and it prints below in real time. How is this being done? Is there a place to find this code?
I can help her get the WiFi or Blue-tooth to connect to their systems, I just don't know how to get it to push to them. The reporting machine will be running Ubuntu. If I need to install Apache, PHP for her that's fine and just guide them to a URL.
It sounds like the Plover software works at a (keyboard) device driver level, and so can be used to enter steno-to-text in any desktop application. Thus I would arrange things this way:
Put Apache on your reporting server, and set up a web application on there which shows a text box. You can use sockets (ideally) or AJAX (as a fallback) to transport your text from a browser to the server. This can then be sent out to any number of clients on a different page, probably via a database as an intermediate store. AJAX requires frequent polls and so is inefficient and slow, but on a LAN with a small number of users it would still be OK. Sockets are better but need a library to implement - take a look here at a PHP example.
Take a look at this answer to understand the different ways a browser and server can communicate (especially the section on HTML5 Websockets). Pusher is mentioned - that makes it really easy, but if you are broadcasting on a LAN it seems pointless to need the internet. I'd do it myself, for what it's worth.
If you want to stick with AJAX, jQuery, MooTools or Prototype is fine. If you want to use sockets there are several libraries that will use sockets first, and then fall back to a variety of technologies (long polling) and then finally AJAX. This will depend mostly on browser support for these various things.
I believe web sockets need a server component for which Apache is generally considered unsuitable. The first link I gave, for the Ratchet library, looks like it has its own listener component. Perhaps a good first step would be to work through the demos, so you can understand the technology and customise it for your needs?

page cut command in php for POS printers

Im working on a project where i need to use POS printer to generate the reciept. The client asked for a new request where the paper need to be cut automatically when the print has been done.. so that if he needs to print 10 recipts at a time it cuts 10 times and makes some difference.
I am having to make a few assumptions here.
The POS printer is connected to the client computer, not the PHP
server.
This is an internal application supporting Windows based POS terminals.
With this said, there are several Serial/COM port plugins available. We currently use an ActiveX plugin at work, though I wont make any recommendations -- I don't know enough about the alternatives. This will need to be installed/approved by the client computer.
Find the Make/Model of your printer and find the control codes for cutting the paper. They should be listed in the back of the manual. You will need to program your PHP script to output the correct data/control codes to the plugin to send to the printer.
Just for the record, I am not a fan of this solution.

Raw Data Printing without dialog from PHP / JAVASCRIPT

I am currently adding features to a PHP web application for a client. They require to be able to print some raw data to a ticket / thermal printer direct from the php which will be run on an internet browser from a self service kiosk.
The data needs to printed on the local kiosk's in built ticket printer.
From my preliminary research I understand that I must perform this task using javascript for any client side actions and wondered if anybody knew of any method or example function that will allow the printing of a string to a designated printer / com port which would bypass the printer dialog box?
Thanks in advance for any help
Alex
This plugin requires Java installed client-side, but after the first security prompt, this will do what you need (works with Linux, Mac, Windows, Solaris -- anything that can run Java desktop application)
https://github.com/qzind/tray
If it has to be cross browser and platform independent, stop right now and run. There is NOT way, and I mean NO way for Javascript to access information about printers, margins, paper size, and all the variables in printers. Even if your browser has some sort of fast print button, print using default settings and default printers, you have no idea the type of paper, the ink, the margins, etc, and you could be printing on A4 paper, or in the US, our legal size, 8.5" X 11.5".
Browsers, for security, do NOT give javascript any access to this information that is supplied to them by the Windows API and the printer drivers. The closest possible that I know of, is in small networks, where the variables are known, and configured using Internet Explorer's JScript or ActiveX. Short of this, your only other easy option is to write your own web browser/addon/plugin, or to modify one that will run on these platforms, that has this built in capability.
More info available here.
EDIT: Though if you really want to make your life simple, tell them to install Firefox, and check out this article for the simplest solution possible. Also, have you considered VBScript? It has this capability, I've seen it done before.
Not possible, at least not without some extra steps.
Without knowing more about the kiosk environment, you have three main options:
1). Install a Web service on the local kiosk. This Web service would manage printing and ultimately be the most extensible solution.
2). Create a plug-in for the print service. This would be uglier, and really tie you to a single browser solution forever.
3). Wrap the browser in custom code to allow external calls. Again, somewhat ugly, but since you're running a kiosk, you're likely to have some sort of custom/extensible wrapper anyway.

Crystal reports, mysql using a php website, Is it possible?

I have been asked to find out if it is possible to connect Cyrstal Reports to a MYSQL database within a php website.
Is this possible?
Are their any alternatives
Thanks
Edit I suppose in the perfect world I am wanting to show crystal reports within a PHP website
As an alternative you can use iReport. You can use it just as you need, with a mysql database from a php website.
In response to your comment:
I would want to show CR within the PHP website
CR being a Windows executable, this will not be directly possible (aside from embedding a Remote Desktop or VNC instance, but this is probably not feasible, and would not be legal.)
Your best bet is to check whether CR has an export format that can be embedded into the web site: PDF, HTML, XML come to mind. Those you could insert into your web page manually.
If you want automated interaction between the web site's user and CR, this probably possible, but not going to be trivial. There are third party products that allow controlling CR from the command line. You may be possible to set up an interaction between PHP and Crystal Reports through the command line on a Windows server, but it's going to be a lot of work.
Your question isn't very clear, if you're trying to ask if you can connect Crystal Reports to a MySQL database (a MySQL database that is connected to a PHP site) then you might be able to, have a look at this article.
If you're tying to connection Crystal Reports to a MySQL database and embed it within a PHP application... well I'm not too sure, perhaps someone else can tackle this problem.
http://www.eakes.org/80/connecting-to-mysql-with-crystal-reports-xi/
Using Crystal Reports to generate reports from a mySQL data base works fine. Install the latest and greatest mySQL ODBC driver and just do it.
If you want to serve up pre-generated Crystal report .rpt files via a PHP-based web site, that is straightforward. You can ask your users to download the Crystal Report Viewer, and just send out those files as if they were, say, .doc or .xls files.
The viewer is here.
The tricky bit is generating Crystal files on demand. You'll need to control the Crystal instance based on input from your web site users. You'll need to ask them to wait while Crystal runs. SAP sells a server edition of their product for this purpose that works well, but it costs money.
Groff Automation makes a product called Crystal Delivery. It works well for running routine reports.

How to implement chat using jQuery, PHP, and MySQL?

I have made a chat script using php, mysql and jquery. It uses json to get data from the server. It makes fixed interval requests to the server with the lastly fetched message id to get new messages from the server. But when multiple users will be chatting then thousands and crores of requests will be made to the server within an hour and the hosting people will block it for sure.
Th gmail chat uses socket I think. Because it does not sends fixed interval requests for sure. Could any one of you please give me some sample code or some direction to solve this issue.
Please I need help desperately.
Many thanks in advance. My respect and regards for all.
If the host you are using would "block it for sure" if it's making that many requests, then you may want to consider getting a different host or upgrading your hosting package before worrying about your code. Check out how Facebook implements their chat:
The method we chose to get text from
one user to another involves loading
an iframe on each Facebook page, and
having that iframe's Javascript make
an HTTP GET request over a persistent
connection that doesn't return until
the server has data for the client.
The request gets reestablished if it's
interrupted or times out. This isn't
by any means a new technique: it's a
variation of Comet, specifically XHR
long polling, and/or BOSH.
You may find it useful to see an example of 'comet' technology in action using Prototype's comet daemon and a jetty webserver. The example code for within the jetty download has an example application for chat.
I recently installed jetty myself so you might find a log of my installation commands useful:
Getting started trying to run a comet service
Download Maven from http://maven.apache.org/
Install Maven using http://maven.apache.org/download.html#Installation
I did the following commands
Extracted to /home/sdwyer/apache-maven-2.0.9
> sdwyer#pluto:~/apache-maven-2.0.9$ export M2_HOME=/home/sdwyer/apache-maven-2.0.9
> sdwyer#pluto:~/apache-maven-2.0.9$ export M2=$M2_HOME/bin
> sdwyer#pluto:~/apache-maven-2.0.9$ export PATH=$M2:$PATH.
> sdwyer#pluto:~/apache-maven-2.0.9$ mvn --version
-bash: /home/sdwyer/apache-maven-2.0.9/bin/mvn: Permission denied
> sdwyer#pluto:~/apache-maven-2.0.9$ cd bin
> sdwyer#pluto:~/apache-maven-2.0.9/bin$ ls
m2 m2.bat m2.conf mvn mvn.bat mvnDebug mvnDebug.bat
> sdwyer#pluto:~/apache-maven-2.0.9/bin$ chmod +x mvn
> sdwyer#pluto:~/apache-maven-2.0.9/bin$ mvn –version
Maven version: 2.0.9
Java version: 1.5.0_08
OS name: “linux” version: “2.6.18-4-686″ arch: “i386″ Family: “unix”
sdwyer#pluto:~/apache-maven-2.0.9/bin$
Download the jetty server from http://www.mortbay.org/jetty/
Extract to /home/sdwyer/jetty-6.1.3
> sdwyer#pluto:~$ cd jetty-6.1.3//examples/cometd-demo
> mvn jetty:run
A whole stack of downloads run
Once it’s completed open a browser and point it to:
http://localhost:8080 and test the demos.
The code for the example demos can be found in the directory:
jetty-6.1.3/examples/cometd-demo/src/main/webapp/examples
Right or wrong, a hosting company might get cranky for a couple reasons:
1) Odds are good they are using apache prefork. Each chat request is probably gonna be a new connection and thus hog up a single apache process. Each apache process eats anywhere from 1mb of memory to 100mb of memory.
2) If they maintain the database server and you, the client, suck at database programming, you can hammer their database. "Suck" means anything from "no proper indexing" to "makes a bazillion tiny queries instead of nice fat ones".
As has been suggested above, make sure your code uses persistent connections. Also:
1) Implement a back-off algorithm on the client. Poll the server once a second during activity, then back off to five seconds, then ten, twenty, etc... That way you dont hammer the server when there is no activity.
2) Multiple tabs will kill you. User opens 10 tabs and they all have your chat widget polling the server once a second? Bad news. Even if your host doesn't get pissed, your performance will degrade.
If this thing gets huge, design your system in a way that you can run the chat-server bits independently from the rest of your web application. In otherwords, the clients would be making a request to "chat.yourwebapp.com", which in turn is running on something like lighttpd.
try socket in javascript
http://code.google.com/p/jsocket/
Why would the host block that? Your making a standard http request for a page, if your host doesn't allow that then it's time to switch.
As for using sockets, there is no native ability to connect to a socket via javascript, although I believe JSocket is a lib that allows you to bridge a socket through an embedded flash which is actually connected to your server. Haven't looked for a jquery plugin that does this, might be one.
Your server side code would also change drastically (persistent vs polling is very different) so you'd have your work cut out for you.
I recommend just doing what you are doing and upgrade your host if it can't handle it. Unless your going to have a huge number of users on at a time? A caching system so your not hitting the db on every single request can probably speed things up if it gets that busy.
You think about embedding a small Flash movie in the page and then use sockets to handle the communication with server. This will take a lot of the load from the server and would make much more easier to keep everything in sync. The UI could still make with JavaScript.
It you will stay with your JavaScript solution then silently ignore my answer :-)

Categories