MythTV  master
v2myth.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QDir>
3 #include <QFileInfo>
4 #include <QCryptographicHash>
5 #include <QHostAddress>
6 #include <QUdpSocket>
7 #include <QNetworkRequest>
8 
9 // MythTV
10 #include "libmythbase/dbutil.h"
15 #include "libmythbase/mythdate.h"
16 #include "libmythbase/mythdb.h"
17 #include "libmythbase/mythdbcon.h"
20 #include "libmythbase/mythversion.h"
22 #include "libmythbase/version.h"
24 #include "libmythtv/tv_rec.h"
25 
26 // MythBackend
27 #include "scheduler.h"
28 #include "v2databaseInfo.h"
29 #include "v2myth.h"
30 #include "v2serviceUtil.h"
31 #include "v2versionInfo.h"
32 #include "v2wolInfo.h"
33 
34 #if CONFIG_SYSTEMD_NOTIFY
35 #include <systemd/sd-daemon.h>
36 static inline void api_sd_notify(const char *str) { sd_notify(0, str); };
37 #else
38 static inline void api_sd_notify(const char */*str*/) {};
39 #endif
40 
41 // This will be initialised in a thread safe manner on first use
43  (MYTH_HANDLE, V2Myth::staticMetaObject, &V2Myth::RegisterCustomTypes))
44 
46 {
47  qRegisterMetaType<V2ConnectionInfo*>("V2ConnectionInfo");
48  qRegisterMetaType<V2VersionInfo*>("V2VersionInfo");
49  qRegisterMetaType<V2DatabaseInfo*>("V2DatabaseInfo");
50  qRegisterMetaType<V2WOLInfo*>("V2WOLInfo");
51  qRegisterMetaType<V2StorageGroupDirList*>("V2StorageGroupDirList");
52  qRegisterMetaType<V2StorageGroupDir*>("V2StorageGroupDir");
53  qRegisterMetaType<V2TimeZoneInfo*>("V2TimeZoneInfo");
54  qRegisterMetaType<V2LogMessage*>("V2LogMessage");
55  qRegisterMetaType<V2LogMessageList*>("V2LogMessageList");
56  qRegisterMetaType<V2LabelValue*>("V2LabelValue");
57  qRegisterMetaType<V2Frontend*>("V2Frontend");
58  qRegisterMetaType<V2FrontendList*>("V2FrontendList");
59  qRegisterMetaType<V2SettingList*>("V2SettingList");
60  qRegisterMetaType<V2BackendInfo*>("V2BackendInfo");
61  qRegisterMetaType<V2EnvInfo*>("V2EnvInfo");
62  qRegisterMetaType<V2LogInfo*>("V2LogInfo");
63  qRegisterMetaType<V2BuildInfo*>("V2BuildInfo");
64 }
65 
66 
68  : MythHTTPService(s_service)
69 {
70 }
71 
73 //
75 
77 {
78  QString sSecurityPin = gCoreContext->GetSetting( "SecurityPin", "");
79 
80  if ( sSecurityPin.isEmpty() )
81  throw( QString( "No Security Pin assigned. Run mythtv-setup to set one." ));
82  //SB: UPnPResult_HumanInterventionRequired,
83 
84  if ((sSecurityPin != "0000" ) && ( sPin != sSecurityPin ))
85  throw( QString( "Not Authorized" ));
86  //SB: UPnPResult_ActionNotAuthorized );
87 
88  DatabaseParams params = GetMythDB()->GetDatabaseParams();
89 
90  // ----------------------------------------------------------------------
91  // Check for DBHostName of "localhost" and change to public name or IP
92  // ----------------------------------------------------------------------
93 
94  QString sServerIP = gCoreContext->GetBackendServerIP();
95  //QString sPeerIP = pRequest->GetPeerAddress();
96 
97  if ((params.m_dbHostName.compare("localhost",Qt::CaseInsensitive)==0
98  || params.m_dbHostName == "127.0.0.1"
99  || params.m_dbHostName == "::1")
100  && !sServerIP.isEmpty()) // &&
101  //(sServerIP != sPeerIP ))
102  {
103  params.m_dbHostName = sServerIP;
104  }
105 
106  // If dbHostName is an IPV6 address with scope,
107  // remove the scope. Unescaped % signs are an
108  // xml violation
109  QString dbHostName(params.m_dbHostName);
110  QHostAddress addr;
111  if (addr.setAddress(dbHostName))
112  {
113  addr.setScopeId(QString());
114  dbHostName = addr.toString();
115  }
116  // ----------------------------------------------------------------------
117  // Create and populate a ConnectionInfo object
118  // ----------------------------------------------------------------------
119 
120  auto *pInfo = new V2ConnectionInfo();
121  V2DatabaseInfo *pDatabase = pInfo->Database();
122  V2WOLInfo *pWOL = pInfo->WOL();
123  V2VersionInfo *pVersion = pInfo->Version();
124 
125  pDatabase->setHost ( dbHostName );
126  pDatabase->setPing ( params.m_dbHostPing );
127  pDatabase->setPort ( params.m_dbPort );
128  pDatabase->setUserName ( params.m_dbUserName );
129  pDatabase->setPassword ( params.m_dbPassword );
130  pDatabase->setName ( params.m_dbName );
131  pDatabase->setType ( params.m_dbType );
132  pDatabase->setLocalEnabled ( params.m_localEnabled );
133  pDatabase->setLocalHostName( params.m_localHostName );
134 
135  pWOL->setEnabled ( params.m_wolEnabled );
136  pWOL->setReconnect ( params.m_wolReconnect.count() );
137  pWOL->setRetry ( params.m_wolRetry );
138  pWOL->setCommand ( params.m_wolCommand );
139 
140  pVersion->setVersion ( MYTH_SOURCE_VERSION );
141  pVersion->setBranch ( MYTH_SOURCE_PATH );
142  pVersion->setProtocol ( MYTH_PROTO_VERSION );
143  pVersion->setBinary ( MYTH_BINARY_VERSION );
144  pVersion->setSchema ( MYTH_DATABASE_VERSION );
145 
146  // ----------------------------------------------------------------------
147  // Return the pointer... caller is responsible to delete it!!!
148  // ----------------------------------------------------------------------
149 
150  return pInfo;
151 }
152 
154 //
156 bool V2Myth::SetConnectionInfo(const QString &Host, const QString &UserName, const QString &Password, const QString &Name, int Port, bool DoTest)
157 {
158  bool bResult = false;
159 
160  QString db("mythconverg");
161  int port = 3306;
162 
163  if (!Name.isEmpty())
164  db = Name;
165 
166  if (Port != 0)
167  port = Port;
168 
169  if (DoTest && !TestDatabase(Host, UserName, Password, db, port))
170  throw( QString( "Database test failed. Not saving database connection information." ));
171 
172  DatabaseParams dbparms;
173  dbparms.m_dbName = db;
174  dbparms.m_dbUserName = UserName;
175  dbparms.m_dbPassword = Password;
176  dbparms.m_dbHostName = Host;
177  dbparms.m_dbPort = port;
178 
179  // Just use some sane defaults for these values
180  dbparms.m_wolEnabled = false;
181  dbparms.m_wolReconnect = 1s;
182  dbparms.m_wolRetry = 3;
183  dbparms.m_wolCommand = QString();
184 
185  bResult = GetMythDB()->SaveDatabaseParams(dbparms, false);
186 
187  return bResult;
188 }
189 
191 //
193 
195 {
196  if (!gCoreContext)
197  throw( QString( "No MythCoreContext in GetHostName." ));
198 
199  return gCoreContext->GetHostName();
200 }
201 
203 //
205 
206 QStringList V2Myth::GetHosts( )
207 {
208  MSqlQuery query(MSqlQuery::InitCon());
209 
210  if (!query.isConnected())
211  throw( QString( "Database not open while trying to load list of hosts" ));
212 
213  query.prepare(
214  "SELECT DISTINCTROW hostname "
215  "FROM settings "
216  "WHERE (not isNull( hostname ))");
217 
218  if (!query.exec())
219  {
220  MythDB::DBError("MythAPI::GetHosts()", query);
221 
222  throw( QString( "Database Error executing query." ));
223  }
224 
225  // ----------------------------------------------------------------------
226  // return the results of the query
227  // ----------------------------------------------------------------------
228 
229  QStringList oList;
230 
231  while (query.next())
232  oList.append( query.value(0).toString() );
233 
234  return oList;
235 }
236 
238 //
240 
241 QStringList V2Myth::GetKeys()
242 {
243  MSqlQuery query(MSqlQuery::InitCon());
244 
245  if (!query.isConnected())
246  throw( QString("Database not open while trying to load settings"));
247 
248  query.prepare("SELECT DISTINCTROW value FROM settings;" );
249 
250  if (!query.exec())
251  {
252  MythDB::DBError("MythAPI::GetKeys()", query);
253 
254  throw( QString( "Database Error executing query." ));
255  }
256 
257  // ----------------------------------------------------------------------
258  // return the results of the query
259  // ----------------------------------------------------------------------
260 
261  QStringList oResults;
262 
263  //pResults->setObjectName( "KeyList" );
264 
265  while (query.next())
266  oResults.append( query.value(0).toString() );
267 
268  return oResults;
269 }
270 
272 // DirListing gets a list of subdirectories
274 
275 QStringList V2Myth::GetDirListing ( const QString &DirName, bool Files)
276 {
277  QDir directory(DirName);
278  QDir::Filters filts = QDir::AllDirs|QDir::NoDotAndDotDot;
279  if (Files)
280  filts = QDir::Files;
281  else
282  filts = QDir::AllDirs|QDir::NoDotAndDotDot;
283  return directory.entryList(filts, QDir::Name);
284 }
285 
286 
288 //
291  const QString &sHostName )
292 {
293  MSqlQuery query(MSqlQuery::InitCon());
294 
295  if (!query.isConnected())
296  throw( QString("Database not open while trying to list "
297  "Storage Group Dirs"));
298 
299  if (!sGroupName.isEmpty() && !sHostName.isEmpty())
300  {
301  query.prepare("SELECT id, groupname, hostname, dirname "
302  "FROM storagegroup "
303  "WHERE groupname = :GROUP AND hostname = :HOST "
304  "ORDER BY groupname, hostname, dirname" );
305  query.bindValue(":HOST", sHostName);
306  query.bindValue(":GROUP", sGroupName);
307  }
308  else if (!sHostName.isEmpty())
309  {
310  query.prepare("SELECT id, groupname, hostname, dirname "
311  "FROM storagegroup "
312  "WHERE hostname = :HOST "
313  "ORDER BY groupname, hostname, dirname" );
314  query.bindValue(":HOST", sHostName);
315  }
316  else if (!sGroupName.isEmpty())
317  {
318  query.prepare("SELECT id, groupname, hostname, dirname "
319  "FROM storagegroup "
320  "WHERE groupname = :GROUP "
321  "ORDER BY groupname, hostname, dirname" );
322  query.bindValue(":GROUP", sGroupName);
323  }
324  else
325  {
326  query.prepare("SELECT id, groupname, hostname, dirname "
327  "FROM storagegroup "
328  "ORDER BY groupname, hostname, dirname" );
329  }
330 
331  if (!query.exec())
332  {
333  MythDB::DBError("MythAPI::GetStorageGroupDirs()", query);
334 
335  throw( QString( "Database Error executing query." ));
336  }
337 
338  // ----------------------------------------------------------------------
339  // return the results of the query plus R/W and size information
340  // ----------------------------------------------------------------------
341 
342  auto* pList = new V2StorageGroupDirList();
343 
344  while (query.next())
345  {
346  V2StorageGroupDir *pStorageGroupDir = pList->AddNewStorageGroupDir();
347  QFileInfo fi(query.value(3).toString());
348  int64_t free = 0;
349  int64_t total = 0;
350  int64_t used = 0;
351 
352  free = getDiskSpace(query.value(3).toString(), total, used);
353 
354  pStorageGroupDir->setId ( query.value(0).toInt() );
355  pStorageGroupDir->setGroupName ( query.value(1).toString() );
356  pStorageGroupDir->setHostName ( query.value(2).toString() );
357  pStorageGroupDir->setDirName ( query.value(3).toString() );
358  pStorageGroupDir->setDirRead ( fi.isReadable() );
359  pStorageGroupDir->setDirWrite ( fi.isWritable() );
360  pStorageGroupDir->setKiBFree ( free );
361  }
362 
363  return pList;
364 }
365 
367 //
369 
370 bool V2Myth::AddStorageGroupDir( const QString &sGroupName,
371  const QString &sDirName,
372  const QString &sHostName )
373 {
374  MSqlQuery query(MSqlQuery::InitCon());
375 
376  if (!query.isConnected())
377  throw( QString("Database not open while trying to add Storage Group "
378  "dir"));
379 
380  if (sGroupName.isEmpty())
381  throw ( QString( "Storage Group Required" ));
382 
383  if (sDirName.isEmpty())
384  throw ( QString( "Directory Name Required" ));
385 
386  if (sHostName.isEmpty())
387  throw ( QString( "HostName Required" ));
388 
389  query.prepare("SELECT COUNT(*) "
390  "FROM storagegroup "
391  "WHERE groupname = :GROUPNAME "
392  "AND dirname = :DIRNAME "
393  "AND hostname = :HOSTNAME;");
394  query.bindValue(":GROUPNAME", sGroupName );
395  query.bindValue(":DIRNAME" , sDirName );
396  query.bindValue(":HOSTNAME" , sHostName );
397  if (!query.exec())
398  {
399  MythDB::DBError("MythAPI::AddStorageGroupDir()", query);
400 
401  throw( QString( "Database Error executing query." ));
402  }
403 
404  if (query.next())
405  {
406  if (query.value(0).toInt() > 0)
407  return false;
408  }
409 
410  query.prepare("INSERT storagegroup "
411  "( groupname, dirname, hostname ) "
412  "VALUES "
413  "( :GROUPNAME, :DIRNAME, :HOSTNAME );");
414  query.bindValue(":GROUPNAME", sGroupName );
415  query.bindValue(":DIRNAME" , sDirName );
416  query.bindValue(":HOSTNAME" , sHostName );
417 
418  if (!query.exec())
419  {
420  MythDB::DBError("MythAPI::AddStorageGroupDir()", query);
421 
422  throw( QString( "Database Error executing query." ));
423  }
424 
425  return true;
426 }
427 
429 //
431 
432 bool V2Myth::RemoveStorageGroupDir( const QString &sGroupName,
433  const QString &sDirName,
434  const QString &sHostName )
435 {
436  MSqlQuery query(MSqlQuery::InitCon());
437 
438  if (!query.isConnected())
439  throw( QString("Database not open while trying to remove Storage "
440  "Group dir"));
441 
442  if (sGroupName.isEmpty())
443  throw ( QString( "Storage Group Required" ));
444 
445  if (sDirName.isEmpty())
446  throw ( QString( "Directory Name Required" ));
447 
448  if (sHostName.isEmpty())
449  throw ( QString( "HostName Required" ));
450 
451  query.prepare("DELETE "
452  "FROM storagegroup "
453  "WHERE groupname = :GROUPNAME "
454  "AND dirname = :DIRNAME "
455  "AND hostname = :HOSTNAME;");
456  query.bindValue(":GROUPNAME", sGroupName );
457  query.bindValue(":DIRNAME" , sDirName );
458  query.bindValue(":HOSTNAME" , sHostName );
459  if (!query.exec())
460  {
461  MythDB::DBError("MythAPI::RemoveStorageGroupDir()", query);
462 
463  throw( QString( "Database Error executing query." ));
464  }
465 
466  return true;
467 }
468 
470 //
472 
474 {
475  auto *pResults = new V2TimeZoneInfo();
476 
477  pResults->setTimeZoneID( MythTZ::getTimeZoneID() );
478  pResults->setUTCOffset( MythTZ::calc_utc_offset() );
479  pResults->setCurrentDateTime( MythDate::current(true) );
480 
481  return pResults;
482 }
483 
485 //
487 
488 QString V2Myth::GetFormatDate(const QDateTime &Date, bool ShortDate)
489 {
491  if (ShortDate)
493 
494  return MythDate::toString(Date, dateFormat);
495 }
496 
498 //
500 
501 QString V2Myth::GetFormatDateTime(const QDateTime &DateTime, bool ShortDate)
502 {
504  if (ShortDate)
506 
507  return MythDate::toString(DateTime, dateFormat);
508 }
509 
511 //
513 
514 QString V2Myth::GetFormatTime(const QDateTime &Time)
515 {
516  return MythDate::toString(Time, MythDate::kTime);
517 }
518 
520 //
522 
523 QDateTime V2Myth::ParseISODateString(const QString& DateTime)
524 {
525  auto dateTime = QDateTime::fromString(DateTime, Qt::ISODate);
526 
527  if (!dateTime.isValid())
528  throw QString( "Unable to parse DateTime" );
529 
530  return dateTime;
531 }
532 
534 //
536 
537 V2LogMessageList* V2Myth::GetLogs( const QString &HostName,
538  const QString &Application,
539  int PID,
540  int TID,
541  const QString &Thread,
542  const QString &Filename,
543  int Line,
544  const QString &Function,
545  const QDateTime &FromTime,
546  const QDateTime &ToTime,
547  const QString &Level,
548  const QString &MsgContains )
549 {
550  auto *pList = new V2LogMessageList();
551 
552  MSqlQuery query(MSqlQuery::InitCon());
553 
554  // Get host name list
555  QString sql = "SELECT DISTINCT host FROM logging ORDER BY host ASC";
556  if (!query.exec(sql))
557  {
558  MythDB::DBError("Retrieving log host names", query);
559  delete pList;
560  throw( QString( "Database Error executing query." ));
561  }
562  while (query.next())
563  {
564  V2LabelValue *pLabelValue = pList->AddNewHostName();
565  QString availableHostName = query.value(0).toString();
566  pLabelValue->setValue ( availableHostName );
567  pLabelValue->setActive ( availableHostName == HostName );
568  pLabelValue->setSelected( availableHostName == HostName );
569  }
570  // Get application list
571  sql = "SELECT DISTINCT application FROM logging ORDER BY application ASC";
572  if (!query.exec(sql))
573  {
574  MythDB::DBError("Retrieving log applications", query);
575  delete pList;
576  throw( QString( "Database Error executing query." ));
577  }
578  while (query.next())
579  {
580  V2LabelValue *pLabelValue = pList->AddNewApplication();
581  QString availableApplication = query.value(0).toString();
582  pLabelValue->setValue ( availableApplication );
583  pLabelValue->setActive ( availableApplication == Application );
584  pLabelValue->setSelected( availableApplication == Application );
585  }
586 
587  if (!HostName.isEmpty() && !Application.isEmpty())
588  {
589  // Get log messages
590  sql = "SELECT host, application, pid, tid, thread, filename, "
591  " line, function, msgtime, level, message "
592  " FROM logging "
593  " WHERE host = COALESCE(:HOSTNAME, host) "
594  " AND application = COALESCE(:APPLICATION, application) "
595  " AND pid = COALESCE(:PID, pid) "
596  " AND tid = COALESCE(:TID, tid) "
597  " AND thread = COALESCE(:THREAD, thread) "
598  " AND filename = COALESCE(:FILENAME, filename) "
599  " AND line = COALESCE(:LINE, line) "
600  " AND function = COALESCE(:FUNCTION, function) "
601  " AND msgtime >= COALESCE(:FROMTIME, msgtime) "
602  " AND msgtime <= COALESCE(:TOTIME, msgtime) "
603  " AND level <= COALESCE(:LEVEL, level) "
604  ;
605  if (!MsgContains.isEmpty())
606  {
607  sql.append(" AND message LIKE :MSGCONTAINS ");
608  }
609  sql.append(" ORDER BY msgtime ASC;");
610 
611 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
612  QVariant ullNull = QVariant(QVariant::ULongLong);
613 #else
614  QVariant ullNull = QVariant(QMetaType(QMetaType::ULongLong));
615 #endif
616  query.prepare(sql);
617 
618  query.bindValue(":HOSTNAME", (HostName.isEmpty()) ? QString() : HostName);
619  query.bindValue(":APPLICATION", (Application.isEmpty()) ? QString() :
620  Application);
621  query.bindValue(":PID", ( PID == 0 ) ? ullNull : (qint64)PID);
622  query.bindValue(":TID", ( TID == 0 ) ? ullNull : (qint64)TID);
623  query.bindValue(":THREAD", (Thread.isEmpty()) ? QString() : Thread);
624  query.bindValue(":FILENAME", (Filename.isEmpty()) ? QString() : Filename);
625  query.bindValue(":LINE", ( Line == 0 ) ? ullNull : (qint64)Line);
626  query.bindValue(":FUNCTION", (Function.isEmpty()) ? QString() : Function);
627  query.bindValue(":FROMTIME", (FromTime.isValid()) ? FromTime : QDateTime());
628  query.bindValue(":TOTIME", (ToTime.isValid()) ? ToTime : QDateTime());
629  query.bindValue(":LEVEL", (Level.isEmpty()) ? ullNull :
630  (qint64)logLevelGet(Level));
631 
632  if (!MsgContains.isEmpty())
633  {
634  query.bindValue(":MSGCONTAINS", "%" + MsgContains + "%" );
635  }
636 
637  if (!query.exec())
638  {
639  MythDB::DBError("Retrieving log messages", query);
640  delete pList;
641  throw( QString( "Database Error executing query." ));
642  }
643 
644  while (query.next())
645  {
646  V2LogMessage *pLogMessage = pList->AddNewLogMessage();
647 
648  pLogMessage->setHostName( query.value(0).toString() );
649  pLogMessage->setApplication( query.value(1).toString() );
650  pLogMessage->setPID( query.value(2).toInt() );
651  pLogMessage->setTID( query.value(3).toInt() );
652  pLogMessage->setThread( query.value(4).toString() );
653  pLogMessage->setFilename( query.value(5).toString() );
654  pLogMessage->setLine( query.value(6).toInt() );
655  pLogMessage->setFunction( query.value(7).toString() );
656  pLogMessage->setTime(MythDate::as_utc(query.value(8).toDateTime()));
657  pLogMessage->setLevel( logLevelGetName(
658  (LogLevel_t)query.value(9).toInt()) );
659  pLogMessage->setMessage( query.value(10).toString() );
660  }
661  }
662 
663  return pList;
664 }
665 
667 //
669 
671 {
672  auto *pList = new V2FrontendList();
673 
674  FillFrontendList(pList->GetFrontends(), pList,
675  OnLine);
676  return pList;
677 }
678 
680 //
682 
683 QString V2Myth::GetSetting( const QString &sHostName,
684  const QString &sKey,
685  const QString &sDefault )
686 {
687  if (sKey.isEmpty())
688  throw( QString("Missing or empty Key (settings.value)") );
689 
690  if (sHostName == "_GLOBAL_")
691  {
692  MSqlQuery query(MSqlQuery::InitCon());
693 
694  query.prepare("SELECT data FROM settings "
695  "WHERE value = :VALUE "
696  "AND (hostname IS NULL)" );
697 
698  query.bindValue(":VALUE", sKey );
699 
700  if (!query.exec())
701  {
702  MythDB::DBError("API Myth/GetSetting ", query);
703  throw( QString( "Database Error executing query." ));
704  }
705 
706  return query.next() ? query.value(0).toString() : sDefault;
707  }
708 
709  QString hostname = sHostName;
710 
711  if (sHostName.isEmpty())
713 
714  return gCoreContext->GetSettingOnHost(sKey, hostname, sDefault);
715 }
716 
718 //
720 
721 V2SettingList* V2Myth::GetSettingList(const QString &sHostName)
722 {
723 
724  MSqlQuery query(MSqlQuery::InitCon());
725 
726  if (!query.isConnected())
727  {
728  throw( QString("Database not open while trying to load settings for host: %1")
729  .arg( sHostName ));
730  }
731 
732  auto *pList = new V2SettingList();
733 
734  pList->setHostName ( sHostName );
735 
736  // ------------------------------------------------------------------
737  // Looking to return all Setting for supplied hostname
738  // ------------------------------------------------------------------
739 
740  if (sHostName.isEmpty())
741  {
742  query.prepare("SELECT value, data FROM settings "
743  "WHERE (hostname IS NULL)" );
744  }
745  else
746  {
747  query.prepare("SELECT value, data FROM settings "
748  "WHERE (hostname = :HOSTNAME)" );
749 
750  query.bindValue(":HOSTNAME", sHostName );
751  }
752 
753  if (!query.exec())
754  {
755  // clean up unused object we created.
756 
757  delete pList;
758 
759  MythDB::DBError("MythAPI::GetSetting() w/o key ", query);
760  throw( QString( "Database Error executing query." ));
761  }
762 
763  while (query.next())
764  pList->Settings().insert( query.value(0).toString(), query.value(1) );
765 
766  return pList;
767 }
768 
770 //
772 
773 bool V2Myth::PutSetting( const QString &sHostName,
774  const QString &sKey,
775  const QString &sValue )
776 {
777  QString hostName = sHostName;
778 
779  if (hostName == "_GLOBAL_")
780  hostName = "";
781 
782  if (!sKey.isEmpty())
783  {
784  return gCoreContext->SaveSettingOnHost( sKey, sValue, hostName );
785  }
786 
787  throw ( QString( "Key Required" ));
788 }
789 
791 //
793 
794 bool V2Myth::DeleteSetting( const QString &sHostName,
795  const QString &sKey)
796 {
797  QString hostName = sHostName;
798 
799  if (hostName == "_GLOBAL_")
800  hostName = "";
801 
802  if (!sKey.isEmpty())
803  {
804  return gCoreContext->GetDB()->ClearSettingOnHost( sKey, hostName );
805  }
806 
807  throw ( QString( "Key Required" ));
808 }
809 
810 
812 //
814 
815 bool V2Myth::TestDBSettings( const QString &sHostName,
816  const QString &sUserName,
817  const QString &sPassword,
818  const QString &sDBName,
819  int dbPort)
820 {
821  bool bResult = false;
822 
823  QString db("mythconverg");
824  int port = 3306;
825 
826  if (!sDBName.isEmpty())
827  db = sDBName;
828 
829  if (dbPort != 0)
830  port = dbPort;
831 
832  bResult = TestDatabase(sHostName, sUserName, sPassword, db, port);
833 
834  return bResult;
835 }
836 
838 //
840 
841 bool V2Myth::SendMessage( const QString &sMessage,
842  const QString &sAddress,
843  int udpPort,
844  int Timeout)
845 {
846  bool bResult = false;
847 
848  if (sMessage.isEmpty())
849  return bResult;
850 
851  if (Timeout < 0 || Timeout > 999)
852  Timeout = 0;
853 
854  QString xmlMessage =
855  "<mythmessage version=\"1\">\n"
856  " <text>" + sMessage + "</text>\n"
857  " <timeout>" + QString::number(Timeout) + "</timeout>\n"
858  "</mythmessage>";
859 
860  QHostAddress address = QHostAddress::Broadcast;
861  unsigned short port = 6948;
862 
863  if (!sAddress.isEmpty())
864  address.setAddress(sAddress);
865 
866  if (udpPort != 0)
867  port = udpPort;
868 
869  auto *sock = new QUdpSocket();
870  QByteArray utf8 = xmlMessage.toUtf8();
871  int size = utf8.length();
872 
873  if (sock->writeDatagram(utf8.constData(), size, address, port) < 0)
874  {
875  LOG(VB_GENERAL, LOG_ERR,
876  QString("Failed to send UDP/XML packet (Message: %1 "
877  "Address: %2 Port: %3")
878  .arg(sMessage, sAddress, QString::number(port)));
879  }
880  else
881  {
882  LOG(VB_GENERAL, LOG_DEBUG,
883  QString("UDP/XML packet sent! (Message: %1 Address: %2 Port: %3")
884  .arg(sMessage,
885  address.toString().toLocal8Bit(),
886  QString::number(port)));
887  bResult = true;
888  }
889 
890  sock->deleteLater();
891 
892  return bResult;
893 }
894 
895 bool V2Myth::SendNotification( bool bError,
896  const QString &Type,
897  const QString &sMessage,
898  const QString &sOrigin,
899  const QString &sDescription,
900  const QString &sImage,
901  const QString &sExtra,
902  const QString &sProgressText,
903  float fProgress,
904  int Timeout,
905  bool bFullscreen,
906  uint Visibility,
907  uint Priority,
908  const QString &sAddress,
909  int udpPort )
910 {
911  bool bResult = false;
912 
913  if (sMessage.isEmpty())
914  return bResult;
915 
916  if (Timeout < 0 || Timeout > 999)
917  Timeout = -1;
918 
919  QString xmlMessage =
920  "<mythnotification version=\"1\">\n"
921  " <text>" + sMessage + "</text>\n"
922  " <origin>" + (sOrigin.isNull() ? tr("MythServices") : sOrigin) + "</origin>\n"
923  " <description>" + sDescription + "</description>\n"
924  " <timeout>" + QString::number(Timeout) + "</timeout>\n"
925  " <image>" + sImage + "</image>\n"
926  " <extra>" + sExtra + "</extra>\n"
927  " <progress_text>" + sProgressText + "</progress_text>\n"
928  " <progress>" + QString::number(fProgress) + "</progress>\n"
929  " <fullscreen>" + (bFullscreen ? "true" : "false") + "</fullscreen>\n"
930  " <visibility>" + QString::number(Visibility) + "</visibility>\n"
931  " <priority>" + QString::number(Priority) + "</priority>\n"
932  " <type>" + (bError ? "error" : Type) + "</type>\n"
933  "</mythnotification>";
934 
935  QHostAddress address = QHostAddress::Broadcast;
936  unsigned short port = 6948;
937 
938  if (!sAddress.isEmpty())
939  address.setAddress(sAddress);
940 
941  if (udpPort != 0)
942  port = udpPort;
943 
944  auto *sock = new QUdpSocket();
945  QByteArray utf8 = xmlMessage.toUtf8();
946  int size = utf8.length();
947 
948  if (sock->writeDatagram(utf8.constData(), size, address, port) < 0)
949  {
950  LOG(VB_GENERAL, LOG_ERR,
951  QString("Failed to send UDP/XML packet (Notification: %1 "
952  "Address: %2 Port: %3")
953  .arg(sMessage, sAddress, QString::number(port)));
954  }
955  else
956  {
957  LOG(VB_GENERAL, LOG_DEBUG,
958  QString("UDP/XML packet sent! (Notification: %1 Address: %2 Port: %3")
959  .arg(sMessage,
960  address.toString().toLocal8Bit(), QString::number(port)));
961  bResult = true;
962  }
963 
964  sock->deleteLater();
965 
966  return bResult;
967 }
968 
970 //
972 
974 {
975  bool bResult = false;
976 
977  DBUtil dbutil;
979  QString filename;
980 
981  LOG(VB_GENERAL, LOG_NOTICE, "Performing API invoked DB Backup.");
982 
983  status = DBUtil::BackupDB(filename);
984 
985  if (status == kDB_Backup_Completed)
986  {
987  LOG(VB_GENERAL, LOG_NOTICE, "Database backup succeeded.");
988  bResult = true;
989  }
990  else
991  {
992  LOG(VB_GENERAL, LOG_ERR, "Database backup failed.");
993  }
994 
995  return bResult;
996 }
997 
999 //
1001 
1002 bool V2Myth::CheckDatabase( bool repair )
1003 {
1004  LOG(VB_GENERAL, LOG_NOTICE, "Performing API invoked DB Check.");
1005 
1006  bool bResult = DBUtil::CheckTables(repair);
1007 
1008  if (bResult)
1009  LOG(VB_GENERAL, LOG_NOTICE, "Database check complete.");
1010  else
1011  LOG(VB_GENERAL, LOG_ERR, "Database check failed.");
1012 
1013  return bResult;
1014 }
1015 
1017 {
1018  auto *scheduler = dynamic_cast<Scheduler*>(gCoreContext->GetScheduler());
1019  if (scheduler == nullptr)
1020  return false;
1021  scheduler->DelayShutdown();
1022  LOG(VB_GENERAL, LOG_NOTICE, "Shutdown delayed 5 minutes for external application.");
1023  return true;
1024 }
1025 
1027 //
1029 
1031 {
1033  LOG(VB_GENERAL, LOG_NOTICE, "Profile Submission...");
1034  profile.GenerateUUIDs();
1035  bool bResult = profile.SubmitProfile();
1036  if (bResult)
1037  LOG(VB_GENERAL, LOG_NOTICE, "Profile Submitted.");
1038 
1039  return bResult;
1040 }
1041 
1043 //
1045 
1047 {
1049  LOG(VB_GENERAL, LOG_NOTICE, "Profile Deletion...");
1050  profile.GenerateUUIDs();
1051  bool bResult = profile.DeleteProfile();
1052  if (bResult)
1053  LOG(VB_GENERAL, LOG_NOTICE, "Profile Deleted.");
1054 
1055  return bResult;
1056 }
1057 
1059 //
1061 
1063 {
1064  QString sProfileURL;
1065 
1067  profile.GenerateUUIDs();
1068  sProfileURL = profile.GetProfileURL();
1069  LOG(VB_GENERAL, LOG_NOTICE, QString("ProfileURL: %1").arg(sProfileURL));
1070 
1071  return sProfileURL;
1072 }
1073 
1075 //
1077 
1079 {
1080  QString sProfileUpdate;
1081 
1083  profile.GenerateUUIDs();
1084  QDateTime tUpdated;
1085  tUpdated = profile.GetLastUpdate();
1086  sProfileUpdate = tUpdated.toString(
1087  gCoreContext->GetSetting( "DateFormat", "MM.dd.yyyy"));
1088 
1089  return sProfileUpdate;
1090 }
1091 
1093 //
1095 
1097 {
1098  QString sProfileText;
1099 
1101  sProfileText = HardwareProfile::GetHardwareProfile();
1102 
1103  return sProfileText;
1104 }
1105 
1107 //
1109 
1111 {
1112 
1113  // ----------------------------------------------------------------------
1114  // Create and populate a Configuration object
1115  // ----------------------------------------------------------------------
1116 
1117  auto *pInfo = new V2BackendInfo();
1118  V2BuildInfo *pBuild = pInfo->Build();
1119  V2EnvInfo *pEnv = pInfo->Env();
1120  V2LogInfo *pLog = pInfo->Log();
1121 
1122  pBuild->setVersion ( MYTH_SOURCE_VERSION );
1123  pBuild->setLibX264 ( CONFIG_LIBX264 );
1124  pBuild->setLibDNS_SD ( CONFIG_LIBDNS_SD );
1125  pEnv->setLANG ( qEnvironmentVariable("LANG") );
1126  pEnv->setLCALL ( qEnvironmentVariable("LC_ALL") );
1127  pEnv->setLCCTYPE ( qEnvironmentVariable("LC_CTYPE") );
1128  pEnv->setHOME ( qEnvironmentVariable("HOME") );
1129  pEnv->setHttpRootDir ( m_request->m_root );
1130  // USER for Linux systems, USERNAME for Windows
1131  pEnv->setUSER ( qEnvironmentVariable("USER",
1132  qEnvironmentVariable("USERNAME")) );
1133  pEnv->setMYTHCONFDIR ( qEnvironmentVariable("MYTHCONFDIR") );
1134  auto *scheduler = dynamic_cast<Scheduler*>(gCoreContext->GetScheduler());
1135  if (scheduler != nullptr)
1136  pEnv->setSchedulingEnabled(scheduler->QueryScheduling());
1137  pLog->setLogArgs ( logPropagateArgs );
1138  pEnv->setIsDatabaseIgnored(gCoreContext->GetDB()->IsDatabaseIgnored());
1139  pEnv->setDBTimezoneSupport(DBUtil::CheckTimeZoneSupport());
1140  QString webOnly;
1141  switch (s_WebOnlyStartup) {
1142  case kWebOnlyNone:
1143  webOnly = "NONE";
1144  break;
1145  case kWebOnlyDBSetup:
1146  webOnly = "DBSETUP";
1147  break;
1148  case kWebOnlyDBTimezone:
1149  webOnly = "DBTIMEZONE";
1150  break;
1151  case kWebOnlyWebOnlyParm:
1152  webOnly = "WEBONLYPARM";
1153  break;
1154  case kWebOnlyIPAddress:
1155  webOnly = "IPADDRESS";
1156  break;
1157  case kWebOnlySchemaUpdate:
1158  webOnly = "SCHEMAUPDATE";
1159  break;
1160  }
1161  pEnv->setWebOnlyStartup (webOnly);
1162 
1163  // ----------------------------------------------------------------------
1164  // Return the pointer... caller is responsible to delete it!!!
1165  // ----------------------------------------------------------------------
1166 
1167  return pInfo;
1168 
1169 }
1170 
1172 //
1174 
1175 bool V2Myth::ManageDigestUser( const QString &sAction,
1176  const QString &sUserName,
1177  const QString &sPassword,
1178  const QString &sNewPassword,
1179  const QString &sAdminPassword )
1180 {
1181 
1182  DigestUserActions sessionAction = DIGEST_USER_ADD;
1183 
1184  if (sAction == "Add")
1185  sessionAction = DIGEST_USER_ADD;
1186  else if (sAction == "Remove")
1187  sessionAction = DIGEST_USER_REMOVE;
1188  else if (sAction == "ChangePassword")
1189  sessionAction = DIGEST_USER_CHANGE_PW;
1190  else
1191  {
1192  LOG(VB_GENERAL, LOG_ERR, QString("Action must be Add, Remove or "
1193  "ChangePassword, not '%1'")
1194  .arg(sAction));
1195  return false;
1196  }
1197 
1198  return MythSessionManager::ManageDigestUser(sessionAction, sUserName,
1199  sPassword, sNewPassword,
1200  sAdminPassword);
1201 }
1202 
1204 //
1206 
1207 bool V2Myth::ManageUrlProtection( const QString &sServices,
1208  const QString &sAdminPassword )
1209 {
1210  LOG(VB_GENERAL, LOG_WARNING, QString("ManageUrlProtection is deprecated."
1211  "Protection unavailable in API V2."));
1212 
1213  if (!MythSessionManager::IsValidUser("admin"))
1214  {
1215  LOG(VB_GENERAL, LOG_ERR, QString("Backend has no '%1' user!")
1216  .arg("admin"));
1217  return false;
1218  }
1219 
1220  if (MythSessionManager::CreateDigest("admin", sAdminPassword) !=
1222  {
1223  LOG(VB_GENERAL, LOG_ERR, QString("Incorrect password for user: %1")
1224  .arg("admin"));
1225  return false;
1226  }
1227 
1228  QStringList serviceList = sServices.split(",");
1229 
1230  serviceList.removeDuplicates();
1231 
1232  QStringList protectedURLs;
1233 
1234  if (serviceList.size() == 1 && serviceList.first() == "All")
1235  {
1236  for (const QString& service : KnownServicesV2)
1237  protectedURLs << '/' + service;
1238  }
1239  else if (serviceList.size() == 1 && serviceList.first() == "None")
1240  {
1241  protectedURLs << "Unprotected";
1242  }
1243  else
1244  {
1245  for (const QString& service : std::as_const(serviceList))
1246  {
1247  if (KnownServicesV2.contains(service))
1248  protectedURLs << '/' + service;
1249  else
1250  LOG(VB_GENERAL, LOG_ERR, QString("Invalid service name: '%1'")
1251  .arg(service));
1252  }
1253  }
1254 
1255  if (protectedURLs.isEmpty())
1256  {
1257  LOG(VB_GENERAL, LOG_ERR, "No valid Services were found");
1258  return false;
1259  }
1260 
1261  return gCoreContext->SaveSettingOnHost("HTTP/Protected/Urls",
1262  protectedURLs.join(';'), "");
1263 }
1264 
1265 bool V2Myth::ManageScheduler ( bool Enable, bool Disable )
1266 {
1267  auto *scheduler = dynamic_cast<Scheduler*>(gCoreContext->GetScheduler());
1268  if (scheduler == nullptr)
1269  throw QString("Scheduler is null");
1270  // One and only one of enable and disable must be supplied
1271  if (Enable == Disable)
1272  return false;
1273  if (Enable)
1274  scheduler->EnableScheduling();
1275  else
1276  {
1277  scheduler->DisableScheduling();
1278  api_sd_notify("STATUS=Scheduling disabled via Services API/Web App.");
1279  }
1280  // Stop EIT scanning
1281  QMapIterator<uint,TVRec*> iter(TVRec::s_inputs);
1282  while (iter.hasNext())
1283  {
1284  iter.next();
1285  auto *tvrec = iter.value();
1286  tvrec->EnableActiveScan(Enable);
1287  }
1288  return true;
1289 }
1290 
1291 bool V2Myth::Shutdown ( int Retcode, bool Restart, bool WebOnly )
1292 {
1293  if (Retcode < 0 || Retcode > 255)
1294  return false;
1295  if (Restart)
1296  {
1297  if (WebOnly)
1298  {
1299  // Retcode 259 is a special value to signal to mythbackend to restart
1300  // in --webonly mode
1301  Retcode = 259;
1302  }
1303  else
1304  {
1305  // Retcode 258 is a special value to signal to mythbackend to restart
1306  // in normal mode
1307  Retcode = 258;
1308  }
1309 
1310  }
1311  QCoreApplication::exit(Retcode);
1312  return true;
1313 }
1314 
1315 QString V2Myth::Proxy ( const QString &urlString)
1316 {
1317  QUrl url(urlString);
1318 
1319  QByteArray data;
1320 
1321  auto *req = new QNetworkRequest(url);
1322  req->setHeader(QNetworkRequest::ContentTypeHeader, QString("application/x-www-form-urlencoded"));
1323 
1324  if (GetMythDownloadManager()->post(req, &data))
1325  {
1326  return {data};
1327  }
1328 
1329  return {};
1330 }
Password
static StandardSetting * Password(bool enabled)
Setting for changing password.
Definition: galleryconfig.cpp:245
V2Myth::GetHostName
static QString GetHostName()
Definition: v2myth.cpp:194
Scheduler
Definition: scheduler.h:45
MythDBBackupStatus
MythDBBackupStatus
Definition: dbutil.h:9
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
MythSessionManager::IsValidUser
static bool IsValidUser(const QString &username)
Check if the given user exists but not whether there is a valid session open for them!
Definition: mythsession.cpp:151
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
V2Myth::DeleteSetting
static bool DeleteSetting(const QString &HostName, const QString &Key)
Definition: v2myth.cpp:794
hardwareprofile.h
V2Myth::GetDirListing
static QStringList GetDirListing(const QString &DirName, bool Files)
Definition: v2myth.cpp:275
MythSessionManager::GetPasswordDigest
static QString GetPasswordDigest(const QString &username)
Load the password digest for comparison in the HTTP Auth code.
Definition: mythsession.cpp:224
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
DatabaseParams::m_dbHostName
QString m_dbHostName
database server
Definition: mythdbparams.h:21
dbutil.h
V2VersionInfo
Definition: v2versionInfo.h:7
V2Myth::GetKeys
static QStringList GetKeys()
Definition: v2myth.cpp:241
MythCoreContext::GetScheduler
MythScheduler * GetScheduler(void)
Definition: mythcorecontext.cpp:1915
V2EnvInfo
Definition: v2envInfo.h:16
V2Myth::ProfileUpdated
static QString ProfileUpdated(void)
Definition: v2myth.cpp:1078
V2Myth::GetFormatDate
static QString GetFormatDate(const QDateTime &Date, bool ShortDate)
Definition: v2myth.cpp:488
mythdb.h
V2WOLInfo
Definition: v2wolInfo.h:7
getDiskSpace
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
Definition: mythcoreutil.cpp:33
MythDate::as_utc
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:28
V2Myth::PutSetting
static bool PutSetting(const QString &HostName, const QString &Key, const QString &Value)
Definition: v2myth.cpp:773
api_sd_notify
static void api_sd_notify(const char *)
Definition: v2myth.cpp:38
V2ConnectionInfo
Definition: v2connectionInfo.h:9
V2Myth::ProfileText
static QString ProfileText(void)
Definition: v2myth.cpp:1096
MythTZ::getTimeZoneID
QString getTimeZoneID(void)
Returns the zoneinfo time zone ID or as much time zone information as possible.
Definition: mythtimezone.cpp:34
V2LogMessageList
Definition: v2logMessageList.h:10
DatabaseParams
Structure containing the basic Database parameters.
Definition: mythdbparams.h:10
Scheduler::DelayShutdown
void DelayShutdown()
Definition: scheduler.cpp:3090
V2LogInfo
Definition: v2logInfo.h:16
V2Myth::DelayShutdown
static bool DelayShutdown(void)
Definition: v2myth.cpp:1016
mythcoreutil.h
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:204
mythdbcon.h
V2TimeZoneInfo
Definition: v2timeZoneInfo.h:8
TestDatabase
bool TestDatabase(const QString &dbHostName, const QString &dbUserName, QString dbPassword, QString dbName, int dbPort)
Definition: mythdbcon.cpp:41
v2myth.h
mythhttpmetaservice.h
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
v2wolInfo.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythSessionManager::CreateDigest
static QByteArray CreateDigest(const QString &username, const QString &password)
Generate a digest string.
Definition: mythsession.cpp:536
DBUtil::CheckTables
static bool CheckTables(bool repair=false, const QString &options="QUICK")
Checks database tables.
Definition: dbutil.cpp:275
DatabaseParams::m_dbType
QString m_dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:27
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:51
V2Myth::s_WebOnlyStartup
static WebOnlyStartup s_WebOnlyStartup
Definition: v2myth.h:66
MythDate::kDateTimeShort
@ kDateTimeShort
Default local time.
Definition: mythdate.h:24
scheduler.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
V2BackendInfo
Definition: v2backendInfo.h:19
DatabaseParams::m_wolReconnect
std::chrono::seconds m_wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:34
FillFrontendList
void FillFrontendList(QVariantList &list, QObject *parent, bool OnLine)
Definition: v2serviceUtil.cpp:946
v2versionInfo.h
V2Myth::ManageScheduler
static bool ManageScheduler(bool Enable, bool Disable)
Definition: v2myth.cpp:1265
V2Myth::SetConnectionInfo
static bool SetConnectionInfo(const QString &Host, const QString &UserName, const QString &Password, const QString &Name, int Port, bool DoTest)
Definition: v2myth.cpp:156
V2DatabaseInfo
Definition: v2databaseInfo.h:7
V2Myth::kWebOnlyWebOnlyParm
@ kWebOnlyWebOnlyParm
Definition: v2myth.h:62
DatabaseParams::m_dbPort
int m_dbPort
database port
Definition: mythdbparams.h:23
mythdate.h
DigestUserActions
DigestUserActions
Definition: mythsession.h:12
V2BuildInfo
Definition: v2buildInfo.h:16
mythlogging.h
logLevelGetName
QString logLevelGetName(LogLevel_t level)
Map a log level enumerated value back to the name.
Definition: logging.cpp:784
v2serviceUtil.h
MythSessionManager::ManageDigestUser
static bool ManageDigestUser(DigestUserActions action, const QString &username, const QString &password, const QString &newPassword, const QString &adminPassword)
Manage digest user entries.
Definition: mythsession.cpp:550
hardwareprofile.scan.profile
profile
Definition: scan.py:96
DatabaseParams::m_dbHostPing
bool m_dbHostPing
No longer used.
Definition: mythdbparams.h:22
MYTH_HANDLE
#define MYTH_HANDLE
Definition: v2myth.h:17
HardwareProfile
Definition: hardwareprofile.h:16
V2LabelValue
Definition: v2labelValue.h:13
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
MythCoreContext::GetBackendServerIP
QString GetBackendServerIP(void)
Returns the IP address of the locally defined backend IP.
Definition: mythcorecontext.cpp:1010
V2Myth::GetLogs
static V2LogMessageList * GetLogs(const QString &HostName, const QString &Application, int PID, int TID, const QString &Thread, const QString &Filename, int Line, const QString &Function, const QDateTime &FromTime, const QDateTime &ToTime, const QString &Level, const QString &MsgContains)
Definition: v2myth.cpp:537
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
logLevelGet
LogLevel_t logLevelGet(const QString &level)
Map a log level name back to the enumerated value.
Definition: logging.cpp:762
V2Myth::ManageUrlProtection
static bool ManageUrlProtection(const QString &Services, const QString &AdminPassword)
Definition: v2myth.cpp:1207
V2Myth::GetFormatTime
static QString GetFormatTime(const QDateTime &Time)
Definition: v2myth.cpp:514
HardwareProfile::GetHardwareProfile
static QString GetHardwareProfile(void)
Definition: hardwareprofile.cpp:263
MythDate::kAutoYear
@ kAutoYear
Add year only if different from current year.
Definition: mythdate.h:28
MythCoreContext::GetDB
MythDB * GetDB(void)
Definition: mythcorecontext.cpp:1763
MythDate::kDateShort
@ kDateShort
Default local time.
Definition: mythdate.h:20
DBUtil
Aggregates database and DBMS utility functions.
Definition: dbutil.h:30
V2Myth::Shutdown
static bool Shutdown(int Retcode, bool Restart, bool WebOnly)
Definition: v2myth.cpp:1291
V2Myth::GetFormatDateTime
static QString GetFormatDateTime(const QDateTime &DateTime, bool ShortDate)
Definition: v2myth.cpp:501
V2Myth::kWebOnlyDBTimezone
@ kWebOnlyDBTimezone
Definition: v2myth.h:61
KnownServicesV2
const QStringList KnownServicesV2
Definition: v2serviceUtil.h:36
DBUtil::BackupDB
static MythDBBackupStatus BackupDB(QString &filename, bool disableRotation=false)
Requests a backup of the database.
Definition: dbutil.cpp:186
V2StorageGroupDirList
Definition: v2storageGroupDirList.h:9
DBUtil::CheckTimeZoneSupport
static bool CheckTimeZoneSupport(void)
Check if MySQL has working timz zone support.
Definition: dbutil.cpp:865
storagegroup.h
DatabaseParams::m_dbPassword
QString m_dbPassword
DB password.
Definition: mythdbparams.h:25
PID
Contains Packet Identifier numeric values.
Definition: mpegtables.h:206
DatabaseParams::m_wolRetry
int m_wolRetry
times to retry to reconnect
Definition: mythdbparams.h:35
v2databaseInfo.h
DatabaseParams::m_dbName
QString m_dbName
database name
Definition: mythdbparams.h:26
V2Myth::Proxy
static QString Proxy(const QString &Url)
Definition: v2myth.cpp:1315
MSqlQuery::isConnected
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:137
V2Myth::BackupDatabase
static bool BackupDatabase(void)
Definition: v2myth.cpp:973
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
MythHTTPService
Definition: mythhttpservice.h:19
MythDate::fromString
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:39
V2Myth::GetFrontends
static V2FrontendList * GetFrontends(bool OnLine)
Definition: v2myth.cpp:670
MythDate::kSimplify
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:26
V2Myth::GetSetting
static QString GetSetting(const QString &HostName, const QString &Key, const QString &Default)
Definition: v2myth.cpp:683
V2Myth::AddStorageGroupDir
static bool AddStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName)
Definition: v2myth.cpp:370
MythTZ::calc_utc_offset
int calc_utc_offset(void)
Definition: mythtimezone.cpp:18
MythHTTPService::Name
QString & Name()
Definition: mythhttpservice.cpp:240
V2Myth::GetConnectionInfo
static V2ConnectionInfo * GetConnectionInfo(const QString &Pin)
Definition: v2myth.cpp:76
kDB_Backup_Unknown
@ kDB_Backup_Unknown
Definition: dbutil.h:11
V2Myth::ParseISODateString
static QDateTime ParseISODateString(const QString &DateTime)
Definition: v2myth.cpp:523
DIGEST_USER_ADD
@ DIGEST_USER_ADD
Definition: mythsession.h:13
V2Myth::kWebOnlySchemaUpdate
@ kWebOnlySchemaUpdate
Definition: v2myth.h:64
V2Myth::GetStorageGroupDirs
static V2StorageGroupDirList * GetStorageGroupDirs(const QString &GroupName, const QString &HostName)
Definition: v2myth.cpp:290
V2LogMessage
Definition: v2logMessage.h:13
mythcorecontext.h
V2Myth::GetHosts
static QStringList GetHosts()
Definition: v2myth.cpp:206
V2StorageGroupDir
Definition: v2storageGroupDir.h:6
DatabaseParams::m_wolCommand
QString m_wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:36
Name
Definition: channelsettings.cpp:103
MythCoreContext::GetSettingOnHost
QString GetSettingOnHost(const QString &key, const QString &host, const QString &defaultval="")
Definition: mythcorecontext.cpp:932
DIGEST_USER_CHANGE_PW
@ DIGEST_USER_CHANGE_PW
Definition: mythsession.h:15
V2Myth::kWebOnlyIPAddress
@ kWebOnlyIPAddress
Definition: v2myth.h:63
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
V2Myth::CheckDatabase
static bool CheckDatabase(bool Repair)
Definition: v2myth.cpp:1002
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
DatabaseParams::m_dbUserName
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:24
V2SettingList
Definition: v2settingList.h:16
V2Myth::ProfileSubmit
static bool ProfileSubmit(void)
Definition: v2myth.cpp:1030
kDB_Backup_Completed
@ kDB_Backup_Completed
Definition: dbutil.h:13
tv_rec.h
V2Myth::GetBackendInfo
V2BackendInfo * GetBackendInfo(void)
Definition: v2myth.cpp:1110
V2Myth::TestDBSettings
static bool TestDBSettings(const QString &HostName, const QString &UserName, const QString &Password, const QString &DBName, int dbPort)
Definition: v2myth.cpp:815
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:19
V2Myth::RegisterCustomTypes
static void RegisterCustomTypes()
V2FrontendList
Definition: v2frontendList.h:18
V2Myth::ProfileURL
static QString ProfileURL(void)
Definition: v2myth.cpp:1062
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:844
logPropagateArgs
QString logPropagateArgs
Definition: logging.cpp:82
V2Myth::ManageDigestUser
static bool ManageDigestUser(const QString &Action, const QString &UserName, const QString &Password, const QString &NewPassword, const QString &AdminPassword)
Definition: v2myth.cpp:1175
MythHTTPService::m_request
HTTPRequest2 m_request
Definition: mythhttpservice.h:35
musicbrainzngs.caa.hostname
string hostname
Definition: caa.py:17
DatabaseParams::m_localEnabled
bool m_localEnabled
true if localHostName is not default
Definition: mythdbparams.h:29
MythDate::kDateTimeFull
@ kDateTimeFull
Default local time.
Definition: mythdate.h:23
Q_GLOBAL_STATIC_WITH_ARGS
Q_GLOBAL_STATIC_WITH_ARGS(MythHTTPMetaService, s_service,(MYTH_HANDLE, V2Myth::staticMetaObject, &V2Myth::RegisterCustomTypes)) void V2Myth
Definition: v2myth.cpp:42
MythDate::kTime
@ kTime
Default local time.
Definition: mythdate.h:22
V2Myth::kWebOnlyNone
@ kWebOnlyNone
Definition: v2myth.h:59
DatabaseParams::m_wolEnabled
bool m_wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:33
mythdownloadmanager.h
build_compdb.filename
filename
Definition: build_compdb.py:21
V2Myth::SendMessage
static bool SendMessage(const QString &Message, const QString &Address, int udpPort, int Timeout)
Definition: v2myth.cpp:841
V2Myth::kWebOnlyDBSetup
@ kWebOnlyDBSetup
Definition: v2myth.h:60
DatabaseParams::m_localHostName
QString m_localHostName
name used for loading/saving settings
Definition: mythdbparams.h:30
V2Myth::SendNotification
static bool SendNotification(bool Error, const QString &Type, const QString &Message, const QString &Origin, const QString &Description, const QString &Image, const QString &Extra, const QString &ProgressText, float Progress, int Timeout, bool Fullscreen, uint Visibility, uint Priority, const QString &Address, int udpPort)
Definition: v2myth.cpp:895
MythCoreContext::SaveSettingOnHost
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
Definition: mythcorecontext.cpp:897
Priority
Definition: channelsettings.cpp:248
mythtimezone.h
MythHTTPMetaService
Definition: mythhttpmetaservice.h:10
DIGEST_USER_REMOVE
@ DIGEST_USER_REMOVE
Definition: mythsession.h:14
V2Myth::RemoveStorageGroupDir
static bool RemoveStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName)
Definition: v2myth.cpp:432
uint
unsigned int uint
Definition: freesurround.h:24
V2Myth::V2Myth
V2Myth()
Definition: v2myth.cpp:67
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:904
GetMythDownloadManager
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
Definition: mythdownloadmanager.cpp:146
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
V2Myth::GetTimeZone
static V2TimeZoneInfo * GetTimeZone()
Definition: v2myth.cpp:473
TVRec::s_inputs
static QMap< uint, TVRec * > s_inputs
Definition: tv_rec.h:433
V2Myth::ProfileDelete
static bool ProfileDelete(void)
Definition: v2myth.cpp:1046
V2Myth::GetSettingList
static V2SettingList * GetSettingList(const QString &HostName)
Definition: v2myth.cpp:721