Skip to content

Login key that uses the minibrowser#

Example: Calls a special login-telephone-number on key-press. But before it does so, it inquires some codes to insert into the phone number from the user by opening a minibrowser.

The key starts a minibrowser and also serves the login.xml that the minibrowser is tasked to show. The minibrowser sends all the entered data to the key, when user presses "Login" within the minibrowser. The key then uses that data to construct the login-telephone-number and calls it.

Warning

This templates needs a valid auth_token, which first needs to be generated via the web ui under Access. Also this generated token is usually different on each device, unless one provisions a fixed token into all devices. Insert the token into the example below (first line of lua-script).

identity_toggle.xml
<templates version="42.47.11" patch="true">
  <template prio="10" name="login" icon="@drawable/login">
    <keyConfiguration>
      <lua>
        <code><![CDATA[
local auth_token = "bq5nIECs;cgfOPiePDnv;m5Zyv)$3XS;" -- must be a valid api-token listed in phones settings under remoteAccess/authTokens/ .. also see WUI->Access (don't forget to click "save" after you've created a new token)
function onActionUrl(url, body, headers, vars)
  local query = vars.query_map
  local cmd = query.cmd
  debug.log("serving request for login.xml, command="..cmd, "d")
  if cmd == "getXml" then
    return 200, [[<?xml version='1.0' encoding='UTF-8'?>
<Menu xmlns='minibrowser_v01.xsd'>
    <Title>Login</Title>
    <Item id='1'>
        <TextInput>
            <Help lang="en">internal phone number</Help>
            <Help lang="de">interne Durchwahl</Help>
            <InputMode>numbersOnly</InputMode>
            <InputType>plain</InputType>
            <Parameter>user</Parameter>
        </TextInput>
    </Item>
    <Item id='2'>
        <TextInput>
            <Help lang="en">enter the PIN</Help>
            <Help lang="de">PIN eingeben</Help>
            <InputMode>numbersOnly</InputMode>
            <InputType>password</InputType>
            <Parameter>pin</Parameter>
        </TextInput>
    </Item>
    <Options>
        <Option>
            <Text lang="en">Cancel</Text>
            <Text lang="de">Abbr.</Text>
            <Quit />
        </Option>
        <Option/>
        <Option/>
        <Option>
            <Text>Login</Text>
            <Url>http://127.0.0.1/api/v1/exec/login.xml?cmd=doLogin&amp;AuthToken=]] .. auth_token .. [[</Url>
        </Option>
    </Options>
</Menu>]]
  elseif cmd == "doLogin" then
    sip.invite{uri="##8" .. query.pin .. "*621" .. query.user .. "#"}
    return 200, [[<?xml version='1.0' encoding='UTF-8'?>
<Dialog xmlns="minibrowser_v01.xsd">
    <AutomatedActions>
        <Quit on="shown" />
    </AutomatedActions>
</Dialog>]]
  else
    debug.log("unknow cmd " .. query.cmd)
  end
end
function onKeyUp()
  -- start the minibrowser
  system.intent{action="android.intent.action.VIEW", component="de.auerswald.minibrowser/.LoadingActivity", data="http://127.0.0.1/api/v1/exec/login.xml?cmd=getXml&AuthToken=" .. auth_token}
end
local mCommandListener = http.listen("login.xml", onActionUrl, true)
key:setLed( "red" )]]>
        </code>
      </lua>
    </keyConfiguration>
  </template>
</templates>