diff options
Diffstat (limited to 'kamailio-model.lua')
-rw-r--r-- | kamailio-model.lua | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/kamailio-model.lua b/kamailio-model.lua index e91e7b3..dcc38e9 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -315,20 +315,25 @@ function mymodule.get_create_database(self, clientdata) databasecreate() end if dbkam and dbkam.engine == db.engine.mysql then + -- parse the kamctlrc file to determine the root user + config = config or format.parse_ini_file(fs.read_file(kamctlrc_file), "") or {} + local user = config.DBROOTUSER or "root" + retval.value.password = cfe({ type="password", label="Password", seq=1 }) + self.handle_clientdata(retval, clientdata) -- MYSQL has some character sets that Kamailio cannot use, namely utf8 and ucs2 -- If it's using one of them, kamdbctl will prompt for which one to use -- so, have to check in advance - local out,err = modelfunctions.run_executable({"mysql", "-h", dbkam.host, "-e", "show variables like '%character_set_server%'"}) + local out,err = modelfunctions.run_executable({"mysql", "-h", dbkam.host, "-e", "show variables like '%character_set_server%'", "-u", user, "-p"..retval.value.password.value}) local charset = string.match(out, "([^%s]+)%s*$") or "" if string.find(charset, "utf8") or string.find(charset, "ucs2") then retval.value.characterset = cfe({ type="select", label="Character Set", option={}, seq=2 }) - out,err = modelfunctions.run_executable({"mysql", "-h", config.DBHOST, "-e", "show character set"}) + out,err = modelfunctions.run_executable({"mysql", "-h", config.DBHOST, "-e", "show character set", "-u", user, "-p"..retval.value.password.value}) local charsets = format.string_to_table(out, "\n") for i,c in ipairs(charsets) do local label = string.match(c, "[^\t]*\t[^\t]*") local value = string.match(c, "[^\t]*") - if value ~= "Charset" and not string.find (value, "utf8") and not string.find(value, "ucs2") then + if label and value and value ~= "Charset" and not string.find (value, "utf8") and not string.find(value, "ucs2") then retval.value.characterset.option[#retval.value.characterset.option+1] = {label=label, value=value} end end @@ -338,7 +343,7 @@ function mymodule.get_create_database(self, clientdata) end function mymodule.create_database(self, create_db) - local input = "y\ny\n" + local input = "y\ny\ny\n" -- MYSQL requires three y's, PGSQL only requires two if create_db.value.characterset then if not modelfunctions.validateselect(create_db.value.characterset) then create_db.errtxt = "Failed to create database" |