{"action":"created","comment":{"url":"https://api.github.com/repos/openwrt/luci/pulls/comments/101603930","pull_request_review_id":22338836,"id":101603930,"diff_hunk":"@@ -0,0 +1,281 @@\n+<%#\n+ Copyright 2016-2017 Dan Luedtke <mail@danrl.com>\n+ Licensed to the public under the Apache License 2.0.\n+-%>\n+\n+<%\n+  function strip(s)\n+    return (s:gsub(\"^%s*(.-)%s*$\", \"%1\"))\n+  end\n+\n+  function is_valid(s)\n+    return (string.len(strip(s)) > 0)\n+  end\n+\n+  function peer_add(peers, public_key)\n+    table.insert(peers, {\n+      public_key = public_key,\n+      endpoint = \"\",\n+      transfer_rx = 0,\n+      transfer_tx = 0,\n+      latest_handshake = -1,\n+      persistent_keepalive = \"\",\n+      allowed_ips = { }\n+    })\n+  end\n+\n+  function peer_set_transfer(peers, public_key, rx, tx)\n+    for key, peer in pairs(peers) do\n+      if peer.public_key == public_key then\n+        peers[key].transfer_rx = rx\n+        peers[key].transfer_tx = tx\n+        break\n+      end\n+    end\n+  end\n+\n+  function peer_set_latest_handshake(peers, public_key, latest_handshake)\n+    for key, peer in pairs(peers) do\n+      if peer.public_key == public_key then\n+        peers[key].latest_handshake = latest_handshake\n+        break\n+      end\n+    end\n+  end\n+\n+  function peer_set_endpoint(peers, public_key, endpoint)\n+    for key, peer in pairs(peers) do\n+      if peer.public_key == public_key then\n+        peers[key].endpoint = endpoint\n+        break\n+      end\n+    end\n+  end\n+\n+  function peer_set_persistent_keepalive(peers, public_key, persistent_keepalive)\n+    for key, peer in pairs(peers) do\n+      if peer.public_key == public_key then\n+        peers[key].persistent_keepalive = persistent_keepalive\n+        break\n+      end\n+    end\n+  end\n+\n+  function peer_set_allowed_ips(peers, public_key, allowed_ips)\n+    for key, peer in pairs(peers) do\n+      if peer.public_key == public_key then\n+        for ipkey, ipvalue in pairs(string.split(allowed_ips, \" \")) do\n+          if is_valid(ipvalue) then\n+            table.insert(peers[key].allowed_ips, strip(ipvalue))\n+          end\n+        end\n+        break\n+      end\n+    end\n+  end\n+\n+  local data = { }\n+\n+  local wg_ifaces = luci.sys.exec(\"wg show interfaces\")\n+  for key, name in pairs(string.split(wg_ifaces, \"\\n\")) do\n+    if not is_valid(name) then break end\n+    name = strip(name)\n+    local public_key = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" public-key\")\n+    local listening_port = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" listen-port\")\n+\n+    local peers = { }\n+    local wg_peers = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" peers\")\n+    for key, public_key in pairs(string.split(wg_peers, \"\\n\")) do\n+      if not is_valid(public_key) then break end\n+      peer_add(peers, public_key)\n+    end\n+\n+    local wg_endpoints = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" endpoints\")\n+    for key, endpoint in pairs(string.split(wg_endpoints, \"\\n\")) do\n+      if not is_valid(endpoint) then break end\n+      local ln = string.split(strip(endpoint), \"\\t\")\n+      peer_set_endpoint(peers, ln[1], strip(ln[2]))\n+    end\n+\n+    local wg_allowed_ips = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" allowed-ips\")\n+    for key, allowed_ips in pairs(string.split(wg_allowed_ips, \"\\n\")) do\n+      if not is_valid(allowed_ips) then break end\n+      local ln = string.split(strip(allowed_ips), \"\\t\", 2)\n+      peer_set_allowed_ips(peers, ln[1], strip(ln[2]))\n+    end\n+\n+    local wg_persistent_keepalives = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" persistent-keepalive\")\n+    for key, persistent_keepalive in pairs(string.split(wg_persistent_keepalives, \"\\n\")) do\n+      if not is_valid(persistent_keepalive) then break end\n+      local ln = string.split(strip(persistent_keepalive), \"\\t\")\n+      peer_set_persistent_keepalive(peers, strip(ln[1]), strip(ln[2]))\n+    end\n+\n+    local wg_latest_handshakes = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" latest-handshakes\")\n+    for key, latest_handshake in pairs(string.split(wg_latest_handshakes, \"\\n\")) do\n+      if not is_valid(latest_handshake) then break end\n+      local ln = string.split(strip(latest_handshake), \"\\t\")\n+      peer_set_latest_handshake(peers, strip(ln[1]), tonumber(ln[2]))\n+    end\n+\n+    local wg_transfers = luci.sys.exec(\"wg show \\\"\" .. name .. \"\\\" transfer\")\n+    for key, transfer in pairs(string.split(wg_transfers, \"\\n\")) do\n+      if not is_valid(transfer) then break end\n+      local ln = string.split(strip(transfer), \"\\t\")\n+      peer_set_transfer(peers, ln[1], strip(ln[2]), strip(ln[3]))\n+    end\n+\n+    table.insert(data, {\n+      name = name,\n+      public_key = strip(public_key),\n+      listening_port = tonumber(strip(listening_port)),\n+      peers = peers\n+    })\n+  end\n+\n+  if luci.http.formvalue(\"status\") == \"1\" then\n+    luci.http.prepare_content(\"application/json\")\n+    luci.http.write_json(data)\n+    return\n+  end\n+-%>\n+\n+<%+header%>\n+\n+<script type=\"text/javascript\" src=\"<%=resource%>/cbi.js\"></script>\n+<script type=\"text/javascript\">//<![CDATA[\n+\n+  function bytes_to_str(bytes) {\n+     var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\n+     if (bytes == 0) return '0 Byte';","path":"applications/luci-app-wireguard/luasrc/view/wireguard.htm","position":150,"original_position":150,"commit_id":"0eafde1804e8f36d785bf931071bc720844b8fed","original_commit_id":"0eafde1804e8f36d785bf931071bc720844b8fed","user":{"login":"zx2c4","id":10643,"avatar_url":"https://avatars.githubusercontent.com/u/10643?v=3","gravatar_id":"","url":"https://api.github.com/users/zx2c4","html_url":"https://github.com/zx2c4","followers_url":"https://api.github.com/users/zx2c4/followers","following_url":"https://api.github.com/users/zx2c4/following{/other_user}","gists_url":"https://api.github.com/users/zx2c4/gists{/gist_id}","starred_url":"https://api.github.com/users/zx2c4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zx2c4/subscriptions","organizations_url":"https://api.github.com/users/zx2c4/orgs","repos_url":"https://api.github.com/users/zx2c4/repos","events_url":"https://api.github.com/users/zx2c4/events{/privacy}","received_events_url":"https://api.github.com/users/zx2c4/received_events","type":"User","site_admin":false},"body":"\"Bytes\" for zero, actually. But it's likely more consistent to just use abbreviations for all of these. Also, since you're dividing by powers of two, you actually want the `i` versions:\r\n\r\n* B\r\n* KiB\r\n* MiB\r\n* GiB\r\n* TiB\r\n* PiB","created_at":"2017-02-16T19:20:37Z","updated_at":"2017-02-16T19:20:37Z","html_url":"https://github.com/openwrt/luci/pull/1022#discussion_r101603930","pull_request_url":"https://api.github.com/repos/openwrt/luci/pulls/1022","_links":{"self":{"href":"https://api.github.com/repos/openwrt/luci/pulls/comments/101603930"},"html":{"href":"https://github.com/openwrt/luci/pull/1022#discussion_r101603930"},"pull_request":{"href":"https://api.github.com/repos/openwrt/luci/pulls/1022"}}},"pull_request":{"url":"https://api.github.com/repos/openwrt/luci/pulls/1022","id":106594214,"html_url":"https://github.com/openwrt/luci/pull/1022","diff_url":"https://github.com/openwrt/luci/pull/1022.diff","patch_url":"https://github.com/openwrt/luci/pull/1022.patch","issue_url":"https://api.github.com/repos/openwrt/luci/issues/1022","number":1022,"state":"open","locked":false,"title":"luci-app-wireguard: initial commit","user":{"login":"danrl","id":859656,"avatar_url":"https://avatars.githubusercontent.com/u/859656?v=3","gravatar_id":"","url":"https://api.github.com/users/danrl","html_url":"https://github.com/danrl","followers_url":"https://api.github.com/users/danrl/followers","following_url":"https://api.github.com/users/danrl/following{/other_user}","gists_url":"https://api.github.com/users/danrl/gists{/gist_id}","starred_url":"https://api.github.com/users/danrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrl/subscriptions","organizations_url":"https://api.github.com/users/danrl/orgs","repos_url":"https://api.github.com/users/danrl/repos","events_url":"https://api.github.com/users/danrl/events{/privacy}","received_events_url":"https://api.github.com/users/danrl/received_events","type":"User","site_admin":false},"body":"This application allows for monitoring of WireGuard interfaces via the\r\nStatus menu.\r\n\r\nSigned-off-by: Dan Luedtke <mail@danrl.com>\r\n\r\nScreenshot (with one online and one offline peer): \r\n![](http://i.imgur.com/CowYEpL.png)\r\n\r\nPlease review, I'll squash after review.\r\n\r\n/cc @p4yne @zx2c4 @zorun","created_at":"2017-02-16T19:15:12Z","updated_at":"2017-02-16T19:20:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc5feb5789c1e2bc667c5712eb6e159de146fe0d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/openwrt/luci/pulls/1022/commits","review_comments_url":"https://api.github.com/repos/openwrt/luci/pulls/1022/comments","review_comment_url":"https://api.github.com/repos/openwrt/luci/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openwrt/luci/issues/1022/comments","statuses_url":"https://api.github.com/repos/openwrt/luci/statuses/0eafde1804e8f36d785bf931071bc720844b8fed","head":{"label":"danrl:luci-app-wireguard","ref":"luci-app-wireguard","sha":"0eafde1804e8f36d785bf931071bc720844b8fed","user":{"login":"danrl","id":859656,"avatar_url":"https://avatars.githubusercontent.com/u/859656?v=3","gravatar_id":"","url":"https://api.github.com/users/danrl","html_url":"https://github.com/danrl","followers_url":"https://api.github.com/users/danrl/followers","following_url":"https://api.github.com/users/danrl/following{/other_user}","gists_url":"https://api.github.com/users/danrl/gists{/gist_id}","starred_url":"https://api.github.com/users/danrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrl/subscriptions","organizations_url":"https://api.github.com/users/danrl/orgs","repos_url":"https://api.github.com/users/danrl/repos","events_url":"https://api.github.com/users/danrl/events{/privacy}","received_events_url":"https://api.github.com/users/danrl/received_events","type":"User","site_admin":false},"repo":{"id":73825938,"name":"lede-luci","full_name":"danrl/lede-luci","owner":{"login":"danrl","id":859656,"avatar_url":"https://avatars.githubusercontent.com/u/859656?v=3","gravatar_id":"","url":"https://api.github.com/users/danrl","html_url":"https://github.com/danrl","followers_url":"https://api.github.com/users/danrl/followers","following_url":"https://api.github.com/users/danrl/following{/other_user}","gists_url":"https://api.github.com/users/danrl/gists{/gist_id}","starred_url":"https://api.github.com/users/danrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrl/subscriptions","organizations_url":"https://api.github.com/users/danrl/orgs","repos_url":"https://api.github.com/users/danrl/repos","events_url":"https://api.github.com/users/danrl/events{/privacy}","received_events_url":"https://api.github.com/users/danrl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/danrl/lede-luci","description":"LuCI - OpenWrt Configuration Interface","fork":true,"url":"https://api.github.com/repos/danrl/lede-luci","forks_url":"https://api.github.com/repos/danrl/lede-luci/forks","keys_url":"https://api.github.com/repos/danrl/lede-luci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/danrl/lede-luci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/danrl/lede-luci/teams","hooks_url":"https://api.github.com/repos/danrl/lede-luci/hooks","issue_events_url":"https://api.github.com/repos/danrl/lede-luci/issues/events{/number}","events_url":"https://api.github.com/repos/danrl/lede-luci/events","assignees_url":"https://api.github.com/repos/danrl/lede-luci/assignees{/user}","branches_url":"https://api.github.com/repos/danrl/lede-luci/branches{/branch}","tags_url":"https://api.github.com/repos/danrl/lede-luci/tags","blobs_url":"https://api.github.com/repos/danrl/lede-luci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/danrl/lede-luci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/danrl/lede-luci/git/refs{/sha}","trees_url":"https://api.github.com/repos/danrl/lede-luci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/danrl/lede-luci/statuses/{sha}","languages_url":"https://api.github.com/repos/danrl/lede-luci/languages","stargazers_url":"https://api.github.com/repos/danrl/lede-luci/stargazers","contributors_url":"https://api.github.com/repos/danrl/lede-luci/contributors","subscribers_url":"https://api.github.com/repos/danrl/lede-luci/subscribers","subscription_url":"https://api.github.com/repos/danrl/lede-luci/subscription","commits_url":"https://api.github.com/repos/danrl/lede-luci/commits{/sha}","git_commits_url":"https://api.github.com/repos/danrl/lede-luci/git/commits{/sha}","comments_url":"https://api.github.com/repos/danrl/lede-luci/comments{/number}","issue_comment_url":"https://api.github.com/repos/danrl/lede-luci/issues/comments{/number}","contents_url":"https://api.github.com/repos/danrl/lede-luci/contents/{+path}","compare_url":"https://api.github.com/repos/danrl/lede-luci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/danrl/lede-luci/merges","archive_url":"https://api.github.com/repos/danrl/lede-luci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/danrl/lede-luci/downloads","issues_url":"https://api.github.com/repos/danrl/lede-luci/issues{/number}","pulls_url":"https://api.github.com/repos/danrl/lede-luci/pulls{/number}","milestones_url":"https://api.github.com/repos/danrl/lede-luci/milestones{/number}","notifications_url":"https://api.github.com/repos/danrl/lede-luci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/danrl/lede-luci/labels{/name}","releases_url":"https://api.github.com/repos/danrl/lede-luci/releases{/id}","deployments_url":"https://api.github.com/repos/danrl/lede-luci/deployments","created_at":"2016-11-15T15:16:21Z","updated_at":"2017-01-10T19:53:29Z","pushed_at":"2017-02-16T19:18:25Z","git_url":"git://github.com/danrl/lede-luci.git","ssh_url":"git@github.com:danrl/lede-luci.git","clone_url":"https://github.com/danrl/lede-luci.git","svn_url":"https://github.com/danrl/lede-luci","homepage":null,"size":29885,"stargazers_count":0,"watchers_count":0,"language":"Lua","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openwrt:master","ref":"master","sha":"c0303598d5420324fa8991bfca8f34d341ab4d44","user":{"login":"openwrt","id":2528830,"avatar_url":"https://avatars.githubusercontent.com/u/2528830?v=3","gravatar_id":"","url":"https://api.github.com/users/openwrt","html_url":"https://github.com/openwrt","followers_url":"https://api.github.com/users/openwrt/followers","following_url":"https://api.github.com/users/openwrt/following{/other_user}","gists_url":"https://api.github.com/users/openwrt/gists{/gist_id}","starred_url":"https://api.github.com/users/openwrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openwrt/subscriptions","organizations_url":"https://api.github.com/users/openwrt/orgs","repos_url":"https://api.github.com/users/openwrt/repos","events_url":"https://api.github.com/users/openwrt/events{/privacy}","received_events_url":"https://api.github.com/users/openwrt/received_events","type":"Organization","site_admin":false},"repo":{"id":24997096,"name":"luci","full_name":"openwrt/luci","owner":{"login":"openwrt","id":2528830,"avatar_url":"https://avatars.githubusercontent.com/u/2528830?v=3","gravatar_id":"","url":"https://api.github.com/users/openwrt","html_url":"https://github.com/openwrt","followers_url":"https://api.github.com/users/openwrt/followers","following_url":"https://api.github.com/users/openwrt/following{/other_user}","gists_url":"https://api.github.com/users/openwrt/gists{/gist_id}","starred_url":"https://api.github.com/users/openwrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openwrt/subscriptions","organizations_url":"https://api.github.com/users/openwrt/orgs","repos_url":"https://api.github.com/users/openwrt/repos","events_url":"https://api.github.com/users/openwrt/events{/privacy}","received_events_url":"https://api.github.com/users/openwrt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openwrt/luci","description":"LuCI - OpenWrt Configuration Interface","fork":false,"url":"https://api.github.com/repos/openwrt/luci","forks_url":"https://api.github.com/repos/openwrt/luci/forks","keys_url":"https://api.github.com/repos/openwrt/luci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openwrt/luci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openwrt/luci/teams","hooks_url":"https://api.github.com/repos/openwrt/luci/hooks","issue_events_url":"https://api.github.com/repos/openwrt/luci/issues/events{/number}","events_url":"https://api.github.com/repos/openwrt/luci/events","assignees_url":"https://api.github.com/repos/openwrt/luci/assignees{/user}","branches_url":"https://api.github.com/repos/openwrt/luci/branches{/branch}","tags_url":"https://api.github.com/repos/openwrt/luci/tags","blobs_url":"https://api.github.com/repos/openwrt/luci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openwrt/luci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openwrt/luci/git/refs{/sha}","trees_url":"https://api.github.com/repos/openwrt/luci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openwrt/luci/statuses/{sha}","languages_url":"https://api.github.com/repos/openwrt/luci/languages","stargazers_url":"https://api.github.com/repos/openwrt/luci/stargazers","contributors_url":"https://api.github.com/repos/openwrt/luci/contributors","subscribers_url":"https://api.github.com/repos/openwrt/luci/subscribers","subscription_url":"https://api.github.com/repos/openwrt/luci/subscription","commits_url":"https://api.github.com/repos/openwrt/luci/commits{/sha}","git_commits_url":"https://api.github.com/repos/openwrt/luci/git/commits{/sha}","comments_url":"https://api.github.com/repos/openwrt/luci/comments{/number}","issue_comment_url":"https://api.github.com/repos/openwrt/luci/issues/comments{/number}","contents_url":"https://api.github.com/repos/openwrt/luci/contents/{+path}","compare_url":"https://api.github.com/repos/openwrt/luci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openwrt/luci/merges","archive_url":"https://api.github.com/repos/openwrt/luci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openwrt/luci/downloads","issues_url":"https://api.github.com/repos/openwrt/luci/issues{/number}","pulls_url":"https://api.github.com/repos/openwrt/luci/pulls{/number}","milestones_url":"https://api.github.com/repos/openwrt/luci/milestones{/number}","notifications_url":"https://api.github.com/repos/openwrt/luci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openwrt/luci/labels{/name}","releases_url":"https://api.github.com/repos/openwrt/luci/releases{/id}","deployments_url":"https://api.github.com/repos/openwrt/luci/deployments","created_at":"2014-10-09T16:02:20Z","updated_at":"2017-02-16T17:19:51Z","pushed_at":"2017-02-16T19:18:26Z","git_url":"git://github.com/openwrt/luci.git","ssh_url":"git@github.com:openwrt/luci.git","clone_url":"https://github.com/openwrt/luci.git","svn_url":"https://github.com/openwrt/luci","homepage":null,"size":29943,"stargazers_count":719,"watchers_count":719,"language":"Lua","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":477,"mirror_url":null,"open_issues_count":96,"forks":477,"open_issues":96,"watchers":719,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openwrt/luci/pulls/1022"},"html":{"href":"https://github.com/openwrt/luci/pull/1022"},"issue":{"href":"https://api.github.com/repos/openwrt/luci/issues/1022"},"comments":{"href":"https://api.github.com/repos/openwrt/luci/issues/1022/comments"},"review_comments":{"href":"https://api.github.com/repos/openwrt/luci/pulls/1022/comments"},"review_comment":{"href":"https://api.github.com/repos/openwrt/luci/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openwrt/luci/pulls/1022/commits"},"statuses":{"href":"https://api.github.com/repos/openwrt/luci/statuses/0eafde1804e8f36d785bf931071bc720844b8fed"}}}}
{"actor":{"display_login":"zx2c4"}}