Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.65 KB | None | 0 0
  1. diff --git a/mythtv/html/setup/js/wizard.js b/mythtv/html/setup/js/wizard.js
  2. index cf86a4c..f26be17 100644
  3. --- a/mythtv/html/setup/js/wizard.js
  4. +++ b/mythtv/html/setup/js/wizard.js
  5. @@ -1,2 +1,22 @@
  6. +function testDBSettings( host, user, pass, dbname, dbport ) {
  7. + var result = 0;
  8. +
  9. + alert("Test Function Called.");
  10. +
  11. + $.ajaxSetup({ async: false });
  12. + $.post("/Myth/TestDBSettings",
  13. + { HostName: host, UserName: user, Password: pass, DBName: dbname, dbPort: dbport},
  14. + function(data) {
  15. + if (data.bool == "true")
  16. + result = 1;
  17. + else
  18. + alert("data.bool != true");
  19. + }, "json").error(function(data) {
  20. + alert("Database connection failed.");
  21. + });
  22. + $.ajaxSetup({ async: true });
  23. +
  24. + return result;
  25. +}
  26.  
  27. $("#wizardtabs").tabs();
  28. diff --git a/mythtv/html/setup/wizard-database.html b/mythtv/html/setup/wizard-database.html
  29. index 76cf7de..9a67a89 100644
  30. --- a/mythtv/html/setup/wizard-database.html
  31. +++ b/mythtv/html/setup/wizard-database.html
  32. @@ -9,6 +9,7 @@
  33. <tr><th align=right>Database Password:</th>
  34. <td><input id='dbPassword' size=20></td></tr>
  35. </table>
  36. +<input type=button value='Test Database Settings' onClick='javascript:testDBSettings( '192.168.0.99', 'mythtv', 'fdfasd', 'mythconverg', 3306 )'>
  37. <hr>
  38. If the setting you are looking for is not available here, you can go to
  39. the <a href="javascript:loadScreen('/setup/menus/advanced.html', '/Config/Database', '/setup/js/Config.js')">Advanced Database Setup Screen</a>
  40. diff --git a/mythtv/libs/libmythbase/mythdbcon.cpp b/mythtv/libs/libmythbase/mythdbcon.cpp
  41. index 6bdcb09..61f4e54 100644
  42. --- a/mythtv/libs/libmythbase/mythdbcon.cpp
  43. +++ b/mythtv/libs/libmythbase/mythdbcon.cpp
  44. @@ -19,6 +19,32 @@
  45.  
  46. static const uint kPurgeTimeout = 60 * 60;
  47.  
  48. +bool TestDatabase(QString dbHostName,
  49. + QString dbUserName,
  50. + QString dbPassword,
  51. + QString dbName,
  52. + int dbPort)
  53. +{
  54. + if (dbHostName.isEmpty() || dbUserName.isEmpty())
  55. + return false;
  56. +
  57. + MSqlDatabase *db = new MSqlDatabase("dbtest");
  58. +
  59. + if (!db)
  60. + return false;
  61. +
  62. + DatabaseParams dbparms;
  63. + dbparms.dbName = dbName;
  64. + dbparms.dbUserName = dbUserName;
  65. + dbparms.dbPassword = dbPassword;
  66. + dbparms.dbHostName = dbHostName;
  67. + dbparms.dbPort = dbPort;
  68. +
  69. + db->SetDBParams(dbparms);
  70. +
  71. + return db->OpenDatabase(true);
  72. +}
  73. +
  74. MSqlDatabase::MSqlDatabase(const QString &name)
  75. {
  76. m_name = name;
  77. @@ -55,7 +81,7 @@ bool MSqlDatabase::isOpen()
  78. return false;
  79. }
  80.  
  81. -bool MSqlDatabase::OpenDatabase()
  82. +bool MSqlDatabase::OpenDatabase(bool skipdb)
  83. {
  84. if (!m_db.isValid())
  85. {
  86. @@ -68,44 +94,45 @@ bool MSqlDatabase::OpenDatabase()
  87.  
  88. if (!m_db.isOpen())
  89. {
  90. - DatabaseParams dbparms = GetMythDB()->GetDatabaseParams();
  91. - m_db.setDatabaseName(dbparms.dbName);
  92. - m_db.setUserName(dbparms.dbUserName);
  93. - m_db.setPassword(dbparms.dbPassword);
  94. - m_db.setHostName(dbparms.dbHostName);
  95. + if (!skipdb)
  96. + m_dbparms = GetMythDB()->GetDatabaseParams();
  97. + m_db.setDatabaseName(m_dbparms.dbName);
  98. + m_db.setUserName(m_dbparms.dbUserName);
  99. + m_db.setPassword(m_dbparms.dbPassword);
  100. + m_db.setHostName(m_dbparms.dbHostName);
  101.  
  102. - if (dbparms.dbHostName.isEmpty()) // Bootstrapping without a database?
  103. + if (m_dbparms.dbHostName.isEmpty()) // Bootstrapping without a database?
  104. {
  105. connected = true; // Pretend to be connected
  106. return true; // to reduce errors
  107. }
  108.  
  109. - if (dbparms.dbPort)
  110. - m_db.setPort(dbparms.dbPort);
  111. + if (m_dbparms.dbPort)
  112. + m_db.setPort(m_dbparms.dbPort);
  113.  
  114. - if (dbparms.dbPort && dbparms.dbHostName == "localhost")
  115. + if (m_dbparms.dbPort && m_dbparms.dbHostName == "localhost")
  116. m_db.setHostName("127.0.0.1");
  117.  
  118. connected = m_db.open();
  119.  
  120. - if (!connected && dbparms.wolEnabled)
  121. + if (!connected && m_dbparms.wolEnabled)
  122. {
  123. int trycount = 0;
  124.  
  125. - while (!connected && trycount++ < dbparms.wolRetry)
  126. + while (!connected && trycount++ < m_dbparms.wolRetry)
  127. {
  128. VERBOSE(VB_GENERAL, QString(
  129. "Using WOL to wakeup database server (Try %1 of %2)")
  130. - .arg(trycount).arg(dbparms.wolRetry));
  131. + .arg(trycount).arg(m_dbparms.wolRetry));
  132.  
  133. - if (myth_system(dbparms.wolCommand) != GENERIC_EXIT_OK)
  134. + if (myth_system(m_dbparms.wolCommand) != GENERIC_EXIT_OK)
  135. {
  136. VERBOSE(VB_IMPORTANT,
  137. QString("Failed to run WOL command '%1'")
  138. - .arg(dbparms.wolCommand));
  139. + .arg(m_dbparms.wolCommand));
  140. }
  141.  
  142. - sleep(dbparms.wolReconnect);
  143. + sleep(m_dbparms.wolReconnect);
  144. connected = m_db.open();
  145. }
  146.  
  147. diff --git a/mythtv/libs/libmythbase/mythdbcon.h b/mythtv/libs/libmythbase/mythdbcon.h
  148. index 77fad59..e6fc099 100644
  149. --- a/mythtv/libs/libmythbase/mythdbcon.h
  150. +++ b/mythtv/libs/libmythbase/mythdbcon.h
  151. @@ -10,9 +10,16 @@
  152. #include <QList>
  153.  
  154. #include "mythbaseexp.h"
  155. +#include "mythdbparams.h"
  156.  
  157. class QSemaphore;
  158.  
  159. +MBASE_PUBLIC bool TestDatabase(QString dbHostName,
  160. + QString dbUserName,
  161. + QString dbPassword,
  162. + QString dbName = "mythconverg",
  163. + int dbPort = 3306);
  164. +
  165. /// \brief QSqlDatabase wrapper, used by MSqlQuery. Do not use directly.
  166. class MBASE_PUBLIC MSqlDatabase
  167. {
  168. @@ -22,9 +29,11 @@ class MBASE_PUBLIC MSqlDatabase
  169. MSqlDatabase(const QString &name);
  170. ~MSqlDatabase(void);
  171.  
  172. + bool OpenDatabase(bool skipdb = false);
  173. + void SetDBParams(DatabaseParams params) { m_dbparms = params; };
  174. +
  175. private:
  176. bool isOpen(void);
  177. - bool OpenDatabase(void);
  178. bool KickDatabase(void);
  179. QString GetConnectionName(void) const { return m_name; }
  180. QSqlDatabase db(void) const { return m_db; }
  181. @@ -34,6 +43,7 @@ class MBASE_PUBLIC MSqlDatabase
  182. QString m_name;
  183. QSqlDatabase m_db;
  184. QDateTime m_lastDBKick;
  185. + DatabaseParams m_dbparms;
  186. };
  187.  
  188. /// \brief DB connection pool, used by MSqlQuery. Do not use directly.
  189. diff --git a/mythtv/libs/libmythservicecontracts/services/mythServices.h b/mythtv/libs/libmythservicecontracts/services/mythServices.h
  190. index 9fbabe4..fdf51d4 100644
  191. --- a/mythtv/libs/libmythservicecontracts/services/mythServices.h
  192. +++ b/mythtv/libs/libmythservicecontracts/services/mythServices.h
  193. @@ -55,6 +55,7 @@ class SERVICE_PUBLIC MythServices : public Service //, public QScriptable ???
  194. Q_CLASSINFO( "AddStorageGroupDir_Method", "POST" )
  195. Q_CLASSINFO( "RemoveStorageGroupDir_Method", "POST" )
  196. Q_CLASSINFO( "ChangePassword_Method", "POST" )
  197. + Q_CLASSINFO( "TestDBSettings_Method", "POST" )
  198.  
  199. public:
  200.  
  201. @@ -87,12 +88,18 @@ class SERVICE_PUBLIC MythServices : public Service //, public QScriptable ???
  202. const QString &DirName,
  203. const QString &HostName ) = 0;
  204.  
  205. - virtual DTC::SettingList* GetSetting ( const QString &HostName,
  206. - const QString &Key,
  207. + virtual bool TestDBSettings ( const QString &HostName,
  208. + const QString &UserName,
  209. + const QString &Password,
  210. + const QString &DBName,
  211. + int dbPort) = 0;
  212. +
  213. + virtual DTC::SettingList* GetSetting ( const QString &HostName,
  214. + const QString &Key,
  215. const QString &Default ) = 0;
  216.  
  217. - virtual bool PutSetting ( const QString &HostName,
  218. - const QString &Key,
  219. + virtual bool PutSetting ( const QString &HostName,
  220. + const QString &Key,
  221. const QString &Value ) = 0;
  222.  
  223. virtual bool ChangePassword ( const QString &UserName,
  224. diff --git a/mythtv/programs/mythbackend/services/myth.cpp b/mythtv/programs/mythbackend/services/myth.cpp
  225. index 90e562e..343341f 100644
  226. --- a/mythtv/programs/mythbackend/services/myth.cpp
  227. +++ b/mythtv/programs/mythbackend/services/myth.cpp
  228. @@ -25,6 +25,7 @@
  229. #include <QCryptographicHash>
  230.  
  231. #include "mythcorecontext.h"
  232. +#include "mythdbcon.h"
  233. #include "storagegroup.h"
  234.  
  235. /////////////////////////////////////////////////////////////////////////////
  236. @@ -523,3 +524,29 @@ bool Myth::ChangePassword( const QString &sUserName,
  237. return bResult;
  238. }
  239.  
  240. +/////////////////////////////////////////////////////////////////////////////
  241. +//
  242. +/////////////////////////////////////////////////////////////////////////////
  243. +
  244. +bool Myth::TestDBSettings( const QString &HostName,
  245. + const QString &UserName,
  246. + const QString &Password,
  247. + const QString &DBName,
  248. + int dbPort)
  249. +{
  250. + bool bResult = false;
  251. +
  252. + QString db("mythconverg");
  253. + int port = 3306;
  254. +
  255. + if (!DBName.isEmpty())
  256. + db = DBName;
  257. +
  258. + if (dbPort != 0)
  259. + port = dbPort;
  260. +
  261. + bResult = TestDatabase(HostName, UserName, Password, db, port);
  262. +
  263. + return bResult;
  264. +}
  265. +
  266. diff --git a/mythtv/programs/mythbackend/services/myth.h b/mythtv/programs/mythbackend/services/myth.h
  267. index c6b6973..931cd96 100644
  268. --- a/mythtv/programs/mythbackend/services/myth.h
  269. +++ b/mythtv/programs/mythbackend/services/myth.h
  270. @@ -64,6 +64,12 @@ class Myth : public MythServices
  271. bool ChangePassword ( const QString &UserName,
  272. const QString &OldPassword,
  273. const QString &NewPassword );
  274. +
  275. + bool TestDBSettings ( const QString &HostName,
  276. + const QString &UserName,
  277. + const QString &Password,
  278. + const QString &DBName,
  279. + int dbPort);
  280. };
  281.  
  282. // --------------------------------------------------------------------------
  283. @@ -137,6 +143,16 @@ class ScriptableMyth : public QObject
  284. {
  285. return m_obj.PutSetting( HostName, Key, Value );
  286. }
  287. +
  288. + bool TestDBSettings( const QString &HostName,
  289. + const QString &UserName,
  290. + const QString &Password,
  291. + const QString &DBName,
  292. + int dbPort)
  293. + {
  294. + return m_obj.TestDBSettings( HostName, UserName, Password,
  295. + DBName, dbPort );
  296. + }
  297. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement