Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Port check when creating allocations #661

Closed
wants to merge 2 commits into from
Closed

Conversation

notAreYouScared
Copy link
Member

Will check the allocations for the given ip and the given ports to see if they already exist in the database, if they do they're removed from the tag list, and a notification is sent telling the user that the port already exists.
chrome_tA1ubW5I2s

This is applied to all three places where you can create an allocation.

Closes #655

Copy link
Member

@lancepioch lancepioch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, it just needs to be optimized a little, awesome!

@@ -122,8 +132,19 @@ public function table(Table $table): Table

$start = max((int) $start, 0);
$end = min((int) $end, 2 ** 16 - 1);
foreach (range($start, $end) as $i) {
$ports->push($i);
$range = $start <= $end ? range($start, $end) : range($end, $start);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the first port number is greater than the second port number, then no numbers should be added.

$ports->push($i);
$range = $start <= $end ? range($start, $end) : range($end, $start);
foreach ($range as $i) {
if ($i > 1024 && $i <= 65535) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert the if statement and continue early!

$range = $start <= $end ? range($start, $end) : range($end, $start);
foreach ($range as $i) {
if ($i > 1024 && $i <= 65535) {
if (Allocation::query()->where('ip', $get('allocation_ip'))->where('port', $portEntry)->exists()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to happen after the foreach loop because of the N+1 problem!

$ports->push((int) $portEntry);

continue;
if (Allocation::query()->where('ip', $get('allocation_ip'))->where('port', $portEntry)->exists()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to happen after the foreach loop because of the N+1 problem!

@@ -247,7 +256,15 @@ public function form(Form $form): Form
$range = $start <= $end ? range($start, $end) : range($end, $start);
foreach ($range as $i) {
if ($i > 1024 && $i <= 65535) {
$ports->push($i);
if (Allocation::query()->where('ip', $get('allocation_ip'))->where('port', $portEntry)->exists()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to happen after the foreach loop because of the N+1 problem!

$ports = collect();
$update = false;
foreach ($state as $portEntry) {
if (!str_contains($portEntry, '-')) {
if (is_numeric($portEntry)) {
$ports->push((int) $portEntry);
if (Allocation::query()->where('ip', $get('allocation_ip'))->where('port', $portEntry)->exists()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to happen after the foreach loop because of the N+1 problem!

$range = $start <= $end ? range($start, $end) : range($end, $start);
foreach ($range as $i) {
if ($i > 1024 && $i <= 65535) {
if (Allocation::query()->where('ip', $get('allocation_ip'))->where('port', $portEntry)->exists()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to happen after the foreach loop because of the N+1 problem!

@@ -118,8 +128,19 @@ public function table(Table $table): Table

$start = max((int) $start, 0);
$end = min((int) $end, 2 ** 16 - 1);
foreach (range($start, $end) as $i) {
$ports->push($i);
$range = $start <= $end ? range($start, $end) : range($end, $start);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as before.

@RMartinOscar
Copy link
Contributor

RMartinOscar commented Oct 25, 2024

What's your take on this ?
main...RMartinOscar:panel:fix/655

It makes it so it still shows the range on Filament like it used to be in Pterodactyl to

@notAreYouScared
Copy link
Member Author

It makes it so it still shows the range on Filament like it used to be in Pterodactyl to

I'd prefer to keep it the same.

Does this push a notification to the end user? Where is the exception displayed? Screenshots?

@RMartinOscar
Copy link
Contributor

RMartinOscar commented Oct 25, 2024

Does this push a notification to the end user? Where is the exception displayed? Screenshots?

image
image
image
Still displays a 400 if a DisplayException is thrown

@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating an allocation that already exists results in a 500
3 participants