panel icon indicating copy to clipboard operation
panel copied to clipboard

Send emails on server suspends

Open anondev-sudo opened this issue 4 years ago • 4 comments

Is your feature request related to a problem? Please describe.

Sometimes it happens that user does not know that their server was suspended. They think that host is down.

Describe the solution you'd like

Add that when admin suspends the server, email will be send to user like pterodactyl is sending emails on account and server create

Describe alternatives you've considered

Make this optional to let the user know, when clicking on suspend, popup prompt should be opened to let the user know or to silently suspend server.

Additional context Add any other context or screenshots about the feature request here.

anondev-sudo avatar Jun 12 '21 16:06 anondev-sudo

If you're integrating with Pterodactyl from a billing software such as WHMCS, that should notify the customer upon service suspension.

RihanArfan avatar Jun 12 '21 17:06 RihanArfan

I think, this feature must be added by a billing system and not pterodactyl in itself.

And then when actions that cause the server to be suspended, will we send an email each time?

lekkerelou avatar Jun 19 '21 07:06 lekkerelou

You may edit the panel's code to do that; I will guide you through a simple implementation, however use it at your own risk!

  1. We need to create a new notification for server deletion. Let's create a new file - app/Notifications/ServerDeleted.php
<?php

namespace Pterodactyl\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class ServerDeleted extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * @var object
     */
    public $server;

    /**
     * Create a new notification instance.
     */
    public function __construct(array $server)
    {
        $this->server = (object) $server;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     *
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     *
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage())
            ->error()
            ->greeting('Hello ' . $this->server->user . '.')
            ->line('Your server has been deleted.')
            ->line('Server Name: ' . $this->server->name)
            ->action('Visit Panel', route('index'));
    }
}
  1. Now we need to trigger the notification; we can do that in the ServerObserver class (app/Observers/ServerObserver.php):

https://github.com/pterodactyl/panel/blob/cc05b0886bf7db554dd12d53fd2c9c3dc4f1e323/app/Observers/ServerObserver.php#L49

In here, under the event() function, let's trigger notify the user:

$server->user->notify(new \Pterodactyl\Notifications\ServerDeleted($server));

This should in theory work, however I haven't tested it; If you have any issues, feel free to reply to this issue.

VottusCode avatar Jun 22 '21 19:06 VottusCode

You may edit the panel's code to do that; I will guide you through a simple implementation, however use it at your own risk!

  1. We need to create a new notification for server deletion. Let's create a new file - app/Notifications/ServerDeleted.php
<?php

namespace Pterodactyl\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class ServerDeleted extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * @var object
     */
    public $server;

    /**
     * Create a new notification instance.
     */
    public function __construct(array $server)
    {
        $this->server = (object) $server;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     *
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     *
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage())
            ->error()
            ->greeting('Hello ' . $this->server->user . '.')
            ->line('Your server has been deleted.')
            ->line('Server Name: ' . $this->server->name)
            ->action('Visit Panel', route('index'));
    }
}
  1. Now we need to trigger the notification; we can do that in the ServerObserver class (app/Observers/ServerObserver.php):

https://github.com/pterodactyl/panel/blob/cc05b0886bf7db554dd12d53fd2c9c3dc4f1e323/app/Observers/ServerObserver.php#L49

In here, under the event() function, let's trigger notify the user:

$server->user->notify(new \Pterodactyl\Notifications\ServerDeleted($server));

This should in theory work, however I haven't tested it; If you have any issues, feel free to reply to this issue. not working

HeratixX avatar May 22 '22 18:05 HeratixX