diff options
author | Underground78 <underground78@users.sourceforge.net> | 2015-08-05 00:54:13 +0300 |
---|---|---|
committer | Underground78 <underground78@users.sourceforge.net> | 2015-08-05 22:12:09 +0300 |
commit | a2548a807a38c3a2fd4a8773933f450d90949ff4 (patch) | |
tree | 8286aa9e51418bd01baeb998c67ad72580cbfdb7 | |
parent | d3264ab4d7e21cbcea6248383b92c4e9d38f899c (diff) |
Web interface: Add an option to disable the preview.
This option is disabled by default since it needs to be used with caution.
Fixes #5411.
-rw-r--r-- | src/mpc-hc/AppSettings.cpp | 7 | ||||
-rw-r--r-- | src/mpc-hc/AppSettings.h | 1 | ||||
-rw-r--r-- | src/mpc-hc/PPageWebServer.cpp | 29 | ||||
-rw-r--r-- | src/mpc-hc/PPageWebServer.h | 6 | ||||
-rw-r--r-- | src/mpc-hc/SettingsDefines.h | 1 | ||||
-rw-r--r-- | src/mpc-hc/WebClientSocket.cpp | 17 | ||||
-rw-r--r-- | src/mpc-hc/mpc-hc.rc | 23 | ||||
-rw-r--r-- | src/mpc-hc/res/web/player.html | 4 | ||||
-rw-r--r-- | src/mpc-hc/resource.h | 2 |
9 files changed, 63 insertions, 27 deletions
diff --git a/src/mpc-hc/AppSettings.cpp b/src/mpc-hc/AppSettings.cpp index c306f9477..ff5c51160 100644 --- a/src/mpc-hc/AppSettings.cpp +++ b/src/mpc-hc/AppSettings.cpp @@ -85,6 +85,7 @@ CAppSettings::CAppSettings() , fWebServerUseCompression(true)
, fWebServerLocalhostOnly(false)
, fWebServerPrintDebugInfo(false)
+ , bWebUIEnablePreview(false)
, nVolume(100)
, fMute(false)
, nBalance(0)
@@ -924,9 +925,10 @@ void CAppSettings::SaveSettings() pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_ENABLEWEBSERVER, fEnableWebServer);
pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERPORT, nWebServerPort);
- pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERPRINTDEBUGINFO, fWebServerPrintDebugInfo);
pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERUSECOMPRESSION, fWebServerUseCompression);
pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERLOCALHOSTONLY, fWebServerLocalhostOnly);
+ pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_WEBUI_ENABLE_PREVIEW, bWebUIEnablePreview);
+ pApp->WriteProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERPRINTDEBUGINFO, fWebServerPrintDebugInfo);
pApp->WriteProfileString(IDS_R_SETTINGS, IDS_RS_WEBROOT, strWebRoot);
pApp->WriteProfileString(IDS_R_SETTINGS, IDS_RS_WEBDEFINDEX, strWebDefIndex);
pApp->WriteProfileString(IDS_R_SETTINGS, IDS_RS_WEBSERVERCGI, strWebServerCGI);
@@ -1567,9 +1569,10 @@ void CAppSettings::LoadSettings() fEnableWebServer = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_ENABLEWEBSERVER, FALSE);
nWebServerPort = pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERPORT, 13579);
- fWebServerPrintDebugInfo = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERPRINTDEBUGINFO, FALSE);
fWebServerUseCompression = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERUSECOMPRESSION, TRUE);
fWebServerLocalhostOnly = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERLOCALHOSTONLY, FALSE);
+ bWebUIEnablePreview = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_WEBUI_ENABLE_PREVIEW, FALSE);
+ fWebServerPrintDebugInfo = !!pApp->GetProfileInt(IDS_R_SETTINGS, IDS_RS_WEBSERVERPRINTDEBUGINFO, FALSE);
strWebRoot = pApp->GetProfileString(IDS_R_SETTINGS, IDS_RS_WEBROOT, _T("*./webroot"));
strWebDefIndex = pApp->GetProfileString(IDS_R_SETTINGS, IDS_RS_WEBDEFINDEX, _T("index.html;index.php"));
strWebServerCGI = pApp->GetProfileString(IDS_R_SETTINGS, IDS_RS_WEBSERVERCGI);
diff --git a/src/mpc-hc/AppSettings.h b/src/mpc-hc/AppSettings.h index f5583e23d..0956b0189 100644 --- a/src/mpc-hc/AppSettings.h +++ b/src/mpc-hc/AppSettings.h @@ -466,6 +466,7 @@ public: int nCmdlnWebServerPort;
bool fWebServerUseCompression;
bool fWebServerLocalhostOnly;
+ bool bWebUIEnablePreview;
bool fWebServerPrintDebugInfo;
CString strWebRoot, strWebDefIndex;
CString strWebServerCGI;
diff --git a/src/mpc-hc/PPageWebServer.cpp b/src/mpc-hc/PPageWebServer.cpp index 370edaecf..97dd62dfb 100644 --- a/src/mpc-hc/PPageWebServer.cpp +++ b/src/mpc-hc/PPageWebServer.cpp @@ -36,9 +36,10 @@ CPPageWebServer::CPPageWebServer() , m_fEnableWebServer(FALSE)
, m_nWebServerPort(0)
, m_launch(_T("http://localhost:13579/"))
- , m_fWebServerPrintDebugInfo(FALSE)
, m_fWebServerUseCompression(FALSE)
, m_fWebServerLocalhostOnly(FALSE)
+ , m_bWebUIEnablePreview(FALSE)
+ , m_fWebServerPrintDebugInfo(FALSE)
, m_fWebRoot(FALSE)
{
}
@@ -55,11 +56,12 @@ void CPPageWebServer::DoDataExchange(CDataExchange* pDX) DDX_Control(pDX, IDC_EDIT1, m_nWebServerPortCtrl);
DDV_MinMaxInt(pDX, m_nWebServerPort, 1, 65535);
DDX_Control(pDX, IDC_STATIC1, m_launch);
- DDX_Check(pDX, IDC_CHECK2, m_fWebServerPrintDebugInfo);
DDX_Check(pDX, IDC_CHECK3, m_fWebServerUseCompression);
+ DDX_Check(pDX, IDC_CHECK5, m_fWebServerLocalhostOnly);
+ DDX_Check(pDX, IDC_CHECK6, m_bWebUIEnablePreview);
+ DDX_Check(pDX, IDC_CHECK2, m_fWebServerPrintDebugInfo);
DDX_Check(pDX, IDC_CHECK4, m_fWebRoot);
DDX_Text(pDX, IDC_EDIT2, m_WebRoot);
- DDX_Check(pDX, IDC_CHECK5, m_fWebServerLocalhostOnly);
DDX_Text(pDX, IDC_EDIT3, m_WebServerCGI);
DDX_Text(pDX, IDC_EDIT9, m_WebDefIndex);
}
@@ -88,9 +90,10 @@ BOOL CPPageWebServer::OnInitDialog() m_fEnableWebServer = s.fEnableWebServer;
m_nWebServerPort = s.nWebServerPort;
- m_fWebServerPrintDebugInfo = s.fWebServerPrintDebugInfo;
- m_fWebServerLocalhostOnly = s.fWebServerLocalhostOnly;
m_fWebServerUseCompression = s.fWebServerUseCompression;
+ m_fWebServerLocalhostOnly = s.fWebServerLocalhostOnly;
+ m_bWebUIEnablePreview = s.bWebUIEnablePreview;
+ m_fWebServerPrintDebugInfo = s.fWebServerPrintDebugInfo;
m_fWebRoot = s.strWebRoot.Find('*') < 0;
m_WebRoot = s.strWebRoot;
m_WebRoot.TrimLeft(_T('*'));
@@ -123,9 +126,10 @@ BOOL CPPageWebServer::OnApply() s.fEnableWebServer = !!m_fEnableWebServer;
s.nWebServerPort = m_nWebServerPort;
- s.fWebServerPrintDebugInfo = !!m_fWebServerPrintDebugInfo;
- s.fWebServerLocalhostOnly = !!m_fWebServerLocalhostOnly;
s.fWebServerUseCompression = !!m_fWebServerUseCompression;
+ s.fWebServerLocalhostOnly = !!m_fWebServerLocalhostOnly;
+ s.bWebUIEnablePreview = !!m_bWebUIEnablePreview;
+ s.fWebServerPrintDebugInfo = !!m_fWebServerPrintDebugInfo;
s.strWebRoot = NewWebRoot;
s.strWebDefIndex = m_WebDefIndex;
s.strWebServerCGI = m_WebServerCGI;
@@ -221,6 +225,7 @@ BEGIN_MESSAGE_MAP(CPPageWebServer, CPPageBase) ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton2)
+ ON_BN_CLICKED(IDC_CHECK6, OnEnablePreviewChecked)
END_MESSAGE_MAP()
@@ -265,3 +270,13 @@ void CPPageWebServer::OnUpdateButton2(CCmdUI* pCmdUI) {
pCmdUI->Enable(GetDlgItem(IDC_EDIT2)->GetWindowTextLength() > 0);
}
+
+void CPPageWebServer::OnEnablePreviewChecked()
+{
+ if (IsDlgButtonChecked(IDC_CHECK6)
+ && (MessageBox(ResStr(IDS_WEBUI_PREVIEW_WARNING), nullptr, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDNO)) {
+ CheckDlgButton(IDC_CHECK6, BST_UNCHECKED);
+ } else {
+ SetModified();
+ }
+}
diff --git a/src/mpc-hc/PPageWebServer.h b/src/mpc-hc/PPageWebServer.h index 565f070ce..93e4aee60 100644 --- a/src/mpc-hc/PPageWebServer.h +++ b/src/mpc-hc/PPageWebServer.h @@ -1,6 +1,6 @@ /*
* (C) 2003-2006 Gabest
- * (C) 2006-2012 see Authors.txt
+ * (C) 2006-2012, 2015 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -47,9 +47,10 @@ public: int m_nWebServerPort;
CIntEdit m_nWebServerPortCtrl;
CStaticLink m_launch;
- BOOL m_fWebServerPrintDebugInfo;
BOOL m_fWebServerUseCompression;
BOOL m_fWebServerLocalhostOnly;
+ BOOL m_fWebServerPrintDebugInfo;
+ BOOL m_bWebUIEnablePreview;
BOOL m_fWebRoot;
CString m_WebRoot;
CString m_WebServerCGI;
@@ -68,4 +69,5 @@ public: afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
afx_msg void OnUpdateButton2(CCmdUI* pCmdUI);
+ afx_msg void OnEnablePreviewChecked();
};
diff --git a/src/mpc-hc/SettingsDefines.h b/src/mpc-hc/SettingsDefines.h index 09f2671da..1fecfc6cc 100644 --- a/src/mpc-hc/SettingsDefines.h +++ b/src/mpc-hc/SettingsDefines.h @@ -179,6 +179,7 @@ #define IDS_RS_ONTOP _T("OnTop")
#define IDS_RS_WEBSERVERPRINTDEBUGINFO _T("WebServerPrintDebugIfo")
#define IDS_RS_WEBSERVERUSECOMPRESSION _T("WebServerUseCompression")
+#define IDS_RS_WEBUI_ENABLE_PREVIEW _T("WebUIEnablePreview")
#define IDS_RS_SNAPSHOTPATH _T("SnapshotPath")
#define IDS_RS_PRIORITY _T("Priority")
#define IDS_RS_SNAPSHOTEXT _T("SnapshotExt")
diff --git a/src/mpc-hc/WebClientSocket.cpp b/src/mpc-hc/WebClientSocket.cpp index 2bcafcbc4..fa0480fcf 100644 --- a/src/mpc-hc/WebClientSocket.cpp +++ b/src/mpc-hc/WebClientSocket.cpp @@ -800,6 +800,12 @@ bool CWebClientSocket::OnError404(CStringA& hdr, CStringA& body, CStringA& mime) bool CWebClientSocket::OnPlayer(CStringA& hdr, CStringA& body, CStringA& mime)
{
m_pWebServer->LoadPage(IDR_HTML_PLAYER, body, AToT(m_path));
+ if (AfxGetAppSettings().bWebUIEnablePreview) {
+ body.Replace("[preview]",
+ "<img src=\"snapshot.jpg\" id=\"snapshot\" alt=\"snapshot\" onload=\"onLoadSnapshot()\" onabort=\"onAbortErrorSnapshot()\" onerror=\"onAbortErrorSnapshot()\">");
+ } else {
+ body.Replace("[preview]", UTF8(ResStr(IDS_WEBUI_DISABLED_PREVIEW_MSG)));
+ }
return true;
}
@@ -807,11 +813,14 @@ bool CWebClientSocket::OnSnapshotJpeg(CStringA& hdr, CStringA& body, CStringA& m {
// TODO: add quality control and return logo when nothing is loaded
- bool fRet = false;
+ bool bRet = false;
BYTE* pData = nullptr;
long size = 0;
- if (m_pMainFrame->GetDIB(&pData, size, true)) {
+ if (!AfxGetAppSettings().bWebUIEnablePreview) {
+ hdr = "HTTP/1.0 403 Forbidden\r\n";
+ bRet = true;
+ } else if (m_pMainFrame->GetDIB(&pData, size, true)) {
PBITMAPINFO bi = reinterpret_cast<PBITMAPINFO>(pData);
PBITMAPINFOHEADER bih = &bi->bmiHeader;
@@ -863,11 +872,11 @@ bool CWebClientSocket::OnSnapshotJpeg(CStringA& hdr, CStringA& body, CStringA& m "Pragma: no-cache\r\n";
body = CStringA((char*)ba.GetData(), (int)ba.GetCount());
mime = "image/jpeg";
- fRet = true;
+ bRet = true;
}
}
- return fRet;
+ return bRet;
}
bool CWebClientSocket::OnViewRes(CStringA& hdr, CStringA& body, CStringA& mime)
diff --git a/src/mpc-hc/mpc-hc.rc b/src/mpc-hc/mpc-hc.rc index 8bc58317b..06512c63b 100644 --- a/src/mpc-hc/mpc-hc.rc +++ b/src/mpc-hc/mpc-hc.rc @@ -812,16 +812,17 @@ BEGIN CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,5,22,284,1
CONTROL "Enable compression",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,26,285,8
CONTROL "Allow access from localhost only",IDC_CHECK5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,38,285,8
- CONTROL "Print debug information",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,50,285,8
- CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,5,62,284,1
- CONTROL "Serve pages from:",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,66,285,8
- EDITTEXT IDC_EDIT2,15,78,167,14,ES_AUTOHSCROLL
- PUSHBUTTON "Browse...",IDC_BUTTON1,186,78,50,14
- PUSHBUTTON "Deploy...",IDC_BUTTON2,240,78,50,14
- LTEXT "Default page:",IDC_STATIC,5,96,285,8
- EDITTEXT IDC_EDIT9,15,108,275,14,ES_AUTOHSCROLL
- LTEXT "CGI handlers: (.ext1=path1;.ext2=path2;...)",IDC_STATIC,5,126,285,8
- EDITTEXT IDC_EDIT3,15,138,275,14,ES_AUTOHSCROLL
+ CONTROL "Enable preview",IDC_CHECK6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,50,285,8
+ CONTROL "Print debug information",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,62,284,8
+ CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,5,74,284,1
+ CONTROL "Serve pages from:",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,78,285,8
+ EDITTEXT IDC_EDIT2,15,90,167,14,ES_AUTOHSCROLL
+ PUSHBUTTON "Browse...",IDC_BUTTON1,186,90,50,14
+ PUSHBUTTON "Deploy...",IDC_BUTTON2,240,90,50,14
+ LTEXT "Default page:",IDC_STATIC,5,108,285,8
+ EDITTEXT IDC_EDIT9,15,120,275,14,ES_AUTOHSCROLL
+ LTEXT "CGI handlers: (.ext1=path1;.ext2=path2;...)",IDC_STATIC,5,138,285,8
+ EDITTEXT IDC_EDIT3,15,150,275,14,ES_AUTOHSCROLL
END
IDD_SUBTITLEDL_DLG DIALOGEX 0, 0, 500, 200
@@ -2702,6 +2703,8 @@ BEGIN IDS_AFTERPLAYBACK_CLOSE "After Playback: Close"
IDS_FRAME_INIT_FAILED "MPC-HC encountered a problem during initialization. With your help we might be able to fix the issue.\n\nDo you want to report it?"
IDS_TIME_SHIFT_TOOLTIP "Enter a positive value if the audio is early, a negative value if it is late."
+ IDS_WEBUI_DISABLED_PREVIEW_MSG "Preview is currently disabled. You can enable it in MPC-HC's options."
+ IDS_WEBUI_PREVIEW_WARNING "This option can be used to preview media files from remote location. Use it only on a properly secured private network.\n\nDo you really want to enable this option?"
END
STRINGTABLE
diff --git a/src/mpc-hc/res/web/player.html b/src/mpc-hc/res/web/player.html index 59aa35198..39f16ab83 100644 --- a/src/mpc-hc/res/web/player.html +++ b/src/mpc-hc/res/web/player.html @@ -1,4 +1,4 @@ -<!DOCTYPE html>
+<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
@@ -49,7 +49,7 @@ </tr>
<tr>
<td id="video" onclick="onCommand(889)">
- <img src="snapshot.jpg" id="snapshot" alt="snapshot" onload="onLoadSnapshot()" onabort="onAbortErrorSnapshot()" onerror="onAbortErrorSnapshot()">
+ [preview]
</td>
</tr>
<tr>
diff --git a/src/mpc-hc/resource.h b/src/mpc-hc/resource.h index 26413af35..79ddc4dec 100644 --- a/src/mpc-hc/resource.h +++ b/src/mpc-hc/resource.h @@ -1471,6 +1471,8 @@ #define IDS_AFTERPLAYBACK_CLOSE 57434
#define IDS_FRAME_INIT_FAILED 57435
#define IDS_TIME_SHIFT_TOOLTIP 57436
+#define IDS_WEBUI_DISABLED_PREVIEW_MSG 57437
+#define IDS_WEBUI_PREVIEW_WARNING 57438
// Next default values for new objects
//
|