function _dig($params) { $user = $params['user']; $channel = $params['channel']; $domain = $params['domain']; $record = $params['record']; if (strpos($domain, '.') === false) { $domain .= '.rockriverstar.com'; } $output = Utils::cmdout($params); $records = array('a' => DNS_A, 'cname' => DNS_CNAME, 'hinfo' => DNS_HINFO, 'mx' => DNS_MX, 'ns' => DNS_NS, 'ptr' => DNS_PTR, 'soa' => DNS_SOA, 'txt' => DNS_TXT, 'aaaa' => DNS_AAAA, 'srv' => DNS_SRV, 'naptr' => DNS_NAPTR, 'a6' => DNS_A6, 'all' => DNS_ALL, 'and' => DNS_ANY); $record = $records[strtolower($record)]; $result = dns_get_record($domain, $record); if (count($result) > 0) { $cols = array_keys(reset($result)); $output .= '<table class="net"><tr>'; foreach ($cols as $col) { $output .= '<th>' . $col . '</th>'; } $output .= '</tr>'; foreach ($result as $res) { $output .= '<tr>'; foreach ($cols as $col) { $output .= '<td>' . $res[$col] . '</td>'; } $output .= '</tr>'; } $output .= '</table>'; } else { $output .= 'No results found.'; } //$output .= '<pre>' . print_r(,1) . '</pre>'; Status::create()->data($output)->user_id($user->id)->channel($channel)->type('message')->cssclass('net ip')->insert(); return true; }
function _queues($params) { $user = $params['user']; $drawers = DB::get()->results("SELECT user_id, username, indexed, added FROM drawers inner join users on users.id = drawers.user_id WHERE indexed LIKE 'queue_%' order by user_id asc, added asc;"); $out = ''; foreach ($drawers as $drawer) { if (preg_match('#_([^_]+)_(\\d+)$#', $drawer->indexed, $matches)) { if ($matches[2] == $user->id) { $out .= "<li>" . '<a href="#" onclick="send(\'/c' . $matches[1] . ' ' . $drawer->username . '\');return false;" style="margin-right:5px;"><img src="'; switch ($matches[1]) { case 'chat': $out .= '/plugins/queue/user_comment_delete.png'; break; default: $out .= '/plugins/queue/phone_delete.png'; break; } $out .= '"></a>' . "{$matches[1]} queued with {$drawer->username} <small>" . date('M j, Y h:ia', strtotime($drawer->added)) . "</small></li>"; } } } if ($out == '') { $out = 'You have no active queues.'; } else { $out = '<ul>' . $out . '</ul>'; } $out = Utils::cmdout($params) . $out; Status::create()->data($out)->type('system')->user_to($user->id)->cssclass('ok')->insert(); return true; }
function _markov($params) { $user = $params['user']; $channel = $params['channel']; $msg = Utils::cmdout($params); $data = DB::get()->val("SELECT data FROM presence WHERE data <> '' AND cssclass='' AND data NOT LIKE '%<%' AND user_id = :user_id ORDER BY RAND() LIMIT 1", array('user_id' => $user->id)); list($word, ) = explode(' ', $data, 2); $output = $word . ' '; for ($z = 0; $z < 20; $z++) { $data = DB::get()->val("SELECT data FROM presence WHERE data LIKE :chain AND cssclass='' AND data NOT LIKE '%<%' AND user_id = :user_id ORDER BY RAND() LIMIT 1", array('user_id' => $user->id, 'chain' => '%' . $word . '%')); if ($data) { $words = explode(' ', $data); $index = array_search($word, $words); if ($index !== false) { if ($word = $words[$index + 1]) { $output .= $word . ' '; } } } else { break; } } $msg .= trim($output); Status::create()->data($msg)->user_id($user->id)->cssclass('markov')->channel($channel)->insert(); return true; }
function _contact($params) { $criteria = $params['criteria']; $user = $params['user']; $channel = $params['channel']; $api = $this->get_api(); if (is_numeric($criteria)) { $bycriteria = array('id' => $criteria); } else { $bycriteria = array('display_name' => $criteria); } $results = $api->requestArray('Contact/Get', $bycriteria); if (isset($results['Result'])) { $result = $results['Result']; if (isset($result['is_error'])) { if ($result['is_error']) { // Error message in $result['error_message'] $msg = $result['error_message']; } else { // No error, just no results. $msg = 'No contacts match that criteria.'; } Status::create()->data($msg)->type('system')->user_to($user->id)->cssclass('error')->channel($channel)->insert(); } elseif (isset($result['contact_id'])) { // Single result was sent back. $callnum = $this->get_call_num($result['phone']); $msg = Utils::cmdout($params); $msg .= '<span class="crm-name"> <a href="http://crm.rockriverstar.com/civicrm/contact/view?reset=1&cid=' . $result['contact_id'] . '" target="_blank">' . $result['display_name'] . '</a>' . '</span>'; $msg .= '<table class="crm-data">'; $msg .= '<tr><td>Primary Phone: ' . $this->get_call_num($result['phone']) . '</td>'; $msg .= '<td>Primary Email: ' . $result['email'] . '</td></tr>'; $msg .= '<tr>' . '<td>Title: ' . $result['job_title'] . '</td>' . '<td>Employer: ' . $result['current_employer'] . '</td>' . '</tr>'; $msg .= '</table>'; Status::create()->data($msg)->user_id($user->id)->cssclass('crm-contact')->channel($channel)->insert(); } else { // Multiple results. $msg = Utils::cmdout($params); $msg .= '<table><thead><tr><th>Name</th><th>Phone</th><th>Email</th></tr></thead>'; foreach ($result as $contact) { if (!$contact['is_deleted']) { $callnum = $this->get_call_num($contact['phone']); $msg .= '<tr>'; $msg .= '<td><a href="http://crm.rockriverstar.com/civicrm/contact/view?reset=1&cid=' . $contact['contact_id'] . '" target="_blank">' . $contact['display_name'] . '</a></td>'; $msg .= '<td>' . $this->get_call_num($contact['phone']) . '</td>'; $msg .= '<td><a href="mailto:' . $contact['email'] . '">' . $contact['email'] . '</a></td>'; $msg .= '</tr>'; } } $msg .= '</table>'; Status::create()->data($msg)->user_id($user->id)->cssclass('crm-contact')->channel($channel)->insert(); } } else { // Something has gone horribly wrong. Status::create()->data('Something has gone horribly wrong.')->type('system')->user_to($user->id)->cssclass('error')->channel($channel)->insert(); } return true; }
function _jar($params) { $jar = $params['jar']; $criteria = $params['criteria']; $user = $params['user']; $channel = $params['channel']; $msg = Utils::cmdout($params); $msg .= "send this to the jar : " . $criteria; Status::create()->data($msg)->user_id($user->id)->cssclass('brainjar')->channel($channel)->insert(); return true; }
function _calc($params) { $user = $params['user']; $channel = $params['channel']; $query = $params['query']; $query = html_entity_decode($query); $calc = new Calc($query); echo htmlspecialchars($expression) . "\n"; echo $calc->infix() . " = " . $calc->calc() . "\n"; $output = Utils::cmdout($params); $output .= $calc->infix() . " = " . $calc->calc(); Status::create()->data($output)->user_id($user->id)->channel($channel)->insert(); return true; }
function _sound($params) { $file = $params['file']; $style = $params['style']; $channel = $params['channel']; $user = Auth::user(); $cssclass = array('sound'); if ($style != '') { $cssclass[] = $style; } if ($filerow = DB::get()->row('SELECT * FROM files WHERE filename = :file', array('file' => $file))) { Status::create()->data(Utils::cmdout($params))->user_id($user->id)->channel($channel)->cssclass(implode(' ', $cssclass))->js('bareffect(function(){play(' . json_encode($filerow->url) . ');});')->insert(); } else { Status::create()->data('Sorry, that file was not found in the file listing.')->user_id($user->id)->type('system')->cssclass('error')->user_to($user->id)->insert(); } return true; }
function _svn_create($params) { $reponame = $params['reponame']; $channel = $params['channel']; $user = Auth::user(); if (preg_match('%^\\w+$%', $reponame)) { $repodir = '/var/svn/repos/' . $reponame; $output = ''; $output .= "\n" . shell_exec('svnadmin create ' . $repodir); $output .= "\n" . shell_exec('chmod -R g+w ' . $repodir); $output .= "\n" . shell_exec('ln -s /var/svn/repos/barchat/hooks/post-commit ' . $repodir . '/hooks/post-commit'); $output .= "\n" . shell_exec('svn mkdir --username rrs --password 1dc6e78c12a7ec76a349bc63730b85aa -m "Initial directory creation" https://sol.rockriverstar.com/svn/' . $reponame . '/trunk https://sol.rockriverstar.com/svn/' . $reponame . '/tags https://sol.rockriverstar.com/svn/' . $reponame . '/branches 2>&1'); Status::create()->data(Utils::cmdout($params) . 'Created repo "' . $reponame . '" at https://sol.rockriverstar.com/svn/' . $reponame . '<br/><pre>' . str_replace("\n", '<br>', trim($output)) . '</pre>')->user_id($user->id)->channel($channel)->cssclass('svn')->insert(); } else { Status::create()->data('Sorry, repo names must not already exist and must not contain spaces.')->user_id($user->id)->type('system')->cssclass('error')->user_to($user->id)->insert(); } return true; }
function _api($params) { $user = $params['user']; $name = $params['name']; $channel = $params['channel']; $output = Utils::cmdout($params); $searchurl = 'http://api.drupal.org/api/search/6/' . urlencode($name); $thtml = file_get_contents($searchurl); $content = SimpleHTML::str_get_html($thtml); $tbody = $content->find('table[class=sticky-enabled]', 0); if (!is_object($tbody)) { $code = $content->find('.active code', 0); $output .= '<code style="font-size: 1.5em;line-height: 2em"><a target="_blank" href="' . $searchurl . '">Reference</a>:' . $code->innertext . '</code>'; } else { $trs = $tbody->find('tr'); $modules = ''; $count = 0; array_shift($trs); foreach ($trs as $tr) { $tds = $tr->find('td'); $a = $tds[0]->find('a', 0); $modules .= '<li><a target="_blank" href="http://drupal.org/' . $a->href . '">' . $a->innertext . '</a>'; // $modules .= htmlspecialchars($tds[2]->innertext); $modules .= '</li>'; if (++$count > 9) { break; } } if ($modules != '') { $output .= '<ul style="margin-left:30px;">' . $modules . '</ul>'; } else { $output .= '<p>No results.</p>'; } } Status::create()->data($output)->user_id($user->id)->cssclass('drupal api')->channel($channel)->insert(); return true; }
function _stats($params) { $nickname = $params['nickname']; $user = $params['user']; $channel = $params['channel']; $statsql = "\r\n\t\t\tselect\r\n\t\t\t\tnp.title as project,\r\n\t\t\t\tccs.csid as csid,\r\n\t\t\t\tccs.case_state_name as status,\r\n\t\t\t\tcount(*) as case_count,\r\n\t\t\t\tp.value as purl\r\n\t\t\tfrom\r\n\t\t\t\tpurl p,\r\n\t\t\t\tog_ancestry oa,\r\n\t\t\t\tnode n,\r\n\t\t\t\tnode_revisions r,\r\n\t\t\t\tusers u,\r\n\t\t\t\tcasetracker_case cc,\r\n\t\t\t\tcasetracker_case cc2,\r\n\t\t\t\tcasetracker_case cc3,\r\n\t\t\t\tcasetracker_case_states ccs,\r\n\t\t\t\tcasetracker_case_states ccs2,\r\n\t\t\t\tcasetracker_case_states ccs3,\r\n\t\t\t\tnode np\r\n\t\t\twhere\r\n\t\t\t\tp.id = oa.group_nid\r\n\t\t\t\tand oa.nid = n.nid\r\n\t\t\t\tand n.vid = r.vid\r\n\t\t\t\tand n.type = 'casetracker_basic_case'\r\n\t\t\t\tand u.uid = n.uid\r\n\t\t\t\tand cc.vid = n.vid\r\n\t\t\t\tand cc.case_status_id = ccs.csid\r\n\t\t\t\tand cc2.vid = n.vid\r\n\t\t\t\tand cc2.case_priority_id = ccs2.csid\r\n\t\t\t\tand cc3.vid = n.vid\r\n\t\t\t\tand cc3.case_type_id = ccs3.csid\r\n\t\t\t\tand ccs.case_state_name <> 'Closed'\r\n\t\t\t\tand ccs.case_state_name <> 'Duplicate'\r\n\t\t\t\tand p.id = np.nid\r\n\t\t"; $uid = false; if ($nickname == '*') { $statsql .= ' group by project, status order by project, status;'; $uid = -1; $sqlparams = array(); } elseif ($nickname != '') { $msg = 'The user "' . htmlspecialchars($params['nickname']) . '" does not exist.'; $target = PresenceController::_userstr($nickname); if ($target) { $msg = 'The user "' . htmlspecialchars($params['nickname']) . '" does not have a PD account associated in the options table.'; $sql = "SELECT value FROM options WHERE grouping = 'identity' AND name = 'pduid' AND user_id = :user_id;"; $uid = DB::get()->val($sql, array('user_id' => $target->id)); } $statsql .= ' and cc.assign_to = :uid group by project, status order by project, status;'; $sqlparams = array('uid' => $uid); } else { $msg = 'You do not have a PD account associated in the options table.'; $uid = Option::get('identity', 'pduid'); $statsql .= ' and cc.assign_to = :uid group by project, status order by project, status;'; $sqlparams = array('uid' => $uid); } if (!$uid || $uid == 0) { Status::create()->data(Utils::cmdout($params) . $msg)->type('system')->cssclass('error')->channel($channel)->insert(); return true; } if (!$this->pdb()) { Status::create()->data('Could not connect to the projects database.')->type('system')->user_to($user->id)->cssclass('error')->channel($channel)->insert(); return true; } $stats = $this->pdb()->results($statsql, $sqlparams); if (count($stats) == 0) { $msg = Utils::cmdout($params); Status::create()->data($msg . 'No open cases found.')->type('system')->cssclass('stats')->channel($channel)->insert(); } else { $msg = Utils::cmdout($params); foreach ($stats as $stat) { $statuses[$stat->csid] = $stat->status; $projects[$stat->purl] = $stat->project; $count[$stat->project][$stat->status] = $stat->case_count; } $msg .= '<table><thead><tr><th>Project Name</th>'; foreach ($statuses as $status) { $msg .= '<th>' . $status . '</th>'; } $msg .= '</tr></thead>'; foreach ($projects as $purl => $project) { $msg .= '<tr><th><a href="http://projects.rockriverstar.com/' . $purl . '/casetracker" target="_blank" onclick="send(\':' . $purl . '\');return false;">' . $project . '</a></th>'; foreach ($statuses as $csid => $status) { if (isset($count[$project][$status])) { $msg .= '<td><a href="http://projects.rockriverstar.com/' . $purl . '/casetracker/filter?keys='; if ($uid > 0) { $msg .= '&assign_to[]=' . $uid; } $msg .= '&pid=All&case_priority_id=All&case_status_id=' . $csid . '" target="_blank">' . $count[$project][$status] . '</a></td>'; } else { $msg .= '<td class="no_cases">—</td>'; } } $msg .= '</tr>'; } $msg .= '</table>'; Status::create()->data($msg)->user_id($user->id)->cssclass('stats')->channel($channel)->insert(); } return true; }
function _archive($params) { $user = $params['user']; $channel = $params['channel']; DB::get()->query("INSERT INTO archive SELECT * FROM presence WHERE msgtime < ?", array(date('Y-m-d H:i:s', strtotime('-1 month')))); DB::get()->query("DELETE FROM presence WHERE msgtime < ?", array(date('Y-m-d H:i:s', strtotime('-1 month')))); DB::get()->query("OPTIMIZE TABLE presence"); $output = Utils::cmdout($params); Status::create()->data($output . 'Messages prior to one month ago have been moved to the archive table.')->user_id($user->id)->cssclass('archive')->channel($channel)->insert(); return true; }
function _cant_connect() { Status::create()->data(Utils::cmdout($params) . 'Couldn\'t connect to http_auth database.')->user_id($user->id)->channel($channel)->cssclass('httpauth')->insert(); return true; }
function _coffee($params) { $user = $params['user']; $channel = $params['channel']; $output = Utils::cmdout($params); $msg = array(); if (isset($params['name'])) { if (in_array(strtolower($nickname), array(strtolower($user->nickname), strtolower($user->username), 'me', 'myself'))) { $nickname = $user->nickname; } else { $nickname = $params['name']; } $target = Utils::user_from_name($nickname); } else { $nickname = $user->nickname; $target = $user; } $restriction = DB::get()->val('SELECT value FROM options WHERE user_id = :user_id AND grouping = "coffee" and name = "restriction"', array('user_id' => $target->id)); if (!empty($restriction)) { $msg[] = $restriction; } else { // process alcohol $bal = DB::get()->val('SELECT value FROM options WHERE user_id = :user_id AND grouping = "beer" and name = "bal"', array('user_id' => $target->id)); $lastbeer = DB::get()->val('SELECT value FROM options WHERE user_id = :user_id AND grouping = "beer" and name = "lastbeer"', array('user_id' => $target->id)); $lastbeer = intval($lastbeer); $bal = max(0, $bal - (strtotime('now') - $lastbeer) / 3600 * 0.04); if ($bal > 0) { $msg[] = 'The coffee helps ' . $target->nickname . " sober up a bit."; $bal = max(0, $bal - (strtotime('now') - $lastbeer) / 3600 * 0.04 - 0.04); if ($bal <= 0) { $msg[] = $target->nickname . " is now completely sober."; } DB::get()->query('DELETE FROM options WHERE user_id = :user_id AND grouping = "beer" and name = "bal"', array('user_id' => $target->id)); DB::get()->query('DELETE FROM options WHERE user_id = :user_id AND grouping = "beer" and name = "lastbeer"', array('user_id' => $target->id)); DB::get()->query('INSERT INTO options (user_id, grouping, name, value) VALUES (:user_id, "beer", "bal", :bal)', array('user_id' => $target->id, 'bal' => $bal)); DB::get()->query('INSERT INTO options (user_id, grouping, name, value) VALUES (:user_id, "beer", "lastbeer", :lastbeer)', array('user_id' => $target->id, 'lastbeer' => time())); } // Get BAL $caffeine = DB::get()->val('SELECT value FROM options WHERE user_id = :user_id AND grouping = "coffee" and name = "caffeine"', array('user_id' => $target->id)); $lastcoffee = DB::get()->val('SELECT value FROM options WHERE user_id = :user_id AND grouping = "coffee" and name = "lastcoffee"', array('user_id' => $target->id)); $lastcoffee = intval($lastcoffee); if ($lastcoffee < strtotime('today') && strtotime('now') - $lastcoffee > 2 * 60 * 60) { array_unshift($msg, $target->nickname . ' gets his first coffee of the day.'); $caffeine = 0.04; } else { $precaf = $caffeine; $caffeine = max(0, $caffeine - (strtotime('now') - $lastcoffee) / 3600 * 0.04) + 0.04; $caffeinepct = floor($caffeine * 100); $msg[] = $target->nickname . "'s caffeine level is {$caffeinepct}%."; if ($precaf > 0.32) { array_unshift($msg, $target->nickname . " is maintaining a state of caffeinated nirvana."); } else { array_unshift($msg, $target->nickname . ' gets another coffee.'); // process caffeine if ($caffeine > 0.32) { $msg[] = $target->nickname . " is so jittery that he can barely hold his hands still enough to drink another coffee."; } elseif ($caffeine > 0.28) { $msg[] = $target->nickname . " is so caffeinated, he seems to be in three places at once."; } elseif ($caffeine > 0.24) { $msg[] = $target->nickname . " it speaking so fast that he sounds like Alvin from the chipmunks."; } elseif ($caffeine > 0.2) { $msg[] = $target->nickname . "'s left eye won't stop twitching."; } elseif ($caffeine > 0.16) { $msg[] = $target->nickname . " is frequently hitting the same key multiple times by accident."; } elseif ($caffeine > 0.12) { $msg[] = $target->nickname . " is buzzing between projects productively."; } elseif ($caffeine > 0.08) { $msg[] = $target->nickname . " is perked up."; } } } DB::get()->query('DELETE FROM options WHERE user_id = :user_id AND grouping = "coffee" and name = "caffeine"', array('user_id' => $target->id)); DB::get()->query('DELETE FROM options WHERE user_id = :user_id AND grouping = "coffee" and name = "lastcoffee"', array('user_id' => $target->id)); DB::get()->query('INSERT INTO options (user_id, grouping, name, value) VALUES (:user_id, "coffee", "caffeine", :bal)', array('user_id' => $target->id, 'bal' => $caffeine)); DB::get()->query('INSERT INTO options (user_id, grouping, name, value) VALUES (:user_id, "coffee", "lastcoffee", :lastcoffee)', array('user_id' => $target->id, 'lastcoffee' => time())); } if (isset($params['name'])) { array_unshift($msg, $user->nickname . ' orders ' . $target->nickname . ' some coffee.'); } $output .= implode('<br />', $msg); if (empty($restriction)) { $js = <<<COFFEESCRIPT bareffect(coffee); COFFEESCRIPT; } else { $js = ''; } DB::get()->query("INSERT INTO presence (data, user_id, channel, cssclass, js) VALUES (:msg, :user_id, :channel, 'coffee', :js)", array('msg' => $output, 'user_id' => $user->id, 'channel' => $channel, 'js' => $js)); return true; }