diff options
author | Ted Trask <ttrask01@yahoo.com> | 2014-11-04 13:32:08 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2014-11-04 13:32:08 +0000 |
commit | 73c48f0c37ba86df1c5de5e2b1a7ebdf96ff63fa (patch) | |
tree | bcd1970573c55f67f4f6394d0a82a51fa48b4296 | |
parent | a35207f4a93d5e1eb3892bc7496d5019a71b3734 (diff) | |
download | acf-kamailio-73c48f0c37ba86df1c5de5e2b1a7ebdf96ff63fa.tar.bz2 acf-kamailio-73c48f0c37ba86df1c5de5e2b1a7ebdf96ff63fa.tar.xz |
More changes to make createdatabase work for MYSQL
-rw-r--r-- | kamailio-controller.lua | 2 | ||||
-rw-r--r-- | kamailio-model.lua | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/kamailio-controller.lua b/kamailio-controller.lua index 7f7073c..f1de20b 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -36,7 +36,7 @@ function mymodule.updateuser(self) end function mymodule.createdatabase(self) - return self.handle_form(self, self.model.get_create_database, self.model.create_database, self.clientdata, "Create", "Create Database", "Database created") + return self.handle_form(self, self.model.get_create_database, self.model.create_database, self.clientdata, "Create", "Create Database") end function mymodule.searchdatabase(self) 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" |