diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..bc56518 --- /dev/null +++ b/app.yaml @@ -0,0 +1,8 @@ +application: slack-integration +version: 1 +runtime: php +api_version: 1 + +handlers: +- url: /(.*\.php)$ + script: scripts/\1 diff --git a/scripts/include/curl.php b/scripts/include/curl.php index d3ff09c..8595231 100644 --- a/scripts/include/curl.php +++ b/scripts/include/curl.php @@ -1,42 +1,33 @@ - array('method' => 'get')); + $context = stream_context_create($context); - $response = curl_exec($crl); - curl_close($crl); - return $response; + return file_get_contents($url, FALSE, $context); } -function get_url_contents_with_basicauth($url, $username, $password) { - $crl = curl_init(); +function get_url_contents_with_basicauth($url, $username, $password) +{ + $auth_header = $username . ':' . $password; + $auth_header = base64_encode($auth_header); + $auth_header = 'Authorization: Basic ' . $auth_header . "\r\n"; - curl_setopt($crl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'); - curl_setopt($crl, CURLOPT_URL, $url); - curl_setopt($crl, CURLOPT_USERPWD, "{$username}:{$password}"); - curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5); + $context = array('http' => array('method' => 'get', 'header' => $auth_header)); + $context = stream_context_create($context); - $ret = curl_exec($crl); - curl_close($crl); - return $ret; + return file_get_contents($url, FALSE, $context); } -function curl_post($uri, $data) +function curl_post($url, $data_string) { - $crl = curl_init($uri); - curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($crl, CURLOPT_POSTFIELDS, $data); - curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($crl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data))); - - $response = curl_exec($crl); - curl_close($crl); - return $response; + $length_header = strlen($data_string); + $length_header = 'Content-Length: ' . $length_header . "\r\n"; + + $context = array('http' => array('method' => 'post', 'header' => $length_header, 'content' => $data_string)); + $context = stream_context_create($context); + + return file_get_contents($url, FALSE, $context); } -?> \ No newline at end of file diff --git a/scripts/include/slack.php b/scripts/include/slack.php index 38639a2..72382bb 100644 --- a/scripts/include/slack.php +++ b/scripts/include/slack.php @@ -1,6 +1,6 @@ $payload, + "text" => $payload, "channel" => "#".$channel, "username"=>$user ); @@ -49,7 +49,7 @@ function slack_incoming_hook_post($uri, $user, $channel, $icon, $emoji, $payload $data_string = "payload=" . json_encode($data, JSON_HEX_AMP|JSON_HEX_APOS|JSON_NUMERIC_CHECK|JSON_PRETTY_PRINT); - mylog('sent.txt',$data_string); + // mylog('sent.txt',$data_string); return curl_post($uri, $data_string); } @@ -58,14 +58,14 @@ function slack_incoming_hook_post($uri, $user, $channel, $icon, $emoji, $payload function slack_incoming_hook_post_with_attachments($uri, $user, $channel, $icon, $payload, $attachments){ $data = array( - "text" => $payload, + "text" => $payload, "channel" => "#".$channel, "username"=>$user, "icon_url"=>$icon, "attachments"=>array($attachments)); $data_string = "payload=" . json_encode($data, JSON_HEX_AMP|JSON_HEX_APOS|JSON_NUMERIC_CHECK|JSON_PRETTY_PRINT); - mylog('sent.txt',$data_string); + // mylog('sent.txt',$data_string); return curl_post($uri, $data_string); } diff --git a/scripts/meme.php b/scripts/meme.php index 4c68a81..8815bcb 100644 --- a/scripts/meme.php +++ b/scripts/meme.php @@ -20,7 +20,7 @@ $payload = json_encode($cmd); -mylog('received.txt',$payload); +// mylog('received.txt',$payload); $cmdText = $cmd->Text; $memetext = str_replace("memebot ", "", $cmdText); @@ -32,11 +32,11 @@ $bottom = urlencode($parts[2]); $meme = CreateNewMeme($gen, $top, $bottom); -mylog('sent.txt',$meme); +// mylog('sent.txt',$meme); $response = slack_incoming_hook_post($config['slack']['hook'], $cmd->UserName, $cmd->ChannelName, null, ":bow:", $meme); -mylog('sent.txt',$response); +// mylog('sent.txt',$response); //str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )