Net-VNC-0.40000755001750001750 011652724570 11615 5ustar00acmeacme000000000000Net-VNC-0.40/CHANGES000444001750001750 407011652724570 12746 0ustar00acmeacme000000000000Revision history for Perl module Net::VNC: 0.40 Sat Oct 29 08:20:07 BST 2011 - Add pointer events (patch by Gugod) 0.39 Fri Sep 16 13:56:21 BST 2011 - Add Apple Remote Desktop authentication (patch by Maurice Castro) 0.38 Sat May 14 16:19:03 BST 2011 - Better error upon connection problems (patch by Ken Dreyer) - Add key events - More distribution metadata 0.37 Mon Nov 23 15:18:38 GMT 2009 - Perltidy - Fix problem with passwords over 8 characters (spotted by binox) - Fix default image name in vnccapture (patch by Joe Julian) - Fix reading the security result (patch by Joe Julian) - Test for connectedness for login failure (patch by Joe Julian) 0.36 Fri Jun 29 19:58:51 BST 2007 - make vnccapture's outfile option work (patch by Owen Crow) 0.35 Fri Jul 28 11:41:23 BST 2006 - fix typo-d 'has_alpha' which breaks with recent Image::Imlib2 0.34 Thu Jul 27 12:12:57 BST 2006 - fixed failing cursor bug with realvnc 3.3 0.33 Sun Jun 25 16:13:33 BST 2006 - fixed a few cross-endian bugs (thanks to Chris Dolan again!) 0.32 Tue Apr 25 20:03:09 BST 2006 - many patches from Chris Dolan: - Added optional support for the mouse cursor - Support for CoRRE encoding - performance enhancement: split out the 8/16/24 bit support into their own modes - rearchitected the encoding system: list all known, but flag them as supported or not - ... this will simplify the addition of new encodings - ... this allows enabling/disabling classes of encodings (like cursor) - bugfix for signedness of encoding type - added skeletal support for the remaining server messages: cut-text and bell 0.31 Mon Mar 13 20:05:27 GMT 2006 - 24-bit truecolour support - non-authenticated login - incremental update - all provided by Chris Dolan 0.30 Mon Jan 23 10:12:05 GMT 2006 - die with a more accurate reason if there was an error connecting - drop the connection timeout to 15 seconds - reordered documentation to try and confuse Leo less 0.29 Thu Jan 19 15:56:05 GMT 2006 - first releaseNet-VNC-0.40/META.yml000444001750001750 122211652724570 13220 0ustar00acmeacme000000000000--- abstract: 'A simple VNC client' author: - 'Leon Brocard acme@astray.com' - 'Chris Dolan clotho@cpan.org' - 'Maurice Castro maurice@ipexchange.com.au' build_requires: {} configure_requires: Module::Build: 0.38 dynamic_config: 1 generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Net-VNC provides: Net::VNC: file: lib/Net/VNC.pm version: 0.40 requires: Class::Accessor::Fast: 0 Crypt::DES: 0 Image::Imlib2: 0 Test::More: 0 resources: license: http://dev.perl.org/licenses/ version: 0.40 Net-VNC-0.40/META.json000444001750001750 205011652724570 13370 0ustar00acmeacme000000000000{ "abstract" : "A simple VNC client", "author" : [ "Leon Brocard acme@astray.com", "Chris Dolan clotho@cpan.org", "Maurice Castro maurice@ipexchange.com.au" ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Net-VNC", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.38" } }, "runtime" : { "requires" : { "Class::Accessor::Fast" : 0, "Crypt::DES" : 0, "Image::Imlib2" : 0, "Test::More" : 0 } } }, "provides" : { "Net::VNC" : { "file" : "lib/Net/VNC.pm", "version" : "0.40" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.40" } Net-VNC-0.40/Build.PL000444001750001750 114511652724570 13247 0ustar00acmeacme000000000000#!perl use strict; use warnings; use Module::Build; my $build = Module::Build->new( create_license => 1, create_readme => 1, license => 'perl', 'meta-spec' => { version => '2', url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec', }, module_name => 'Net::VNC', requires => { 'Class::Accessor::Fast' => '0', 'Crypt::DES' => '0', 'Image::Imlib2' => '0', 'Test::More' => '0', }, script_files => ['bin/vnccapture'], sign => 1, ); $build->create_build_script; Net-VNC-0.40/SIGNATURE000644001750001750 251111652724570 13237 0ustar00acmeacme000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.68. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 a2690a5d393995ac371244e9fd73d6c603a7bb3e Build.PL SHA1 27770103f01d74bf506516f7dbfccfb381df0714 CHANGES SHA1 5a1e906e623bd6e2fccd155029705556b7007c5e LICENSE SHA1 f65dd5800cc60976b49cc35e64af7bc7fda6890b MANIFEST SHA1 bd6802e3022351ec614fc436344202c4da8e2365 META.json SHA1 490e51eae61208053ea62a770647782cd85ee130 META.yml SHA1 86265e7cc00ef4dea940e2871a119af162740455 README SHA1 99fafdbccf0cb9a62eff6e93f5dc4e7c536aa037 bin/vnccapture SHA1 6b2558559dc7feeeec24cb0590508b767980fa86 lib/Net/VNC.pm SHA1 0190346d7072d458c8a10a45c19f86db641dcc48 t/pod.t SHA1 6da39b48ce64b584e4c3274bff96fc76ff484820 t/pod_coverage.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk6rqXgACgkQnvdMljFk9hVqUwCfRqRTCYvtaKK4zHqAlJoQPtj5 kssAnAhI8L+ynXKzuvTe+mtgcz8sRhAA =6hjJ -----END PGP SIGNATURE----- Net-VNC-0.40/LICENSE000444001750001750 4431311652724570 13004 0ustar00acmeacme000000000000This software is copyright (c) 2011 by Leon Brocard acme@astray.com & Chris Dolan clotho@cpan.org & Maurice Castro maurice@ipexchange.com.au. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2011 by Leon Brocard acme@astray.com & Chris Dolan clotho@cpan.org & Maurice Castro maurice@ipexchange.com.au. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2011 by Leon Brocard acme@astray.com & Chris Dolan clotho@cpan.org & Maurice Castro maurice@ipexchange.com.au. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Net-VNC-0.40/MANIFEST000444001750001750 26111652724570 13062 0ustar00acmeacme000000000000bin/vnccapture Build.PL CHANGES lib/Net/VNC.pm LICENSE MANIFEST This list of files META.json META.yml README t/pod.t t/pod_coverage.t SIGNATURE Added here by Module::Build Net-VNC-0.40/README000444001750001750 1310511652724570 12652 0ustar00acmeacme000000000000NAME Net::VNC - A simple VNC client SYNOPSIS use Net::VNC; my $vnc = Net::VNC->new({hostname => $hostname, password => $password}); $vnc->depth(24); $vnc->login; print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; my $image = $vnc->capture; $image->save("out.png"); DESCRIPTION Virtual Network Computing (VNC) is a desktop sharing system which uses the RFB (Remote FrameBuffer) protocol to remotely control another computer. This module acts as a VNC client and communicates to a VNC server using the RFB protocol, allowing you to capture the screen of the remote computer. This module dies upon connection errors (with a timeout of 15 seconds) and protocol errors. This implementation is based largely on the RFB Protocol Specification, . That document has an error in the DES encryption description, which is clarified via . METHODS new The constructor. Given a hostname and a password returns a Net::VNC object: my $vnc = Net::VNC->new({hostname => $hostname, password => $password}); Optionally, you can also specify a port, which defaults to 5900. For ARD (Apple Remote Desktop) authentication you must also specify a username. You must also install Crypt::GCrypt::MPI and Crypt::Random. login Logs into the remote computer: $vnc->login; name Returns the name of the remote computer: print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; width Returns the width of the remote screen: print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; height Returns the height of the remote screen: print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; capture Captures the screen of the remote computer, returning an Image::Imlib2 object: my $image = $vnc->capture; $image->save("out.png"); You may call capture() multiple times. Each time, the $image buffer is overwritten with the updated screen. So, to create a series of ten screen shots: for my $n (1..10) { my $filename = sprintf 'snapshot%02d.png', $n++; $vnc->capture()->save($filename); print "Wrote $filename\n"; } depth Specify the bit depth for the screen. The supported choices are 24, 16 or 8. If unspecified, the server's default value is used. This property should be set before the call to login(). save_bandwidth Accepts a boolean, defaults to false. Specifies whether to use more CPU-intensive algorithms to compress the VNC datastream. LAN or localhost connections may prefer to leave this false. This property should be set before the call to login(). list_encodings Returns a list of encoding number/encoding name pairs. This can be used as a class method like so: my %encodings = Net::VNC->list_encodings(); send_key_event_down Send a key down event. The keys are the same as the corresponding ASCII value. Other common keys: BackSpace 0xff08 Tab 0xff09 Return or Enter 0xff0d Escape 0xff1b Insert 0xff63 Delete 0xffff Home 0xff50 End 0xff57 Page Up 0xff55 Page Down 0xff56 Left 0xff51 Up 0xff52 Right 0xff53 Down 0xff54 F1 0xffbe F2 0xffbf F3 0xffc0 F4 0xffc1 ... ... F12 0xffc9 Shift (left) 0xffe1 Shift (right) 0xffe2 Control (left) 0xffe3 Control (right) 0xffe4 Meta (left) 0xffe7 Meta (right) 0xffe8 Alt (left) 0xffe9 Alt (right) 0xffea $vnc->send_key_event_down('A'); send_key_event_up Send a key up event: $vnc->send_key_event_up('A'); send_key_event Send a key down event followed by a key up event: $vnc->send_key_event('A'); send_key_event_string Send key events for every character in a string: $vnc->send_key_event_string('Hello'); send_pointer_event( $button_mask, $x, $y ) Send pointer event (usually a mouse). This is used to move the pointer or make clicks or drags. It is easier to call the "mouse_move" or methods instead. mouse_move_to($x, $y) Send the pointer to the given position. The cursor instantly jumps there instead of smoothly moving to there. mouse_click Click on current pointer position. mouse_right_click Right-click on current pointer position. BUGS AND LIMITATIONS Bit depth We do not yet support 8-bit true-colour mode, which is commonly supported by servers but is rarely employed by clients. Byte order We have currently tested this package against servers with the same byte order as the client. This might break with a little-endian server/big-endian client or vice versa. We're working on tests for those latter cases. Testing and patching help would be appreciated. Efficiency We've implemented a subset of the data compression algorithms supported by most VNC servers. We hope to add more of the high-compression transfer encodings in the future. AUTHORS Leon Brocard acme@astray.com Chris Dolan clotho@cpan.org Apple Remote Desktop authentication based on LibVNCServer Maurice Castro maurice@ipexchange.com.au Many thanks for Foxtons Ltd for giving Leon the opportunity to write the original version of this module. Copyright (C) 2006, Leon Brocard This module is free software; you can redistribute it or modify it under the same terms as Perl itself. Net-VNC-0.40/lib000755001750001750 011652724570 12363 5ustar00acmeacme000000000000Net-VNC-0.40/lib/Net000755001750001750 011652724570 13111 5ustar00acmeacme000000000000Net-VNC-0.40/lib/Net/VNC.pm000444001750001750 12106011652724570 14272 0ustar00acmeacme000000000000package Net::VNC; use strict; use warnings; use base qw(Class::Accessor::Fast); use Crypt::DES; use Image::Imlib2; use IO::Socket::INET; use bytes; __PACKAGE__->mk_accessors( qw(hostname port username password socket name width height depth save_bandwidth hide_cursor server_endian _pixinfo _colourmap _framebuffer _cursordata _rfb_version _bpp _true_colour _big_endian _image_format ) ); our $VERSION = '0.40'; my $MAX_PROTOCOL_VERSION = 'RFB 003.008' . chr(0x0a); # Max version supported # Precompute booleans for specific Image::Imlib2 features my $CAN_CREATE_RAW_IMAGE = Image::Imlib2->can('new_using_data'); my $CAN_CHANGE_BLEND = Image::Imlib2->can('will_blend'); # This line comes from perlport.pod my $AM_BIG_ENDIAN = unpack( 'h*', pack( 's', 1 ) ) =~ /01/ ? 1 : 0; # The numbers in the hashes below were acquired from the VNC source code my %supported_depths = ( '24' => { bpp => 32, true_colour => 1, red_max => 255, green_max => 255, blue_max => 255, red_shift => 16, green_shift => 8, blue_shift => 0, }, '16' => { bpp => 16, true_colour => 1, red_max => 31, green_max => 31, blue_max => 31, red_shift => 10, green_shift => 5, blue_shift => 0, }, '8' => { bpp => 8, true_colour => 0, red_max => 255, green_max => 255, blue_max => 255, red_shift => 16, green_shift => 8, blue_shift => 0, }, # Unused right now, but supportable '8t' => { bpp => 8, true_colour => 1, #!!! red_max => 7, green_max => 7, blue_max => 3, red_shift => 0, green_shift => 3, blue_shift => 6, }, ); my @encodings = ( # These ones are defined in rfbproto.pdf { num => 0, name => 'Raw', supported => 1, }, { num => 1, name => 'CopyRect', supported => 1, }, { num => 2, name => 'RRE', supported => 1, }, { num => 4, name => 'CoRRE', supported => 1, }, { num => 5, name => 'Hextile', supported => 1, bandwidth => 1, }, { num => 16, name => 'ZRLE', supported => 0, bandwidth => 1, }, { num => -239, name => 'Cursor', supported => 1, cursor => 1, }, { num => -223, name => 'DesktopSize', supported => 0, }, # Learned about these from cvs://cotvnc.sf.net/cotvnc/Source/rfbproto.h # None of them are currently used map( { { num => -256 + $_, name => 'CompressLevel' . $_, supported => 0, compress => 1, } } 0 .. 9 ), { num => -240, name => 'XCursor', supported => 0, cursor => 1, }, { num => -224, name => 'LastRect', supported => 0, }, map( { { num => -32 + $_, name => 'QualityLevel' . $_, supported => 0, quality => 1, } } 0 .. 9 ), # Learned about this one from pyvnc2swf/rfb.py, but I don't understand where it comes from # It doesn't seem to be documented in CotVNC or VNC 4.1.1 source code { num => -232, name => 'CursorPos', supported => 1, cursor => 1, }, ); sub list_encodings { my $pkg_or_self = shift; my %encmap = map { $_->{num} => $_->{name} } @encodings; return %encmap; } sub login { my $self = shift; my $hostname = $self->hostname; my $port = $self->port; my $socket = IO::Socket::INET->new( PeerAddr => $hostname || 'localhost', PeerPort => $port || '5900', Proto => 'tcp', ) || die "Error connecting to $hostname: $@"; $socket->timeout(15); $self->socket($socket); eval { $self->_handshake_protocol_version(); $self->_handshake_security(); $self->_client_initialization(); $self->_server_initialization(); }; my $error = $@; # store so it doesn't get overwritten if ($error) { # clean up so socket can be garbage collected $self->socket(undef); die $error; } } sub _handshake_protocol_version { my $self = shift; my $socket = $self->socket; $socket->read( my $protocol_version, 12 ) || die 'unexpected end of data'; # warn "prot: $protocol_version"; my $protocol_pattern = qr/\A RFB [ ] (\d{3}\.\d{3}) \s* \z/xms; if ( $protocol_version !~ m/$protocol_pattern/xms ) { die 'Malformed RFB protocol: ' . $protocol_version; } $self->_rfb_version($1); if ( $protocol_version gt $MAX_PROTOCOL_VERSION ) { $protocol_version = $MAX_PROTOCOL_VERSION; # Repeat with the changed version if ( $protocol_version !~ m/$protocol_pattern/xms ) { die 'Malformed RFB protocol'; } $self->_rfb_version($1); } if ( $self->_rfb_version lt '003.003' ) { die 'RFB protocols earlier than v3.3 are not supported'; } # let's use the same version of the protocol, or the max, whichever's lower $socket->print($protocol_version); } sub _handshake_security { my $self = shift; my $socket = $self->socket; # Retrieve list of security options my $security_type; if ( $self->_rfb_version ge '003.007' ) { $socket->read( my $number_of_security_types, 1 ) || die 'unexpected end of data'; $number_of_security_types = unpack( 'C', $number_of_security_types ); # warn "types: $number_of_security_types"; if ( $number_of_security_types == 0 ) { die 'Error authenticating'; } my @security_types; foreach ( 1 .. $number_of_security_types ) { $socket->read( my $security_type, 1 ) || die 'unexpected end of data'; $security_type = unpack( 'C', $security_type ); # warn "sec: $security_type"; push @security_types, $security_type; } my @pref_types = ( 1, 2 ); @pref_types = ( 30, 1, 2 ) if $self->username; for my $preferred_type (@pref_types) { if ( 0 < grep { $_ == $preferred_type } @security_types ) { $security_type = $preferred_type; last; } } } else { # In RFB 3.3, the server dictates the security type $socket->read( $security_type, 4 ) || die 'unexpected end of data'; $security_type = unpack( 'N', $security_type ); } if ( !$security_type ) { die 'Connection failed'; } elsif ( $security_type == 2 ) { # DES-encrypted challenge/response if ( $self->_rfb_version ge '003.007' ) { $socket->print( pack( 'C', 2 ) ); } $socket->read( my $challenge, 16 ) || die 'unexpected end of data'; # warn "chal: " . unpack('h*', $challenge) . "\n"; # the RFB protocol only uses the first 8 characters of a password my $key = substr( $self->password, 0, 8 ); $key = '' if ( !defined $key ); $key .= pack( 'C', 0 ) until ( length($key) % 8 ) == 0; my $realkey; # warn unpack('b*', $key); foreach my $byte ( split //, $key ) { $realkey .= pack( 'b8', scalar reverse unpack( 'b8', $byte ) ); } # warn unpack('b*', $realkey); my $cipher = Crypt::DES->new($realkey); my $response; my $i = 0; while ( $i < 16 ) { my $word = substr( $challenge, $i, 8 ); # warn "$i: " . length($word); $response .= $cipher->encrypt($word); $i += 8; } # warn "resp: " . unpack('h*', $response) . "\n"; $socket->print($response); } elsif ( $security_type == 1 ) { # No authorization needed! if ( $self->_rfb_version ge '003.007' ) { $socket->print( pack( 'C', 1 ) ); } } elsif ( $security_type == 30 ) { require Crypt::GCrypt::MPI; require Crypt::Random; # ARD - Apple Remote Desktop - authentication $socket->print( pack( 'C', 30 ) ); # use ARD $socket->read( my $gen, 2 ) || die 'unexpected end of data'; $socket->read( my $len, 2 ) || die 'unexpected end of data'; my $keylen = $self->_bin_int($len); $socket->read( my $mod, $keylen ) || die 'unexpected end of data'; $socket->read( my $resp, $keylen ) || die 'unexpected end of data'; my $genmpi = Crypt::GCrypt::MPI::new( secure => 0, value => $self->_bin_int($gen), format => Crypt::GCrypt::MPI::FMT_USG() ); my $modmpi = Crypt::GCrypt::MPI::new( secure => 0, value => $mod, format => Crypt::GCrypt::MPI::FMT_USG() ); my $respmpi = Crypt::GCrypt::MPI::new( secure => 0, value => $resp, format => Crypt::GCrypt::MPI::FMT_USG() ); my $privmpi = $self->_mpi_randomize($keylen); my $pubmpi = $genmpi->copy()->powm( $privmpi, $modmpi ); my $keympi = $respmpi->copy()->powm( $privmpi, $modmpi ); my $pub = $self->_mpi_2_bytes( $pubmpi, $keylen ); my $key = $self->_mpi_2_bytes( $keympi, $keylen ); my $md5 = Crypt::GCrypt->new( type => 'digest', algorithm => 'md5' ); $md5->write($key); my $shared = $md5->read(); my $passlen = length( $self->password ) + 1; my $userlen = length( $self->username ) + 1; $passlen = 64 if ( $passlen > 64 ); my $passpad = 64 - $passlen; $userlen = 64 if ( $userlen > 64 ); my $userpad = 64 - $userlen; my $up = Crypt::Random::makerandom_octet( Length => $userpad, Strength => 1 ); my $pp = Crypt::Random::makerandom_octet( Length => $passpad, Strength => 1 ); my $userpass = pack "a*xa*a*xa*", $self->username, $up, $self->password, $pp; my $aes = Crypt::GCrypt->new( type => 'cipher', algorithm => 'aes', mode => 'ecb' ); $aes->start('encrypting'); $aes->setkey($shared); my $cyptxt = $aes->encrypt($userpass); $cyptxt .= $aes->finish; $socket->write( $cyptxt, 128 ); # appears to be only writing 16 bytes $socket->write( $pub, $keylen ); # appears to be only writing 16 bytes $socket->read( my $security_result, 4 ) || die 'unexpected end of data'; $security_result = $self->_bin_int($security_result); if ( $security_result == 1 ) { $socket->read( my $len, 4 ) || die 'unexpected end of data'; $socket->read( my $msg, $self->_bin_int($len) ) || die 'unexpected end of data'; die "VNC Authentication Failed: $msg"; } elsif ( $security_result == 2 ) { # too many die "VNC Authentication Failed - too many tries"; } } else { die "no supported vnc authentication mechanism"; } # the RFB protocol always returns a result for type 2, # but type 1, only for 003.008 and up if ( ( $self->_rfb_version ge '003.008' && $security_type == 1 ) || $security_type == 2 ) { $socket->read( my $security_result, 4 ) || die 'unexpected end of data'; $security_result = unpack( 'I', $security_result ); # warn $security_result; die 'login failed' if $security_result; } elsif ( !$socket->connected ) { die 'login failed'; } } sub _mpi_randomize { my ( $self, $l ) = @_; my $bits = int( $l / 8 ) * 8; my $bytes = int( $bits / 8 ); my $r = Crypt::Random::makerandom_octet( Length => $bytes, Strength => 1 ); my @ra = unpack( "C*", $r ); my $mpi = Crypt::GCrypt::MPI::new( secure => 0, value => 0 ); my $tfs = Crypt::GCrypt::MPI::new( secure => 0, value => 256 ); for ( my $i = 0; $i < $bytes; $i++ ) { $mpi = $mpi->mul($tfs); my $n = $ra[$i]; $mpi = $mpi->add( Crypt::GCrypt::MPI::new( secure => 0, value => $n ) ); } return $mpi; } sub _mpi_2_bytes { my ( $self, $mpi, $sz ) = @_; my $s = $mpi->print( Crypt::GCrypt::MPI::FMT_USG() ); my $pad = $sz - length($s); return pack( "x[$pad]a*", $s ); } sub _bin_int { my ( $self, $s ) = @_; my @a = unpack( "C*", $s ); my $r = 0; for ( my $i = 0; $i < @a; $i++ ) { $r = 256 * $r; $r += $a[$i]; } return $r; } sub _client_initialization { my $self = shift; my $socket = $self->socket; $socket->print( pack( 'C', 1 ) ); # share } sub _server_initialization { my $self = shift; my $socket = $self->socket; $socket->read( my $server_init, 24 ) || die 'unexpected end of data'; my ( $framebuffer_width, $framebuffer_height, $bits_per_pixel, $depth, $big_endian_flag, $true_colour_flag, %pixinfo, $name_length ); ( $framebuffer_width, $framebuffer_height, $bits_per_pixel, $depth, $big_endian_flag, $true_colour_flag, $pixinfo{red_max}, $pixinfo{green_max}, $pixinfo{blue_max}, $pixinfo{red_shift}, $pixinfo{green_shift}, $pixinfo{blue_shift}, $name_length ) = unpack 'nnCCCCnnnCCCxxxN', $server_init; # warn "$framebuffer_width x $framebuffer_height"; # warn "$bits_per_pixel bpp / depth $depth / $big_endian_flag be / $true_colour_flag tc / $pixinfo{red_max},$pixinfo{green_max},$pixinfo{blue_max} / $pixinfo{red_shift},$pixinfo{green_shift},$pixinfo{blue_shift}"; # warn $name_length; if ( !$self->depth ) { # client did not express a depth preference, so check if the server's preference is OK if ( !$supported_depths{$depth} ) { die 'Unsupported depth ' . $depth; } if ( $bits_per_pixel != $supported_depths{$depth}->{bpp} ) { die 'Unsupported bits-per-pixel value ' . $bits_per_pixel; } if ($true_colour_flag ? !$supported_depths{$depth}->{true_colour} : $supported_depths{$depth}->{true_colour} ) { die 'Unsupported true colour flag'; } $self->depth($depth); # Use server's values for *_max and *_shift } elsif ( $depth != $self->depth ) { for my $key ( qw(red_max green_max blue_max red_shift green_shift blue_shift)) { $pixinfo{$key} = $supported_depths{ $self->depth }->{$key}; } } if ( !$self->width ) { $self->width($framebuffer_width); } if ( !$self->height ) { $self->height($framebuffer_height); } $self->_pixinfo( \%pixinfo ); $self->_bpp( $supported_depths{ $self->depth }->{bpp} ); $self->_true_colour( $supported_depths{ $self->depth }->{true_colour} ); $self->_big_endian( $self->server_endian ? $big_endian_flag : $AM_BIG_ENDIAN ); $socket->read( my $name_string, $name_length ) || die 'unexpected end of data'; $self->name($name_string); # warn $name_string; # setpixelformat $socket->print( pack( 'CCCCCCCCnnnCCCCCC', 0, # message_type 0, # padding 0, # padding 0, # padding $self->_bpp, $self->depth, $self->_big_endian, $self->_true_colour, $pixinfo{red_max}, $pixinfo{green_max}, $pixinfo{blue_max}, $pixinfo{red_shift}, $pixinfo{green_shift}, $pixinfo{blue_shift}, 0, # padding 0, # padding 0, # padding ) ); # set encodings my @encs = grep { $_->{supported} } @encodings; # Prefer the higher-numbered encodings @encs = reverse sort { $a->{num} <=> $b->{num} } @encs; if ( !$self->save_bandwidth ) { @encs = grep { !$_->{bandwidth} } @encs; } if ( $self->hide_cursor ) { @encs = grep { !$_->{cursor} } @encs; } $socket->print( pack( 'CCn', 2, # message_type 0, # padding scalar @encs, # number_of_encodings ) ); for my $enc (@encs) { # Make a big-endian, signed 32-bit value # method: # pack as own-endian, signed e.g. -239 # unpack as own-endian, unsigned e.g. 4294967057 # pack as big-endian my $num = pack 'N', unpack 'L', pack 'l', $enc->{num}; $socket->print($num); } } sub capture { my $self = shift; my $socket = $self->socket; $self->_send_update_request(); while ( ( my $message_type = $self->_receive_message() ) != 0 ) { # warn $message_type; } return $self->_image_plus_cursor; } sub _image_plus_cursor { my $self = shift; my $image = $self->_framebuffer; my $cursor = $self->_cursordata; if ( !$self->hide_cursor && $cursor && $cursor->{image} && defined $cursor->{x} ) { #$cursor->{image}->save('cursor.png'); # temporary -- debugging $image = $image->clone(); # make a duplicate so we can overlay the cursor $image->blend( $cursor->{image}, 1, # don't modify destination alpha 0, 0, $cursor->{width}, $cursor->{height}, # source dimensions $cursor->{x}, $cursor->{y}, $cursor->{width}, $cursor->{height}, # destination dimensions ); } return $image; } sub _send_key_event { my ( $self, $down_flag, $key ) = @_; # A key press or release. Down-flag is non-zero (true) if the key is now pressed, zero # (false) if it is now released. The key itself is specified using the “keysym” values # defined by the X Window System. my $socket = $self->socket; $socket->print( pack( 'CCnN', 4, # message_type $down_flag, # down-flag 0, # padding $key, # key ) ); } sub send_key_event_down { my ( $self, $key ) = @_; $self->_send_key_event( 1, $key ); } sub send_key_event_up { my ( $self, $key ) = @_; $self->_send_key_event( 0, $key ); } sub send_key_event { my ( $self, $key ) = @_; $self->send_key_event_down($key); $self->send_key_event_up($key); } sub send_key_event_string { my ( $self, $string ) = @_; foreach my $key ( map {ord} split //, $string ) { warn $key; $self->send_key_event($key); } } sub send_pointer_event { my ( $self, $button_mask, $x, $y ) = @_; $self->socket->print( pack( 'CCnn', 5, # message type $button_mask, # button-mask $x, # x-position $y, # y-position ) ); } sub _send_update_request { my $self = shift; # frame buffer update request my $socket = $self->socket; my $incremental = $self->_framebuffer ? 1 : 0; $socket->print( pack( 'CCnnnn', 3, # message_type $incremental, # incremental 0, # x 0, # y $self->width, $self->height, ) ); } sub _receive_message { my $self = shift; my $socket = $self->socket; $socket->read( my $message_type, 1 ) || die 'unexpected end of data'; $message_type = unpack( 'C', $message_type ); # warn $message_type; # This result is unused. It's meaning is different for the different methods my $result = !defined $message_type ? die 'bad message type received' : $message_type == 0 ? $self->_receive_update() : $message_type == 1 ? $self->_receive_colour_map() : $message_type == 2 ? $self->_receive_bell() : $message_type == 3 ? $self->_receive_cut_text() : die 'unsupported message type received'; return $message_type; } sub _receive_update { my $self = shift; my $image = $self->_framebuffer; if ( !$image ) { $self->_framebuffer( $image = Image::Imlib2->new( $self->width, $self->height ) ); if ( $self->_image_format ) { $image->image_set_format( $self->_image_format ); } if ($CAN_CREATE_RAW_IMAGE) { # We're going to be splatting pixels, so make sure every pixel is opaque $image->set_colour( 0, 0, 0, 255 ); $image->fill_rectangle( 0, 0, $self->width, $self->height ); } } my $socket = $self->socket; $socket->read( my $header, 3 ) || die 'unexpected end of data'; my $number_of_rectangles = unpack( 'xn', $header ); # warn $number_of_rectangles; my $depth = $self->depth; my $big_endian = $self->_big_endian; my $read_and_set_colour = $depth == 24 ? ( $big_endian ? \&_read_and_set_colour_24_be : \&_read_and_set_colour_24_le ) : $depth == 16 ? ( $big_endian ? \&_read_and_set_colour_16_be : \&_read_and_set_colour_16_le ) : $depth == 8 ? \&_read_and_set_colour_8 : die 'unsupported depth'; foreach ( 1 .. $number_of_rectangles ) { $socket->read( my $data, 12 ) || die 'unexpected end of data'; my ( $x, $y, $w, $h, $encoding_type ) = unpack 'nnnnN', $data; # unsigned -> signed conversion $encoding_type = unpack 'l', pack 'L', $encoding_type; # warn "$x,$y $w x $h $encoding_type"; ### Raw encoding ### if ( $encoding_type == 0 ) { if ( $CAN_CREATE_RAW_IMAGE && $depth == 24 && $AM_BIG_ENDIAN == $self->_big_endian ) { # Performance boost: splat raw pixels into the image $socket->read( my $data, $w * $h * 4 ); my $raw = Image::Imlib2->new_using_data( $w, $h, $data ); $raw->has_alpha(0); $image->blend( $raw, 0, 0, 0, $w, $h, $x, $y, $w, $h ); } else { for my $py ( $y .. $y + $h - 1 ) { for my $px ( $x .. $x + $w - 1 ) { $self->$read_and_set_colour(); $image->draw_point( $px, $py ); } } } ### CopyRect encooding ### } elsif ( $encoding_type == 1 ) { $socket->read( my $srcpos, 4 ) || die 'unexpected end of data'; my ( $srcx, $srcy ) = unpack 'nn', $srcpos; my $copy = $image->crop( $srcx, $srcy, $w, $h ); $image->blend( $copy, 0, 0, 0, $w, $h, $x, $y, $w, $h ); ### RRE and CoRRE encodings ### } elsif ( $encoding_type == 2 || $encoding_type == 4 ) { $socket->read( my $num_sub_rects, 4 ) || die 'unexpected end of data'; $num_sub_rects = unpack 'N', $num_sub_rects; $self->$read_and_set_colour(); $image->fill_rectangle( $x, $y, $w, $h ); # RRE is U16, CoRRE is U8 my $geombytes = $encoding_type == 2 ? 8 : 4; my $format = $encoding_type == 2 ? 'nnnn' : 'CCCC'; for my $i ( 1 .. $num_sub_rects ) { $self->$read_and_set_colour(); $socket->read( my $subrect, $geombytes ) || die 'unexpected end of data'; my ( $sx, $sy, $sw, $sh ) = unpack $format, $subrect; $image->fill_rectangle( $x + $sx, $y + $sy, $sw, $sh ); } ### Hextile encoding ### } elsif ( $encoding_type == 5 ) { my $maxx = $x + $w; my $maxy = $y + $h; my $background; my $foreground; # Step over 16x16 tiles in the target rectangle for ( my $ry = $y; $ry < $maxy; $ry += 16 ) { my $rh = $maxy - $ry > 16 ? 16 : $maxy - $ry; for ( my $rx = $x; $rx < $maxx; $rx += 16 ) { my $rw = $maxx - $rx > 16 ? 16 : $maxx - $rx; $socket->read( my $mask, 1 ) || die 'unexpected end of data'; $mask = unpack 'C', $mask; if ( $mask & 0x1 ) { # Raw tile for my $py ( $ry .. $ry + $rh - 1 ) { for my $px ( $rx .. $rx + $rw - 1 ) { $self->$read_and_set_colour(); $image->draw_point( $px, $py ); } } } else { if ( $mask & 0x2 ) { # background set $background = $self->$read_and_set_colour(); } if ( $mask & 0x4 ) { # foreground set $foreground = $self->$read_and_set_colour(); } if ( $mask & 0x8 ) { # has subrects $socket->read( my $nsubrects, 1 ) || die 'unexpected end of data'; $nsubrects = unpack 'C', $nsubrects; if ( !$mask & 0x10 ) { # use foreground colour $image->set_colour( @{$foreground} ); } for my $i ( 1 .. $nsubrects ) { if ( $mask & 0x10 ) { # use per-subrect colour $self->$read_and_set_colour(); } $socket->read( my $pos, 1 ) || die 'unexpected end of data'; $pos = unpack 'C', $pos; $socket->read( my $size, 1 ) || die 'unexpected end of data'; $size = unpack 'C', $size; my $sx = $pos >> 4; my $sy = $pos & 0xff; my $sw = 1 + ( $size >> 4 ); my $sh = 1 + ( $size & 0xff ); $image->fill_rectangle( $rx + $sx, $ry + $sy, $sw, $sh ); } } else { # no subrects $image->set_colour( @{$background} ); $image->fill_rectangle( $rx, $ry, $rw, $rh ); } } } } ### Cursor ### } elsif ( $encoding_type == -239 ) { # realvnc 3.3 sends empty cursor messages, so skip next unless $w || $h; my $cursordata = $self->_cursordata; if ( !$cursordata ) { $self->_cursordata( $cursordata = {} ); } $cursordata->{image} = Image::Imlib2->new( $w, $h ); $cursordata->{hotspotx} = $x; $cursordata->{hotspoty} = $y; $cursordata->{width} = $w; $cursordata->{height} = $h; my $cursor = $cursordata->{image} || die "Failed to create cursor buffer $w x $h"; $cursor->has_alpha(1); my @pixbuf; for my $i ( 1 .. $w * $h ) { push @pixbuf, $self->$read_and_set_colour(); } my $masksize = int( ( $w + 7 ) / 8 ) * $h; my $maskrowsize = int( ( $w + 7 ) / 8 ) * 8; $socket->read( my $mask, $masksize ) || die 'unexpected end of data'; $mask = unpack 'B*', $mask; #print "masksize: $masksize\n"; #print "maskrowsize: $maskrowsize\n"; #print "mask: $mask\n"; #open my $fh, '>', $ENV{HOME}.'/Desktop/cursor.txt'; $cursor->will_blend(0) if ($CAN_CHANGE_BLEND); for my $cy ( 0 .. $h - 1 ) { for my $cx ( 0 .. $w - 1 ) { my $pixel = shift @pixbuf; $pixel || die 'not enough pixels'; if ( !substr( $mask, $cx + $cy * $maskrowsize, 1 ) ) { @{$pixel} = ( 0, 0, 0, 0 ); } #print "$cx, $cy: @$pixel\n"; #print $fh "$cx, $cy: @$pixel\n"; $cursor->set_colour( @{$pixel} ); $cursor->draw_point( $cx, $cy ); } } $cursor->will_blend(1) if ($CAN_CHANGE_BLEND); #$cursor->save('vnccursor.png'); #print "wrote cursor\n"; ### CursorPos ### } elsif ( $encoding_type == -232 ) { my $cursordata = $self->_cursordata; if ( !$cursordata ) { $self->_cursordata( $cursordata = {} ); } $cursordata->{x} = $x; $cursordata->{y} = $y; #print "Cursor pos: $x, $y\n"; } else { die 'unsupported update encoding ' . $encoding_type; } } return $number_of_rectangles; } sub _read_and_set_colour_8 { my $self = shift; $self->socket->read( my $pixel, 1 ) || die 'unexpected end of data'; my $colours = $self->_colourmap; my $index = unpack( 'C', $pixel ); my $colour = $colours->[$index]; my @colour = ( $colour->{r}, $colour->{g}, $colour->{b}, 255 ); $self->_framebuffer->set_colour(@colour); return \@colour; } sub _read_and_set_colour_16_le { my $self = shift; $self->socket->read( my $pixel, 2 ) || die 'unexpected end of data'; my $colour = unpack 'v', $pixel; my @colour = ( ( $colour >> 10 & 31 ) << 3, ( $colour >> 5 & 31 ) << 3, ( $colour & 31 ) << 3, 255 ); $self->_framebuffer->set_colour(@colour); return \@colour; } sub _read_and_set_colour_16_be { my $self = shift; $self->socket->read( my $pixel, 2 ) || die 'unexpected end of data'; my $colour = unpack 'n', $pixel; my @colour = ( ( $colour >> 10 & 31 ) << 3, ( $colour >> 5 & 31 ) << 3, ( $colour & 31 ) << 3, 255 ); $self->_framebuffer->set_colour(@colour); return \@colour; } sub _read_and_set_colour_24_le { my $self = shift; $self->socket->read( my $pixel, 4 ) || die 'unexpected end of data'; my $colour = unpack 'V', $pixel; my @colour = ( $colour >> 16 & 255, $colour >> 8 & 255, $colour & 255, 255, ); $self->_framebuffer->set_colour(@colour); return \@colour; } sub _read_and_set_colour_24_be { my $self = shift; $self->socket->read( my $pixel, 4 ) || die 'unexpected end of data'; my $colour = unpack 'N', $pixel; my @colour = ( $colour >> 16 & 255, $colour >> 8 & 255, $colour & 255, 255, ); $self->_framebuffer->set_colour(@colour); return \@colour; } # The following is the full version that supports all 8, 16, and 32 # bpp and arbitrary pixel formats. This version is only used when one # of the faster functions declared above cannot be used due to # specific VNC settings. sub _read_and_set_colour { my $self = shift; my $pixel = shift; my $colours = $self->_colourmap; my $bytes_per_pixel = $self->_bpp / 8; if ( !$pixel ) { $self->socket->read( $pixel, $bytes_per_pixel ) || die 'unexpected end of data'; } my @colour; if ($colours) { # indexed colour, depth is 8 my $index = unpack( 'C', $pixel ); my $colour = $colours->[$index]; @colour = ( $colour->{r}, $colour->{g}, $colour->{b}, 255 ); } else { # true colour, depth is 24 or 16 my $pixinfo = $self->_pixinfo; my $format = $bytes_per_pixel == 4 ? ( $self->_big_endian ? 'N' : 'V' ) : $bytes_per_pixel == 2 ? ( $self->_big_endian ? 'n' : 'v' ) : die 'Unsupported bits-per-pixel value'; my $colour = unpack $format, $pixel; my $r = $colour >> $pixinfo->{red_shift} & $pixinfo->{red_max}; my $g = $colour >> $pixinfo->{green_shift} & $pixinfo->{green_max}; my $b = $colour >> $pixinfo->{blue_shift} & $pixinfo->{blue_max}; if ( $bytes_per_pixel == 4 ) { @colour = ( $r, $g, $b, 255 ); } else { @colour = ( $r * 255 / $pixinfo->{red_max}, $g * 255 / $pixinfo->{green_max}, $b * 255 / $pixinfo->{blue_max}, 255 ); } } $self->_framebuffer->set_colour(@colour); return \@colour; } sub _receive_colour_map { my $self = shift; # set colour map entries my $socket = $self->socket; $socket->read( my $padding, 1 ) || die 'unexpected end of data'; $socket->read( my $first_colour, 2 ) || die 'unexpected end of data'; $first_colour = unpack( 'n', $first_colour ); $socket->read( my $number_of_colours, 2 ) || die 'unexpected end of data'; $number_of_colours = unpack( 'n', $number_of_colours ); # warn "colours: $first_colour.. ($number_of_colours)"; my @colours; foreach my $i ( $first_colour .. $first_colour + $number_of_colours - 1 ) { $socket->read( my $r, 2 ) || die 'unexpected end of data'; $r = unpack( 'n', $r ); $socket->read( my $g, 2 ) || die 'unexpected end of data'; $g = unpack( 'n', $g ); $socket->read( my $b, 2 ) || die 'unexpected end of data'; $b = unpack( 'n', $b ); # warn "$i $r/$g/$b"; # The 8-bit colours are in the top byte of each field $colours[$i] = { r => $r >> 8, g => $g >> 8, b => $b >> 8 }; } $self->_colourmap( \@colours ); return 1; } sub _receive_bell { my $self = shift; # And discard it... return 1; } sub _receive_cut_text { my $self = shift; my $socket = $self->socket; $socket->read( my $cut_msg, 7 ) || die 'unexpected end of data'; my $cut_length = unpack 'xxxN', $cut_msg; $socket->read( my $cut_string, $cut_length ) || die 'unexpected end of data'; # And discard it... return 1; } sub mouse_move_to { my ( $self, $x, $y ) = @_; $self->send_pointer_event( 0, $x, $y ); my $cursordata = $self->_cursordata; if ( !$cursordata ) { $self->_cursordata( $cursordata = {} ); } $cursordata->{x} = $x; $cursordata->{y} = $y; } sub mouse_click { my ($self) = @_; my $cursordata = $self->_cursordata; if ( !$cursordata ) { $self->_cursordata( $cursordata = { x => 0, y => 0 } ); } $self->send_pointer_event( 1, $cursordata->{x}, $cursordata->{y} ); $self->send_pointer_event( 0, $cursordata->{x}, $cursordata->{y} ); } sub mouse_right_click { my ($self) = @_; my $cursordata = $self->_cursordata; if ( !$cursordata ) { $self->_cursordata( $cursordata = { x => 0, y => 0 } ); } $self->send_pointer_event( 4, $cursordata->{x}, $cursordata->{y} ); $self->send_pointer_event( 0, $cursordata->{x}, $cursordata->{y} ); } 1; __END__ =head1 NAME Net::VNC - A simple VNC client =head1 SYNOPSIS use Net::VNC; my $vnc = Net::VNC->new({hostname => $hostname, password => $password}); $vnc->depth(24); $vnc->login; print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; my $image = $vnc->capture; $image->save("out.png"); =head1 DESCRIPTION Virtual Network Computing (VNC) is a desktop sharing system which uses the RFB (Remote FrameBuffer) protocol to remotely control another computer. This module acts as a VNC client and communicates to a VNC server using the RFB protocol, allowing you to capture the screen of the remote computer. This module dies upon connection errors (with a timeout of 15 seconds) and protocol errors. This implementation is based largely on the RFB Protocol Specification, L. That document has an error in the DES encryption description, which is clarified via L. =head1 METHODS =head2 new The constructor. Given a hostname and a password returns a L object: my $vnc = Net::VNC->new({hostname => $hostname, password => $password}); Optionally, you can also specify a port, which defaults to 5900. For ARD (Apple Remote Desktop) authentication you must also specify a username. You must also install Crypt::GCrypt::MPI and Crypt::Random. =head2 login Logs into the remote computer: $vnc->login; =head2 name Returns the name of the remote computer: print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; =head2 width Returns the width of the remote screen: print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; =head2 height Returns the height of the remote screen: print $vnc->name . ": " . $vnc->width . ' x ' . $vnc->height . "\n"; =head2 capture Captures the screen of the remote computer, returning an L object: my $image = $vnc->capture; $image->save("out.png"); You may call capture() multiple times. Each time, the C<$image> buffer is overwritten with the updated screen. So, to create a series of ten screen shots: for my $n (1..10) { my $filename = sprintf 'snapshot%02d.png', $n++; $vnc->capture()->save($filename); print "Wrote $filename\n"; } =head2 depth Specify the bit depth for the screen. The supported choices are 24, 16 or 8. If unspecified, the server's default value is used. This property should be set before the call to login(). =head2 save_bandwidth Accepts a boolean, defaults to false. Specifies whether to use more CPU-intensive algorithms to compress the VNC datastream. LAN or localhost connections may prefer to leave this false. This property should be set before the call to login(). =head2 list_encodings Returns a list of encoding number/encoding name pairs. This can be used as a class method like so: my %encodings = Net::VNC->list_encodings(); =head2 send_key_event_down Send a key down event. The keys are the same as the corresponding ASCII value. Other common keys: BackSpace 0xff08 Tab 0xff09 Return or Enter 0xff0d Escape 0xff1b Insert 0xff63 Delete 0xffff Home 0xff50 End 0xff57 Page Up 0xff55 Page Down 0xff56 Left 0xff51 Up 0xff52 Right 0xff53 Down 0xff54 F1 0xffbe F2 0xffbf F3 0xffc0 F4 0xffc1 ... ... F12 0xffc9 Shift (left) 0xffe1 Shift (right) 0xffe2 Control (left) 0xffe3 Control (right) 0xffe4 Meta (left) 0xffe7 Meta (right) 0xffe8 Alt (left) 0xffe9 Alt (right) 0xffea $vnc->send_key_event_down('A'); =head2 send_key_event_up Send a key up event: $vnc->send_key_event_up('A'); =head2 send_key_event Send a key down event followed by a key up event: $vnc->send_key_event('A'); =head2 send_key_event_string Send key events for every character in a string: $vnc->send_key_event_string('Hello'); =head2 send_pointer_event( $button_mask, $x, $y ) Send pointer event (usually a mouse). This is used to move the pointer or make clicks or drags. It is easier to call the C or methods instead. =head2 mouse_move_to($x, $y) Send the pointer to the given position. The cursor instantly jumps there instead of smoothly moving to there. =head2 mouse_click Click on current pointer position. =head2 mouse_right_click Right-click on current pointer position. =head1 BUGS AND LIMITATIONS =head2 Bit depth We do not yet support 8-bit true-colour mode, which is commonly supported by servers but is rarely employed by clients. =head2 Byte order We have currently tested this package against servers with the same byte order as the client. This might break with a little-endian server/big-endian client or vice versa. We're working on tests for those latter cases. Testing and patching help would be appreciated. =head2 Efficiency We've implemented a subset of the data compression algorithms supported by most VNC servers. We hope to add more of the high-compression transfer encodings in the future. =head1 AUTHORS Leon Brocard acme@astray.com Chris Dolan clotho@cpan.org Apple Remote Desktop authentication based on LibVNCServer Maurice Castro maurice@ipexchange.com.au Many thanks for Foxtons Ltd for giving Leon the opportunity to write the original version of this module. Copyright (C) 2006, Leon Brocard This module is free software; you can redistribute it or modify it under the same terms as Perl itself. Net-VNC-0.40/t000755001750001750 011652724570 12060 5ustar00acmeacme000000000000Net-VNC-0.40/t/pod.t000444001750001750 21411652724570 13141 0ustar00acmeacme000000000000#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Net-VNC-0.40/t/pod_coverage.t000444001750001750 25411652724570 15020 0ustar00acmeacme000000000000#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); Net-VNC-0.40/bin000755001750001750 011652724570 12365 5ustar00acmeacme000000000000Net-VNC-0.40/bin/vnccapture000555001750001750 556611652724570 14636 0ustar00acmeacme000000000000#!/usr/bin/perl -w use warnings; use strict; use Net::VNC; use Getopt::Long; use Pod::Usage; my %opts = ( password => '', host => 'localhost', port => 5900, depth => 24, type => 'png', cursor => 0, outfile => undef, endian => undef, verbose => 0, help => 0, version => 0, ); Getopt::Long::Configure('bundling'); GetOptions('P|password=s' => \$opts{password}, 'H|host=s' => \$opts{host}, 'p|port=s' => \$opts{port}, 'd|depth=s' => \$opts{depth}, 't|type=s' => \$opts{type}, 'C|cursor' => \$opts{cursor}, 'o|outfile=s' => \$opts{outfile}, 'e|endian' => \$opts{endian}, 'v|verbose' => \$opts{verbose}, 'h|help' => \$opts{help}, 'V|version' => \$opts{version}, ) or pod2usage(1); if ($opts{help}) { pod2usage(-exitstatus => 0, -verbose => 2); } if ($opts{version}) { print "Net::VNC v$Net::VNC::VERSION\n"; exit 0; } my $end = shift || 1; $end = 1 if ($end =~ /\D/); my $vnc = Net::VNC->new({hostname => $opts{host}, port => $opts{port}, password => $opts{password}, }); $vnc->server_endian($opts{endian}); $vnc->depth($opts{depth}); $vnc->login(); print "Logged in\n" if ($opts{verbose}); $vnc->hide_cursor(!$opts{cursor}); for my $n (1..$end) { my $filename = defined $opts{outfile} ? $opts{outfile}.($end == 1 ? q{} : q{.}.$n) : sprintf 'snapshot%04d.%s', $n, $opts{type}; $vnc->capture()->save($filename); print "Wrote $filename\n" if ($opts{verbose}); } __END__ =head1 NAME vnccapture - Capture a screenshot via VNC =head1 SYNOPSIS vnccapture [options] [numcaptures] Options: -P --password=str password for the VNC server, if applicable -H --host=str address of VNC server (default: 'localhost') -p --port=num TCP port for VNC server (default: 5900) -d --depth=8|16|24 screen depth for capture (default: 24) -t --type=ext image type for output (default: 'png') -C --cursor include the mouse cursor in the image -o --outfile capture to the specified path otherwise capture to "snapshot." -v --verbose print status and diagnostics to STDOUT -h --help verbose help message -V --version print the Net::VNC version =head1 DESCRIPTION Connect to a VNC server and capture the screen one or more times. The output is written to, for example, C. The number is the sequence of captures and the extension is specified by the C<--type> argument. The C<--type> argument can be any format that L can support. =head1 SEE ALSO L L =head1 AUTHOR Chris Dolan, I =cut