Created
October 18, 2011 11:35
-
-
Save primalmotion/1295224 to your computer and use it in GitHub Desktop.
This file can be set as endpoint for LPCrashReported. It supports version, so it's better to use with my fork of LPKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| # reports.php | |
| # | |
| # Copyright (C) 2010 Antoine Mercadal <antoine.mercadal@inframonde.eu> | |
| # This file is part of ArchipelProject | |
| # http://archipelproject.org | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU Affero General Public License as | |
| # published by the Free Software Foundation, either version 3 of the | |
| # License, or (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU Affero General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU Affero General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| /* | |
| CONFIG: GITHUB ISSUE POSTING | |
| */ | |
| // The name of the github repo (ie. 'archipel') | |
| $CFG_GITHUB_PROJECT = "archipel"; | |
| // The label you want to apply to the crash reports | |
| $CFG_GITHUB_ISSUE_LABEL = "CrashReport"; | |
| // Contains the login and the Github API token of the crash submitter | |
| $CFG_GITHUB_REPO_SUBMITTER = array("login" => "YourCrashReporter", "token" => "API TOKEN A"); | |
| // Contains the login and the Github API token of the repository owner | |
| $CFG_GITHUB_REPO_OWNER = array("login" => "primalmotion", "token" => "API TOKEN B"); | |
| /* | |
| CONFIG: JABBER NOTIFICATION | |
| */ | |
| // If set to True, the crash report will be notified trought XMP | |
| $CFG_JABBER_ACTIVE = True; | |
| // If you want to use JABBER notification, uncomment the following, | |
| // You need PECL/XMPPHP module | |
| include_once('XMPPHP/XMPP.php'); | |
| // The XMPP server | |
| $CFG_JABBER_SERVER_HOST = "jabber.fr"; | |
| // The port of the XMPP server | |
| $CFG_JABBER_SERVER_PORT = "5222"; | |
| // The JID node | |
| $CFG_JABBER_JID_NODE = "crashreporter"; | |
| // The JID domain | |
| $CFG_JABBER_JID_DOMAIN = $CFG_JABBER_SERVER_HOST; | |
| // the JID password | |
| $CFG_JABBER_JID_PASSWORD = "YOUR XMPP PASSWORD"; | |
| // The list of recipients | |
| $CFG_JABBER_RECIPIENTS = array('usera@domain.com', 'userb@domain.fr'); | |
| /* | |
| CONFIG: IRC NOTIFICATION | |
| */ | |
| // If set to True, the crash report will be notified trought IRC | |
| $CFG_IRC_ACTIVE = True; | |
| // If you want to use IRC notification, uncomment the following, | |
| // You need PECL/SmartIRC | |
| include_once('Net/SmartIRC.php'); | |
| // The IRC server | |
| $CFG_IRC_SERVER_HOST = "irc.freenode.net"; | |
| // The IRC server port | |
| $CFG_IRC_SERVER_PORT = 6667; | |
| // The channels in which you want to notify | |
| $CFG_IRC_CHANNELS = array('#archipel'); | |
| // The nickname to use to post the crash | |
| $CFG_IRC_NICKNAME = "archcrashes"; | |
| /****************************************************************************/ | |
| /* Let the police do its job */ | |
| /****************************************************************************/ | |
| $crashinfo = array("name" => $_POST["name"], | |
| "reason" => $_POST["reason"], | |
| "useragent" => $_POST["userAgent"], | |
| "description" => $_POST["description"], | |
| "stacktrace" => $_POST["stackTrace"], | |
| "version" => $_POST["version"]); | |
| function curl_post($url, array $post = NULL, array $options = array()) | |
| { | |
| $defaults = array( | |
| CURLOPT_POST => 1, | |
| CURLOPT_HEADER => 0, | |
| CURLOPT_URL => $url, | |
| CURLOPT_FRESH_CONNECT => 1, | |
| CURLOPT_RETURNTRANSFER => 1, | |
| CURLOPT_FORBID_REUSE => 1, | |
| CURLOPT_TIMEOUT => 4, | |
| CURLOPT_POSTFIELDS => http_build_query($post) | |
| ); | |
| $ch = curl_init(); | |
| curl_setopt_array($ch, ($options + $defaults)); | |
| if( ! $result = curl_exec($ch)) | |
| { | |
| trigger_error(curl_error($ch)); | |
| } | |
| curl_close($ch); | |
| return $result; | |
| } | |
| function github_post($repo, $label, $submiterinfo, $ownerinfo, $crashinfo) | |
| { | |
| $crashinfo["stacktrace"] = str_replace("),", ")\n", urldecode($crashinfo["stacktrace"])); | |
| $crashinfo["stacktrace"] = str_replace("\\\"", "\"", $crashinfo["stacktrace"]); | |
| $options = array( "login" => $submiterinfo["login"], | |
| "token" => $submiterinfo["token"], | |
| "title" => "[CRASH REPORT] ". $crashinfo["name"] ." (".$crashinfo["version"].")", | |
| "body" => "**Name:** ".$crashinfo["name"]."\n". | |
| "**Reason:** ".$crashinfo["reason"]."\n". | |
| "**User Agent:** ".$crashinfo["useragent"]."\n". | |
| "**Version:** ".$crashinfo["version"]."\n\n". | |
| "**User Description:** ".$crashinfo["description"]."\n\n". | |
| "**StackTrace:**\n\n```".$crashinfo["stacktrace"]."```"); | |
| $ret = json_decode(curl_post("http://github.com/api/v2/json/issues/open/".$ownerinfo["login"]."/$repo", $options)); | |
| $optionsLabel = array( "token" => $ownerinfo["token"], | |
| "login" => $ownerinfo["login"]); | |
| curl_post("https://github.com/api/v2/json/issues/label/add/".$ownerinfo["login"]."/$repo/$label/".$ret->issue->number, $optionsLabel); | |
| return $ret->issue->html_url; | |
| } | |
| function jabber_post($server, $port, $jid_node, $jid_domain, $jid_password, $recipients, $url) | |
| { | |
| $conn = new XMPPHP_XMPP($server, $port, $jid_node, $jid_password, 'xmpphp', $jid_domain, $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO); | |
| $xmppmessage = $message; | |
| try | |
| { | |
| $conn->connect(); | |
| $conn->processUntil('session_start'); | |
| foreach ($recipients as $recipient) | |
| $conn->message($recipient, "Hello, a new crash report has been posted at ". $url); | |
| $conn->disconnect(); | |
| } | |
| catch(XMPPHP_Exception $e) | |
| { | |
| ; | |
| } | |
| } | |
| ini_set('display_errors', 1); | |
| function irc_post($server, $port, $channels, $nick, $url) | |
| { | |
| class mybot | |
| { | |
| public $url; | |
| public $channels; | |
| function onjoin(&$irc, &$data) | |
| { | |
| foreach($this->channels as $channel) | |
| $irc->message(SMARTIRC_TYPE_CHANNEL, $channel, "Hello. A user just report the following crash " . $this->url); | |
| $irc->part($this->channels); | |
| } | |
| function onsent(&$irc, &$data) | |
| { | |
| exit; | |
| } | |
| } | |
| $bot = &new mybot(); | |
| $bot->url = $url; | |
| $bot->channels = $channels; | |
| $irc = &new Net_SmartIRC(); | |
| $irc->setUseSockets(TRUE); | |
| $irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'onjoin'); | |
| $irc->registerActionhandler(SMARTIRC_TYPE_PART, '.*', $bot, 'onsent'); | |
| $irc->connect($server, $port); | |
| $irc->login("archcrashes", 'PHP', 0, 'Net_SmartIRC'); | |
| $irc->join($channels); | |
| $irc->listen(); | |
| $irc->disconnect(); | |
| } | |
| //GITHUB | |
| $url = github_post($CFG_GITHUB_PROJECT, $CFG_GITHUB_ISSUE_LABEL, $CFG_GITHUB_REPO_SUBMITTER, $CFG_GITHUB_REPO_OWNER, $crashinfo); | |
| // XMPP | |
| if ($CFG_JABBER_ACTIVE) | |
| jabber_post($CFG_JABBER_SERVER_HOST, $CFG_JABBER_SERVER_PORT, $CFG_JABBER_JID_NODE, $CFG_JABBER_JID_DOMAIN, $CFG_JABBER_JID_PASSWORD, $CFG_JABBER_RECIPIENTS, $url); | |
| // IRC | |
| if ($CFG_IRC_ACTIVE) | |
| irc_post($CFG_IRC_SERVER_HOST, $CFG_IRC_SERVER_PORT, $CFG_IRC_CHANNELS, $CFG_IRC_NICKNAME, $url); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| # reports.php | |
| # | |
| # Copyright (C) 2010 Antoine Mercadal <antoine.mercadal@inframonde.eu> | |
| # This file is part of ArchipelProject | |
| # http://archipelproject.org | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU Affero General Public License as | |
| # published by the Free Software Foundation, either version 3 of the | |
| # License, or (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU Affero General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU Affero General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| /* | |
| CONFIG: GITHUB ISSUE POSTING | |
| */ | |
| // The name of the github repo (ie. 'archipel') | |
| $CFG_GITHUB_PROJECT = "archipel"; | |
| // The label you want to apply to the crash reports | |
| $CFG_GITHUB_ISSUE_LABEL = "CrashReport"; | |
| // Contains the login and the Github API token of the crash submitter | |
| $CFG_GITHUB_REPO_SUBMITTER = array("login" => "YourCrashReporter", "token" => "API TOKEN A"); | |
| // Contains the login and the Github API token of the repository owner | |
| $CFG_GITHUB_REPO_OWNER = array("login" => "primalmotion", "token" => "API TOKEN B"); | |
| /* | |
| CONFIG: JABBER NOTIFICATION | |
| */ | |
| // If set to True, the crash report will be notified trought XMP | |
| $CFG_JABBER_ACTIVE = True; | |
| // If you want to use JABBER notification, uncomment the following, | |
| // You need PECL/XMPPHP module | |
| include_once('XMPPHP/XMPP.php'); | |
| // The XMPP server | |
| $CFG_JABBER_SERVER_HOST = "jabber.fr"; | |
| // The port of the XMPP server | |
| $CFG_JABBER_SERVER_PORT = "5222"; | |
| // The JID node | |
| $CFG_JABBER_JID_NODE = "crashreporter"; | |
| // The JID domain | |
| $CFG_JABBER_JID_DOMAIN = $CFG_JABBER_SERVER_HOST; | |
| // the JID password | |
| $CFG_JABBER_JID_PASSWORD = "YOUR XMPP PASSWORD"; | |
| // The list of recipients | |
| $CFG_JABBER_RECIPIENTS = array('usera@domain.com', 'userb@domain.fr'); | |
| /* | |
| CONFIG: IRC NOTIFICATION | |
| */ | |
| // If set to True, the crash report will be notified trought IRC | |
| $CFG_IRC_ACTIVE = True; | |
| // If you want to use IRC notification, uncomment the following, | |
| // You need PECL/SmartIRC | |
| include_once('Net/SmartIRC.php'); | |
| // The IRC server | |
| $CFG_IRC_SERVER_HOST = "irc.freenode.net"; | |
| // The IRC server port | |
| $CFG_IRC_SERVER_PORT = 6667; | |
| // The channels in which you want to notify | |
| $CFG_IRC_CHANNELS = array('#archipel'); | |
| // The nickname to use to post the crash | |
| $CFG_IRC_NICKNAME = "archcrashes"; | |
| /****************************************************************************/ | |
| /* Let the police do its job */ | |
| /****************************************************************************/ | |
| $crashinfo = array("name" => $_POST["name"], | |
| "reason" => $_POST["reason"], | |
| "useragent" => $_POST["userAgent"], | |
| "description" => $_POST["description"], | |
| "stacktrace" => $_POST["stackTrace"], | |
| "version" => $_POST["version"]); | |
| function curl_post($url, array $post = NULL, array $options = array()) | |
| { | |
| $defaults = array( | |
| CURLOPT_POST => 1, | |
| CURLOPT_HEADER => 0, | |
| CURLOPT_URL => $url, | |
| CURLOPT_FRESH_CONNECT => 1, | |
| CURLOPT_RETURNTRANSFER => 1, | |
| CURLOPT_FORBID_REUSE => 1, | |
| CURLOPT_TIMEOUT => 4, | |
| CURLOPT_POSTFIELDS => http_build_query($post) | |
| ); | |
| $ch = curl_init(); | |
| curl_setopt_array($ch, ($options + $defaults)); | |
| if( ! $result = curl_exec($ch)) | |
| { | |
| trigger_error(curl_error($ch)); | |
| } | |
| curl_close($ch); | |
| return $result; | |
| } | |
| function github_post($repo, $label, $submiterinfo, $ownerinfo, $crashinfo) | |
| { | |
| $crashinfo["stacktrace"] = str_replace("),", ")\n", urldecode($crashinfo["stacktrace"])); | |
| $crashinfo["stacktrace"] = str_replace("\\\"", "\"", $crashinfo["stacktrace"]); | |
| $options = array( "login" => $submiterinfo["login"], | |
| "token" => $submiterinfo["token"], | |
| "title" => "[CRASH REPORT] ". $crashinfo["name"] ." (".$crashinfo["version"].")", | |
| "body" => "**Name:** ".$crashinfo["name"]."\n". | |
| "**Reason:** ".$crashinfo["reason"]."\n". | |
| "**User Agent:** ".$crashinfo["useragent"]."\n". | |
| "**Version:** ".$crashinfo["version"]."\n\n". | |
| "**User Description:** ".$crashinfo["description"]."\n\n". | |
| "**StackTrace:**\n\n```".$crashinfo["stacktrace"]."```"); | |
| $ret = json_decode(curl_post("http://github.com/api/v2/json/issues/open/".$ownerinfo["login"]."/$repo", $options)); | |
| $optionsLabel = array( "token" => $ownerinfo["token"], | |
| "login" => $ownerinfo["login"]); | |
| curl_post("https://github.com/api/v2/json/issues/label/add/".$ownerinfo["login"]."/$repo/$label/".$ret->issue->number, $optionsLabel); | |
| return $ret->issue->html_url; | |
| } | |
| function jabber_post($server, $port, $jid_node, $jid_domain, $jid_password, $recipients, $url) | |
| { | |
| $conn = new XMPPHP_XMPP($server, $port, $jid_node, $jid_password, 'xmpphp', $jid_domain, $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO); | |
| try | |
| { | |
| $conn->connect(); | |
| $conn->processUntil('session_start'); | |
| foreach ($recipients as $recipient) | |
| $conn->message($recipient, "Hello, a new crash report has been posted at ". $url); | |
| $conn->disconnect(); | |
| } | |
| catch(XMPPHP_Exception $e) | |
| { | |
| ; | |
| } | |
| } | |
| ini_set('display_errors', 1); | |
| function irc_post($server, $port, $channels, $nick, $url) | |
| { | |
| class mybot | |
| { | |
| public $url; | |
| public $channels; | |
| function onjoin(&$irc, &$data) | |
| { | |
| foreach($this->channels as $channel) | |
| $irc->message(SMARTIRC_TYPE_CHANNEL, $channel, "Hello. A user just report the following crash " . $this->url); | |
| $irc->part($this->channels); | |
| } | |
| function onsent(&$irc, &$data) | |
| { | |
| exit; | |
| } | |
| } | |
| $bot = &new mybot(); | |
| $bot->url = $url; | |
| $bot->channels = $channels; | |
| $irc = &new Net_SmartIRC(); | |
| $irc->setUseSockets(TRUE); | |
| $irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'onjoin'); | |
| $irc->registerActionhandler(SMARTIRC_TYPE_PART, '.*', $bot, 'onsent'); | |
| $irc->connect($server, $port); | |
| $irc->login("archcrashes", 'PHP', 0, 'Net_SmartIRC'); | |
| $irc->join($channels); | |
| $irc->listen(); | |
| $irc->disconnect(); | |
| } | |
| //GITHUB | |
| $url = github_post($CFG_GITHUB_PROJECT, $CFG_GITHUB_ISSUE_LABEL, $CFG_GITHUB_REPO_SUBMITTER, $CFG_GITHUB_REPO_OWNER, $crashinfo); | |
| // XMPP | |
| if ($CFG_JABBER_ACTIVE) | |
| jabber_post($CFG_JABBER_SERVER_HOST, $CFG_JABBER_SERVER_PORT, $CFG_JABBER_JID_NODE, $CFG_JABBER_JID_DOMAIN, $CFG_JABBER_JID_PASSWORD, $CFG_JABBER_RECIPIENTS, $url); | |
| // IRC | |
| if ($CFG_IRC_ACTIVE) | |
| irc_post($CFG_IRC_SERVER_HOST, $CFG_IRC_SERVER_PORT, $CFG_IRC_CHANNELS, $CFG_IRC_NICKNAME, $url); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment