Advertisement
cetipabo

gaterway.lp

Mar 3rd, 2018
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. --pretranslated: do not change this file
  2.  
  3. -- Enable localization
  4. gettext.textdomain('webui-core')
  5.  
  6. local proxy = require("datamodel")
  7. local ui_helper = require("web.ui_helper")
  8. local content_helper = require("web.content_helper")
  9.  
  10. local find, sub = string.find, string.sub
  11. local floor, ipairs = math.floor, ipairs
  12. local format = string.format
  13.  
  14. -- Non-configurable data
  15. local content = {
  16.   software_name = "uci.version.version.@version[0].marketing_name",
  17.   software_version = "uci.version.version.@version[0].marketing_version",
  18.   factory_id = "uci.env.rip.factory_id",
  19.   serial_number = "uci.env.rip.serial",
  20. }
  21.  
  22. content_helper.getExactContent(content)
  23.  
  24. content["uptime"] = content_helper.readfile("/proc/uptime","number",floor)
  25.  
  26. local name = proxy.get("uci.env.var.friendly_sw_version_activebank")
  27. if name then
  28.     name = name[1].value
  29.     name = name:gsub("_"," ")
  30. else
  31.     name = ""
  32. end
  33.  
  34. local board = proxy.get("uci.env.rip.board_mnemonic")
  35. if board then
  36.     board = board[1].value
  37. else
  38.     board = ""
  39. end
  40.  
  41.  
  42. -- Construct an uptime string from the number of seconds
  43. local function secondsToTime(uptime)
  44.   local days =  floor(uptime / 86400)
  45.   local hours =  floor(uptime / 3600) % 24
  46.   local minutes = floor(uptime / 60) % 60
  47.   local seconds = uptime % 60
  48.   if (days > 0) then
  49.     return format(T"%ddays %dhours %dmin %dsec", days, hours, minutes, seconds)
  50.   elseif (hours > 0) then
  51.     return format(T"%dhours %dmin %dsec", hours, minutes, seconds)
  52.   elseif (minutes > 0) then
  53.     return format(T"%dmin %dsec", minutes, seconds)
  54.   else
  55.     return format(T"%dsec", seconds)
  56.   end
  57. end
  58.  
  59. local session = ngx.ctx.session
  60. if session:hasAccess("/modals/gateway-modal.lp") then
  61.  
  62. local headerAttr = {
  63.     icon = {
  64.         class = "icon-cogs"
  65.     }
  66. }
  67.  
  68.   ngx.print('\
  69. <div class="span3">\
  70.  <div class="smallcard">\
  71.    ');  ngx.print( ui_helper.createCardHeader(T"Gateway", "modals/gateway-modal.lp", nil, nil, headerAttr) ); ngx.print('\
  72.    <div class="content">\
  73.      <div class="light green"></div>\
  74.      <p>');  ngx.print( T"Version: " ); ngx.print(' <strong>');  ngx.print( content.software_name .. " (" .. content.software_version .. ")" ); ngx.print('</strong></p>\
  75.      <p class="subinfos">');  ngx.print( T"Firmware: " ); ngx.print(' '); ngx.print('<b>'); ngx.print( name ); ngx.print('</b>'); ngx.print('</p>\
  76.       <p class="subinfos">');  ngx.print( T"Board: " ); ngx.print(' '); ngx.print('<b>'); ngx.print( board ); ngx.print('</b>'); ngx.print('</p>\
  77.      <p class="subinfos">');  ngx.print( T"Uptime: " ); ngx.print(' <b>');  ngx.print( secondsToTime(content["uptime"]) ); ngx.print('</b></p>\
  78.      <div data-toggle="modal" data-remote="modals/gateway-modal.lp" data-id="gateway-modal">\
  79.      </div>\
  80.    </div>\
  81.  </div>\
  82. </div>\
  83. ');  
  84. end
  85.   ngx.print('\
  86. ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement