Skip to content

Commit 175cb78

Browse files
nullishzeropde
authored andcommitted
Add a way to inspect ruleset source from within the UI
Because rulesets are shipped with comments stripped out, this is implemented by fetching them from the source repo itself.
1 parent 41ad47b commit 175cb78

17 files changed

Lines changed: 119 additions & 9 deletions

‎makexpi.sh‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fi
4242

4343
if [ -f relaxng.xml -a -x "$(which xmllint)" ] >&2
4444
then
45-
if xmllint --noout --relaxng relaxng.xml src/chrome/content/rules/*.xml
45+
if xmllint --noout --relaxng relaxng.xml src/chrome/content/rules/*.xml
4646
then
4747
echo Validation of rulesets with RELAX NG grammar completed. >&2
4848
else
@@ -74,13 +74,27 @@ fi
7474

7575
[ -d pkg ] || mkdir pkg
7676

77+
# Used for figuring out which branch to pull from when viewing source for rules
78+
GIT_OBJECT_FILE=".git/refs/heads/master"
79+
GIT_COMMIT_ID="HEAD"
80+
if [ -e "$GIT_OBJECT_FILE" ]; then
81+
GIT_COMMIT_ID=$(cat "$GIT_OBJECT_FILE")
82+
fi
83+
7784
# Merge all the .xml rulesets into a single "default.rulesets" file -- this
7885
# prevents inodes from wasting disk space, but more importantly, works around
7986
# the fact that zip does not perform well on a pile of small files.
8087
cd src
8188
RULESETS=chrome/content/rules/default.rulesets
82-
echo "<rulesetlibrary>" > $RULESETS
83-
cat chrome/content/rules/*.xml >> $RULESETS
89+
echo "Creating ruleset library..."
90+
echo "<rulesetlibrary gitcommitid=\"${GIT_COMMIT_ID}\">" > $RULESETS
91+
# Include the filename.xml as the "f" attribute
92+
for file in chrome/content/rules/*.xml; do
93+
xmlInsertString="<ruleset"
94+
fileName=$(basename "$file")
95+
fileContent=$(sed "s/${xmlInsertString}/${xmlInsertString} f=\"${fileName}\"/" "chrome/content/rules/${fileName}")
96+
echo "$fileContent" >> $RULESETS
97+
done
8498
echo "</rulesetlibrary>" >> $RULESETS
8599

86100
echo "Removing whitespaces and comments..."

‎src/chrome/content/code/HTTPSRules.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ function Exclusion(pattern) {
1010
}
1111

1212
function CookieRule(host, cookiename) {
13-
this.host = host
13+
this.host = host;
1414
this.host_c = new RegExp(host);
1515
this.name = cookiename;
1616
this.name_c = new RegExp(cookiename);
1717
}
1818

1919
localPlatformRegexp = new RegExp("firefox");
2020
ruleset_counter = 0;
21-
function RuleSet(name, match_rule, default_off, platform) {
21+
function RuleSet(name, xmlName, match_rule, default_off, platform) {
2222
this.id="httpseR" + ruleset_counter;
2323
ruleset_counter += 1;
2424
this.on_by_default = true;
2525
this.name = name;
26+
this.xmlName = xmlName;
2627
//this.ruleset_match = match_rule;
2728
this.notes = "";
2829
if (match_rule) this.ruleset_match_c = new RegExp(match_rule)
@@ -254,6 +255,12 @@ const RuleWriter = {
254255
// The root of the XML tree has a name, which means it should be single a ruleset...
255256
this.parseOneRuleset(xmlblob, rule_store, file);
256257
} else {
258+
if (xmlblob.@gitcommitid == xmlblob.@nonexistantthing) {
259+
this.log(DBUG, "gitcommitid tag not found in <xmlruleset>");
260+
rule_store.gitcommitid = "HEAD";
261+
} else {
262+
rule_store.GITCommitID = xmlblob.@gitcommitid;
263+
}
257264
// The root of the XML tree should be a <rulesetlibrary> with many
258265
// <ruleset> children
259266
var lngth = xmlblob.ruleset.length(); // premature optimisation
@@ -280,7 +287,7 @@ const RuleWriter = {
280287
if (xmlruleset.@match_rule.length() > 0) match_rl = xmlruleset.@match_rule;
281288
if (xmlruleset.@default_off.length() > 0) dflt_off = xmlruleset.@default_off;
282289
if (xmlruleset.@platform.length() > 0) platform = xmlruleset.@platform;
283-
var rs = new RuleSet(xmlruleset.@name, match_rl, dflt_off, platform);
290+
var rs = new RuleSet(xmlruleset.@name, xmlruleset.@f, match_rl, dflt_off, platform);
284291

285292
if (xmlruleset.target.length() == 0) {
286293
var msg = "Error: As of v0.3.0, XML rulesets require a target domain entry,";

‎src/chrome/content/preferences.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rulesets = Array.slice(https_everywhere.https_rules.rulesets);
1212

1313
const id_prefix = "he_enable";
1414
const pref_prefix = "extensions.https_everywhere.";
15+
const GITID = https_everywhere.https_rules.GITCommitID;
1516

1617
// Disable all rules.
1718
function disable_all() {
@@ -90,6 +91,32 @@ function toggleSelected() {
9091
}
9192
}
9293

94+
95+
function viewXMLSource() {
96+
var start = {};
97+
var end = {};
98+
var st = document.getElementById('sites_tree');
99+
var sel = st.view.selection;
100+
var numRanges = sel.getRangeCount();
101+
var menuitem = document.getElementById("revert_menuitem");
102+
103+
for (var t = 0; t < numRanges; t++){
104+
sel.getRangeAt(t, start, end);
105+
for (var v = start.value; v <= end.value; v++){
106+
var rs = treeView.rules[v];
107+
108+
//This *should* not violate TorButton's State Control, but someone should double check
109+
//this code just in case
110+
var aWin = CC['@mozilla.org/appshell/window-mediator;1']
111+
.getService(CI.nsIWindowMediator)
112+
.getMostRecentWindow('navigator:browser');
113+
aWin.openDialog("chrome://https-everywhere/content/fetch-source.xul",
114+
rs.xmlName, "chrome,centerscreen",
115+
{xmlName: rs.xmlName, GITCommitID: GITID} );
116+
}
117+
}
118+
}
119+
93120
function getValue(row, col) {
94121
switch (col.id) {
95122
case "site_col":

‎src/chrome/content/preferences.xul‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<menupopup id="tree-contextmenu" onpopupshowing="resetSelectedMenu()">
2727
<menuitem label="&https-everywhere.prefs.reset_default;" oncommand="resetSelected();" id="revert_menuitem"/>
2828
<menuitem label="&https-everywhere.prefs.toggle;" oncommand="toggleSelected();"/>
29+
<menuitem label="&https-everywhere.prefs.view_xml_source;" oncommand="viewXMLSource();"/>
2930
</menupopup>
3031
</popupset>
3132

@@ -34,7 +35,7 @@
3435
align="center"/>
3536
<vbox>
3637
&https-everywhere.prefs.search;: <textbox id="tree_search" oninput="treeView.search(this);" />
37-
</vbox>
38+
</vbox>
3839
<tree id="sites_tree" editable="true" flex="1" context="tree-contextmenu">
3940
<treecols>
4041
<treecol id="enabled_col" type="checkbox" label="&https-everywhere.prefs.enabled;"

‎src/chrome/content/rules/Spontex.org.xml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<target host="stats.spontex.org" />
88
<target host="m.spontex.org" />
99
<target host="adminmedia.spontex.org" />
10-
<securecookie host="^((adminmedia|m|www|fr|en|stats|media)?\.)?spontex\.org$"
11-
name=".+" />
10+
<securecookie host="^((adminmedia|m|www|fr|en|stats|media)?\.)?spontex\.org$" name=".+" />
1211
<securecookie host="^spontex\.org$" name=".+" />
1312
<rule from="^http://spontex\.org/" to="https://spontex.org/" />
1413
<rule from="^http://(adminmedia|m|www|fr|en|stats|media)\.spontex\.org/"

‎src/chrome/locale/ar/https-everywhere.dtd‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@
3131
<!ENTITY https-everywhere.prefs.reset_default "استعادة الإعداد الافتراضي">
3232
<!-- Untranslated -->
3333
<!ENTITY https-everywhere.about.title "About HTTPS Everywhere">
34+
<!ENTITY https-everywhere.prefs.view_xml_source "View XML Source">
35+
36+
<!ENTITY https-everywhere.source.downloading "Downloading">
37+
<!ENTITY https-everywhere.source.filename "Filename">
38+
<!ENTITY https-everywhere.source.unable_to_download "Unable to download source.">

‎src/chrome/locale/de/https-everywhere.dtd‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@
2727
<!ENTITY https-everywhere.menu.globalDisable "HTTPS Everywhere deaktivieren">
2828
<!ENTITY https-everywhere.prefs.toggle "Toggle">
2929
<!ENTITY https-everywhere.prefs.reset_default "Reset to Default">
30+
<!ENTITY https-everywhere.prefs.view_xml_source "View XML Source">
31+
32+
<!ENTITY https-everywhere.source.downloading "Downloading">
33+
<!ENTITY https-everywhere.source.filename "Filename">
34+
<!ENTITY https-everywhere.source.unable_to_download "Unable to download source.">

‎src/chrome/locale/en/https-everywhere.dtd‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@
2828
<!ENTITY https-everywhere.prefs.here_link "here">
2929
<!ENTITY https-everywhere.prefs.toggle "Toggle">
3030
<!ENTITY https-everywhere.prefs.reset_default "Reset to Default">
31+
<!ENTITY https-everywhere.prefs.view_xml_source "View XML Source">
32+
33+
<!ENTITY https-everywhere.source.downloading "Downloading">
34+
<!ENTITY https-everywhere.source.filename "Filename">
35+
<!ENTITY https-everywhere.source.unable_to_download "Unable to download source.">
36+
37+

‎src/chrome/locale/es/https-everywhere.dtd‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828
<!ENTITY https-everywhere.prefs.here_link "aqui">
2929
<!ENTITY https-everywhere.prefs.toggle "Toggle">
3030
<!ENTITY https-everywhere.prefs.reset_default "Reset to Default">
31+
<!ENTITY https-everywhere.prefs.view_xml_source "View XML Source">
32+
33+
<!ENTITY https-everywhere.source.downloading "Downloading">
34+
<!ENTITY https-everywhere.source.filename "Filename">
35+
<!ENTITY https-everywhere.source.unable_to_download "Unable to download source.">

‎src/chrome/locale/fa/https-everywhere.dtd‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828
<!ENTITY https-everywhere.prefs.here_link "اینجا">
2929
<!ENTITY https-everywhere.prefs.toggle "تغییر">
3030
<!ENTITY https-everywhere.prefs.reset_default "بازگشت به تنظیم‌های اولیه">
31+
<!ENTITY https-everywhere.prefs.view_xml_source "View XML Source">
32+
33+
<!ENTITY https-everywhere.source.downloading "Downloading">
34+
<!ENTITY https-everywhere.source.filename "Filename">
35+
<!ENTITY https-everywhere.source.unable_to_download "Unable to download source.">

0 commit comments

Comments
 (0)