Skip to content

Commit

Permalink
Merge branch 'develop' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
#	app/Repositories/Proxmox/Server/ProxmoxBackupRepository.php
#	app/Repositories/Proxmox/Server/ProxmoxConfigRepository.php
#	app/Services/Servers/NetworkService.php
#	package-lock.json
  • Loading branch information
ericwang401 committed Oct 12, 2024
2 parents 77be077 + c780ca0 commit 12d1435
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ lang/php_*.json
._.DS_Store
**/.DS_Store
**/._.DS_Store
.php-cs-fixer.cache
.php-cs-fixer.cache
.phpunit.cache
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,43 @@ This file is a running track of new features and fixes to each version of the pa

This project follows [Semantic Versioning](http://semver.org) guidelines.

## v4.2.3-rc.1
## v4.2.4

### Changes

- Fixed a bug where initiating a backup with no compression fails. #87

## v4.2.3

### Changes

- Updated code for applying rate limits to NIC. Convoy will no longer override settings other than ratelimit, NIC
model (e.g., e1000, vmxnet3, virtio, etc.), and firewall status.

#### From v4.2.2-rc.2

- Fix US keyboard characters validation #80
- Fixed a visual bug on the bandwidth usage card where the text wasn't centered.

#### From v4.2.2-rc.1

- Fix special character support in environment file.
- Added checks in server creation to use unique VMID. #78
- Add error messages instead of generic server error messages. #49
- Scope route model binding by default to prevent unauthorized access of related resources.
- Removed a lot of dead code.
- Added more tests (getting closer to full release! 😁😩).

#### From v4.2.1-rc.1

- Potential fix for disk resize timeout?

## v4.2.2-rc.2

### Changes

- Fix US keyboard characters validation #80
- Fixed a visual bug on the bandwidth usage card where the text wasn't centered.

## v4.2.2-rc.1

Expand Down
26 changes: 18 additions & 8 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Convoy Software End User License Agreement (EULA)

**Effective Date:** March 4th, 2024
**Effective Date:** March 3th, 2024

**Last Updated:** March 13th, 2024

**License Grantor:** Performave

Expand Down Expand Up @@ -70,44 +72,52 @@ may also apply as outlined elsewhere in this EULA or as otherwise determined by

Any modifications, enhancements, derivative works of the Software, or any code from the Software that is incorporated into other works by you or any third party are considered part of the Software and subject to the terms and conditions of this EULA. Such modifications, derivative works, or incorporated code must be offered under the same terms and conditions as those set forth in this EULA, including any provisions regarding distribution and sublicensing. You may not alter the terms of this EULA or sublicense any modifications, derivative works, or incorporated code under terms that differ from those specified in this EULA.

## 5. Intellectual Property Rights
## 5. License Enforcement and Digital Rights Management

Performave employs various measures, including Digital Rights Management (DRM), to enforce the terms of this EULA and prevent unauthorized use of the Software. These measures may include, but are not limited to, remotely disabling access to the Software or specific features of the Software for users who are found to be in violation of this EULA. By using the Software, you acknowledge and agree that Performave may, at its sole discretion, implement such measures.

You further agree that Performave shall not be responsible or liable for any loss, damage, or inconvenience you may suffer as a result of such actions taken to enforce this EULA. Your rights under this EULA may be subject to termination and denial of access to the Software without notice if any form of tampering with or circumvention of the DRM or other license enforcement mechanisms is detected.

This section is designed to inform users of the license enforcement practices and to legally protect Performave from liability for actions taken in good faith to protect its intellectual property rights.

## 6. Intellectual Property Rights

The Software is protected by intellectual property laws and treaties. Performave or its suppliers own all title,
copyright, and interest in and to the Software, including any intellectual property rights therein. This EULA grants you
no rights to use such content. All rights not expressly granted are reserved by Performave.

## 6. Termination
## 7. Termination

This EULA is effective until terminated. Your rights under this EULA will terminate automatically without notice from
Performave if you fail to comply with any term(s) of this EULA. Upon termination, you shall cease all use of the
Software and destroy all copies, full or partial, of the Software.

## 7. Disclaimer of Warranty
## 8. Disclaimer of Warranty

The Software is provided "AS IS," with all faults, without warranty of any kind, and Performave hereby disclaims all
warranties and conditions with respect to the Software, either express, implied, or statutory, including, but not
limited to, the implied warranties and/or conditions of merchantability, of satisfactory quality, of fitness for a
particular purpose, of accuracy, of quiet enjoyment, and non-infringement of third-party rights.

## 8. Limitation of Liability
## 9. Limitation of Liability

In no event shall Performave be liable for any indirect, incidental, special, consequential, or punitive damages
whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business
information, or any other pecuniary loss) arising out of the use of or inability to use the Software, even if Performave
has been advised of the possibility of such damages.

## 9. Governing Law
## 10. Governing Law

This EULA shall be governed by the laws of the jurisdiction in which Performave is located, without reference to
conflict of laws principles.

## 10. Entire Agreement
## 11. Entire Agreement

This EULA constitutes the entire agreement between you and Performave relating to the Software and supersedes all prior
or contemporaneous oral or written communications, proposals, and representations with respect to the Software or any
other subject matter covered by this EULA.

## 11. Amendment
## 12. Amendment

Performave reserves the right to amend this EULA at any time, at its sole discretion, by posting an updated version to
its website or through the Software. Your continued use of the Software following the posting of an updated EULA will
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Please [visit this page](https://convoypanel.com/docs/project/about.html#acknowl

## License

Convoy is licensed under the Business Source License. Production use of Convoy without an active license from Performave is strictly disallowed.
Convoy is licensed under our own proprietary license.

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FConvoyPanel%2Fpanel.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FConvoyPanel%2Fpanel?ref=badge_large)
139 changes: 115 additions & 24 deletions app/Services/Servers/NetworkService.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php

namespace App\Services\Servers;

use App\Data\Server\Deployments\CloudinitAddressConfigData;
use App\Data\Server\Eloquent\ServerAddressesData;
use App\Data\Server\MacAddressData;
use App\Enums\Network\AddressType;
use App\Models\Address;
use App\Models\Server;
use App\Repositories\Eloquent\AddressRepository;
use App\Repositories\Proxmox\Server\ProxmoxCloudinitRepository;
use App\Repositories\Proxmox\Server\ProxmoxConfigRepository;
use App\Repositories\Proxmox\Server\ProxmoxFirewallRepository;
use Illuminate\Database\ConnectionInterface;
namespace Convoy\Services\Servers;

use Convoy\Data\Server\Deployments\CloudinitAddressConfigData;
use Convoy\Data\Server\Eloquent\ServerAddressesData;
use Convoy\Data\Server\MacAddressData;
use Convoy\Enums\Network\AddressType;
use Convoy\Models\Address;
use Convoy\Models\Server;
use Convoy\Repositories\Eloquent\AddressRepository;
use Convoy\Repositories\Proxmox\Server\ProxmoxCloudinitRepository;
use Convoy\Repositories\Proxmox\Server\ProxmoxConfigRepository;
use Convoy\Repositories\Proxmox\Server\ProxmoxFirewallRepository;
use Illuminate\Support\Arr;
use function collect;
use function is_null;

class NetworkService
{
Expand All @@ -23,7 +24,6 @@ public function __construct(
private CloudinitService $cloudinitService,
private ProxmoxCloudinitRepository $cloudinitRepository,
private ProxmoxConfigRepository $allocationRepository,
private ConnectionInterface $connection,
) {
}

Expand All @@ -40,7 +40,7 @@ public function deleteIpset(Server $server, string $name)
return $this->firewallRepository->deleteIpset($name);
}

public function clearIpsets(Server $server)
public function clearIpsets(Server $server): void
{
$this->firewallRepository->setServer($server);

Expand All @@ -51,7 +51,7 @@ public function clearIpsets(Server $server)
}
}

public function lockIps(Server $server, array $addresses, string $ipsetName)
public function lockIps(Server $server, array $addresses, string $ipsetName): void
{
$this->firewallRepository->setServer($server);

Expand All @@ -62,7 +62,7 @@ public function lockIps(Server $server, array $addresses, string $ipsetName)
}
}

public function getMacAddresses(Server $server, bool $eloquent = true, bool $proxmox = false)
public function getMacAddresses(Server $server, bool $eloquent = true, bool $proxmox = false): MacAddressData
{
if ($eloquent) {
$addresses = $this->getAddresses($server);
Expand Down Expand Up @@ -102,7 +102,7 @@ public function getAddresses(Server $server): ServerAddressesData
]);
}

public function syncSettings(Server $server)
public function syncSettings(Server $server): void
{
$macAddresses = $this->getMacAddresses($server, true, true);
$addresses = $this->getAddresses($server);
Expand Down Expand Up @@ -131,21 +131,112 @@ public function syncSettings(Server $server)
);
}

public function updateRateLimit(Server $server, ?int $mebibytes = null)
public function updateRateLimit(Server $server, ?int $mebibytes = null): void
{
$macAddresses = $this->getMacAddresses($server, true, true);
$macAddress = $macAddresses->eloquent ?? $macAddresses->proxmox;
$rawConfig = $this->allocationRepository->setServer($server)->getConfig();
$networkConfig = collect($rawConfig)->where('key', '=', 'net0')->first();

if (is_null($networkConfig)) {
return;
}

$parsedConfig = $this->parseConfig($networkConfig['value']);

// List of possible models
$models = ['e1000', 'e1000-82540em', 'e1000-82544gc', 'e1000-82545em', 'e1000e', 'i82551', 'i82557b', 'i82559er', 'ne2k_isa', 'ne2k_pci', 'pcnet', 'rtl8139', 'virtio', 'vmxnet3'];

// Update the model with the new MAC address
$modelFound = false;
foreach ($parsedConfig as $item) {
if (in_array($item->key, $models)) {
$item->value = $macAddress;
$modelFound = true;
break;
}
}

// If no model key exists, add the default model with the MAC address
if (!$modelFound) {
$parsedConfig[] = (object) ['key' => 'virtio', 'value' => $macAddress];
}

// Update or create the bridge value
$bridgeFound = false;
foreach ($parsedConfig as $item) {
if ($item->key === 'bridge') {
$item->value = $server->node->network;
$bridgeFound = true;
break;
}
}

if (!$bridgeFound) {
$parsedConfig[] = (object) ['key' => 'bridge', 'value' => $server->node->network];
}

// Update or create the firewall key
$firewallFound = false;
foreach ($parsedConfig as $item) {
if ($item->key === 'firewall') {
$item->value = 1;
$firewallFound = true;
break;
}
}

if (!$firewallFound) {
$parsedConfig[] = (object) ['key' => 'firewall', 'value' => 1];
}

// Handle the rate limit
if (is_null($mebibytes)) {
// Remove the 'rate' key if $mebibytes is null
$parsedConfig = array_filter($parsedConfig, fn ($item) => $item->key !== 'rate');
} else {
// Add or update the 'rate' key
$rateUpdated = false;
foreach ($parsedConfig as $item) {
if ($item->key === 'rate') {
$item->value = $mebibytes;
$rateUpdated = true;
break;
}
}

if (!$rateUpdated) {
$parsedConfig[] = (object) ['key' => 'rate', 'value' => $mebibytes];
}
}

// Rebuild the configuration string
$newConfig = implode(',', array_map(fn ($item) => "{$item->key}={$item->value}", $parsedConfig));

// Update the Proxmox configuration
$this->allocationRepository->setServer($server)->update(['net0' => $newConfig]);
}

private function parseConfig(string $config): array
{
// Split components by commas
$components = explode(',', $config);

// Array to hold the parsed objects
$parsedObjects = [];

$payload = "virtio={$macAddress},bridge={$server->node->network},firewall=1";
foreach ($components as $component) {
// Split each component into key and value
[$key, $value] = explode('=', $component);

if (!is_null($mebibytes)) {
$payload .= ',rate=' . $mebibytes;
// Create an associative array (or object) for key-value pairs
$parsedObjects[] = (object) ['key' => $key, 'value' => $value];
}

$this->allocationRepository->setServer($server)->update(['net0' => $payload]);
return $parsedObjects;
}

public function updateAddresses(Server $server, array $addressIds)
public function updateAddresses(Server $server, array $addressIds): void
{
$currentAddresses = $server->addresses()->get()->pluck('id')->toArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const ServerDetailsBlock = () => {

<Card className='flex flex-col justify-between items-center col-span-10 lg:col-span-2'>
<h5 className='h5'>{tStrings('bandwidth_usage')}</h5>
<div className='grid place-items-center mt-5'>
<div className='relative grid place-items-center mt-5'>
<h4 className='absolute text-3xl font-semibold text-foreground'>
{Math.floor(bandwidth.percentage)}
</h4>
Expand Down Expand Up @@ -227,4 +227,4 @@ const ServerDetailsBlock = () => {
)
}

export default ServerDetailsBlock
export default ServerDetailsBlock
20 changes: 19 additions & 1 deletion tests/Unit/Services/Nodes/ServerRateLimitsSyncServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,25 @@

it('can rate limit servers if over limit', function () {
Http::fake([
'*' => Http::response(['data' => 'dummy-upid'], 200),
'/api2/json/nodes/*/qemu/*/config' => Http::sequence()
->push(
file_get_contents(
base_path(
'tests/Fixtures/Repositories/Server/GetServerConfigData.json',
),
),
200
)
->push(
file_get_contents(
base_path(
'tests/Fixtures/Repositories/Server/GetServerConfigData.json',
),
),
200,
)
->push(['data' => 'dummy-upid'], 200)

]);

[$_, $_, $node, $server] = createServerModel();
Expand Down

0 comments on commit 12d1435

Please sign in to comment.