FritzBox Wählhilfe

Marco-P

Erfahrenes Mitglied
Hallo an alle,

ich bin dabei eine Plattform zu Programmieren wo Adressen gespeichert werden und auch Telefonnummern. Wenn ich diese Nummern nun anrufen möchte, wähle ich die Nummer per Hand. aber in der FritzBox selbst gibt es die Wahlhilfe und ein Addon (Fritz!Box Dial) für den Firefox gibt es.

Bin nun so schlau gewesen und hab mir das Addon mal genau angeschaut und hab mir den Code rausgesucht baer ich bin bei Java so was von unfähig und vielelihct kennt das ja schon jemand.
Code:
//////////////////////////////////////

var fritzboxdialStrBundle;
var PhoneNumber;
var fbSelected; // Fritz!Box which has radio 'on' on PrefDialog
var fbHostname;	// Fritz!Box hostname
var password;	// Fritz!Box password
var host;	// written by checkSettings() and read by afterPwdgetSip()
var pwrd;
var boxline;
var ds;


// Service used by functions 'popDialerPad()' and 'searchSIPinRDF(ua, name, registrar)'
var RDF = '@mozilla.org/rdf/rdf-service;1';
RDF = Components.classes[RDF].getService(Components.interfaces.nsIRDFService);

var RDFC = '@mozilla.org/rdf/container;1';
RDFC = Components.classes[RDFC].createInstance(Components.interfaces.nsIRDFContainer);

var RDFCUtils = '@mozilla.org/rdf/container-utils;1';
RDFCUtils = Components.classes[RDFCUtils].getService(Components.interfaces.nsIRDFContainerUtils);


// Every time a new browser window is made fritzboxdialInit will be called
window.addEventListener('load', fritzBoxDialInit, false);

function fritzBoxDialInit() {
	var menus = new Array('menu_ToolsPopup', 'contentAreaContextMenu', 
		'taskPopup', 'messagePaneContext', 'msgComposeContext');

	for (var i = 0; i < menus.length; ++i){
		if (document.getElementById(menus[i])){
			document.getElementById(menus[i]).addEventListener('popupshowing', menuitemFritzBoxDial, false);
		}
	}
	fritzboxdialStrBundle = srGetStrBundle('chrome://fritzboxdial/locale/fritzboxdial.properties');
}


// Getting and setting global variables 'fbLocation', 'fbHostname' and 'password' 
// from 'cfgURL'. Will be called from any opening chrome window.

function initVars() {
	var ds, subject, predicate, target, value
	fritzboxdialStrBundle = srGetStrBundle('chrome://fritzboxdial/locale/fritzboxdial.properties');
	password = '';
	fbHostname = 'fritz.box';

	makeURL();
	ds = RDF.GetDataSourceBlocking(cfgURL);
	
	target = RDF.GetLiteral('true');
	predicate = RDF.GetResource('http://fritzboxdial/rdf#selected');
	subject = ds.GetSource(predicate, target, true);
	fbSelected = subject.Value;

	predicate = RDF.GetResource('http://fritzboxdial/rdf#hostname');
	target = ds.GetTarget(subject, predicate, true);
	fbHostname = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;

	predicate = RDF.GetResource('http://fritzboxdial/rdf#password');
	target = ds.GetTarget(subject, predicate, true);
	password = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
}


// Take the given PhoneNumber and remove superfluous characters

function cleanPhoneNumber(selection) {
	if (selection != '' && /\d+/.test(selection)) {
		// Cut left and right from characters allowed
		selection = /\+?\d+(\d|\(|\)|\[|\]|\/|\s|\.|-|,|;)+/.exec(selection)[0];
		
		// Convert '+' into '00'
		selection = selection.replace(/^\+/, '00');
		
		// Remove '(0)' and also '[0]' if behind country code
		selection = selection.replace(/(00\d{1,3})(\/|\s|\.|-|,|;){0,3}(\(0\)|\[0\])/, '$1');
		
		// Remove non-number characters
		selection = selection.replace(/(\(|\)|\[|\]|\/|\s|\.|-|,|;)/g, '');

		PhoneNumber = selection;
	}
	else PhoneNumber = '';
}


// Get a phone number from selected text in window

function getPhoneNumber() {
	var node = document.popupNode;

	var selection = '';
	
	if ((node instanceof HTMLTextAreaElement) || (node instanceof HTMLInputElement && node.type == 'text')) {
		selection = node.value.substring(node.selectionStart, node.selectionEnd);
	} 
	else {
		var focusedWindow = new XPCNativeWrapper(document.commandDispatcher.focusedWindow, 'document', 'getSelection()');
		selection = focusedWindow.getSelection().toString();
	}
	PhoneNumber = selection;
}


// Put some text into overlay menu items.
// One in tools menu and another in context menu.
// Text depends on 'PhoneNumber' having value.

function menuitemFritzBoxDial() { 
	getPhoneNumber();
	cleanPhoneNumber(PhoneNumber);
	
	var menuText = fritzboxdialStrBundle.GetStringFromName('menuText');
	var menuQuotes = fritzboxdialStrBundle.GetStringFromName('menuQuotes').split('$');
	
	var toolsItem = document.getElementById('toolsmenuFritzBoxDial');
	var contextItem = document.getElementById('contmenuFritzBoxDial');
	
	// Hide the context menu item if no selection to dial
	// But 'addressbook.xul' does not provide any selectable contextmenu
	if (contextItem) contextItem.hidden = true;
	
	if (PhoneNumber!='') {
		if (contextItem) contextItem.hidden = false;
		
		// Put the quotes around 'PhoneNumber'
		menuText = menuText + menuQuotes[0] + PhoneNumber + menuQuotes[1];
		contextItem.label = menuText;
		toolsItem.label = menuText;
	}
	//No PhoneNumber? So put the bare menuText here!
	toolsItem.label = menuText;
}


// Open dialerpad. This will be called from the
// menu items in context menu and tools menu.
// Most of the following actions come from this dialerpad.

function popDialerPad() {
	makeURL();
	RDF.GetDataSourceBlocking(cfgURL);
	RDF.GetDataSourceBlocking('chrome://fritzboxdial/content/dialports.rdf');
	window.open('chrome://fritzboxdial/content/dialerpad.xul', '', 'chrome');
}


// Check by hostname if Fritz!Box is available.
// Called by opening 'dialerpad.xul' and by function 'checkSettings()'.

function checkHost(tHost, followup) {
	xmlhttpPost('GET', 'ckHost', 'http://' + tHost, '', followup);
}


// Next function is called if 'checkHost()' is called by 'onload()' of 'dialerpad.xul'.

function pwdOnloadDialerpad(responseText) {
	noResponse = fritzboxdialStrBundle.GetStringFromName('noResponse').split('$');
	if (responseText == '') {
		alert(noResponse[0] + fbHostname + noResponse[1])
		window.close();
		window.open('chrome://fritzboxdial/content/fritzboxdialPrefDialog.xul', '', 'chrome');
	}
	else sendPwd(fbHostname, password, 'afterPwdDialerpad')
}


// Make data string for posting password and pass it to xmlhttpPost.
// Called by opening 'dialerpad.xul' and by 'checkSettings()'.

function sendPwd(pwdhost, pwrd, after) {
	var url = 'http://' + pwdhost + '/cgi-bin/webcm';
	
	var reqParams = new Array('getpage=../html/de/menus/menu2.html',
				'errorpage=../html/index.html',
				'&var:lang=de',
				'&var:pagename=route',
				'&var:menu=fon',
				'&login:command/password=', pwrd)
				
	var data = reqParams.join('');			      
	
	xmlhttpPost('POST', 'pwdPost', url, data, after);
}


// Having sent the password by 'onload()' of 'dialerpad.xul', 
// evaluate response and change texts on dialerpad.
// For password to be ok, responseText needs to be ''.
// If password is wrong it will ask to check the settings.

function afterPwdDialerpad(responseText) {
	var wrongPW = fritzboxdialStrBundle.GetStringFromName('wrongPW').split('$');
	var goodPW  = fritzboxdialStrBundle.GetStringFromName('goodPW').split('$');
	
	if (responseText != '') {
		document.getElementById('pwLegend').value = wrongPW[0] + fbHostname + wrongPW[1];
		alert(wrongPW[0] + fbHostname + wrongPW[1]);
		window.close();
		window.open('chrome://fritzboxdial/content/fritzboxdialPrefDialog.xul', '', 'chrome');
	}
	else {
		document.getElementById('pwLegend').value = goodPW[0] + fbHostname + goodPW[1];
	}
}

		
// Get PhoneNumber from the opener and set some text on dialerpad.
// Like 'checkHost()' this function is called by 'onload()' event of 'dailerpad.xul'.

function setNumber() {
	initVars();
	var NoNumber = fritzboxdialStrBundle.GetStringFromName('NoNumber');
	var AskIfDial = fritzboxdialStrBundle.GetStringFromName('AskIfDial');

	document.getElementById('routePopup').ref = fbSelected + '/SIP';
	document.getElementById('routePopup').datasources = cfgURL;
	
	/*
	if (!PhoneNumber) {
	*/
	if (!opener.PhoneNumber) {
		document.getElementById('DialerLegend').label = NoNumber;
		doRoute();
		doClir();
		document.getElementById('telcfgDial').focus();
	}
	else {
		document.getElementById('DialerLegend').label = AskIfDial;
		document.getElementById('telcfgDial').value = opener.PhoneNumber;
		doRoute();
		doClir();
		document.getElementById('dialbutton').focus();
	}
}


// Prepend '*31#' to PhoneNumber. Called by checkbox on 'dialerpad.xul'.

function doClir() {
	var rawNumber = document.getElementById('telcfgDial').value
	if (document.getElementById('clirCheckb').checked) {
		document.getElementById('telcfgDial').value = '*31#' + rawNumber;
	}
	else if (!document.getElementById('clirCheckb').checked) {
		rawNumber = rawNumber.replace(/\*31\#/g, '');
		document.getElementById('telcfgDial').value = rawNumber;
	}
}


// Prepend '*12x# (Keycode)' to PhoneNumber

function doRoute() {
	var routing = document.getElementById('routeList').value;
	var rawNumber = document.getElementById('telcfgDial').value;
	rawNumber = rawNumber.replace(/\*1(1|2)\d?\#/g, '');
	document.getElementById('telcfgDial').value = routing + rawNumber;

	// Grabbing 'username' and 'registrar' from stored datasource
	var target, predicate, subject, user, provider;
	ds = RDF.GetDataSourceBlocking(cfgURL);
	subject = RDF.GetResource(fbSelected + '/' + routing);
	user = RDF.GetResource('http://fritzboxdial/rdf#username');
	provider = RDF.GetResource('http://fritzboxdial/rdf#registrar');
	
	if (ds.hasArcOut(subject, user) && ds.hasArcOut(subject, provider)) {
		user = ds.GetTarget(subject, user, true)
			.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
		provider = ds.GetTarget(subject, provider, true)
			.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
		document.getElementById('routeLegend').value = user + '@' + provider;
	} 
	// If not using SIP account ...
	else document.getElementById('routeLegend').value = '';
}


// Finally, here comes the dialing! Called by dialer button in 'dialerpad.xul'. 
// Collects data from dialerpad and uses global variables fbHostname and password.
// Makes string of them and passes it to xmlhttpPost.

function dial() {
	var url = 'http://' + fbHostname + '/cgi-bin/webcm';
	var dialport = document.getElementById('Dialport').value;
	var Number = document.getElementById('telcfgDial').value;
	
	var reqParams = new Array('getpage=../html/de/menus/menu2.html',
	                          'errorpage=../html/de/menus/menu2.html',
	                          '&var:lang=de',
	                          '&var:pagename=foncalls',
	                          '&var:errorpagename=foncalls',
	                          '&var:menu=fon',
	                          '&telcfg:settings/DialPort=', dialport,
	                          '&login:command/password=', password,
	                          '&telcfg:command/Dial=', Number)
	
	var data = reqParams.join('');			      
	
	xmlhttpPost('POST', 'dial', url, data, 'afterDialing');
}


// Next function is called as the argument of 'eval(strResultFunc)' in 'xmlhttpPost()'.
// And also offer something to cancel the call.

function afterDialing(responseText) {
	var AskIfCancel = fritzboxdialStrBundle.GetStringFromName('AskIfCancel');
	var CancelLabel = fritzboxdialStrBundle.GetStringFromName('cancelButton');
	var CancelAccKey = fritzboxdialStrBundle.GetStringFromName('cancelButtonAccesskey');
	var pWordReq = fritzboxdialStrBundle.GetStringFromName('wrongPW');
	
	if (responseText == '') {
		document.getElementById('DialerLegend').label = AskIfCancel;
		document.getElementById('telcfgDial').value = ' ';
		document.getElementById('dialbutton').label = CancelLabel + ' (F8)';
		document.getElementById('dialbutton').accessKey = CancelAccKey;
		setTimeout(close, 10000);
	}
	if (responseText.match('FRITZ!Box Anmeldung')) {
		document.getElementById('pwLegend').label = pWordReq;
	}
}


// Send request to server. Different requests are separated by 'reqId'.

function xmlhttpPost(method, reqId, strURL, POSTDATA, strResultFunc) {

	reqId = new XMLHttpRequest();

	reqId.open(method, strURL, true);
	
	reqId.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	reqId.onreadystatechange = function() {
		if (reqId.readyState == 4) {
			eval(strResultFunc + '(reqId.responseText);');
		}
	}
	reqId.send(POSTDATA);
}


// Getting the path of this extension's directory in the user's profile.
// Appending filename 'configfritzbox.rdf' and getting URL of that file. 
// Reference: (http://kb.mozillazine.org/File_IO#Getting_special_files)

var cfgfile, cfgURL, msg;

function makeURL() {
	fritzboxdialStrBundle = srGetStrBundle('chrome://fritzboxdial/locale/fritzboxdial.properties');

	cfgfile = Components.classes["@mozilla.org/extensions/manager;1"]
		.getService(Components.interfaces.nsIExtensionManager)
		.getInstallLocation('{d480644b-a183-47ce-a476-5eb483744fa7}')
		.getItemLocation('{d480644b-a183-47ce-a476-5eb483744fa7}');

	cfgfile.append('configfritzbox.rdf');

	cfgURL = Components.classes['@mozilla.org/network/io-service;1']
		.getService(Components.interfaces.nsIIOService)
		.getProtocolHandler('file')
		.QueryInterface(Components.interfaces.nsIFileProtocolHandler)
		.getURLSpecFromFile(cfgfile);
}


// 'fritzboxdialPrefDialog.xul' 
// An array holding all textfield ids. '$' is used later for 
// splitting into 'subject' and 'predicate'.

// Array with 'location', 'hostname' and 'password' of some boxes
var inputs = new Array(
	'box1$selected', 'box1$location', 'box1$hostname', 'box1$password',
	'box2$selected', 'box2$location', 'box2$hostname', 'box2$password',
	'box3$selected', 'box3$location', 'box3$hostname', 'box3$password',
	'box4$selected', 'box4$location', 'box4$hostname', 'box4$password',
	'box5$selected', 'box5$location', 'box5$hostname', 'box5$password');
	
	
// Collect data from 'fritzboxdialPrefDialog.xul' textboxes and write them to RDF.
// http://www.mozilla.org/rdf/back-end-architecture.html#Example
// http://developer.mozilla.org/en/docs/RDF_in_Mozilla_FAQ#How_do_I_create_a_datasource_from_an_RDF.2FXML_file.3F

function writeConfigRDF() {
	var subject, predicate, value, old
	makeURL();
	document.getElementById('rdfSource').disabled = true;
	
	// 'whichbox' is the radiogroup.
	value = document.getElementById('whichbox').selectedIndex;
	value = RDF.GetLiteral(value);
	subject = RDF.GetResource('http://fritzboxdial/whichbox');
	predicate = RDF.GetResource('http://fritzboxdial/rdf#selectedItem');
	old = ds.GetTarget(subject, predicate, true);

	ds.Change(subject, predicate, old, value);
	msg = fritzboxdialStrBundle.GetStringFromName('newCfg') + "\n" + cfgfile.path;

	for (var i = 0; i < inputs.length; ++i) {
		var splitparts = inputs[i].split('$');
		// First suppose textfield and get its 'value' attibute
		value = document.getElementById(inputs[i]).value;
		// The radio buttons instead have a 'selected' attribute.
		if (splitparts[1] == 'selected') {
			value = document.getElementById(inputs[i]).selected;
		}
		value = RDF.GetLiteral(value);
		subject = RDF.GetResource('http://fritzboxdial/' + splitparts[0]);
		predicate = RDF.GetResource('http://fritzboxdial/rdf#' + splitparts[1]);
		old = ds.GetTarget(subject, predicate, true);
		ds.Change(subject, predicate, old, value);
	}
	ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush;

	alert(msg);
	window.location.reload();
}


// Function 'showConfigRDF' is called on opening 'fritzboxdialPrefDialog.xul'. 
// It reads data from cfgfile in extension's  directory and puts them in the textboxes. 

function showConfigRDF() {
	var subject, predicate, target, value
	makeURL();
	
	// First, disable all 'check' buttons
	var boxes = new Array('box1', 'box2', 'box3', 'box4', 'box5');
	for (var i in boxes) {
		document.getElementById(boxes[i] + 'SIPbutton').disabled = true;
	}
	
	msg = fritzboxdialStrBundle.GetStringFromName('readingCfg');
	ds = RDF.GetDataSourceBlocking(cfgURL);

	subject = RDF.GetResource('http://fritzboxdial/whichbox');
	predicate = RDF.GetResource('http://fritzboxdial/rdf#selectedItem');
	target = ds.GetTarget(subject, predicate, true);
	value = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
	document.getElementById('whichbox').selectedIndex = value;

	for (var i = 0; i < inputs.length; ++i) {
		var splitparts = inputs[i].split('$');
		subject = RDF.GetResource('http://fritzboxdial/' + splitparts[0]);
		predicate = RDF.GetResource('http://fritzboxdial/rdf#' + splitparts[1]);
		target = ds.GetTarget(subject, predicate, true);
		value = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
		// Prevent setting 'selected' (readonly) attribute of 'radio'.
		if (splitparts[1] != 'selected') {
			document.getElementById(inputs[i]).value = value;
		}
		// Enable button if hostname is given
		if (splitparts[1] == 'hostname' && value != '') {
			document.getElementById(splitparts[0] + 'SIPbutton').disabled = false;
		}
	}

	alert(msg);
}


function dsblbt(whichbutton) {
	document.getElementById(whichbutton + 'SIPbutton').disabled = true;
}


// Get hostname and password of the right box from configuration
// This function is called by the 'check' buttons on each line in 'fritzboxdialPrefDialog.xul'.
// It calls the 'checkHost()' function which indirectly triggers 'sendPwd()'.

function checkSettings() {
	var subject, predicate, target, value
	
	subject = RDF.GetResource('http://fritzboxdial/' + boxline);
	
	predicate = RDF.GetResource('http://fritzboxdial/rdf#hostname');
	if (ds.hasArcOut(subject, predicate)) {
		target = ds.GetTarget(subject, predicate, true);
		host = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
	}
	
	predicate = RDF.GetResource('http://fritzboxdial/rdf#password');
	if (ds.hasArcOut(subject, predicate)) {
		target = ds.GetTarget(subject, predicate, true);
		pwrd = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
	}

	if (host != '') {
		checkHost(host, 'pwdAfterCheckbtn');
	}
}


function pwdAfterCheckbtn(responseText) {
	var noResponse = fritzboxdialStrBundle.GetStringFromName('noResponse').split('$');
	if (responseText == '') alert(noResponse[0] + host + noResponse[1])
	else sendPwd(host, pwrd, 'afterPwdgetSip')
}


function afterPwdgetSip(responseText) {
	var wrongPW = fritzboxdialStrBundle.GetStringFromName('wrongPW').split('$');
	var goodPW  = fritzboxdialStrBundle.GetStringFromName('goodPW').split('$');

	if (responseText == '') {
		alert(goodPW[0] + host + goodPW[1]);
		getConfig('showSip', host);
	}
	else {
		alert(wrongPW[0] + host + wrongPW[1]);
	}
}


// Get 'fritzbox.export' which means all configuration data.
// Just only view the settings of the box. For now.
// This was most complicated part of my work, because I had 
// to learn about of complicated creation of requestbody.
// The argument 'strResultFunc' is provided by calling this 
// function from 'getConfig.xul'.

function getConfig(strResultFunc, cfghost) {
	var url = 'http://' + cfghost + '/cgi-bin/firmwarecfg';
	var requestbody = '--12345678987654321' + '\n'
			+ 'Content-Disposition: form-data; name="ConfigExport"' + '\n'
			+ '\n'
			+ '\n'
			+ '--12345678987654321';

	xmlhttpPost('POST', 'cfgs', url, requestbody, strResultFunc);
}


// Extract single SIP accounts from Voicfg and then 
// Still looking for a replacement for that ugly 'brackets' regular expression.

function showSip(responseText) {
	var subject, predicate, target, value, seq

	// Initialize RDF:Seq
	seq = RDF.GetResource('http://fritzboxdial/' + boxline + '/SIP');
	datasource = ds.QueryInterface(Components.interfaces.nsIRDFDataSource);
	// init sequence
	try {
	   RDFC.Init(datasource,seq);
	} catch (e) {
	   RDFCUtils.MakeSeq(datasource,seq);
	   RDFC.Init(datasource,seq);
	}
	
	// Attach sequence to the correct box data
	value = RDF.GetResource('http://fritzboxdial/' + boxline + '/SIP');
	subject = RDF.GetResource('http://fritzboxdial/' + boxline);
	predicate = RDF.GetResource('http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq');
	ds.Assert(subject, predicate, value, true);

	// Clean sequence before getting new accounts from Fritz!Box
	var i=0;
	var children = RDFC.GetElements();
	while (children.hasMoreElements()){
		var child = children.getNext();
		if (child instanceof Components.interfaces.nsIRDFResource){
			removeElement(child);
			RDFC.RemoveElement(child , false)
		}
		i++; // use this to count number of times this runs.
	}

	// Here use response from xmlhttpPost
	var brackets = /voipcfg\s?\{((([^\}\{])|(\{((([^\}\{])|(\{([^\}\{])*\})))*\})))*\}/;
	var voipcfg = brackets.exec(responseText)[0];
	
	//                         [^\}\{]		which is not { or }
	//                      \{(       )*\}		zero or more times
	var pattern = /ua\d?\d\s\{([^\}\{])*\}/g;
	var sip;
		
	while ((sip = pattern.exec(voipcfg))) {
		
		var ua = /\bua\d?\d/.exec(sip)[0];
		var name = /\bname\s=\s".*"/.exec(sip)[0];
		var registrar = /\bregistrar\s=\s".*"/.exec(sip);

		ua = ua.replace(/(\bua\d?)(.)/, '*12$2#');
		// Extracting characters from between the quotes
		name = /"(.*)"/.exec(name)[1];
		registrar = /"(.*)"/.exec(registrar)[1];

		alert( 'Fritz!Box Entries:\n' + ua + '\n' + name + '\n' + registrar );

		RDFC.AppendElement(RDF.GetResource('http://fritzboxdial/' + boxline + '/' + ua));
		
		subject = RDF.GetResource('http://fritzboxdial/' + boxline + '/' + ua);
		
		predicate = RDF.GetResource('http://fritzboxdial/rdf#keycode');
		value = RDF.GetLiteral(ua);
		ds.Assert(subject, predicate, value, true);
		
		predicate = RDF.GetResource('http://fritzboxdial/rdf#acctname');
		value = RDF.GetLiteral(name);
		ds.Assert(subject, predicate, value, true);
		
		predicate = RDF.GetResource('http://fritzboxdial/rdf#registrar');
		value = RDF.GetLiteral(registrar);
		ds.Assert(subject, predicate, value, true);

		acctFromWebUi(ua, host, ua);
	}

	// Create the first two entries 'Default Line' and 'Fixed Network' 
	// These are localized entities, not coming from Fritz!Box.
	var DefLine = new Array('noRoute$', 'fixedNetwork$*11#');
	for (var i in DefLine) {
		var splitparts = DefLine[i].split('$');
		RDFC.AppendElement(RDF.GetResource('http://fritzboxdial/' + boxline + '/' + splitparts[1]));
		subject = RDF.GetResource('http://fritzboxdial/' + boxline + '/' + splitparts[1]);

		predicate = RDF.GetResource('http://fritzboxdial/rdf#keycode');
		value = RDF.GetLiteral(splitparts[1]);
		ds.Assert(subject, predicate, value, true);

		predicate = RDF.GetResource('http://fritzboxdial/rdf#acctname');
		value = RDF.GetLiteral(fritzboxdialStrBundle.GetStringFromName(splitparts[0]));

		ds.Assert(subject, predicate, value, true);
	}

	// Add the MSN without getting anything from Fritz!Box
	var MSN = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
	for (var i in MSN) {
		RDFC.AppendElement(RDF.GetResource('http://fritzboxdial/' + boxline + '/' + MSN[i].replace(/\d?(.)/,'*11$1#')));
		subject = RDF.GetResource('http://fritzboxdial/' + boxline + '/' + MSN[i].replace(/\d?(.)/,'*11$1#'));

		predicate = RDF.GetResource('http://fritzboxdial/rdf#keycode');
		value = RDF.GetLiteral(MSN[i].replace(/\d?(.)/,'*11$1#'));
		ds.Assert(subject, predicate, value, true);

		predicate = RDF.GetResource('http://fritzboxdial/rdf#acctname');
		value = RDF.GetLiteral('MSN ' + MSN[i]);
		ds.Assert(subject, predicate, value, true);
	}
	
	ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush;
}


// Called by the above function

function removeElement(element) {
	var targets, predicate, target, value
	targets = datasource.ArcLabelsOut(element);
	while (targets.hasMoreElements()){
		predicate = targets.getNext();
		if (predicate instanceof Components.interfaces.nsIRDFResource){
			target = datasource.GetTarget(element, predicate, true);
			if (target instanceof Components.interfaces.nsIRDFResource){
				predicate = target;
			}
			else if (target instanceof Components.interfaces.nsIRDFLiteral){
				value = target;
			}
			ds.Unassert(element, predicate, value);
		}
	}
}


// Test evaluating html pages from web interface of Fritz!Box
// 

function acctFromWebUi(reqId, cfghost, ua) {
	var url = 'http://' + cfghost + '/cgi-bin/webcm';
	
	var ub = ua.replace(/(\*12)(.)#/, '$2') - 1;
	
	var reqParams = new Array('getpage=../html/de/menus/menu2.html',
	                          '&var:lang=de',
	                          '&var:pagename=sip1',
	                          '&var:menu=fon',
	                          '&var:sipnr=sip' + ub,
	                          '&var:telnr=SIP' + ub,
	                          '&login:command/password=', pwrd)
	
	var data = reqParams.join('');			      
	
	reqId = new XMLHttpRequest();

	reqId.open('POST', url, true);
	
	reqId.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	reqId.onreadystatechange = function() {
		if (reqId.readyState == 4) {
			eval('WebUi' + '(ua, reqId.responseText);');
		}
	}
	reqId.send(data);
}
function WebUi(ua, responseText) {	
	var username;
        username = /(.*)id="uiPostUsername"(.*)/.exec(responseText)[0];
	username = /value="([^"]*)"/.exec(username)[1];
		
	subject = RDF.GetResource('http://fritzboxdial/' + boxline + '/' + ua);
	predicate = RDF.GetResource('http://fritzboxdial/rdf#username');
	value = RDF.GetLiteral(username);
	ds.Assert(subject, predicate, value, true);
	/*
	alert( 'Fritz!Box Webinterface:\n' + username );
	*/
}
Ich möchte im grunde einfach sagen können wenn ich die Nummer auf der Seite anklicke dann soll die FritzBox wählen und das mit einem bestimmten Telefon verbinden.

Hoffe es kennt das jemand.

MFG Marco
 

Neue Beiträge

Zurück