-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented middlware. Added readme and install script
- Loading branch information
1 parent
794652c
commit 7a37a19
Showing
8 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace CloudPanelApi.App.Http.Middleware; | ||
|
||
public class ApiKeyMiddleware | ||
{ | ||
private readonly RequestDelegate Next; | ||
private readonly string? ApiKey; | ||
|
||
public ApiKeyMiddleware(RequestDelegate next) | ||
{ | ||
Next = next; | ||
ApiKey = Environment.GetEnvironmentVariable("API_KEY"); | ||
} | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
if (string.IsNullOrEmpty(ApiKey)) | ||
await Next(context); | ||
else | ||
{ | ||
string authHeader = context.Request.Headers["Authorization"]; | ||
|
||
if (authHeader == null || !authHeader.StartsWith("Bearer ")) | ||
{ | ||
context.Response.StatusCode = 401; | ||
await context.Response.WriteAsync("Unauthorized"); | ||
return; | ||
} | ||
|
||
string token = authHeader.Substring("Bearer ".Length).Trim(); | ||
|
||
if (token != ApiKey) | ||
{ | ||
context.Response.StatusCode = 401; | ||
await context.Response.WriteAsync("Unauthorized"); | ||
return; | ||
} | ||
|
||
await Next(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
|
||
<ItemGroup> | ||
<Folder Include="App\Helpers\" /> | ||
<Folder Include="App\Http\Middleware\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!-- PROJECT LOGO --> | ||
<br /> | ||
<div align="center"> | ||
<a href="https://github.com/Endelon-Hosting/CloudPanelApi"> | ||
<img src="ReadmeStuff/Logo.png" alt="Logo" width="80" height="80"> | ||
</a> | ||
|
||
<h3 align="center">Cloud Panel Api</h3> | ||
|
||
<p align="center"> | ||
An external api server build using the coud panel cli | ||
</p> | ||
</div> | ||
|
||
<img src="ReadmeStuff/screenshot.png" alt="Logo"> | ||
<br> | ||
|
||
|
||
|
||
|
||
|
||
|
||
### Installation | ||
|
||
|
||
Install as systemd service **Only tested on Ubuntu 22.04 so far** | ||
```sh | ||
sh <(curl https://raw.githubusercontent.com/Endelon-Hosting/CloudPanelApi/install.sh || wget -O - https://raw.githubusercontent.com/Endelon-Hosting/CloudPanelApi/install.sh) | ||
``` | ||
Enable and start the service | ||
```sh | ||
systemctl enable --now cpapiserver | ||
``` | ||
|
||
### Configuration | ||
|
||
API Key: | ||
|
||
You can specify an api key by providing it using the following environment variable. | ||
|
||
``API_KEY=<YOUR API KEY HERE>`` | ||
|
||
This can be any string. To authenticate you need to provide the api key in your requests as a bearer token | ||
|
||
``Authorization: Bearer <YOUR API KEY HERE>`` | ||
|
||
SSH: | ||
|
||
The cloud panel api server is also able to use remote cloud panel instances using ssh. To enable ssh mode, provide following environment variables | ||
|
||
``SSH_HOST=<YOUR SSH HOST HERE>`` | ||
|
||
``SSH_PORT=<YOUR SSH PORT HERE>`` | ||
|
||
``SSH_USERNAME=<YOUR SSH USERNAME HERE>`` | ||
|
||
``SSH_PASSWORD=<YOUR SSH PASSWORD HERE>`` | ||
|
||
### Contributing | ||
|
||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. | ||
|
||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue an tell us your ideas. | ||
Don't forget to give the project a star! Thanks ^^! |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=cpapiserver | ||
Wants=network.target | ||
After=network.target | ||
|
||
[Service] | ||
User=root | ||
WorkingDirectory=/lib/cpapiserver/ | ||
ExecStart=/bin/sh -c "/lib/cpapiserver/CloudPanelApi >> /var/log/cpapiserver.log" | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! /bin/bash | ||
|
||
echo "Installing cloud panel api server" | ||
|
||
mkdir /lib/cpapiserver/ | ||
|
||
curl -L -o /lib/cpapiserver/CloudPanelApi "https://github.com/Endelon-Hosting/CloudPanelApi/releases/latest/download/CloudPanelApi_linux_([[ "$(uname -m)" == "x86_64" ]] && echo "amd64" || echo "arm64")" | ||
curl -L -o /lib/cpapiserver/CloudPanelApi.pdb "https://github.com/Endelon-Hosting/CloudPanelApi/releases/latest/download/cpapiserver_linux_([[ "$(uname -m)" == "x86_64" ]] && echo "amd64" || echo "arm64")" | ||
|
||
curl -L -o /etc/systemd/system/cpapiserver.service https://raw.githubusercontent.com/Endelon-Hosting/CloudPanelApi/cpapiserver.service | ||
chmod 664 /etc/systemd/system/cpapiserver.service | ||
chmod +x /lib/cpapiserver/CloudPanelApi | ||
systemctl daemon-reload |