Share
Embed
Laravel-zeroで楽して情報収集する?
maki
February 16, 2019
Transcript
22 slides
-
w ࠃτοϓϨϕϧͷΞϓϦઃܭ։ൃɾେنαʔϏεӡ༻࣮ଟ w ϑϥοτͳ৫ϚωʔδϝϯτϨε w Ͱ͖Δڥษڧ͠์ ͋ΒΏΔΠϯϓοτʹରͯ͠ࣄલਃෆཁˋձࣾิॿ w ऩࣗݾਃࠂਓࣄධՁϊϧϚͳ͍ɾϓϩϏδϣφϧαϥϦʔˢˢˢ w
༗څऔΓ์ w ͓ࡊࢧڅ ΤϯδχΞʹخ੍͍͕ͨ͘͠͞Μ ژɹ౦ژ ࡳຈ େࡕɹԬ -
public function handle() { $this->browse(function($browser) { // login $browser->visit('https://site1.test/login') ->type('email',
config('service.site1_email')) ->type('password', config('service.site1_password')) ->press('Login'); // get text $text = $browser->text('#app > main > div > div > div > div > div.card-body'); \Log::info($text); $this->notify(‘Hello Web Artisan’, $text, 'icon.png'); }); } -
$ php zero site1:login Visit https://site1.test/login: ✔ Type email [email protected]:
✔ Type password secret!: ✔ Press Login: ✔ Text #app > main > div > div > div > div > div.card-body: ✔ [2019-02-16 03:30:24] development.INFO: You are logged in! -
$this->browse(function($browser) { // login $browser->visit('https://site1.test/login') ->type('email', config('service.site1_email')) ->type('password', config('service.site1_password')) ->press('Login');
// get text $text = $browser->text('#app > main > div > div > div > div > div.card-body'); // slack post $guzzle = new \GuzzleHttp\Client(); $guzzle->post(config('service.slack.webhook_url'), [ 'body' => json_encode([ 'channel' => config('service.slack.channel'), 'text' => $text, 'username' => config('service.slack.username'), 'icon_emoji' => config('service.slack.icon'), ]), ]); }); -
$ php zero site1:slack Visit https://site1.test/login: ✔ Type email [email protected]:
✔ Type password password: ✔ Press Login: ✔ Text #app > main > div > div > div > div > div.card-body: ✔ Screenshot login: ✔ -
$this->task('get site1', function () { $this->browse(function ($browser) { // login
$browser->visit('https://site1.test/login') ->type('email', config('service.site1_email')) ->type('password', config('service.site1_password')) ->press('Login'); // get text $this->site1['text'] = $browser->text('#app > main > div > div > div > div > div.card-body'); $browser->screenshot('login'); $this->site1['screenshots'] = storage_path('laravel-console-dusk/screenshots') . '/login.png'; }); }); -
$this->task('upload to s3', function () { // upload to s3
$guzzle = new \GuzzleHttp\Client(); $gyazo = $guzzle->post(config('service.gyazo.url'), [ 'headers' => [ 'content-type' => 'image/png', 'x-api-key' => config('service.gyazo.api_key') ], 'body' => fopen($this->site1['screenshots'], 'r'), ]); if (200 !== $gyazo->getStatusCode()) { throw new \Exception('s3 upload failed.'); } $this->imageUrl = $gyazo->getBody()->getContents(); }); -
$this->task('post slack', function() { // slack message $payload = [
'channel' => config('service.slack.channel'), 'text' => $this->site1['text'], 'username' => config('service.slack.username'), 'icon_emoji' => config('service.slack.icon'), 'attachments' => [ [ 'image_url' => $this->imageUrl, 'color' => 'good' ] ] ]; $guzzle = new \GuzzleHttp\Client(); $guzzle->post(config('service.slack.webhook_url'), [ 'body' => json_encode($payload), ]); }); -
$ php zero site1:slack-image Visit https://site1.test/login: ✔ Type email [email protected]:
✔ Type password password: ✔ Press Login: ✔ Text #app > main > div > div > div > div > div.card-body: ✔ Screenshot login: ✔ get site1: ✔ upload to s3: ✔ post slack: ✔ -
ΞΠσΟΞ w ۈଵཧγεςϜ ύϒϦοΫͳ"1*ͳͲͳ͍ʜ w ฏ༦ํʹಈ͘ w ϑΥʔϜϩάΠϯ w
λΠϜΧʔυը໘Λ։͘ w ࠓͷग़ۈ࣌ࠁΛऔಘ w ࠓ݄ͷ࿑ಇ࣌ؒɺฏۉΛܭࢉ w σεΫτοϓTMBDL௨ -
ΞΠσΟΞ w ۀใࠂγεςϜ ύϒϦοΫͳ"1*ͳͲͳ͍ʜ w ճ ேPS༦ํ w
ϑΥʔϜϩάΠϯ w ը໘ʹදࣔ͞ΕΔܯࠂΛऔಘঝೝґཔະ֬ఆ w σεΫτοϓTMBDL௨ -
ΞΠσΟΞ w ӡ༻தαʔϏεͷཧը໘ ύϒϦοΫͳ"1*ͳͲͳ͍ʜ w ࣌ؒʹճ w ࢦఆͨ͠Օॴʹදࣔ͞ΕΔΛऔಘ w
εΫϦʔϯγϣοτΛऔΔ w TMBDLʹը૾Ξοϓϩʔυ