net/wol: make UDP port configurable (default 9)#5448
Conversation
sopex
left a comment
There was a problem hiding this comment.
My suggestions for improvement:
- You have to create a simple migration file for the saved WOL hosts to keep the already used port when users update.
- The saved hosts shall also show the port in the table.
- Make this a
<br>instead of and<hr> - Add a
<br>here:
Also, some minor things.
| <Default>00:00:00:00:00:00</Default> | ||
| <ValidationMessage>Should be 6 groups of 2 hex characters (a-fA-F0-9) separated by ':'.</ValidationMessage> | ||
| </mac> | ||
| <port type="IntegerField"> |
There was a problem hiding this comment.
Give PortField a try here https://docs.opnsense.org/development/frontend/models_fieldtypes.html#portfield
There was a problem hiding this comment.
Done, will be in next commit. Thanks for the input !
Suggest by sopex: Cleaner update Co-authored-by: Konstantinos Spartalis <scoon405@gmail.com>
sopex suggestion merge 2 Co-authored-by: Konstantinos Spartalis <scoon405@gmail.com>
Changed Integerfield to PortField in WoL.xml Modified index.volt to include port Added migration script
|
Thanks @sopex ! All your suggestions were added. |
sopex
left a comment
There was a problem hiding this comment.
I will test it later, but it looks good to me and pretty useful!
| <?php | ||
|
|
||
| /* | ||
| * Copyright (C) 2026 <your name> |
| /** | ||
| * Existing WoL hosts predate the configurable port and were always | ||
| * sent to UDP port 40000 (the previous hard-coded value). Preserve | ||
| * that behaviour on upgrade so existing hosts keep working; only new | ||
| * hosts get the sane default of 9. | ||
| * @param $model | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * Existing WoL hosts predate the configurable port and were always | |
| * sent to UDP port 40000 (the previous hard-coded value). Preserve | |
| * that behaviour on upgrade so existing hosts keep working; only new | |
| * hosts get the sane default of 9. | |
| * @param $model | |
| */ | |
| /** | |
| * Migrates from hardcoded port | |
| * @param $model | |
| */ |
Changed function for autofill 40000 for migration by default. Port will be 9 as default for new installs.
|
Are you sure about removing the if statement? Have you tested the migration? I am not sure, just asking |
Yes, the if would have added a condition if people already did it themselves but I would rather have a proper update that would treat the previous version as untouched. |
|
Alright, I tested the latest changes locally and it seems to work (tested the migration as well, port is put at 40000). New ports are pre filled at 9, packet capture confirms it works as intended. Thank you so much for your support |
|
@fichtner If you have a moment, I believe it's ready for prime time. Thanks! |
Co-authored-by: Konstantinos Spartalis <scoon405@gmail.com>
Co-authored-by: Konstantinos Spartalis <scoon405@gmail.com>
Just applied, do you mind explaining ? |
|
I know things are busy, but there is no plugin maintainer here. FWIW: I have tested it, and it works great. |
| $result['status'] = trim($backend->configdRun("wol wake {$broadcast_ip} " . escapeshellarg((string)$wolent->mac))); | ||
| $port = escapeshellarg((string)$wolent->port); | ||
| $mac = escapeshellarg((string)$wolent->mac); | ||
| $result['status'] = trim($backend->configdRun("wol wake {$port} {$broadcast_ip} {$mac}")); |
There was a problem hiding this comment.
this needs to be rewritten for configdpRun() second argument is the array with all unescaped values.. ideally from getValue() and not string cast
| <ValidationMessage>Should be 6 groups of 2 hex characters (a-fA-F0-9) separated by ':'.</ValidationMessage> | ||
| </mac> | ||
| <port type="PortField"> | ||
| <Required>Y</Required> |
There was a problem hiding this comment.
the issue with requiring this is now the user needs to input it or else validation fails. "9" isn't added automatically and the migration uses '4000' which would be automatic if we used that default ;)
|
@sopex I guess you meant me ;) @touzenesmy It's not bad but the assumptions for 4000 vs. 9 derails this. An optional port field would be more user friendly (even hide under advanced and we don't really need it in the grid). While I don't have strong opinions about which value is more correct trying to appease both is not going to work. |
|
@fichtner Absolutely :) |
The 40000 is for those who already preconfigured their firewall to allow the request on port 40000 in the previous version (I think its UNIX default). Port 9 is prefilled in directly without user input but can be changed by the user if needed (Most systems today and also most tutorials I've checked for WoL assume port 9 is used) |


Important notices
Before you submit a pull request, we ask you kindly to acknowledge the following:
If AI was used, please disclose:
Describe the problem
The actual WoL implementation of the plugin doesn't allow for port configuration and default to the 40000 BSOD default value. There is no way to configure the WoL port.
Describe the proposed solution
Add a field port that defaults to 9, users can just use it when they have a specific need as seen previously. I've edited the script to take in that parameter as well.
EDIT: Already modified locally and verified to work on correct ports with packet capture.
Related issue
If this pull request relates to an issue, link it here.
#2967, #4079, #1648