sohotcall

raw-print-server.php

Aug 3rd, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. // RawPrintServer INSTALL "EPSON LX-310 ESC/P" 2481
  3. if ( isset( $_REQUEST['q'] ) ){
  4.     $socket = socket_create( AF_INET, SOCK_STREAM, 0 ) or die( "Error socket\r\n" );
  5.     $result = socket_connect( $socket, "127.0.0.1", 2481 ) or die( "Error connecting\r\n" );
  6.     $message = $_REQUEST['q'];
  7.     socket_write( $socket, $message, strlen( $message ) ) or die( "Error sending\r\n" );
  8.     socket_close( $socket );
  9.     die( strlen( $_REQUEST['q'] ) );
  10. }
  11. ?>
  12. <textarea name=q readonly cols=152 rows=25 >{1B}{21}{01}{1B}M{0F}{1B}{C1}{0B}Hello, world!
  13. {0E}Double-width{14}
  14. </textarea>
  15. <button type=button name=button value=button >Print</button>
  16. <script>
  17. document.querySelector( '[name=button]' ).addEventListener( 'click', e=>{
  18.     var http = new XMLHttpRequest();
  19.     http.open( 'POST', 'raw-print-server.php', true );
  20.     http.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
  21.     http.onreadystatechange = function() {
  22.         if ( http.readyState == 4 && http.status == 200 ) {
  23.             console.log( http.response );
  24.             alert( "Printed: " + http.response + " bytes" );
  25.         }
  26.     }
  27.     var params = 'q=' + encodeURIComponent( document.querySelector('[name=q]').value
  28.         .replace(/\{([0-9a-fA-F][0-9a-fA-F])\}/g, function(m,x){
  29.             return String.fromCharCode(parseInt(x, 16));
  30.         }) );
  31.     http.send(params);
  32. }, false );
  33. </script>
  34.  
Add Comment
Please, Sign In to add comment