Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
app-notes:dashboard [2023/10/31 13:03] – [Check your installation] klueppelapp-notes:dashboard [2023/11/02 08:48] (current) – [Check your installation] klueppel
Line 7: Line 7:
  
 {{ :app-notes:dashboard.png?800 |}} {{ :app-notes:dashboard.png?800 |}}
- 
 ===== Prerequierments ===== ===== Prerequierments =====
  
Line 34: Line 33:
 In the script tab copy and paste the sdk script.  In the script tab copy and paste the sdk script. 
  
-<code> +{{ :app-notes:dashboard-script.png?800 |}} 
-SUPER DUPER SCRIPT+ 
 +<code c dashboard.are
 +ID = 1; 
 +hotlink = ""; 
 + 
 + 
 +string pp_var(var) { 
 + 
 +    tmp=tolower(var); 
 +    tmp=explode(tmp); 
 + 
 +    tmp[0] = toupper(tmp[0]); 
 +    for (i=0; i<length(tmp); i++) { 
 + 
 +        if (tmp[i] == '_' ) { 
 +            tmp[i] = ' '; 
 +            tmp[i+1] = toupper(tmp[i+1]); 
 +        } 
 +    } 
 +    return implode(tmp); 
 + 
 +
 + 
 +string pp(value) { 
 +    switch (value) { 
 +        case "up":         return '<font color="green">up</front>'; 
 +        case "good":       return '<font color="green">good</front>'; 
 +        case "excelent":   return '<font color="green">excelent</front>'; 
 + 
 +        case "dialing":    return '<font color="orange">dialing</font>'; 
 +        case "medium":     return '<font color="orange">medium</font>'; 
 + 
 +        case "weak":       return '<font color="red">weak</font>'; 
 +        case "down":       return '<font color="red">down</font>'; 
 +    } 
 + 
 +    return value; 
 +
 + 
 + 
 +void print_table(array fields) { 
 +     nb_page_respond(page, '<table>\n'); 
 +     nb_page_respond(page, '<tr><th><b>'); 
 +     nb_page_respond(page, left(fields[0], 8)); 
 +     nb_page_respond(page, '</b></th><th>'); 
 + 
 +     if (struct_get(wan, "WAN_HOTLINK") != left(fields[0], 8) ) { 
 +        nb_page_respond(page, '<form action="sdkPage.php" type="GET" style="padding-top: 2px;margin-bottom: 2px;margin-top: 2px;right;text-align: right;"> 
 +                               <input type="hidden" id="id" name="id" value="00000001">'); 
 +        nb_page_respond(page,  sprintf("<input type='hidden' id='hotlink' name='hotlink' value='%s'>",left(fields[0], 8))); 
 +        nb_page_respond(page, '<input style="margin-top: 0px" type="submit" value="Use as Hotlink"></form>'); 
 +     }  
 + 
 +     nb_page_respond(page, '</th></tr>'); 
 + 
 +         for (i=0; i < length(fields); i++) { 
 +             nb_page_respond(page, '<tr>\n'); 
 +             nb_page_respond(page, '<td>%s</td>', sprintf("%s", pp_var(substr(fields[i], 9)))); 
 +             nb_page_respond(page, sprintf("<td align='right'>%s</td>", pp(struct_get(wan, fields[i])))); 
 +             nb_page_respond(page, '</tr>\n'); 
 +         } 
 + 
 +         nb_page_respond(page, '</table>\n'); 
 +         nb_page_respond(page, '<br>\n'); 
 + 
 +
 +  
 + 
 + 
 +     /* register page */ 
 +     page = nb_userpage_register(ID, "Wanlink", "Switch"); 
 +     if (is_void(page)) { 
 +         printf("unable to register page\n"); 
 +         exit(1); 
 +     } 
 +  
 +     while (1) { 
 + 
 +        printf("waiting for requests...\n"); 
 +        /* wait for page request */ 
 +        request = nb_page_request(page); 
 + 
 +        if (!is_void(request)) { 
 +           /* evaluate GET params */ 
 +           GET = struct_get(request, "GET"); 
 +        } 
 +        for (k = 0; k < length(GET); k++) { 
 +            key = struct_get(GET[k], "key"); 
 +            if (key == "hotlink") { 
 +                hotlink = struct_get(GET[k], "value"); 
 +            } 
 +            if (key == "action") { 
 +                action = struct_get(GET[k], "value"); 
 +                if (action == "reboot")  
 +                    nb_reboot(0); 
 +            } 
 +        } 
 +        if (hotlink != "") { 
 +            nb_wanlink_priorize(hotlink, 2); 
 +            sleep(5); 
 +        } 
 + 
 + 
 +        fields = mkarray(); 
 + 
 +        wan = nb_status("wan"); 
 +        for (i=1; i <=9; i++) {  
 +          
 +            wan_state = struct_get(wan, sprintf("WANLINK%d_STATE", i)); 
 +            wan_idx =  sprintf("WANLINK%d", i); 
 + 
 +            if (strlen(wan_state) > 0) { 
 +                 
 +                // Attributes for WWAN link 
 +                wan_array = mkarray(sprintf("%s_STATE", wan_idx),  
 +                                    sprintf("%s_TYPE", wan_idx),  
 +                                    sprintf("%s_SIGNAL_LEVEL", wan_idx),  
 +                                    sprintf("%s_SIGNAL_QUALITY", wan_idx),  
 +                                    sprintf("%s_SERVICE_TYPE", wan_idx),  
 +                                    sprintf("%s_NETWORK", wan_idx) 
 +                                    ); 
 + 
 +                // Attributes for ETH/LAN link 
 +                eth_array = mkarray(sprintf("%s_STATE", wan_idx),  
 +                                    sprintf("%s_TYPE", wan_idx),  
 +                                    sprintf("%s_ADDRESS", wan_idx),  
 +                                    sprintf("%s_GATEWAY", wan_idx) 
 +                                    ); 
 + 
 + 
 +                type = struct_get(wan, sprintf("WANLINK%d_TYPE", i)); 
 +                switch (type) { 
 +                    case "eth": tmp_array = eth_array; 
 +                            break; 
 +                    case "wwan": tmp_array = wan_array; 
 +                            break; 
 +                } 
 +                fields[i-1] = tmp_array; 
 +            } 
 +        } 
 + 
 +        nb_page_respond(page, '<table>\n'); 
 +        nb_page_respond(page, '<tr>\n'); 
 +        nb_page_respond(page, '<td>Hotlink</td>'); 
 +         
 +        nb_page_respond(page, sprintf("<td align='right'>%s</td>", struct_get(wan, "WAN_HOTLINK"))); 
 +        nb_page_respond(page, '</tr></table>\n'); 
 +        nb_page_respond(page, '<br>\n'); 
 + 
 +        nb_page_respond(page, '<table>\n'); 
 +        nb_page_respond(page,'<tr><td>Reebot</td><td align="right"> 
 +                             <form action="sdkPage.php" type="GET"> 
 +                             <input type="hidden" id="id" name="id" value="00000001"> 
 +                             <input type="hidden" id="action" name="action" value="reboot"> 
 +                             <input style="margin-top: 0px" type="submit" value="reboot"></td></tr></form>\n'); 
 +         
 +        nb_page_respond(page, '</tr></table>\n'); 
 +        nb_page_respond(page, '<br>\n'); 
 + 
 + 
 +        for (j=0; j<length(fields); j++) { 
 +            if (!is_void(fields[j])) { 
 +                print_table(fields[j]); 
 +            } 
 +        } 
 + 
 +        nb_page_finish(page); 
 +  } 
 + 
 +nb_page_unregister(page); 
 +exit(0); 
 + 
 </code> </code>
  
  
-{{ :app-notes:dashboard-script.png?800 |}}+ 
 + 
  
 === Create a SDK job === === Create a SDK job ===
Line 57: Line 230:
 After the sdk has been started, you should have a new status page. After the sdk has been started, you should have a new status page.
  
-Goto HOME -> Overwiev -> Interfaces+Navigate to HOME -> Overwiev -> Interfaces
  
 +{{ :app-notes:dashboard.png?800 |}}
  
  
 The page might look diffrent, depending on your number of wanlinks. The page might look diffrent, depending on your number of wanlinks.
  
-{{ :app-notes:dashboard.png?800 |}} 
  
  
Line 69: Line 242:
 Your current hotlink is displayed at the top. Also, each enabled wanlink will be listet on the new status page. Your current hotlink is displayed at the top. Also, each enabled wanlink will be listet on the new status page.
 All links, except for the current hotlink, have a button "Use as hotlink". This can be used to change the current hotlink. All links, except for the current hotlink, have a button "Use as hotlink". This can be used to change the current hotlink.
-This may take some time, sometimes the hotlink will be shows as "n/a"You should reload the page and the new hotlink will be displayed.+This may take some time, sometimes the hotlink will be shown as "n/a"Reload the page and the new hotlink will be displayed.
  
 ==== Reboot the Router ==== ==== Reboot the Router ====
-The page has also a reboot button. The device will reboot after 5 seconds.+The page has a reboot button. The device will reboot after 5 seconds.
  
  
 ==== Extend the info for a wanlink ==== ==== Extend the info for a wanlink ====
-You can add/remove the fields that will be shown. +You can add/remove the fields that are shown. 
  
  
Line 100: Line 273:
  
  
-A full list for all availible attributes can be listed on the shell via:+For all attributes, use the shell command "cli status -s wan":
  
 <code> <code>
Line 146: Line 319:
 </code> </code>
  
 +
 +Thats it. Enjoy your new status page.