Assembla home | Assembla project page
 

root/trunk/Phergie/Plugin/Eval.php

Revision 223, 3.3 kB (checked in by Slynderdale, 7 months ago)

Various bug fixes and enhancements:

Notable Changes:

  • Bot.php: The auto loader now strips out the "Phergie_" prefix from class names while getting the path to the class file to include for those who don't have the bot in a directory called Phergie. Both the Phergie directory and the parent directory were added to the include path. Also added a check to see if they have a timezone is set in PHP.ini, if not, set the timezone to the default timezone to prevent strict errors while using date.
  • Streams.php: Added support for invite requests and also fixed a small bug where an empty command gets ent to call_user_func due to a packet getting cut off.
  • Base.php: Added onInvite and changed fromAdmin so the first argunent needs to be set to true for hostmask admin checking.
  • Lart.php: Improved lart a bit and fixed bugs where you couldn't remove certain terms due to spacing/character casing issues
  • Seen.php: Added a quote command to get a random quote by a specified user
  • Users.php: Renamed Users to ServerInfo to prepare it for future changes to make it store more information about users, channels and the server. Also fixed a bug where halfops and voiced users were considered an OP.
Line 
1 <?php
2
3 /**
4  * Handles requests from administrators to evaluate a string
5  */
6 class Phergie_Plugin_Eval extends Phergie_Plugin_Abstract_Command
7 {
8     /**
9      * Flag indicating whether or not the plugin is an admin plugin or not
10      *
11      * @var bool
12      */
13     public $needsAdmin = true;
14
15     /**
16      * Evaluates the given string and outputs the evaluated statement while any
17      * any dumped data gets dumped to the console.
18      *
19      * @return void
20      */
21     public function onDoEval($code)
22     {
23         $user = $this->event->getNick();
24
25         // Check to see if the admin is a hostmask admin only and not an op
26         if ($this->fromAdmin(true)) {
27             $code = trim($code);
28             if (empty($code)) {
29                 return;
30             }
31
32             // Check to see if the -r arg is set, if so, run the code as is, else prepend return
33             if (substr(strtolower($code), 0, 2) == '-r') {
34                 $code = trim(substr($code, 2));
35             } else {
36                 $code = trim((strtolower(substr($code, 0, 6)) != 'return' ? 'return ' : '') . $code);
37             }
38
39             if (!empty($code)) {
40                 if (substr($code, -1) != ';') {
41                     $code .= ';';
42                 }
43
44                 // Use output buffering to catch any output from eval
45                 ob_start();
46                 $eval = eval($code);
47                 $contents = ob_get_contents();
48                 ob_end_clean();
49
50                 // Dump the content of the output buffering to the console
51                 if (!empty($contents)) {
52                     $this->debug('OUTPUT:' . PHP_EOL . trim($contents));
53                     unset($contents);
54                 }
55
56                 if (!empty($eval)) {
57                     $this->doPrivmsg($this->event->getSource(), trim($eval));
58                     unset($eval);
59                 }
60             }
61         } else {
62             $this->doNotice($user, 'You do not have permission to use eval.');
63         }
64     }
65
66     /**
67      * Executes the given string and outputs the last line that exec returns
68      * while the full exec request gets dumped to the console if the-c flag
69      * is specified.
70      *
71      * @return void
72      */
73     public function onDoExec($code)
74     {
75         $user = $this->event->getNick();
76
77         // Check to see if the admin is a hostmask admin only and not an op
78         if ($this->fromAdmin(true)) {
79             $code = trim($code);
80             if (empty($code)) {
81                 return;
82             }
83
84             $console = false;
85             // Check to see if the -c arg is set, if so, dump the entire exec result to console
86             if (substr(strtolower($code), 0, 2) == '-c') {
87                 $code = trim(substr($code, 2));
88                 $console = true;
89             }
90
91             if (!empty($code)) {
92                 $exec = exec($code, $output);
93                 if (!empty($exec)) {
94                     $this->doPrivmsg($this->event->getSource(), trim($exec));
95                     unset($exec);
96                 }
97                 if (!empty($output)) {
98                     if ($console) {
99                         $this->debug('OUTPUT:' . PHP_EOL . implode(PHP_EOL, $output));
100                     }
101                     unset($output);
102                 }
103             }
104         } else {
105             $this->doNotice($user, 'You do not have permission to use exec.');
106         }
107     }
108 }
109
Note: See TracBrowser for help on using the browser.