Magellan Linux

Diff of /alx-src/branches/alx-web-070/include/socket_send.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9660 by niro, Fri Jan 29 12:57:52 2016 UTC revision 9661 by niro, Wed Aug 2 13:21:57 2017 UTC
# Line 1  Line 1 
1  <?  <?
 // $address = "192.168.0.6";  
 // $port = "6666";  
 //  
 // // create and connect socket  
 // $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);  
 // socket_connect($sock, $address, $port);  
 //  
 // // send the message to the daemon  
 // //$mesg = "resolution=800x600\nquit";  
 // $mesg = "resolution\nquit";  
 // //$mesg = "printer\ngfxcard\nnetcard\nkeyboard\nmouse\nsound\nquit";  
 // socket_write($sock, $mesg, strlen($mesg));  
 //  
 // // close socket  
 // socket_close($sock);  
   
   
 /* fgets needs 'auto-detect-line-endings = On' in php.ini to detect unix CRLFs!  
  * see: http://www.php.net/manual/de/filesystem.configuration.php#ini.auto-detect-line-endings  
  */  
   
 // // ssl  
 // $fp = fsockopen("sslv3://192.168.0.6", 6666, $errno, $errstr, 30);  
 // if (!$fp) {  
 // echo "$errstr ($errno)<br />\n";  
 // } else {  
 // $out = "resolution\n";  
 // $out .= "quit\n";  
 // fwrite($fp, $out);  
 // while (!feof($fp)) {  
 // echo fgets($fp, 128);  
 // }  
 // fclose($fp);  
 // }  
   
2  include("config.inc.php");  include("config.inc.php");
3    
4  function mcore_socket_send($ip, $port, $cmd)  function mcore_socket_send($ip, $port, $cmd)
5  {  {
6   global $mcore_certificate;   global $mcore_certificate;
7    
  // use sslv3  
  $schema = "sslv3://";  
   
8   // do not print output of system   // do not print output of system
9   ob_start();   ob_start();
10   $fingerprint = system("openssl x509 -noout -modulus -in ".$mcore_certificate." | openssl sha1 | sed 's:(stdin)=\ ::'", $retval);   $fingerprint = system("openssl x509 -noout -modulus -in ".$mcore_certificate." | openssl sha1 | sed 's:(stdin)=\ ::'", $retval);
11   ob_clean();   ob_clean();
12   if ($retval == 0)   if ($retval == 0)
13   {   {
14   $fp = fsockopen($schema.$ip, $port, $errno, $errstr, 30);   ob_start();
15   if (!$fp) {   system("/usr/bin/mcore-socket-send --ip='".$ip."' --port='".$port."' --fingerprint='".$fingerprint."' --command='".$cmd."'", $sockretval);
16   echo "$errstr ($errno)<br />\n";   ob_clean();
17   } else {   if ($sockretval == 0) echo "socket send succesfull";
18   $out = "certauth ".$fingerprint."\n";   else "echo socket send failed";
  $out .= $cmd."\n";  
  $out .= "quit\n";  
  fwrite($fp, $out);  
  while (!feof($fp)) {  
  echo fgets($fp, 128);  
  }  
  fclose($fp);  
  }  
19   }   }
20  }  }
21  ?>  ?>

Legend:
Removed from v.9660  
changed lines
  Added in v.9661