What's new

[Dev] Q&A for Merlin Addons API

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Anyone have an idea why this JavaScript / jquery code does not work on John's fork but happily in Merlin's?
Code:
if (custom_settings.Div_p_page !== undefined) {
   if (custom_settings.Div_p_page == "index") {
       $('#thisContent').load('/user/diversion/div-index.html');
   } else {
       $('#thisContent').load('/user/diversion/div-lists.html');
   }
}
The console error is for the first $('#thisContent').load('/user/diversion/div-index.html');
TypeError: $(...) is null


id #thisContent is set in <td bgcolor="#4D595D" colspan="3" valign="top" id="thisContent"></td>

I'm loading these js files, jquery is from Merlins, but even with johns built in it does not work:
Code:
/user/diversion/div-jquery.js
/state.js
/general.js
/popup.js
/help.js
/detect.js
/base64.js
[Fork] Asuswrt-Merlin 374.43 LTS releases (V44E5)

You would need to use a jQuery.noConflict() statement and replace $ with $j.
Code:
var $j=jQuery.noConflict();
...
if (custom_settings.Div_p_page !== undefined) {
   if (custom_settings.Div_p_page == "index") {
       $j('#thisContent').load('/user/diversion/div-index.html');
   } else {
       $j('#thisContent').load('/user/diversion/div-lists.html');
   }
}
 
[Fork] Asuswrt-Merlin 374.43 LTS releases (V44E5)

You would need to use a jQuery.noConflict() statement and replace $ with $j.
Code:
var $j=jQuery.noConflict();
...
if (custom_settings.Div_p_page !== undefined) {
   if (custom_settings.Div_p_page == "index") {
       $j('#thisContent').load('/user/diversion/div-index.html');
   } else {
       $j('#thisContent').load('/user/diversion/div-lists.html');
   }
}
Love you! Thanks, I looked at Jack's code and saw the $j's but thought this is j's functions. Silly me.
 
I've submitted a PR to Merlin regarding am_get_webui_page that addresses the case when the function will ignore a match to an existing page if there is an empty mount point before your existing page (example in the PR).

I'm not entirely happy with my solution since I loop through twice, so I'd like you guys to see if you have a better solution. I may be the only one who relies on the function directly from helper.sh, but I know Adamm and Jack have essentially cloned it for their scripts and may encounter the same issue.
 
I've submitted a PR to Merlin regarding am_get_webui_page that addresses the case when the function will ignore a match to an existing page if there is an empty mount point before your existing page (example in the PR).

I'm not entirely happy with my solution since I loop through twice, so I'd like you guys to see if you have a better solution. I may be the only one who relies on the function directly from helper.sh, but I know Adamm and Jack have essentially cloned it for their scripts and may encounter the same issue.
Since mounting should really only happen at boot time, or script updates how often do you hit this case in normal usage? Surely this only happens if you have uninstalled a script that had occupied a lower "slot", and then updated yours?

Not saying it's not worth fixing, I just see it as being a fairly low likelihood of being hit
 
Since mounting should really only happen at boot time, or script updates how often do you hit this case in normal usage? Surely this only happens if you have uninstalled a script that had occupied a lower "slot", and then updated yours?

Not saying it's not worth fixing, I just see it as being a fairly low likelihood of being hit
In my case, I check that the ASP is mounted every time it runs since it can be triggered often with firewall restarts. I may not need to do that, but it's a bit of a holdover from my predecessor. And right now, I'm doing a lot of development updates, so I was noticing my page jumping around a lot, requiring a full browser refresh to reload menuTree.js in the UI. On an update/replacement, I'm currently getting a new slot for the updated ASP, then deleting any existing user*.asp that contain FlexQoS, creating the gaps myself. Maybe if I get the page of the existing ASP before downloading the replacement, I can avoid that process.

I think I have another option to propose in the PR that only loops through once, but remembers the first empty slot if no matches found.
 
In my case, I check that the ASP is mounted every time it runs since it can be triggered often with firewall restarts. I may not need to do that, but it's a bit of a holdover from my predecessor. And right now, I'm doing a lot of development updates, so I was noticing my page jumping around a lot, requiring a full browser refresh to reload menuTree.js in the UI. On an update/replacement, I'm currently getting a new slot for the updated ASP, then deleting any existing user*.asp that contain FlexQoS, creating the gaps myself. Maybe if I get the page of the existing ASP before downloading the replacement, I can avoid that process.

I think I have another option to propose in the PR that only loops through once, but remembers the first empty slot if no matches found.
I ran into the same problem. With my current approach (not the Diversion beta) I save the user page name and use that to remount or remove it. Works 100% ever since.
 
There's been a lot of noise lately about AddOn tabs and contention during boot. What can we each do to safely add our menuTree.js modifications without causing problems for each other (or in Jack's case with himself AND others)?

Do we need to devise a type of semaphore that we usleep while waiting for it to be released? Like writing our PID to /tmp/menuTree.lock while we sed the /tmp/menuTree.js?

If we fail to sed -i the menuTree.js file, should we expect a non-zero return from sed that we can sleep and try again?

I haven't encountered this issue myself to be able to test these ideas, but I think we can come up with some safeguarded method to apply our updates in a reliable way.
 
There's been a lot of noise lately about AddOn tabs and contention during boot. What can we each do to safely add our menuTree.js modifications without causing problems for each other (or in Jack's case with himself AND others)?

Do we need to devise a type of semaphore that we usleep while waiting for it to be released? Like writing our PID to /tmp/menuTree.lock while we sed the /tmp/menuTree.js?

If we fail to sed -i the menuTree.js file, should we expect a non-zero return from sed that we can sleep and try again?

I haven't encountered this issue myself to be able to test these ideas, but I think we can come up with some safeguarded method to apply our updates in a reliable way.
Use the flock code verbatim from my updates, written by @Martineau

the flock -x won't return until it can get an exclusive lock on the /tmp/addonwebui.lock file so the mount will simply wait until the "lock holder" releases it

I believe it will be making its way into Unbounds GUI method too, if its not already there
 
Last edited:
Use the flock code verbatim from my updates, written by @Martineau

the flock -x won't return until it can get an exclusive lock on the /tmp/addonwebui.lock file so the mount will simply wait until the "lock holder" releases it

I believe it will be making its way into Unbounds GUI method too, if its not already there
If the locker never releases it for any reason, will it just wait forever? I don't see that busybox flock supports a timeout.
 
If the locker never releases it for any reason, will it just wait forever? I don't see that busybox flock supports a timeout.
yes it would wait forever, but there shouldn't be a reason for the flock -u to not be called.
cp, sed, and mount -o bind should never end up not returning. i've been using the new code in my scripts for a while now without issue, as have many users (whether they noticed or not!). the problem is that it will only be 100% effective if all WebUI scripter adhere to the same approach. i still include arbitrary sleep delays in my scripts alongside the flock currently to offset concurrent seds. those will be removed if/when flock is adopted by all webui addons
 
yes it would wait forever, but there shouldn't be a reason for the flock -u to not be called.
cp, sed, and mount -o bind should never end up not returning. i've been using the new code in my scripts for a while now without issue, as have many users (whether they noticed or not!). the problem is that it will only be 100% effective if all WebUI scripter adhere to the same approach. i still include arbitrary sleep delays in my scripts alongside the flock currently to offset concurrent seds. those will be removed if/when flock is adopted by all webui addons
Is there anything special or unique about the 386 file descriptor?
 
yes it would wait forever, but there shouldn't be a reason for the flock -u to not be called.
cp, sed, and mount -o bind should never end up not returning. i've been using the new code in my scripts for a while now without issue, as have many users (whether they noticed or not!). the problem is that it will only be 100% effective if all WebUI scripter adhere to the same approach. i still include arbitrary sleep delays in my scripts alongside the flock currently to offset concurrent seds. those will be removed if/when flock is adopted by all webui addons
FYI, The serialisation concept mandates ideally you should use the MUTEX every time you need to ensure EXCLUSIVE safe access to the resource, rather than cherry-pick when you think you may need it

So clearly this recently published code snippet is still potentially exposed....
Code:
Menu_Uninstall(){
    Print_Output true "Removing $SCRIPT_NAME..." "$PASS"
    Auto_Startup delete 2>/dev/null
    Auto_Cron delete 2>/dev/null
    Auto_ServiceEvent delete 2>/dev/null
    
    Get_WebUI_Page "$SCRIPT_DIR/vnstat-ui.asp"
    if [ -n "$MyPage" ] && [ "$MyPage" != "none" ] && [ -f "/tmp/menuTree.js" ]; then
        sed -i "\\~$MyPage~d" /tmp/menuTree.js
        umount /www/require/modules/menuTree.js
        mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js
        rm -rf "{$SCRIPT_WEBPAGE_DIR:?}/$MyPage"
    fi
    
    <snip>
 
FYI, The serialisation concept mandates ideally you should use the MUTEX every time you need to ensure EXCLUSIVE safe access to the resource, rather than cherry-pick when you think you may need it

So clearly this recently published code snippet is still potentially exposed....
Code:
Menu_Uninstall(){
    Print_Output true "Removing $SCRIPT_NAME..." "$PASS"
    Auto_Startup delete 2>/dev/null
    Auto_Cron delete 2>/dev/null
    Auto_ServiceEvent delete 2>/dev/null
   
    Get_WebUI_Page "$SCRIPT_DIR/vnstat-ui.asp"
    if [ -n "$MyPage" ] && [ "$MyPage" != "none" ] && [ -f "/tmp/menuTree.js" ]; then
        sed -i "\\~$MyPage~d" /tmp/menuTree.js
        umount /www/require/modules/menuTree.js
        mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js
        rm -rf "{$SCRIPT_WEBPAGE_DIR:?}/$MyPage"
    fi
   
    <snip>
while uninstall is vulnerable, it is unlikely that an uninstall will take place while a script is still "starting up" from a reboot. it's a risk, yes, but the primary concern was targeting reboot events when multiple scripts run concurrently
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top