Upgrade to Pro — share decks privately, control downloads, hide ads and more …

知られざる世界 〜WEB以外のPHP〜

uzulla
August 05, 2017

知られざる世界 〜WEB以外のPHP〜

uzulla
builderscon tokyo 2017
2017/08/05

uzulla

August 05, 2017
Tweet

More Decks by uzulla

Other Decks in Science

Transcript

  1. ͦͷ··kikappͷshellͰ৽نϓϩδΣΫτΛ࡞Δ KikApp > new -testapp -/tmp/kikappsrc/ » testapp͕ΞϓϦ໊ ʢΞϓϦ໊͸ॏෳෆՄʣ »

    /tmp/kikappsrc/ ͕ϕʔεσΟϨΫτϦʹͳΓ ʢϑϧύεΛࢦఆ͠ͳ͍ͱɺޙʑॺ໊ͰίέΔʣ ʢύεʹϋΠϑϯ͕͋ΔͱΤϥʔʹͳΔʢʣʣ » /tmp/kikappsrc/testapp ʹϑΝΠϧ͕࡞ΒΕΔ ʢ͜͜Β΁Μ৭ʑΞϯυΩϡϝϯτͳ᠘ָ͕͔͋ͬͯͬͨ͠ʢʣʣ
  2. <?php // ͳΜͱ͜ΕͰίʔυશମͰ͢ $win = new SDPanel(); $win -> setCaption("Hello

    world!"); $mainTable = new Table(); $button = new Button(); $button -> setCaption("Click me!"); $button -> onTap(clickme()); $mainTable -> addControl($button,1,1); $win -> addControl($mainTable); function clickme(){ echo "hello smartphone!"; } ?>
  3. // Ϗϧυ࣌Τϥʔϝοηʔδ Generating to main.php line 17:0 missing '?>' at

    '<EOF>' » ࠷ޙͷ?>ΛলུͰ͖ͳ͍ » ʢ࠷ۙ͸লུ͢Δͷ͕౰વʣ
  4. $city = new InputText(); $city -> setReadOnly(true); function refresh(){ //

    ུ $city = $struct['nombreCiudad']; } » ʮಥવม਺͕άϩʔόϧʹʂʁʯ » ʢPHPerͰͳ͍ํʹઆ໌͢Δͱɺ͜ΕͰ͸άϩʔό ϧม਺ʹͳΒͳ͍ʣ
  5. ଞʹ΋… » ৘ใ͕ͱʹ͔͘ແ͍ » αϯϓϧίʔυ͸݁ߏ͋Δ͕… » StackOverflow΁ͷϦϯΫ͕͋Δ͕ɺ0݅ʢসʣ » ϦϞʔτ΁ͷ௨৴͕ϔϯςί »

    file_get_contents΍curl͸͔ͭ͑ͳ͍ɺ ṖͷHTTP ClientΫϥεϥΠϒϥϦΛ͔ͭ͏ » ௨৴͸ɺඞͣαʔόʔʹઃஔͨ͠ʢੜ੒ͨ͠ʣ PHPͷProxyΛҰ౓ܦ༝͢Δʢඞવੑ͕Ṗʣ
  6. » json ͷύʔε͕ʮߏ଄ମΛͭͬͯ͘ɺϙΠϯλ͔ͭ ͬͯύʔε͢ΔʯΈ͍ͨͳײ͡Ͱ΢έΔʢʁʁʣ $result = $httpClient -> Execute('GET',$url); $struct

    = array( array( "id" => DataType::Numeric(6), "name" => DataType::Character(150), ) ); Data::FromJson($struct,$result); foreach ($struct as $product){ $id = $product['id']; $title = $product['name']; }
  7. ·ͱΊ » ϋολϦɺҰൃωλͱͯ͠͸ڧ͍(͔ͭΈʹ࠷ߴ) » ίʔυ͸࣮ࡍʮ௒؆୯ʯɺίʔυ௒୹͍ » ·ͬͨ͘PHPerͷࢥ͍௨Γʹ͸Ͱ͖ͳ͍(স » ʢͳ͔ͥʣ௨৴ʹ͸αʔόʔ͕ඞཁ »

    Πϯετʔϧগʑ໘౗ɺυΩϡϝϯτ͕ແ͍ » কདྷతʹϥΠηϯε΍Ձ͕֨Ͳ͏ͳΔͷ͔Ṗ » फڭͰPHPҎ֎͔ͭ͑ͳ͍ਓʹ͸Αͦ͞͏(ʁ)
  8. ׬

  9. nightrain » PHP WebΞϓϦΛ app,exeʹύοΫͰ͖Δ » PHP(όΠφϦ) +Python(ύοΫࡁ) » http://

    uzulla.hateblo.jp/ entry/ 2014/12/12/235020 » ੲࣗ෼ͷϒϩάʹॻ͍ͨ
  10. $ git clone $ pip install pyinstaller $ brew install

    wxpython $ vi Classes/Compiler.py 179ߦ໨ call(["pyinstaller.py", "--clean", "-w", "-y", "-F", spec_path, application_icon, "-n", "nightrain", "Application.py"]) ↓ call(["pyinstaller", "--clean", "-w", "-y", "-F", spec_path, application_icon, "-n", "nightrain", "Application.py"]) $ python build.py …Έ͍ͨͳ͜ͱΛ΍ͬͯΈ͚ͨͲ
  11. » Ϗϧυ͸Ͱ͖͚ͨͲ࣮ߦ͢ ΔͱηάͬͯམͪΔ » pyinstaller ͱ wx ͷ৯߹ ͤʁ »

    otool΍ install_name_toolΉ͍ͣ » ʮ͏͔ͬΓpythonͱdylib ʹৄ͘͠ͳͬͨʂ͜Ε͔ͩ ΒPHP࠷ߴʂʯ » (sierra͋ͨΓ͔Β৭ʑͳ෺ ͷϏϧυ೉қ౓্͕ͬͯͳ ͍ʁ)
  12. phpack » https://github.com/uzulla/phpack » Electron + PHPͰPack » NightrainΛJSͰͭ͘Γͳ͓ͨ͠Α͏ͳ΋ͷ »

    PHP͸ͱΓ͋͑ͣSystem PHPΛ͔͍ͭͬͯΔ͕ɺ fatpack΋΍Ζ͏ͱ͓΋͑͹Ͱ͖Δ » OSX༻ʢͱΓ͋͑ͣʣ
  13. ίʔυ͸ಛʹݟΔ΂͖ͱ͜Ζ͸ͳ͍͚ΕͲ <html> <head> <title>Glitch</title> </head> <body> <form action="./glitch.php" method="POST" enctype="multipart/form-data">

    <input name="random_param" value="5"> <input name="max_jump_window_param" value="0.5"> img: <input type="file" name="img"><br> <input type="submit"> </form> </body>
  14. <?php $raw = file_get_contents($_FILES['img']['tmp_name']); $max_jump_window_param = $_POST['max_jump_window_param']; $random_param = $_POST['random_param'];

    $max_jump_window = strlen($raw) * $max_jump_window_param; $offset = 100; while(1){ $total_len = strlen($raw); $offset += (int)rand(1, $max_jump_window); if($offset > $total_len){ $offset = $total_len ; } $head = substr($raw, 0, $offset); $tail = substr($raw, $offset, $total_len-$offset); $padding = get_random_str( (int)rand(0, $random_param) ); $raw = $head . $padding . $tail; if($total_len <= $offset){ break; } } header("Content-Type: ".$_FILES['userfile']['type']); echo $raw; function get_random_str($num){ $char_tmp = []; $char_tmp = array_merge($char_tmp, range('A','Z')); $char_tmp = array_merge($char_tmp, range('a','z')); $char_tmp = array_merge($char_tmp, range('0','9')); $char_tmp_len = count($char_tmp); $str = ''; for($i=1; $i<=$num; $i++){ shuffle($char_tmp); $str .= $char_tmp[0]; } return $str; }
  15. ίʔυ… <html lang="ja"> <head> <meta charset="utf-8"> <title>ൿ఻ͷόϧΫϝʔϥʔ</title> </head> <body> <h1>ൿ఻ͷόϧΫϝʔϥʔ</h1>

    <form action="do.php" method="post" onsubmit="return confirm('ϗϯτʹૹ৴͠·͢ʁ');"> <p>gmail id</p> <input style="width:100%;" name="gmail_id"/> <p>gmail ΞϓϦύεϫʔυ(GMAILͷΞΧ΢ϯτͷύεϫʔυͰ͸ͳ͍ʂʣ</p> ※ https://myaccount.google.com/security ͔Βઃఆ͢Δ͜ͱ <input style="width:100%;" name="gmail_pass"/> <p>FROM ද໊ࣔ</p> <input style="width:100%;" name="from_name"/> <p>FROM ϝΞυ</p> <input style="width:100%;" name="from_email"/> <p>໊݅</p> <input style="width:100%;" name="subject"/> <p>ຊจ</p> <textarea style="width:100%;height:400px;" name="body"></textarea> <p>ѼઌʢϝΞυվߦ۠੾Γ</p> <textarea style="width:100%;height:400px;" name="mail_list"></textarea> <p> ຊ౰ʹ࣮ߦ͢ΔͳΒɺ͜͜Λonʹ</p> <input type="checkbox" value=1 name="no_dry_run"> <hr> <input type="submit" value="ϝʔϧૹ৴"> </form> </body> </html>
  16. <html lang="ja"> <head> <meta charset="utf-8"> <title>ൿ఻ͷόϧΫϝʔϥʔ</title> </head> <body> <?php date_default_timezone_set('Asia/Tokyo');

    ini_set('display_errors', 1); echo "<pre>"; require_once("vendor/autoload.php"); $gmail_id = $_POST['gmail_id']; $gmail_pass = $_POST['gmail_pass']; $transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl')) ->setUsername($gmail_id) ->setPassword($gmail_pass); $mailer = new Swift_Mailer($transport); $subject = $_POST['subject']; echo htmlspecialchars("\n໊݅:\n{$subject}", ENT_QUOTES); $body = $_POST['body']; echo htmlspecialchars("\nຊจ:\n{$body}", ENT_QUOTES); $from_name = $_POST['from_name']; echo htmlspecialchars("\nFROM ໊લ:\n{$from_name}", ENT_QUOTES); $from_email = $_POST['from_email']; echo htmlspecialchars("\nFROM email:\n{$from_email}", ENT_QUOTES); $is_no_dry_run = (isset($_POST['no_dry_run']) && $_POST['no_dry_run']==1) ? true : false ; $mail_list_raw = explode("\n", $_POST['mail_list']); $mail_list = []; foreach($mail_list_raw as $email){ if(!preg_match("/@/", $email)) continue; $mail_list[] = trim($email); } echo htmlspecialchars("\n to addresses :\n", ENT_QUOTES); echo htmlspecialchars(var_dump($mail_list), ENT_QUOTES); echo "<hr>"; $message = new Swift_Message($subject); $message ->setFrom([$from_email => $from_name]) ->setBody($body); foreach($mail_list as $to){ echo htmlspecialchars("{$to}\n", ENT_QUOTES); $message->setTo($to); // Send the message if($is_no_dry_run){ $result = $mailer->send($message); var_dump($result); } } echo "<hr> ऴྃ͠·ͨ͠";
  17. cairo install $ wget https://pecl.php.net/get/Cairo-0.3.2.tgz $ cd Cairo $ phpize

    $ make $ make install $ vi path/to/php.ini // add extension=cairo.so
  18. php-gtk install $ git clone https://github.com/php/php-gtk-src $ cd php-gtk-src $./buildconf

    $ ./configure $ make $ make install $ vi path/to/php.ini // add extension=php_gtk2.so
  19. run demo » demosҎԼʹ৭ʑ͋Γ·͢ $ cd demos $ php phpgtk2-demo.php

    2017-08-05 00:47:12.529 php[43302:71455160] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. » (·͋ͳΜ͔WarnͰ·͚͢Ͳɺݟͳ͔ͬͨ͜ͱʹ͠ ·͠ΐ͏
  20. class ButtonBox extends GtkWindow { function __construct($parent = null) {

    parent::__construct(); if ($parent) $this->set_screen($parent->get_screen()); else $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->set_title(__CLASS__); $this->set_position(Gtk::WIN_POS_CENTER); $this->set_default_size(-1, 500); $this->set_border_width(8); $this->add($this->__create_box()); $this->show_all(); } /* .... */ if (!@$GLOBALS['framework']) { new ButtonBox(); Gtk::main(); }
  21. function create_framedbox($horizontal, $title, $spacing, $layout) { $frame = new GtkFrame($title);

    if ($horizontal) { $box = new GtkHButtonBox(); } else { $box = new GtkVButtonBox(); } $box->set_border_width(5); $box->set_layout($layout); $box->set_spacing($spacing); $frame->add($box); $button = GtkButton::new_from_stock(Gtk::STOCK_OK); $box->add($button);
  22. Delphi for PHP » https://www.componentsource.co.jp/product/ delphi-for-php-j/about » ʮRADϏδϡΞϧPHP։ൃ؀ڥɻίϯϙʔωϯτʹ ΑΔυϥοάˍυϩοϓ։ൃΛ࣮ݱͨ͠ϏδϡΞϧ౷ ߹։ൃ؀ڥͰ͢ʯ

    » ͕ɺHTML5 Builder ͱ͍͏੡඼ʹϦωʔϜ͞Ε… » ʮHTML5 Builder ੡඼ͷ୯ମൢച͸ऴྃ͞Εɺݱࡏ ͸ RAD Studio ʹ෇ଐ͓ͯ͠Γ·͢ɻʯ » ऴྃ
  23. wxphpͷҰྫͱͯ͠ » https://github.com/AndrewRose/Grease » PHP editor written in PHP with

    remote debugger and plugin API. » ͳΜͱPHPͰͰ͖ͨ౷߹։ൃ؀ڥͰ͋Δ
  24. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried

    to allocate 18446744073709551396 bytes ) in /tmp/phptk/tk-0.1.1/test.php on line 4 Segmentation fault: 11
  25. SDL2 » https://github.com/Ponup/phpsdl » PHP5.6 ϏϧυͰίέʢry » ͱ͓΋ͬͨΒɺPHP7Ͱ௨Δ » ͱ͓΋ͬͨΒɺ

    PHP Startup: SDL: Unable to initialize module » ׬ʢ͋ͬɺ΋͏͍͍Ͱ͔͢ʁʣ
  26. <?php $pcap = pcap_open_live( "lo0", // ϧʔϓόοΫσόΠε 65535, // len

    1, //promiscuous mode 10000, // ଴ͪड͚Δmsɺ௒͑ͨΒऴྃ $errbuf); $i = 0; while(($data = pcap_next($pcap, $header)) && $i++ < 50) { echo $data; } $ret = pcap_close($pcap);
  27. ͳΜ͔ΰϛ͕͋Γ·͢Ͷɺ HEXDUMPͯ͠Έ·͠ΐ͏ while(($data = pcap_next($pcap, $header)) && $i++ < 50)

    { hexdump ( $data, 0 ); } » ʢhexdumpؔ਺͸ͪ͜ΒΑΓ http:// www.aidanlister.com/2004/04/viewing-binary- data-as-a-hexdump-in-php/ʣ
  28. -------------------------------------------------------------------------------- 0000 02 00 00 00 45 00 00 82

    79 b5 40 00 40 06 00 00 ....E..� y�@.@... 0010 7f 00 00 01 7f 00 00 01 f5 19 1f 90 51 8d 0a 80 ...... �..�Q�.� 0020 f7 f0 63 c5 80 18 31 d7 fe 76 00 00 01 01 08 0a ��cŀ.1� �v...... 0030 12 6f 3f 63 12 6f 3f 63 47 45 54 20 2f 20 48 54 .o?c.o?c GET / HT 0040 54 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 31 32 TP/1.1.. Host: 12 0050 37 2e 30 2e 30 2e 31 3a 38 30 38 30 0d 0a 55 73 7.0.0.1: 8080..Us 0060 65 72 2d 41 67 65 6e 74 3a 20 63 75 72 6c 2f 37 er-Agent : curl/7 0070 2e 35 31 2e 30 0d 0a 41 63 63 65 70 74 3a 20 2a .51.0..A ccept: * 0080 2f 2a 0d 0a 0d 0a /*....
  29. while(($data = pcap_next($pcap, $header)) && $i++ < 50) { echo

    substr(56, $data); } » (substr͸όΠτྻૢ࡞ʹ΋͔ͭ͑·͢ʣ
  30. GET / HTTP/1.1 Host: 127.0.0.1:8080 User-Agent: curl/7.51.0 Accept: */* HTTP/1.1

    404 Not Found Host: 127.0.0.1:8080 Date: Fri, 28 Jul 2017 10:49:57 +0000 Connection: close Content-Type: text/html; charset=UTF-8 Content-Length: 533 <!doctype html><html><head><title>404 Not Found</title> <style> <SNIP> </style> </head><body> <h1>Not Found</h1> <p>The requested resource <code class="url">/</code> was not found on this server.</p></body></html>
  31. GPIOͷpin » ͸Μͩ෇͚ or ѹೖ » ී௨ʹ͸Μͩ෇͚͕ྑ͍ » ѹೖʢϋϯϚʔʣऔΓ෇͚͓͢͢Ί͠ͳ͍ »

    ج൫ΛΨϯΨϯϋϯϚʔͰୟ͘ͷ͸ͦΕͳΓʹ୾ ྗ͕͍Δ » Ψλ͍ͭͨͷͰ݁ہ͸Μͩ෇͚ͨ͠ʢʣ
  32. <?php // Ϙλϯ͕ԡ͞Ε͔ͨ؂ࢹ͢Δίʔυ require "vendor/autoload.php"; use PiPHP\GPIO\GPIO; use PiPHP\GPIO\Pin\InputPinInterface; $gpio

    = new GPIO(); $pin = $gpio->getInputPin(12); $pin->setEdge(InputPinInterface::EDGE_BOTH); $interruptWatcher = $gpio->createWatcher(); $interruptWatcher->register($pin, function (InputPinInterface $pin, $value) { if($value == 0){ echo "PUSHED!" } return true; }); while ($interruptWatcher->watch(5000))
  33. <?php // πΠʔτ͢Δίʔυ require "vendor/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; include_once "config.php"; $connection

    = new TwitterOAuth( CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $media1 = $connection->upload('media/upload', ['media' => 'img.png']); $parameters = [ 'status' => 'πΠʔτςΩετ #builderscon', 'media_ids' => implode(',', [$media1->media_id_string]) ]; $result = $connection->post('statuses/update', $parameters);
  34. <?php //શ෦૊Έ߹ΘͤͨΒ͜͏ͳΔ require "vendor/autoload.php"; include_once "config.php"; use Cvuorinen\Raspicam\Raspistill; use Abraham\TwitterOAuth\TwitterOAuth;

    use PiPHP\GPIO\GPIO; use PiPHP\GPIO\Pin\InputPinInterface; $gpio = new GPIO(); $pin = $gpio->getInputPin(12); // a button $pin->setEdge(InputPinInterface::EDGE_BOTH); $interruptWatcher = $gpio->createWatcher(); $interruptWatcher->register($pin, function (InputPinInterface $pin, $value) { if($value != 0){ return true; } $camera = new Raspistill(); $camera->width(1024)->height(768)->takePicture('pic.jpg'); $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $media1 = $connection->upload('media/upload', ['media' => 'pic.jpg']); $parameters = [ 'status' => '#builderscon', 'media_ids' => implode(',', [$media1->media_id_string]) ]; $result = $connection->post('statuses/update', $parameters); }); while ($interruptWatcher->watch(5000)){}
  35. ·ͱΊ » PHPʴRaspi͸ָͰָ͍͠ɺे෼࢖͑Δ » rasberrypi zero w͸ಛʹ͍҆͠ɺͨͷ͍͠ » PHPerͰ΋ຊ౰ʹ؆୯ʹ৭ʑͰ͖ͯ࠷ߴ »

    ʮຊ෺ͷʯPHPͳͷͰɺը૾ม׵ͱ͔΋Ͱ͖·͢ » ʢॳ৺ऀͷLinux+PHP؀ڥͱͯ͠΋खܰͰ͍͍ͷ͔ ΋͠Εͳ͍ʣ
  36. » git cloneͯ͠ » composer installͯ͠ » php bin/pssht »

    ssh -T -p 22222 your_id@localhost » 伴ೝূ͋Δ͍͸ύεϫʔυpssht
  37. // src/Application/EchoService.php public function handle( <SNIP> ) { $message =

    \fpoirotte\Pssht\Messages\CHANNEL\DATA::unserialize($decoder); $channel = $message->getChannel(); $ೖྗ͞Εͨจࣈྻ = $message->getData(); $ૹ৴͍ͨ͠จࣈྻ = "޷͖ʹͨ͠ΒΑ͍"; $response = new \fpoirotte\Pssht\Messages\CHANNEL\DATA($channel, $ૹ৴͍ͨ͠จࣈྻ); $transport->writeMessage($response); return true; }
  38. PocketMine-MP » MineCraft PocketEditionͷαʔόʔ » https://github.com/pmmp/PocketMine-MP » A highly customisable,

    open source server software for Minecraft: Pocket Edition written in PHP » (ଞʹ΋ɺiTXTech/Genisysͱ͔͋Δʣ
  39. UltimaPHP » Ultima Online ͷOpensourceαʔόʔ » https://github.com/joaoescribano/UltimaPHP » UltimaPHP is

    a modern Ultima Online server written in PHP 7.0 » ʢ͔ͭͬͨ͜ͱ͸ͳ͍ʣ
  40. ೉ಡԽʢεΫϥϯϒϧʣ » phpίʔυ͸ฏจͰ͕͢ɺಡΊͳ͍ͨ͘͠ͱ͍͏ध ཁ͸͠͹͠͹͋Γ·͢ » ionCube Encoder » http://www.ioncube.com/ »

    zend Guard » http://www.zend.com/en/products/zend-guard » php beast » https://github.com/liexusong/php-beast
  41. Trailing commas in list syntax $a = [ 1, 2,

    3, // લ͔ΒOK ]; myFunc( 1, 2, 3, // ͨͱ͑͹͜͏͍͏ͷΛOKʹ ) » Ұ෦͸௨Γͦ͏
  42. Deprecate and Remove Bareword (Unquoted) Strings $a = bare_word; echo

    $a; // -> bare_word // notice͸ͰΔ͚Ͳɺ͏͍ͯ͝͠·͏ » "falsu"Έ͍ͨͳͷΛආ͚Δҝ » ॱ౰Ͱ͸
  43. Debugging PDO Prepared Statement Emulation $stmt = $db->prepare('SELECT :string'); $stmt->bindValue(':string',

    'foo'); // returns unparsed query before execution var_dump($stmt->activeQueryString()); // => string(14) "SELECT :string" // returns parsed query after execution $stmt->execute(); var_dump($stmt->activeQueryString()); // => string(11) "SELECT 'foo'" » ੜ੒͞ΕΔSQL͕ݟΕΔ » ॿ͔Δ
  44. Debugging PDO Prepared Statement Emulation v2 $sth = $dbh->prepare('SELECT name,

    colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->bindParam(1, $calories, PDO::PARAM_INT); $sth->bindValue(2, $colour, PDO::PARAM_STR); $sth->execute(); $sth->debugDumpParams(); Output: SQL: [82] SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ? Sent SQL: [88] SELECT name, colour, calories FROM fruit WHERE calories < 150 AND colour = 'red' Params: 2 Key: Position #0: paramno=0 name=[0] "" is_param=1 param_type=1 Key: Position #1: paramno=1 name=[0] "" is_param=1 param_type=2 ΋ͬͱ͔ͨ͢Δ