{"action":"created","issue":{"url":"https://api.github.com/repos/openwrt/luci/issues/668","repository_url":"https://api.github.com/repos/openwrt/luci","labels_url":"https://api.github.com/repos/openwrt/luci/issues/668/labels{/name}","comments_url":"https://api.github.com/repos/openwrt/luci/issues/668/comments","events_url":"https://api.github.com/repos/openwrt/luci/issues/668/events","html_url":"https://github.com/openwrt/luci/issues/668","id":139899949,"number":668,"title":"cannot delete ssh keys","user":{"login":"feckert","id":553091,"avatar_url":"https://avatars.githubusercontent.com/u/553091?v=3","gravatar_id":"","url":"https://api.github.com/users/feckert","html_url":"https://github.com/feckert","followers_url":"https://api.github.com/users/feckert/followers","following_url":"https://api.github.com/users/feckert/following{/other_user}","gists_url":"https://api.github.com/users/feckert/gists{/gist_id}","starred_url":"https://api.github.com/users/feckert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feckert/subscriptions","organizations_url":"https://api.github.com/users/feckert/orgs","repos_url":"https://api.github.com/users/feckert/repos","events_url":"https://api.github.com/users/feckert/events{/privacy}","received_events_url":"https://api.github.com/users/feckert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-10T14:18:28Z","updated_at":"2016-03-10T17:01:54Z","closed_at":null,"body":"Hello,\r\n\r\nI cannot remove my added ssh key from the form section under administration.\r\nLuci always complains that the form field is empty.\r\nA workaround is to hint enter in the form and save this.\r\n\r\nI have looked into the code under \"model/cbi/admin_system/admin.lua\". And add a validate function to check if the form is empty and if so return a new line Charakter '\\n' but nothing happens the value will not be written to disk.\r\n\r\nfunction keys.validate(self,value)\r\n  local i=value\r\n  if value == nil then\r\n    i=\"\\n\"\r\n  end\r\n  return i\r\nend\r\n\r\nWhat can i do?\r\n\r\nKind Regards\r\n\r\nFlo"},"comment":{"url":"https://api.github.com/repos/openwrt/luci/issues/comments/194956682","html_url":"https://github.com/openwrt/luci/issues/668#issuecomment-194956682","issue_url":"https://api.github.com/repos/openwrt/luci/issues/668","id":194956682,"user":{"login":"hnyman","id":7926856,"avatar_url":"https://avatars.githubusercontent.com/u/7926856?v=3","gravatar_id":"","url":"https://api.github.com/users/hnyman","html_url":"https://github.com/hnyman","followers_url":"https://api.github.com/users/hnyman/followers","following_url":"https://api.github.com/users/hnyman/following{/other_user}","gists_url":"https://api.github.com/users/hnyman/gists{/gist_id}","starred_url":"https://api.github.com/users/hnyman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hnyman/subscriptions","organizations_url":"https://api.github.com/users/hnyman/orgs","repos_url":"https://api.github.com/users/hnyman/repos","events_url":"https://api.github.com/users/hnyman/events{/privacy}","received_events_url":"https://api.github.com/users/hnyman/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T17:01:54Z","updated_at":"2016-03-10T17:01:54Z","body":"Relevant code is found at https://github.com/openwrt/luci/blob/master/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/admin.lua#L102\r\n\r\n```\r\nkeys = s2:option(TextValue, \"_data\", \"\")\r\nkeys.wrap    = \"off\"\r\nkeys.rows    = 3\r\nkeys.rmempty = false\r\n\r\nfunction keys.cfgvalue()\r\n\treturn fs.readfile(\"/etc/dropbear/authorized_keys\") or \"\"\r\nend\r\n\r\nfunction keys.write(self, section, value)\r\n\tif value then\r\n\t\tfs.writefile(\"/etc/dropbear/authorized_keys\", value:gsub(\"\\r\\n\", \"\\n\"))\r\n\tend\r\nend\r\n```\r\n\r\nThe reason why nothing gets written with empty input is probably the if clause at line 113 in the write function.\r\n\r\nI think that one alternative would be modify the if clause with an else statement to handle the empty value case. Something like\r\n```\r\n\tif value then\r\n\t\tfs.writefile(\"/etc/dropbear/authorized_keys\", value)\r\n\telse \r\n\t\tfs.writefile(\"/etc/dropbear/authorized_keys\", \"\")\r\n\tend\r\n```\r\n\r\nOr the if clause could be reformulated to first do the possible newline string substitution if there is value and alternatively set value to \"\\n\" (or \"\", if that can passed to writefile). Something like \r\n```\r\n\tif value then\r\n\t\tvalue = value:gsub(\"\\r\\n\", \"\\n\")\r\n\telse \r\n\t\tvalue = \"\"\r\n\tend\r\n\tfs.writefile(\"/etc/dropbear/authorized_keys\", value)\r\n```\r\n\r\n\r\n"}}