Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

protonemedia/eddy-server-management

507 stars
2 code files
View protonemedia/eddy-server-management on GitHub

app/Jobs/InstallCertificate.php

Open in GitHub
use App\Models\Certificate;
use App\Models\TlsSetting;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Throwable;
 
class InstallCertificate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
public function __construct(public Certificate $certificate, public ?User $user = null)
{
}
 
public function handle()
{
$site = $this->certificate->site;
 
$site->uploadAsUser($this->certificate->certificatePath(), $this->certificate->certificate, throw: true);
$site->uploadAsUser($this->certificate->privateKeyPath(), $this->certificate->private_key, throw: true);
 
// Get rid of the certificate and private key in database
$this->certificate->forceFill([
'private_key' => null,
'certificate' => null,
'uploaded_at' => now(),
])->save();
 
dispatch(new UpdateSiteTlsSetting($site, TlsSetting::Custom, $this->certificate));
}
 
public function failed(Throwable $exception)
{
$this->certificate->site->forceFill([
'pending_tls_update_since' => null,
])->save();
 
$this->certificate->delete();
 
$this->certificate->site->server
->exceptionHandler()
->notify($this->user)
->about($exception)
->withReference(__('Install a custom SSL certificate for :site', ['site' => $this->certificate->site->address]))
->send();
}
}

app/Http/Controllers/SiteSslController.php

Open in GitHub
use App\Jobs\InstallCertificate;
use App\Models\Server;
use App\Models\Site;
use Illuminate\Http\Request;
use ProtoneMedia\Splade\Facades\Toast;
 
class SiteSslController extends Controller
{
// ...
 
public function update(Request $request, Server $server, Site $site)
{
// ...
 
if ($newCertificate) {
dispatch(new InstallCertificate($newCertificate, $this->user()));
 
Toast::info(__('The certificate will be uploaded to the server and installed. This may take a few minutes.'));
} elseif ($site->tls_setting !== $newTlsSetting) {
dispatch(new UpdateSiteTlsSetting($site, $newTlsSetting, $newCertificate, $this->user()));
 
Toast::info(__('The site SSL settings will be updated. It might take a few minutes before the changes are applied.'));
} else {
Toast::warning(__('No changes were made.'));
 
$site->pending_tls_update_since = null;
}
 
// ...
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.