Start: Do not access the internet in start page before user explicitely allowed it

This commit is contained in:
Yorik van Havre
2018-03-13 12:19:50 -03:00
parent 25d47ae652
commit 2c2d781aa6
5 changed files with 52 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ if(BUILD_GUI)
StartPage.css
StartPage.js
StartPage.html
EnableDownload.py
images/Background.jpg
images/FreeCAD.png
images/PartDesign.png

View File

@@ -0,0 +1,26 @@
#***************************************************************************
#* *
#* Copyright (c) 2012 *
#* Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD,FreeCADGui
rf=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start")
rf.SetBool("AllowDownload",True)

View File

@@ -1,4 +1,5 @@
var linkDescriptions = [];
var allowDownloads = 0;
function JSONscriptRequest(fullUrl) {
// REST request path
@@ -85,6 +86,10 @@ function stripTags(text) {
function showTweets(data) {
ddiv = document.getElementById('news');
if (allowDownloads == 0) {
ddiv.innerHTML = '<a href="EnableDownload.py" onClick="enableDownloads()">text70</a> text71';
return;
}
ddiv.innerHTML = "Received";
var html = ['<ul>'];
for (var i = 0; i < 4; i++) {
@@ -103,6 +108,17 @@ function showTweets(data) {
resize(); // intentional javascript hack
}
function enableDownloads() {
allowDownloads = 1;
// load latest news
ddiv = document.getElementById("news");
ddiv.innerHTML = "Connecting...";
var tobj=new JSONscriptRequest('https://api.github.com/repos/FreeCAD/FreeCAD/commits?callback=showTweets');
tobj.buildScriptTag(); // Build the script tag
tobj.addScriptTag(); // Execute (add) the script tag
ddiv.innerHTML = "Downloading latest news...";
}
function showDescr(d) {
if (d) {
show(linkDescriptions[d-1]);

View File

@@ -38,7 +38,7 @@ from .TranslationTexts import (text01, text02, text03, text04, text05, text06,
text49, text50, text51, text52, text53, text54,
text55, text56, text57, text58, text59, text60,
text61, text62, text63, text64, text65, text66,
text67, text68, text69)
text67, text68, text69, text70, text71)
try:
import io as cStringIO
@@ -284,6 +284,8 @@ def replace_js_text(html):
html = html.replace("text58", text58)
html = html.replace("text59", text59)
html = html.replace("text63", text63)
html = html.replace("text70", text70)
html = html.replace("text71", text71)
return html
def handle():
@@ -298,6 +300,10 @@ def handle():
# add custom blocks
html = html.replace("customblocks",getCustomBlocks())
# enable web access if permitted
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("AllowDownload",False):
html = html.replace("var allowDownloads = 0;","var allowDownloads = 1;")
html = replace_html_text(html)
# fetches system colors

View File

@@ -124,3 +124,5 @@ text66 = translate("StartPage", "Author")
text67 = translate("StartPage", "Company")
text68 = translate("StartPage", "License")
text69 = translate("StartPage", "Load an FEM 3D new solver example analysis")
text70 = translate("StartPage", "Click here")
text71 = translate("StartPage", "to allow FreeCAD to access the internet")