Skip to content

Commit d8d8180

Browse files
committed
documentation update
1 parent 5b3e6c7 commit d8d8180

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

README.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Perl Executing Browser
22
----------------------------------------------------------------------------------------
33

4-
Perl Executing Browser (PEB) is a C++ [Qt 5] (https://www.qt.io/) WebKit implementation of a minimalistic HTML framework for local [Perl 5] (https://www.perl.org/) scripts executed without server as desktop data-driven applications. Perl 5 scripts can be fed from HTML forms using GET and POST methods or from AJAX requests. HTML interface for interaction with the built-in Perl debugger is also available.
4+
Perl Executing Browser (PEB) is a C++ [Qt 5] (https://www.qt.io/) WebKit implementation of a minimalistic HTML framework for local [Perl 5] (https://www.perl.org/) scripts executed without server as desktop data-driven applications. Perl 5 scripts can be fed directly from HTML forms using GET and POST methods or using AJAX requests. HTML interface for interaction with the built-in Perl debugger is also available.
5+
Inspired by [NW.js] (http://nwjs.io/) and [Electron] (http://electron.atom.io/), PEB is another reuse of web technologies for the development of desktop applications, but with Perl doing the heavy lifting.
56

67
## Design Objectives
78

@@ -23,18 +24,18 @@ Perl Executing Browser (PEB) is a C++ [Qt 5] (https://www.qt.io/) WebKit impleme
2324
## Features
2425

2526
**Usability:**
26-
* Perl 5 scripts can be fed from HTML forms using GET or POST methods or from AJAX requests.
27-
* Single file or multiple files, new filename, existing or new directory can be selected by user and supplied with their full paths to local Perl scripts.
28-
* Basic security restrictions are imposed on every Perl script.
27+
* Perl 5 scripts can be fed directly from HTML forms using GET or POST methods or using AJAX requests.
2928
* Any version of Perl 5 can be used.
29+
* Basic security restrictions are imposed on every Perl script.
3030
* PEB can be started from any folder.
31-
* Cross-site scripting is disabled for all web pages.
31+
* PEB is usefull for both single-page or multi-page applications.
32+
* Single file or multiple files, new filename, existing or new directory can be selected by user.
33+
Their full paths are displayed in the calling local page and they can be supplied to local Perl scripts.
3234
* Browser functions are accessible from special URLs.
3335
* Any icon can be displayed on windows and message boxes.
34-
* Every aspect of the graphical user interface can be customized using HTML & JavaScript.
35-
* Usefull for both single-page or multi-page applications.
3636
* Optional JavaScript translation of context menu and dialog boxes.
3737
* Optional warning for unsaved data in HTML forms before closing a window to prevent accidental data loss.
38+
* Cross-site scripting is disabled for all web pages.
3839

3940
**Development goodies:**
4041
* PEB can interact with the Perl 5 debugger in graphical mode - see section *HTML Interface for the Perl Debugger*
@@ -46,7 +47,7 @@ Perl Executing Browser (PEB) is a C++ [Qt 5] (https://www.qt.io/) WebKit impleme
4647
GCC compiler and Qt 5.1 - Qt 5.5 headers (including ```QtWebKit``` headers).
4748
Later versions of Qt are unusable due to the deprecation of ```QtWebKit```.
4849

49-
The most important Qt dependency of PEB is actually not ```QtWebkit```, but ```QNetworkAccessManager``` class, which is subclassed to implement CGI-like POST and AJAX GET and POST requests to local Perl scripts. The removal of this class from the ecosystem of ```QtWebEngine```, the new Blink-based web engine of Qt, means that transition to ```QtWebEngine``` remains problematic.
50+
The most important Qt dependency of PEB is actually not ```QtWebkit```, but ```QNetworkAccessManager``` class, which is subclassed to implement non-AJAX POST and AJAX GET and POST requests to local Perl scripts. The removal of this class from the ecosystem of ```QtWebEngine```, the new Blink-based web engine of Qt, means that transition to ```QtWebEngine``` remains problematic.
5051

5152
Compiled and tested successfully using:
5253
* [Qt Creator 2.8.1 and Qt 5.1.1] (http://download.qt.io/official_releases/qt/5.1/5.1.1/) on 32-bit Debian Linux,
@@ -65,6 +66,49 @@ Compiled and tested successfully using:
6566
* Perl 5 distribution - any Linux, Mac or Windows Perl distribution.
6667
[Strawberry Perl] (http://strawberryperl.com/) PortableZIP edition is successfully used with all Windows builds of PEB.
6768

69+
## How to Call Local Perl Scripts from a Local Page?
70+
PEB recognizes two types of local Perl scripts: non-AJAX scripts and AJAX scripts.
71+
* **Non-AJAX Perl scripts:**
72+
Non-AJAX Perl scripts are expected to produce a complete HTML page that will replace the calling page when script output becomes available. Note that there could be multiple chunks of script output from non-AJAX scripts - PEB accumulates them and displays everything it has when a new piece of script output comes out.
73+
74+
There is no timeout for all Perl scripts executed by PEB (non-AJAX and AJAX), but slow scripts should be optimized to avoid degradation of the user experinece.
75+
76+
There is no special naming convention for non-AJAX scripts and they are called from hyperlinks or HTML forms just like any Perl CGI script was called in the olden days of Perl CGI scripting:
77+
78+
```html
79+
<form action="perl/test.pl" method="post">
80+
<input type="text" id="value1" name="value1" placeholder="Value 1" title="Value 1">
81+
<input type="text" id="value2" name="value2" placeholder="Value 2" title="Value 2">
82+
83+
<input type="reset" value="Reset">
84+
<input type="submit" value="Submit">
85+
</form>
86+
```
87+
88+
* **AJAX Perl scripts:**
89+
AJAX scripts don't have to produce a complete HTML page, but they have two differences compared to non-AJAX scripts.
90+
91+
PEB returns all output from AJAX scripts in one piece after the script has finished with no timeout.
92+
93+
AJAX scripts must have the keyword ```ajax``` somewhere in their pathname so that PEB is able to distinguish between AJAX and non-AJAX scripts. So an AJAX script could be named ```ajax-test.pl``` or all AJAX scripts could be placed in a folder called ```ajax-scripts``` somewhere inside the application directory - see section *Settings*.
94+
95+
The following example illustrates how to call a local AJAX Perl script from a local page:
96+
97+
```javascript
98+
$(document).ready(function() {
99+
$('#ajax-button').click(function() {
100+
$.ajax({
101+
url: 'http://perl-executing-browser-pseudodomain/perl/ajax-test.pl',
102+
method: 'GET',
103+
dataType: 'text',
104+
success: function(data) {
105+
$('#ajax-results').html(data);
106+
}
107+
});
108+
});
109+
});
110+
```
111+
68112
## Settings
69113

70114
**Settings based on the existence of certain files and folders:**
@@ -75,12 +119,14 @@ PEB is designed to run from any directory without setting anything beforehand an
75119
Application directory must be ```{PEB_binary_directory}/resources/app```. All files used by PEB, with the exception of data files, must be located within this folder. Application directory is hardcoded in C++ code for compatibility with the [Electron] (http://electron.atom.io/) framework. [Epigraphista] (https://github.com/ddmitov/epigraphista) provides an example of a PEB-based application, that is also compatible with [Electron] (http://electron.atom.io/) and [NW.js] (http://nwjs.io/).
76120
* **Data directory:**
77121
Data directory is not hardcoded in C++ code, but a separation of data files from code is generally a good practice. Data directory should contain any SQLite database(s) or other files, that a PEB-based application is going to use or produce. The recommended path for data directory is inside the ```{PEB_binary_directory}/resources``` directory. ```data``` is a good directory name, although not mandatory. Perl scripts can access this folder using the following code:
122+
78123
```perl
79124
use Cwd;
80125

81126
my $current_working_directory = cwd();
82127
my $data_directory = "$current_working_directory/resources/data";
83128
```
129+
84130
* **Perl interpreter:**
85131
PEB expects to find Perl interpreter in ```{PEB_binary_directory}/perl/bin``` folder. The interpreter must be named ```perl``` on Linux and Mac machines and ```perl.exe``` on Windows machines. If Perl interpreter is not found in the above location, PEB will try to find the first Perl interpreter on PATH. If no Perl interpreter is found, an error message is displayed instead of the start page. No Perl interpreter is a showstopper for PEB.
86132
* **Start page:**
@@ -280,7 +326,7 @@ JavaScript-based settings are created to facilitate the development of fully tra
280326

281327
**Security features based on Perl code:**
282328
* Perl scripts are executed in an ```eval``` function after banning potentially unsafe core functions. This feature is implemented in a special script named ```censor.pl```, which is compiled into the resources of the browser binary and is executed from memory when Perl script is started. All core functions from the :dangerous group - ```syscall```, ```dump``` and ```chroot```, as well as ```fork``` are banned.
283-
* The environment of all Perl scripts is once again filtered in the ```BEGIN``` block of ```censor.pl``` to ensure no unwanted environment variables are inserted from the operating system.
329+
* The environment of all Perl scripts is once again filtered in the ```BEGIN``` block of ```censor.pl``` to ensure no unwanted environment variables are inserted by the operating system.
284330

285331
**Perl Debugger Interaction:**
286332
* Any Perl script can be selected for debugging, which is also a security risk. So if Perl debugger interaction is not needed, it can be turned off by a compile-time variable. Just change ```PERL_DEBUGGER_INTERACTION = 1``` to ```PERL_DEBUGGER_INTERACTION = 0``` in the project file of the browser (peb.pro) and compile the binary.
@@ -296,7 +342,7 @@ JavaScript-based settings are created to facilitate the development of fully tra
296342

297343
* PEB is not a general purpose web browser and does not have all traditional features of general purpose web browsers.
298344
* Unlike JavaScript in general purpose web browsers, Perl scripts executed by PEB have no access to the HTML DOM tree of any page.
299-
* PEB is not an implementation of the CGI protocol. It uses only three environment variables (see below) together with the GET and POST methods from the CGI protocol in a purely local context without any attempt to communicate with the outside world.
345+
* PEB is not an implementation of the CGI protocol. It uses only three environment variables together with the GET and POST methods from the CGI protocol in a purely local context without any attempt to communicate with the outside world.
300346
* PEB does not embed any Perl interpreter in itself and rellies on an external Perl distribution, which could be easily changed or upgraded independently.
301347
* PEB has no sandbox for Perl scripts - they are treated like and executed as ordinary desktop applications with normal user privileges.
302348

src/peb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ QPage::QPage()
634634
this,
635635
SLOT(qStartScriptSlot(QUrl, QByteArray)));
636636

637-
// Connect signals and slots for all local CGI-like Perl scripts:
637+
// Connect signals and slots for all local non-AJAX Perl scripts:
638638
QObject::connect(&scriptHandler, SIGNAL(readyReadStandardOutput()),
639639
this, SLOT(qScriptOutputSlot()));
640640
QObject::connect(&scriptHandler, SIGNAL(readyReadStandardError()),

src/peb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class QAccessManager : public QNetworkAccessManager
440440
}
441441

442442
// GET requests to the browser pseudodomain -
443-
// local files and CGI-like scripts:
443+
// local files and non-AJAX scripts:
444444
if (operation == GetOperation and
445445
request.url().authority() == PSEUDO_DOMAIN and
446446
(!request.url().path().contains("ajax"))) {
@@ -536,7 +536,7 @@ class QAccessManager : public QNetworkAccessManager
536536
}
537537
}
538538

539-
// POST requests to the browser pseudodomain - CGI-like scripts:
539+
// POST requests to the browser pseudodomain - non-AJAX scripts:
540540
if (operation == PostOperation and
541541
request.url().authority() == PSEUDO_DOMAIN and
542542
(!request.url().path().contains("ajax"))) {

0 commit comments

Comments
 (0)