Forráskód Böngészése

Add beginnings of work on IRC provider. Currently doesn't work.

Andy Baugh 8 éve
szülő
commit
cc2f662f1e
4 módosított fájl, 113 hozzáadás és 2 törlés
  1. 1 1
      README.md
  2. 5 1
      TODO
  3. 49 0
      lib/Cpanel/iContact/Provider/IRC.pm
  4. 58 0
      lib/Cpanel/iContact/Provider/Schema/IRC.pm

+ 1 - 1
README.md

@@ -4,7 +4,7 @@ Extra "Contact Manager" Providers for cPanel and WHM
 Current plugins:
 ================
 * XMPP  -- Stable XMPP provider (as I've received no external bug reports and it has worked well for me for over a month)
-* IRC   -- Still WIP, completely untested.
+* IRC   -- Still WIP, don't use this, as it is completely untested and currently no-op on send.
 * Slack -- Works presuming you have an incoming WebHook URL, much like CpanelRicky's MatterMost plugin.
 
 Installation and Use:

+ 5 - 1
TODO

@@ -7,7 +7,11 @@ XMPP provider:
 Slack Provider:
 * Add more tests, remove Cpanel namespace deps from driver lib
 
+IRC Provider:
+* Make it actually work instead of being no-op on send, etc.
+* Add tests
+
 Other Providers:
-* IRC
 * Discord
+* Telegraph
 * ... Whatever else is hanging out on the feature site that sounds interesting

+ 49 - 0
lib/Cpanel/iContact/Provider/IRC.pm

@@ -0,0 +1,49 @@
+package Cpanel::iContact::Provider::IRC;
+
+use strict;
+use warnings;
+
+use parent 'Cpanel::iContact::Provider';
+
+sub send {
+    my ($self) = @_;
+
+    my $args_hr = $self->{'args'};
+    my @errs;
+
+    my $subject_copy = $args_hr->{'subject'};
+    my $body_copy    = ${ $args_hr->{'text_body'} };
+
+    require Encode;
+    my $subject      = Encode::decode_utf8( $subject_copy, $Encode::FB_QUIET );
+    my $body         = Encode::decode_utf8( $body_copy, $Encode::FB_QUIET );
+
+    foreach my $destination ( @{ $args_hr->{'to'} } ) {
+        local $@;
+        eval {
+            my $response;
+            $self->_send(
+                'destination' => $destination,
+                'subject' => $subject,
+                'content' => $body
+            );
+        };
+        push( @errs, $@ ) if $@;
+    }
+
+    if (@errs) {
+        die "One or more notification attempts failed. Details below:\n"
+          . join( "\n", @errs );
+    }
+
+    return 1;
+}
+
+sub _send {
+    my ( $self, %args ) = @_;
+    # TODO research what is installed on cP boxes to see what I can use here
+
+    return;
+}
+
+1;

+ 58 - 0
lib/Cpanel/iContact/Provider/Schema/IRC.pm

@@ -0,0 +1,58 @@
+package Cpanel::iContact::Provider::Schema::IRC;
+
+use strict;
+use warnings;
+
+sub get_settings {
+    my $help1 = <<HALP;
+<p>The IRC <em>channels</em> you wish to send cPanel & WHM notifications <em>to</em>.<br />
+For multiple channels, delimit them with commas.<br />
+Example: "#YOLO,#swag"</p>
+HALP
+    my $help2 = <<HALP;
+<p>The IRC <em>nickname</em> you wish for cPanel & WHM notifications to use.<br />
+Example: "cPSaurus"</p>
+HALP
+    my $help3 =<<HALP;
+<p>Whether or not the IRC server your Notification User is registered at supports SSL/TLS.<br />
+If set improperly, this will cause sending notifications to fail (some IRC servers <em>require</em> SSL/TLS, some <em>don't support it</em>).
+</p>
+HALP
+    return {
+        'CONTACTIRC' => {
+            'shadow'   => 1,
+            'type'     => 'text',
+            'checkval' => sub {
+                my $value = shift;
+                my @chans = split( ",", $value );
+                @chans = grep { index( $_, '#' ) != -1 } @chans;
+                return join( ",", @chans );
+            },
+            'label' => 'IRC Notification Destinations',
+            'help' => $help1,
+        },
+        'IRCNICK' => {
+            'shadow'   => 1,
+            'type'     => 'text',
+            'label' => 'IRC Notification Bot Nickname',
+            'help' => $help2,
+        },
+        'IRCUSESSL' => {
+            'type'     => 'binary',
+            'label' => 'IRC: Use SSL/TLS?',
+            'help' => $help4,
+        },
+    };
+}
+
+sub get_config {
+    my $svg = "%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Cdefs%3E%3ClinearGradient%20gradientUnits%3D%22userSpaceOnUse%22%20x2%3D%2247%22%20x1%3D%220%22%3E%3Cstop%20stop-color%3D%22%23a9a3d4%22%2F%3E%3Cstop%20offset%3D%22.47%22%20stop-color%3D%22%2387baff%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%2389ec85%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%220%22%20y1%3D%22556.24%22%20x2%3D%220%22%20y2%3D%22510.24%22%20gradientUnits%3D%22userSpaceOnUse%22%3E%3Cstop%20stop-color%3D%22%232e5378%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23387898%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%221%22%20x1%3D%22421.9%22%20y1%3D%22540.44%22%20x2%3D%22422.52%22%20y2%3D%22522.5%22%20gradientUnits%3D%22userSpaceOnUse%22%3E%3Cstop%20stop-color%3D%22%231584d8%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%231cb2ff%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Cg%20transform%3D%22matrix%281.04866%200%200%201.04866-511.61-528.36%29%22%20stroke-width%3D%221.317%22%3E%3Crect%20y%3D%22510.24%22%20x%3D%22296.96%22%20height%3D%2246%22%20width%3D%2246%22%20fill%3D%22url%28%230%29%22%20rx%3D%2223%22%20stroke-width%3D%222.164%22%20transform%3D%22matrix%28.99507%200%200%20.99507%20192.37-3.883%29%22%2F%3E%3Cpath%20d%3D%22m423.44%20523.59l-1.172%204.7h3.223l1.184-4.7h2.698l-1.184%204.7h3.381v2.6h-4.03l-.842%203.345h3.467v2.625h-4.102l-1.172%204.675h-2.698l1.172-4.675h-3.223l-1.172%204.675h-2.722l1.172-4.675h-3.406v-2.625h4l.854-3.345h-3.455v-2.6h4.126l1.172-4.7h2.722m1.379%207.3h-3.223l-.854%203.345h3.223l.854-3.345%22%20fill%3D%22%23fff%22%20fill-opacity%3D%22.85%22%20transform%3D%22matrix%281.33747%200%200%201.33747-54.714-185.56%29%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E";
+    return {
+        'default_level'    => 'All',
+        'display_name'     => 'IRC',
+        'icon_name'        => 'IRC',
+        'icon'             => "data:image/svg+xml,$svg",
+    };
+}
+
+1;