Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Synzvato/decentraleyes
  • gkrishnaks/decentraleyes
  • ExE-Boss/decentraleyes
  • whtsky/decentraleyes
  • grtgarrett/decentraleyes
  • An_dz/decentraleyes
  • Alaska/decentraleyes
  • finn/decentraleyes
  • klippy/decentraleyes
9 results
Show changes
Showing
with 0 additions and 589 deletions
icons/icon96.png

8.3 KiB

/**
* Data Handler
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2014-05-30
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Imports
*/
var { Cc, Ci } = require('chrome');
var self = require('sdk/self');
//noinspection JSUnresolvedFunction
var ioService = Cc['@mozilla.org/network/io-service;1']
.getService(Ci.nsIIOService);
/**
* Absolute resource file paths.
* @var {object} files
*/
var files = require('./files');
/**
* Constants
*/
const DELIVERY_NOTICE = '/**\n * Local delivery by Decentraleyes (' + self.version + ').\n */\n\n';
/**
* Variables
*/
var resourceData = self.data;
/**
* Public Methods
*/
function getRedirectionURI(targetPath, characterSet, type) {
var data, dataURI, redirectionURI;
data = _loadResource(targetPath);
dataURI = _buildDataURI(type, characterSet, data);
redirectionURI = ioService.newURI(dataURI, null, null);
return redirectionURI;
}
/**
* Exports
*/
exports.getRedirectionURI = getRedirectionURI;
/**
* Private Methods
*/
function _loadResource(targetPath) {
var resource;
// Find the result inside a static path index.
if (!files[targetPath]) {
throw new Error('The requested resource is missing.');
}
// Attempt to load resource contents.
return resource = resourceData.load(targetPath);
}
function _buildDataURI(type, characterSet, data) {
var addNotice, dataURI;
//noinspection JSUnresolvedVariable
addNotice = require('sdk/simple-prefs').prefs.addNotice;
dataURI = 'data:' + type + ';charset=' + characterSet + ',';
// Remove the syntax invalidation character.
data = data.substring(1);
if (!addNotice) {
dataURI = dataURI + encodeURIComponent(data);
} else {
dataURI = dataURI + encodeURIComponent(DELIVERY_NOTICE + data);
}
return dataURI;
}
/**
* Interceptor
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2014-05-30
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Imports
*/
var { Class } = require('sdk/core/heritage');
var { Unknown } = require('sdk/platform/xpcom');
var { Cc, Ci, Cr } = require('chrome');
/**
* Gets and sets add-on specific preferences.
* @var {object} simplePreferences
*/
var simplePreferences = require('sdk/simple-prefs');
/**
* Retains data across application restarts.
* @var {object} simpleStorage
*/
var simpleStorage = require('sdk/simple-storage');
//noinspection JSUnresolvedFunction
var observerService = Cc['@mozilla.org/observer-service;1']
.getService(Ci.nsIObserverService);
var requestAnalyzer = require('./request-analyzer');
var dataHandler = require('./data-handler');
/**
* Variables
*/
var preferences = simplePreferences.prefs;
var storage = simpleStorage.storage;
/**
* Interceptor Class
*/
var Interceptor = new Class({
extends: Unknown,
interfaces: ['nsIObserver'],
topic: 'http-on-modify-request',
register: function () {
observerService.addObserver(this, this.topic, false);
},
unregister: function () {
observerService.removeObserver(this, this.topic);
},
/**
* Called whenever an HTTP request is made.
* @param httpChannel
*/
observe: function (httpChannel) {
var validCandidate, target, characterSet, redirectionURI;
// Enable runtime discovery.
httpChannel.QueryInterface(Ci.nsIHttpChannel);
// Determine the validity of the candidate.
validCandidate = requestAnalyzer.isValidCandidate(httpChannel);
if (!validCandidate) {
return;
}
// Remove referer header from request.
httpChannel.setRequestHeader('Referer', null, false);
// Convert the original request URI to a local target.
target = requestAnalyzer.getLocalTarget(httpChannel.URI.host, httpChannel.URI.path);
if (!target) {
return this.handleMissingCandidate(httpChannel);
}
characterSet = httpChannel.URI.originCharset;
// Fetch local data and create a redirection URI.
try {
redirectionURI = dataHandler.getRedirectionURI(target.path, characterSet, target.type);
} catch (exception) {
return this.handleMissingCandidate(httpChannel);
}
// Fix for reported edge-case issues with specific websites.
var initiatorDomain =
httpChannel.loadInfo && httpChannel.loadInfo.loadingDocument && httpChannel.loadInfo.loadingDocument.domain ||
httpChannel.referrer && httpChannel.referrer.host;
if (storage.taintedDomains[initiatorDomain] || /yandex\./.test(initiatorDomain)) {
return this.handleMissingCandidate(httpChannel);
}
// Redirect the HTTP channel to the the local destination.
httpChannel.redirectTo(redirectionURI);
//noinspection JSUnresolvedVariable
preferences.amountInjected++;
},
/**
* Called when a valid candidate cannot be injected.
* @param httpChannel
*/
handleMissingCandidate: function (httpChannel) {
//noinspection JSUnresolvedVariable
if (preferences.blockMissing) {
httpChannel.cancel(Cr.NS_ERROR_NOT_AVAILABLE);
}
}
});
/**
* Exports
*/
module.exports = Interceptor;
/**
* Load Watcher
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2016-02-04
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Imports
*/
var { Class } = require('sdk/core/heritage');
var { Unknown, Factory } = require('sdk/platform/xpcom');
var { Cc, Ci, Cu } = require('chrome');
var xpcom = require('sdk/platform/xpcom');
/**
* Resource version mappings.
* @var {object} mappings
*/
var mappings = require('./mappings');
/**
* Retains data across application restarts.
* @var {object} simpleStorage
*/
var simpleStorage = require('sdk/simple-storage');
//noinspection JSUnresolvedFunction
var categoryManager = Cc['@mozilla.org/categorymanager;1']
.getService(Ci.nsICategoryManager);
/**
* Constants
*/
const CONTRACT_ID = '@decentraleyes.org/load-watcher;1';
const SCRIPT_CONTENT_TYPE = Ci.nsIContentPolicy.TYPE_SCRIPT;
const SCRIPT_ELEMENT = Ci.nsIDOMHTMLScriptElement;
const REQUEST_ACCEPTATION = Ci.nsIContentPolicy.ACCEPT;
/**
* Variables
*/
var storage = simpleStorage.storage;
/**
* Tainted domains that are not automatically detectable.
* @var {object} undetectableTaintedDomains
*/
var undetectableTaintedDomains = {
'identi.ca': true,
'minigames.mail.ru': true,
'passport.twitch.tv': true,
'ya.ru': true,
'yadi.sk': true
};
/**
* Initializations
*/
Object.extend = function (destination, source) {
for (var property in source) {
if (source.hasOwnProperty(property)) {
destination[property] = source[property];
}
}
return destination;
};
storage.taintedDomains = storage.taintedDomains || {};
storage.taintedDomains = Object.extend(storage.taintedDomains, undetectableTaintedDomains);
/**
* Load Watcher Class
*/
var LoadWatcher = new Class({
extends: Unknown,
interfaces: ['nsIContentPolicy'],
get wrappedJSObject() {
return this
},
register: function () {
categoryManager.deleteCategoryEntry('content-policy', CONTRACT_ID, false);
categoryManager.addCategoryEntry('content-policy', CONTRACT_ID, CONTRACT_ID, false, true);
},
shouldLoad: function (contentType, contentLocation, requestOrigin, node) {
if (contentType == SCRIPT_CONTENT_TYPE && mappings[contentLocation.host]) {
if (node instanceof SCRIPT_ELEMENT) {
if (node.hasAttribute('crossorigin') || node.hasAttribute('integrity')) {
// Add corresponding origin domain to the list of tainted domains.
storage.taintedDomains[requestOrigin.host] = true;
}
}
}
// Accept the resource load request.
return REQUEST_ACCEPTATION;
}
});
/**
* Load Watcher Factory
*/
var factory = Factory({
contract: CONTRACT_ID,
Component: LoadWatcher,
unregister: false
});
/**
* Unregister
*/
var unload = require('sdk/system/unload');
unload.when(function () {
function trueUnregister() {
categoryManager.deleteCategoryEntry('content-policy', CONTRACT_ID, false);
try {
xpcom.unregister(factory);
} catch (exception) {
Cu.reportError(exception);
}
}
if ('dispatch' in Cu) {
Cu.dispatch(trueUnregister, trueUnregister);
} else {
Cu.import('resource://gre/modules/Services.jsm');
Services.tm.mainThread.dispatch(trueUnregister, 0);
}
});
/**
* Exports
*/
module.exports = LoadWatcher;
/**
* Entry Point
* Belongs to Decentraleyes.
*
* @author Thomas Rientjes
* @since 2014-05-30
* @license MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Imports
*/
var Interceptor = require('./interceptor');
var LoadWatcher = require('./load-watcher');
var preferences = require('sdk/simple-prefs').prefs;
var self = require('sdk/self');
var tabs = require("sdk/tabs");
/**
* Main
*/
var interceptor = new Interceptor();
var loadWatcher = new LoadWatcher();
var featurelessVersions = {
'1.3.7': true
};
// Executed as soon as the add-on is loaded.
exports.main = function (options) {
// Initialize add-on state.
interceptor.register();
loadWatcher.register();
if (preferences.showReleaseNotes) {
if (options.loadReason === 'install' || (options.loadReason === 'upgrade' && !featurelessVersions[self.version])) {
if (preferences['sdk.baseURI']) {
tabs.open(preferences['sdk.baseURI'] + 'static/release-notes.html');
}
}
}
};
// Executed as soon as the add-on is unloaded.
exports.onUnload = function () {
// Clean up add-on state.
interceptor.unregister();
};
<!ENTITY options.addNotice.title "Добавяне на коментари към местно извлечени файлове">
<!ENTITY options.addNotice.description "Автоматично вмъкване на известие към извлечените документи, за да се сигнализира местна доставка.">
<!ENTITY options.blockMissing.title "Блокиране на заявки за липсващи ресурси">
<!ENTITY options.blockMissing.description "Отмяна на прехванатата заявка, ако изисквания ресурс не е наличен на местно ниво.">
<!ENTITY options.domainWhitelist.title "Изключване на домейните от инспекции">
<!ENTITY options.domainWhitelist.description "Въведете домейни, които да се добавят в белия списък. Отделете стойностите с точка и запетая.">
<!ENTITY options.amountInjected.title "Брояч за местно вмъкнати ресурси">
<!ENTITY options.amountInjected.description "Количество на местни вмъквания на ресурси от началото на инсталацията.">
<!ENTITY options.addNotice.title "Tilføj kommentarer til lokalt hentede filer">
<!ENTITY options.addNotice.description "Tilføj automatiskt en notits til filer, så det fremgår at de er leveret lokalt.">
<!ENTITY options.blockMissing.title "Bloker anmodninger om manglende ressourcer">
<!ENTITY options.blockMissing.description "Annullerer en anmodning hvis den forespurgte ressource ikke findes lokalt.">
<!ENTITY options.domainWhitelist.title "Udeluk disse domæner fra inspektion">
<!ENTITY options.domainWhitelist.description "Tilføj domæner der ikke skal opfanges. Separer flere med semikolon (;).">
<!ENTITY options.amountInjected.title "Optælling af lokalt leverede ressourcer">
<!ENTITY options.amountInjected.description "Antal injektioner af lokale ressourcer siden installation.">
<!ENTITY options.addNotice.title "Kennzeichne lokal abgerufene Dateien">
<!ENTITY options.addNotice.description "Füge automatisch Kommentare an lokal ausgelieferte Bibliotheken hinzu.">
<!ENTITY options.blockMissing.title "Blockiere Anfordern fehlender Inhalte">
<!ENTITY options.blockMissing.description "Abgefangene Anforderung unterbinden, falls angeforderte Datei nicht lokal verfügbar ist.">
<!ENTITY options.domainWhitelist.title "Domains von Prüfung ausschließen">
<!ENTITY options.domainWhitelist.description "Gebe zu ignorierende Domains an. Trenne mehrere Einträge durch Semikolons (;).">
<!ENTITY options.amountInjected.title "Zähler für lokal injizierte Ressourcen">
<!ENTITY options.amountInjected.description "Anzahl der lokalen Injektionen von den CDN-Ressourcen seit der Installation.">
<!ENTITY options.addNotice.title "Add comments to locally fetched files">
<!ENTITY options.addNotice.description "Automatically prepend a notice to retrieved documents to signal local delivery.">
<!ENTITY options.blockMissing.title "Block requests for missing resources">
<!ENTITY options.blockMissing.description "Cancel intercepted request if the required resource is not locally available.">
<!ENTITY options.domainWhitelist.title "Exclude domains from inspections">
<!ENTITY options.domainWhitelist.description "Enter domains to whitelist them. Separate multiple entries with semi-colons (;).">
<!ENTITY options.amountInjected.title "Counter for locally injected resources">
<!ENTITY options.amountInjected.description "Amount of local Content Delivery Network resource injections since installation.">
<!ENTITY options.addNotice.title "Add comments to locally fetched files">
<!ENTITY options.addNotice.description "Automatically prepend a notice to retrieved documents to signal local delivery.">
<!ENTITY options.blockMissing.title "Block requests for missing resources">
<!ENTITY options.blockMissing.description "Cancel intercepted request if the required resource is not locally available.">
<!ENTITY options.domainWhitelist.title "Exclude domains from inspections">
<!ENTITY options.domainWhitelist.description "Enter domains to whitelist them. Separate multiple entries with semi-colons (;).">
<!ENTITY options.amountInjected.title "Counter for locally injected resources">
<!ENTITY options.amountInjected.description "Amount of local Content Delivery Network resource injections since installation.">
<!ENTITY options.addNotice.title "Aldoni komentojn al lokaj dosieroj">
<!ENTITY options.addNotice.description "Aldoni sciigon al enmetitaj dokumentoj por marki ke ili estas lokaj risurcoj.">
<!ENTITY options.blockMissing.title "Bloki petojn por mankaj risurcoj">
<!ENTITY options.blockMissing.description "Bloki petojn interkaptitajn se la petitan risurcon ne loke haveblas.">
<!ENTITY options.domainWhitelist.title "Neinspektendaj domajnoj">
<!ENTITY options.domainWhitelist.description "Entajpu demajnojn, kiujn Decentraleyes ne devas inspekti. Disigu domajnojn per punktokomoj (;).">
<!ENTITY options.amountInjected.title "Nombrilo de loke enmetiaj risurcoj">
<!ENTITY options.amountInjected.description "Kvanto de lokaj CDN-risurcoj enmetitaj ekde instaliĝo.">
<!ENTITY options.addNotice.title "Añadir notas a archivos obtenidos localmente">
<!ENTITY options.addNotice.description "Anteponer un aviso a documentos obtenidos para señalar entrega local.">
<!ENTITY options.blockMissing.title "Bloquear peticiones de fuentes faltantes">
<!ENTITY options.blockMissing.description "Cancelar peticiones detenidas si la fuente requerida no se encuentra localmente.">
<!ENTITY options.domainWhitelist.title "Excluir dominios de inspecciones">
<!ENTITY options.domainWhitelist.description "Ingresar dominios a ser ignorados. Separar múltiples entradas con punto y coma (;).">
<!ENTITY options.amountInjected.title "Contador para fuentes inyectadas localmente">
<!ENTITY options.amountInjected.description "Cifra de inyecciones de fuentes de Redes de Entrega de Contenido desde instalación.">
<!ENTITY options.addNotice.title "Merkitse korvatut tiedostot">
<!ENTITY options.addNotice.description "Lisää alkuun ilmoituksen paikallisesti noudetuille tiedostoille.">
<!ENTITY options.blockMissing.title "Estä pyynnöt puuttuviin resursseihin">
<!ENTITY options.blockMissing.description "Estää pyynnöt jos paikallista sisältöä ei ole saatavilla.">
<!ENTITY options.domainWhitelist.title "Poissulje verkkotunnukset">
<!ENTITY options.domainWhitelist.description "Lisää verkkotunnus jottei sitä korvata. Erota rivit puolipisteellä (;).">
<!ENTITY options.amountInjected.title "Korvatut pyynnöt">
<!ENTITY options.amountInjected.description "Korvatut sisältöpyynnöt lisäosan asennuksen jälkeen.">
<!ENTITY options.addNotice.title "Pointer les documents joints localement">
<!ENTITY options.addNotice.description "Accoler une notice aux documents récupérés pour en signaler l'origine locale.">
<!ENTITY options.blockMissing.title "Bloquer les ressources manquantes">
<!ENTITY options.blockMissing.description "Annuler une demande de ressource si elle est indisponible localement.">
<!ENTITY options.domainWhitelist.title "Ne pas inspecter certains domaines">
<!ENTITY options.domainWhitelist.description "Indiquez les domaines à exclure. Séparer les noms par un point-virgule (;).">
<!ENTITY options.amountInjected.title "Compteur des ressources injectées">
<!ENTITY options.amountInjected.description "Total des ressources des CDN injectées localement depuis l'installation.">
<!ENTITY options.addNotice.title "Tambahkan komentar ke berkas lokal yang disimpan">
<!ENTITY options.addNotice.description "Secara otomatis menambahkan pemberitahuan untuk mengambil dokumen untuk sinyal pengiriman lokal.">
<!ENTITY options.blockMissing.title "Blokir permintaan untuk sumber daya yang hilang">
<!ENTITY options.blockMissing.description "Batalkan intersep permintaan jika sumber daya yang dibutuhkan tidak tersedia secara lokal.">
<!ENTITY options.domainWhitelist.title "Cegah inspeksi domain">
<!ENTITY options.domainWhitelist.description "Masukkan domain ke daftar putih. Pisahkan entri dengan titik koma (;).">
<!ENTITY options.amountInjected.title "Sumber daya lokal yang disematkan">
<!ENTITY options.amountInjected.description "Jumlah penyematan sumber daya Jaringan Distribusi Konten lokal sejak pemasangan.">
<!ENTITY options.addNotice.title "Aggiungere commenti a file raccolti localmente">
<!ENTITY options.addNotice.description "Antepone automaticamente un avviso ai documenti recuperati per segnalare la distribuzione locale.">
<!ENTITY options.blockMissing.title "Bloccare richieste di risorse mancanti">
<!ENTITY options.blockMissing.description "Annullare la richiesta intercettata se la risorsa necessaria non è disponibile localmente.">
<!ENTITY options.domainWhitelist.title "Escludere domini dalle ispezioni">
<!ENTITY options.domainWhitelist.description "Inserire domini nella whitelist per escluderli. Separare voci multiple con punti e virgola (;).">
<!ENTITY options.amountInjected.title "Contatore per risorse iniettate localmente">
<!ENTITY options.amountInjected.description "Quantità di iniezioni di risorse dalla Rete di Distribuzione di Contenuti locale sin dall'installazione.">
<!ENTITY options.addNotice.title "ローカルからのファイルにコメントを追加する">
<!ENTITY options.addNotice.description "ローカルCDNから取得したドキュメントにその旨を記載する。">
<!ENTITY options.blockMissing.title "存在しないリソースへの要求をブロック">
<!ENTITY options.blockMissing.description "必要なリソースがローカルで利用できない場合、リクエストを取り消す。">
<!ENTITY options.domainWhitelist.title "保護から除外するドメイン">
<!ENTITY options.domainWhitelist.description "ホワイト リストにドメインを入力します。複数のエントリをセミコロン (;) で区切ります。">
<!ENTITY options.amountInjected.title "ローカルから挿入されたリソースの数">
<!ENTITY options.amountInjected.description "インストールから起算した、ローカルCDNのリソース使用数。">
<!ENTITY options.addNotice.title "Notities aan lokale bestanden toevoegen">
<!ENTITY options.addNotice.description "Voorzie alle door deze add-on opgehaalde bestanden automatisch van een notitie.">
<!ENTITY options.blockMissing.title "Stop verzoeken voor ontbrekende items">
<!ENTITY options.blockMissing.description "Annuleer een onderschept verzoek wanneer het bestand niet lokaal beschikbaar is.">
<!ENTITY options.domainWhitelist.title "Sluit domeinen uit van inspecties">
<!ENTITY options.domainWhitelist.description "Voer de te negeren domeinen in. Scheid de waarden met puntkomma's (;).">
<!ENTITY options.amountInjected.title "Teller voor lokaal geïnjecteerde bestanden">
<!ENTITY options.amountInjected.description "Aantal lokale Content Delivery Network-bestandsinjecties sinds installatie.">
<!ENTITY options.addNotice.title "Dodaj komentarz do plików przechowywanych lokalnie">
<!ENTITY options.addNotice.description "Automatycznie dodawaj powiadomienie do pobranych dokumentów aby zasygnalizować lokalne dostarczanie.">
<!ENTITY options.blockMissing.title "Blokuj żądania brakujących zasobów">
<!ENTITY options.blockMissing.description "Anuluj przechwycone żądania jeśli wymagany zasób nie jest dostępny lokalnie.">
<!ENTITY options.domainWhitelist.title "Wyklucz domeny z analizy">
<!ENTITY options.domainWhitelist.description "Podaj domeny aby dodać je do białej listy. Oddziel wpisy średnikami (;).">
<!ENTITY options.amountInjected.title "Licznik zasobów podanych lokalnie">
<!ENTITY options.amountInjected.description "Ilość wstrzyknięć z lokalnego Content Delivery Network od czasu instalacji.">
<!ENTITY options.addNotice.title "Adicionar comentários aos ficheiros obtidos localmente">
<!ENTITY options.addNotice.description "Preceder automaticamente um aviso aos documentos readquiridos para sinalizar a entrega local.">
<!ENTITY options.blockMissing.title "Bloquear pedidos por falta de recursos">
<!ENTITY options.blockMissing.description "Cancelar pedido intercetado se o recurso necessário não estiver disponível localmente.">
<!ENTITY options.domainWhitelist.title "Excluir domínios de inspeções">
<!ENTITY options.domainWhitelist.description "Insira domínios para os colocar na lista branca. Separe múltiplas entradas com pontos e vírgulas (;).">
<!ENTITY options.amountInjected.title "Contador para recursos injetados localmente">
<!ENTITY options.amountInjected.description "Quantidade de injeções de recurso Content Delivery Network locais desde a instalação.">