]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Further on the channel details
authorValerie Pond <redacted>
Wed, 29 Mar 2023 14:38:15 +0000 (15:38 +0100)
committerValerie Pond <redacted>
Wed, 29 Mar 2023 14:38:15 +0000 (15:38 +0100)
Classes/class-cmodes.php
channels/details.php
composer.lock
misc/channel-lookup-misc.php
vendor/phpmailer/phpmailer/src/DSNConfigurator.php [new file with mode: 0644]

index a8c7037f93dac921b9b16a9d47ffd26cc3cae729..93b7924f5c244cc2b2a03d2cdd2209abab76b637 100644 (file)
@@ -4,7 +4,8 @@
  * A set of reference lists
  */
 class IRCList {
-    static $cmodes =
+
+    public static $cmodes =
     [
         "a" =>  [
             "name" => "Admin",
@@ -21,6 +22,11 @@ class IRCList {
             "description" => "Prevents users from sending CTCP's to the channel",
             "requires" => "HalfOp"
         ],
+        "d" => [
+            "name" => "Delay Join",
+            "description" => "Delay showing joins until someone actually speaks.",
+            "requires" => "Operator"
+        ],
         "e" => [
             "name" => "Ban Exemption",
             "description" => "Marks an exemption from channel bans",
@@ -191,4 +197,19 @@ class IRCList {
             "requires" => "Server"
         ]
     ];
+    static function setmodes($modes)
+    {
+        $g = [];
+        if (is_array($modes))
+        {
+            self::$uplink = $modes;
+            return;
+        }
+        else if (!strstr($modes,","))
+            $g = [$modes];
+        else $g = split($g,",");
+        self::$uplink = $g;
+    }
+    static $uplink = [];
+    
 }
\ No newline at end of file
index 115d24289797b71bcf4afd44f32eb74c72b1a186..8fb37f5af3debb5461dd0df5a8d2fb695421abf5 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 require_once "../common.php";
 require_once "../header.php";
-require_once "../misc/channel-lookup-misc.php";
 
+if ($uplink = $rpc->server()->get())
+       IRCList::setmodes($uplink->server->features->chanmodes);
 $title = "Channel Lookup";
 $channel = "";
 $channame = "";
@@ -291,11 +292,11 @@ if (!empty($_POST))
 </div>
 
 <!-- Modal for Add Ban Exceptions -->
-<div class="modal fade" id="except" tabindex="-1" role="dialog" aria-labelledby="add_except_modal" aria-hidden="true">
+<div class="modal fade" id="except" tabindex="-1" role="dialog" aria-labelledby="except" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
                <div class="modal-content">
                <div class="modal-header">
-                       <h5 class="modal-title" id="add_except_modal">Add New Channel Ban Exception</h5>
+                       <h5 class="modal-title" >Add New Channel Ban Exception</h5>
                        <div type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                </div>
@@ -342,6 +343,32 @@ if (!empty($_POST))
        </div>
 </div>
 
+<!-- Modal for Edit Channel Modes -->
+<div class="modal fade" id="editchmodes" tabindex="-1" role="dialog" aria-labelledby="editchmodes" aria-hidden="true">
+       <div class="modal-dialog  modal-dialog-centered" role="document">
+               <div class="modal-content">
+               <div class="modal-header">
+                       <h5 class="modal-title" id="editchmodes">Edit Channel Modes</h5>
+                       <div type="button" class="close" data-dismiss="modal" aria-label="Close">
+                       <span aria-hidden="true">&times;</span>
+               </div>
+               </div>
+               <div class="modal-body">
+                       <form method="post">
+                       
+                       <?php generate_edit_chmodes($channelObj); ?>
+
+               </div>
+               <div class="modal-footer">
+                       <input type="hidden" id="server" name="add_chex" value="e"></input>
+                       <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
+                       <button type="submit" action="post" class="btn btn-danger">Update</button>
+                       </form>
+               </div>
+               </div>
+       </div>
+</div>
+
 <br>
 <h6>
        Topic:<br></h6>
@@ -441,19 +468,22 @@ if ($topicset)
                
                <div class="tab-content">
                
-               <div role="tabpanel" class="tab-pane fade in" id="chanmodes">
-                       <p class="card-text"><?php generate_html_chansettings($channelObj); ?></p>
-               </div>
-               
-               <div role="tabpanel" class="tab-pane fade in" id="chanbans">
-                       <p class="card-text"><?php generate_chanbans_table($channelObj); ?></p>
-               </div>
-               <div role="tabpanel" class="tab-pane fade in" id="chaninv">
-                       <p class="card-text"><?php generate_chaninvites_table($channelObj); ?></p>
-               </div>
-               <div role="tabpanel" class="tab-pane fade in" id="chanex">
-                       <p class="card-text"><?php generate_chanexcepts_table($channelObj); ?></p>
-               </div>
+                       <div role="tabpanel" class="tab-pane fade in" id="chanmodes">
+                               <p class="card-text"><?php generate_html_chansettings($channelObj); ?></p>
+                       </div>
+                       
+                       <div role="tabpanel" class="tab-pane fade in" id="chanbans">
+                               <p class="card-text"><?php generate_chanbans_table($channelObj); ?></p>
+                       </div>
+                       <div role="tabpanel" class="tab-pane fade in" id="chaninv">
+                               <p class="card-text"><?php generate_chaninvites_table($channelObj); ?></p>
+                       </div>
+                       <div role="tabpanel" class="tab-pane fade in" id="chanex">
+                               <p class="card-text"><?php generate_chanexcepts_table($channelObj); ?></p>
+                       </div>
+                       <div role="tabpanel" class="tab-pane fade in" id="chanmodes_edit">
+                               <p class="card-text"><?php /* insert hacks here */ ?></p>
+                       </div>
                
                </div>
         </div>
index 89d4bf7eb155f2fdd5459b508a8f72ba57247d2b..63fd5b6ec6321ffa271dec7d699915235f121281 100644 (file)
             "source": {
                 "type": "git",
                 "url": "https://github.com/unrealircd/unrealircd-rpc-php.git",
-                "reference": "1446a5db1b55608472c42aea7c5dc0a4c66558f1"
+                "reference": "249f865d50d543087288a4fae426a444fd39ec24"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/unrealircd/unrealircd-rpc-php/zipball/1446a5db1b55608472c42aea7c5dc0a4c66558f1",
-                "reference": "1446a5db1b55608472c42aea7c5dc0a4c66558f1",
+                "url": "https://api.github.com/repos/unrealircd/unrealircd-rpc-php/zipball/249f865d50d543087288a4fae426a444fd39ec24",
+                "reference": "249f865d50d543087288a4fae426a444fd39ec24",
                 "shasum": ""
             },
             "require": {
                 "issues": "https://github.com/unrealircd/unrealircd-rpc-php/issues",
                 "source": "https://github.com/unrealircd/unrealircd-rpc-php/tree/main"
             },
-            "time": "2023-03-27T08:42:38+00:00"
+            "time": "2023-03-27T11:36:49+00:00"
         }
     ],
     "packages-dev": [],
     "prefer-lowest": false,
     "platform": [],
     "platform-dev": [],
-    "plugin-api-version": "2.3.0"
+    "plugin-api-version": "2.2.0"
 }
index 81d435c646fd1fe0908ade676dcedfc3d5cfa88d..8c101b8ff9ecbef8b5b7b440883066075e9190b6 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 function generate_chanbans_table($channel)
 {
        global $rpc;
@@ -135,12 +134,14 @@ function generate_chan_occupants_table($channel)
        <thead class="table-info">
                <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
                <th>Name</th>
-               <th>Host</th>
                <th>Status</th>
+               <th>Host</th>
        </thead>
        <tbody>
                <?php
                $m = sort_user_list($channel->members);
+
+               $i = 0;
                foreach ($m as $member)
                {
                        $lvlstring = "";
@@ -174,14 +175,15 @@ function generate_chan_occupants_table($channel)
                                        }
                                }
                        }
+                       
                        echo "<tr>";
                        ?><form method="post" action=""><?php
                        $disabled = (current_user_can(PERMISSION_EDIT_CHANNEL_USER)) ? "" : "disabled";
                        $disabledcolor = ($disabled) ? "btn-secondary" : "btn-primary";
                        echo "<td scope=\"row\"><input type=\"checkbox\" value='$member->id' name=\"checkboxes[]\"></td>";
                        echo "<td><a href=\"".BASE_URL."users/details.php?nick=$member->id\">".htmlspecialchars($member->name)."</a></td>";
-                       echo "<td><code>".(property_exists($member, 'hostname') ? htmlspecialchars($member->hostname) : "")."</code></td>";
                        echo "<td class='text-right'>$lvlstring</td>";
+                       echo "<td><code>".((property_exists($member, 'hostname')) ? htmlspecialchars($member->hostname) : "")."</code></td>";
                        echo "</tr>";
                }
 
@@ -195,9 +197,11 @@ function generate_chan_occupants_table($channel)
 
 function generate_html_chansettings($channel)
 {
-       global $rpc;
        ?>
-
+       
+       <p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#editchmodes" <?php echo (current_user_can(PERMISSION_EDIT_CHANNEL)) ? "" : "disabled"; ?>>
+                       Edit
+       </button></p>
     <table class="table-sm table-responsive caption-top table-hover">
         <tbody>
            <?php
@@ -210,15 +214,12 @@ function generate_html_chansettings($channel)
                                $tok = split($fmodes);
                                $modes = $tok[0];
                                $params = rparv($fmodes);
-                               $uplink = $rpc->server()->get();
-                               if (!$uplink) // whaaaa?!¿
-                                       die("Could not find our uplink. Weird and should not have happened");
-                               
-                               $groups = $uplink->server->features->chanmodes;
                                
                 for ($i=0; ($mode = (isset($modes[$i])) ? $modes[$i] : NULL); $i++)
                 {
                                        $modeinfo = IRCList::$cmodes[$mode];
+                                       if (!$modeinfo)
+                                               continue;
                                        ?>
                                                <tr>
                                                        <th><?php echo $modeinfo['name']; ?></th>
@@ -237,6 +238,71 @@ function generate_html_chansettings($channel)
     <?php
 }
 
+function generate_edit_chmodes($chan)
+{
+       ?>
+       
+    <table class="table-sm table-responsive caption-top table-hover">
+        <tbody>
+           <?php
+                               if (!isset($chan->modes))
+                               {
+                                       echo "No modes set";
+                                       return;
+                               }
+                               $fmodes = $chan->modes;
+                               $tok = split($fmodes);
+                               $modes = $tok[0];
+                               $params = rparv($fmodes);
+                               $paramed_modes = sort_paramed_modes($modes, $params);
+                               foreach (IRCList::$uplink as $m)
+                                       for ($i=0; ($mode = (isset($m[$i])) ? $m[$i] : NULL); $i++)
+                                       {
+                                               $group = get_chmode_group($mode);
+                                               if (!$group || $group == 1)
+                                                       continue;
+                                               $modeinfo = (isset(IRCList::$cmodes[$mode])) ? IRCList::$cmodes[$mode] : ['name' => "Unknown mode", 'description' => "Unknown mode +$mode"];
+                                               $checked = (strstr($modes,$mode)) ? "checked" : "";
+                                               $disabled = "";
+                                               switch($mode)
+                                               {
+                                                       case "Z":
+                                                       case "d":
+                                                               $disabled = "disabled";
+                                               }
+                                               ?>
+                                                       <tr><th scope="row"><input <?php echo $checked." ".$disabled; ?> type="checkbox" value='$mode' name="newmodes[]"></th>
+                                                               <th data-toggle="tooltip" data-placement="top" title="<?php echo htmlspecialchars($modeinfo['description']); ?>"><?php echo htmlspecialchars($modeinfo['name'])." (<code>+$mode</code>)";  ?></th>
+                                                               <td>
+                                                                       <?php
+                                                                               
+                                                                               if ($group == 2 || $group == 3)
+                                                                               {
+                                                                                       ?><input type="text" class="form-control" name="<?php echo $mode; ?>" id="<?php echo $mode; ?>" value="<?php echo ($checked) ? htmlspecialchars($paramed_modes[$mode]) : ""; ?>"><?php
+                                                                               }
+                                                                       ?>
+                                                               </td>
+                                                       </tr>
+                                               <?php
+                                       }
+                               
+
+           ?>
+        </tbody>
+    </table>
+
+    <?php
+}
+
+function get_chmode_group(string $mode) : int
+{
+       foreach(IRCList::$uplink as $i => $grp)
+               if (strstr($grp,$mode))
+                       return $i + 1;
+
+       return 0; // invalid
+}
+
 /**
  *     Force loading of a particular modal by name
  */
@@ -251,6 +317,24 @@ function chlkup_autoload_modal($name)
        <?php
 }
 
+/**
+ * Returns an array of parametered modes and their params
+ */
+function sort_paramed_modes($modes, $params) : array
+{
+       $m = [];
+       for ($i=0; isset($modes[$i]) && $mode = $modes[$i]; $i++)
+       {
+               $group = get_chmode_group($mode);
+               if ($group != 2 && $group != 3)
+                       continue;
+               $p = split($params);
+               $m[$mode] = $p[0];
+               $p[0] = NULL;
+               $params = glue($p);
+       }
+       return $m;
+}
 
 function _do_chan_item_delete($chan, string $type, array $list, array &$errors) : bool
 {
diff --git a/vendor/phpmailer/phpmailer/src/DSNConfigurator.php b/vendor/phpmailer/phpmailer/src/DSNConfigurator.php
new file mode 100644 (file)
index 0000000..ab707d2
--- /dev/null
@@ -0,0 +1,247 @@
+<?php
+
+/**
+ * PHPMailer - PHP email creation and transport class.
+ * PHP Version 5.5.
+ *
+ * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
+ *
+ * @author    Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
+ * @author    Jim Jagielski (jimjag) <jimjag@gmail.com>
+ * @author    Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
+ * @author    Brent R. Matzelle (original founder)
+ * @copyright 2012 - 2023 Marcus Bointon
+ * @copyright 2010 - 2012 Jim Jagielski
+ * @copyright 2004 - 2009 Andy Prevost
+ * @license   http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
+ * @note      This program is distributed in the hope that it will be useful - WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+namespace PHPMailer\PHPMailer;
+
+/**
+ * Configure PHPMailer with DSN string.
+ *
+ * @see https://en.wikipedia.org/wiki/Data_source_name
+ *
+ * @author Oleg Voronkovich <oleg-voronkovich@yandex.ru>
+ */
+class DSNConfigurator
+{
+    /**
+     * Create new PHPMailer instance configured by DSN.
+     *
+     * @param string $dsn        DSN
+     * @param bool   $exceptions Should we throw external exceptions?
+     *
+     * @return PHPMailer
+     */
+    public static function mailer($dsn, $exceptions = null)
+    {
+        static $configurator = null;
+
+        if (null === $configurator) {
+            $configurator = new DSNConfigurator();
+        }
+
+        return $configurator->configure(new PHPMailer($exceptions), $dsn);
+    }
+
+    /**
+     * Configure PHPMailer instance with DSN string.
+     *
+     * @param PHPMailer $mailer PHPMailer instance
+     * @param string    $dsn    DSN
+     *
+     * @return PHPMailer
+     */
+    public function configure(PHPMailer $mailer, $dsn)
+    {
+        $config = $this->parseDSN($dsn);
+
+        $this->applyConfig($mailer, $config);
+
+        return $mailer;
+    }
+
+    /**
+     * Parse DSN string.
+     *
+     * @param string $dsn DSN
+     *
+     * @throws Exception If DSN is malformed
+     *
+     * @return array Configuration
+     */
+    private function parseDSN($dsn)
+    {
+        $config = $this->parseUrl($dsn);
+
+        if (false === $config || !isset($config['scheme']) || !isset($config['host'])) {
+            throw new Exception(
+                sprintf('Malformed DSN: "%s".', $dsn)
+            );
+        }
+
+        if (isset($config['query'])) {
+            parse_str($config['query'], $config['query']);
+        }
+
+        return $config;
+    }
+
+    /**
+     * Apply configuration to mailer.
+     *
+     * @param PHPMailer $mailer PHPMailer instance
+     * @param array     $config Configuration
+     *
+     * @throws Exception If scheme is invalid
+     */
+    private function applyConfig(PHPMailer $mailer, $config)
+    {
+        switch ($config['scheme']) {
+            case 'mail':
+                $mailer->isMail();
+                break;
+            case 'sendmail':
+                $mailer->isSendmail();
+                break;
+            case 'qmail':
+                $mailer->isQmail();
+                break;
+            case 'smtp':
+            case 'smtps':
+                $mailer->isSMTP();
+                $this->configureSMTP($mailer, $config);
+                break;
+            default:
+                throw new Exception(
+                    sprintf(
+                        'Invalid scheme: "%s". Allowed values: "mail", "sendmail", "qmail", "smtp", "smtps".',
+                        $config['scheme']
+                    )
+                );
+        }
+
+        if (isset($config['query'])) {
+            $this->configureOptions($mailer, $config['query']);
+        }
+    }
+
+    /**
+     * Configure SMTP.
+     *
+     * @param PHPMailer $mailer PHPMailer instance
+     * @param array     $config Configuration
+     */
+    private function configureSMTP($mailer, $config)
+    {
+        $isSMTPS = 'smtps' === $config['scheme'];
+
+        if ($isSMTPS) {
+            $mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
+        }
+
+        $mailer->Host = $config['host'];
+
+        if (isset($config['port'])) {
+            $mailer->Port = $config['port'];
+        } elseif ($isSMTPS) {
+            $mailer->Port = SMTP::DEFAULT_SECURE_PORT;
+        }
+
+        $mailer->SMTPAuth = isset($config['user']) || isset($config['pass']);
+
+        if (isset($config['user'])) {
+            $mailer->Username = $config['user'];
+        }
+
+        if (isset($config['pass'])) {
+            $mailer->Password = $config['pass'];
+        }
+    }
+
+    /**
+     * Configure options.
+     *
+     * @param PHPMailer $mailer  PHPMailer instance
+     * @param array     $options Options
+     *
+     * @throws Exception If option is unknown
+     */
+    private function configureOptions(PHPMailer $mailer, $options)
+    {
+        $allowedOptions = get_object_vars($mailer);
+
+        unset($allowedOptions['Mailer']);
+        unset($allowedOptions['SMTPAuth']);
+        unset($allowedOptions['Username']);
+        unset($allowedOptions['Password']);
+        unset($allowedOptions['Hostname']);
+        unset($allowedOptions['Port']);
+        unset($allowedOptions['ErrorInfo']);
+
+        $allowedOptions = \array_keys($allowedOptions);
+
+        foreach ($options as $key => $value) {
+            if (!in_array($key, $allowedOptions)) {
+                throw new Exception(
+                    sprintf(
+                        'Unknown option: "%s". Allowed values: "%s"',
+                        $key,
+                        implode('", "', $allowedOptions)
+                    )
+                );
+            }
+
+            switch ($key) {
+                case 'AllowEmpty':
+                case 'SMTPAutoTLS':
+                case 'SMTPKeepAlive':
+                case 'SingleTo':
+                case 'UseSendmailOptions':
+                case 'do_verp':
+                case 'DKIM_copyHeaderFields':
+                    $mailer->$key = (bool) $value;
+                    break;
+                case 'Priority':
+                case 'SMTPDebug':
+                case 'WordWrap':
+                    $mailer->$key = (int) $value;
+                    break;
+                default:
+                    $mailer->$key = $value;
+                    break;
+            }
+        }
+    }
+
+    /**
+     * Parse a URL.
+     * Wrapper for the built-in parse_url function to work around a bug in PHP 5.5.
+     *
+     * @param string $url URL
+     *
+     * @return array|false
+     */
+    protected function parseUrl($url)
+    {
+        if (\PHP_VERSION_ID >= 50600 || false === strpos($url, '?')) {
+            return parse_url($url);
+        }
+
+        $chunks = explode('?', $url);
+        if (is_array($chunks)) {
+            $result = parse_url($chunks[0]);
+            if (is_array($result)) {
+                $result['query'] = $chunks[1];
+            }
+            return $result;
+        }
+
+        return false;
+    }
+}