Commit 5ec36c4b authored by François Billioud's avatar François Billioud

Initial import

parents
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
AuthType "Basic"
AuthName "nom"
AuthUserFile "http://localhost/dav/.htpasswd"
Header always set Access-Control-Allow-Methods "GET, POST, DELETE, OPTIONS, PUT"
Header always set Access-Control-Allow-Headers "Content-Type, X-Requested-With, X-HTTP-Method-Override, Accept, Authorization"
Header always set Access-Control-Allow-Credentials "true"
Header always set Access-Control-Allow-Origin "*"
CSQdhQSKD
QSDFSDKJGQ
SDFJGSKDJ
djflsjfdghsl </br>
sdfgmj
\ No newline at end of file
{"author":"test","title":"test","content":"<div align=\"center\">\u000a <h1>Test</h1>\u000a <h2 align=\"left\"><u style=\"color: #ff1f1f;\">Mon site HTML</u></h2>\u000a <h5 align=\"left\"><font face=\"wingdings\">C'est moche, mais ça marche !</font><br /></h5>\u000a </div>\u000a <div align=\"center\"> </div>","creation":"Mon, 06 Jun 2011 15:27:08 GMT","lastModif":"Tue, 07 Jun 2011 12:26:31 GMT"}
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<Document>
<Auth></Auth>
<LastMod></LastMod>
<Title></Title>
<Content>test</Content>
</Document>
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<script text="javascript"> function reloc(url) {window.location = url;}</script>
</head>
<body onload="reloc('theme.html');">
<textarea id="errors" name="errors" style="width:100%; height:100px; background:silver;"></textarea>
</body>
</html>
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode : function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
// public method for decoding
decode : function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
/**
* Editors
*/
var Xinha = function() {
this.name = "Xinha";
this.load = function() {
_editor_url = "http://www.ungproject.com/xinha/";
getCurrentPage().include("xinha/XinhaCore.js","script");
getCurrentPage().include("xinha/config.js","script");
xinha_init();
}
this.saveEdition = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
getCurrentDocument().setContent(textArea.content);
//saveCurrentDocument(); : JIO function
}
this.loadContent = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
textArea.content = getCurrentDocument().getContent();
}
this.load();
}
/**
* Text documents
*/
var JSONTextDocument = function() {
JSONDocument.call(this);//inherits from JSONDocument
this.type = "text";
}
JSONTextDocument.prototype = new JSONDocuement();
JSONTextDocument.prototype.saveEdition = function(content) {
this.setContent(content);
this.setLastModification(currentTime());
setCurrentDocument(this);
}
JSONTextDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this);
getCurrentPage().displayAuthorName(this);
getCurrentPage().displayLastModification(this);
setCurrentDocument(this);
}
getCurrentDocument = function() {
var doc = JSON.parse(localStorage.getItem("currentDocument"));
doc.__proto__ = JSONTextDocument.prototype;
return doc;
}
new JSONTextDocument();//load the document (it's just for testing)
/*
// save
saveCurrentDocument = function() {
//gestion fichier
var currentDocument = getLocalDocument();
currentDocument.updateDocument();
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {alert("Please install a more recent browser")}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr.open("PUT", currentUser.storage+"/dav/temp.json", true);
xhr.setRequestHeader("Authorization", "Basic "+"nom:test");
//END HACK.
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status != 200 && xhr.status != 201 && xhr.status != 204) {
alert("error: got status "+xhr.status+" when doing basic auth PUT on url "+Base64.encode("nom:test")+" " + xhr.statusText);
} else {
lastModificationArea.innerHTML = currentDocument.getLastModification();
}
}
}
xhr.withCredentials = "true";
xhr.send(JSON.stringify(currentDocument.getDocument()));
}
// load
loadDocument = function() {
//create request
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
{
try {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e2)
{
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {}
}
}
xhr.open("GET", currentUser.storage+"/dav/temp.json", false);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var cDoc = null;
if(xhr.status == 200) {
cDoc = new Document(JSON.parse(xhr.responseText));
} else {
alert("error: got status "+xhr.status+" when doing basic auth GET on url "+"nom:test"+" " + xhr.statusText);
cDoc = new Document(null);
}
cDoc.updateHTML();
setLocalDocument(cDoc);
}
}
xhr.send();
}*/
/*
* global variables
*/
var languages = ["fr","en"];
var availableLanguages = window.document.getElementById("available_languages");
var currentPage = null;
/*
* load page functions
*/
var Page = function(page) {
this.name = page;
this.html = window.document;
this.xml = null;
this.editor = null;
//define as current page
currentPage = this;
this.loadXML("xml/"+page+".xml");
}
Page.prototype = {
setXML: function(data) {
this.xml = data;
this.loadPage();
},
//getters
getXML: function() {return this.xml;},
getHTML: function() {return this.html;},
getTitle: function() {return $(this.getXML()).find("title").text();},
getContent: function() {return $(this.getXML()).find("content").html();},
getDependencies: function() {return $(this.getXML()).find("dependencies");},
//loaders
/* load the xml document which contains the web page information */
loadXML: function(source) {
$.ajax( {
type: "GET",
url: source,
dataType: "html",
async: false,
success: function(data) {
currentPage.setXML(data);
}
});
},
/* update the HTML page from the XML document */
loadPage: function() {
this.displayPageTitle();
this.displayPageContent();
var dependencies = this.getDependencies();
$(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js
$(dependencies).find("linkfile").each(function() {currentPage.include($(this).text(),"link");});//includes css
switch(this.name) {
case "editor":
this.editor = new Xinha();
break;
}
},
/* include a javascript or a css file */
include: function(file,type) {
var object = null;
switch(type) {
case "script":
object = this.getHTML().createElement("script");
object.type = "text/javascript";
object.src = file;
break;
case "style":
object = this.getHTML().createElement("link");
object.rel = "stylesheet";
object.href = file;
object.type = "text/css";
break;
}
var head = this.getHTML().getElementsByTagName("head");
$(head[0]).append(object);
},
//printers
//user information
/* display the list of availaible languages */
displayLanguages: function(user) {
var avLang = "";
for (var l in languages) {
if(l==user.getLanguage()) {this.getHTML().getElementById("current_language").innerHTML = l;}
else {
avLang = avLang + "<li><span onclick='getCurrentUser.setLanguage(this.innerHTML)' id="+l+">"+l+"</span></li>\n"
}
}
this.getHTML().getElementById("available_languages").innerHTML = avLang;
},
displayUserName: function(user) {this.getHTML().getElementById("userName").innerHTML = user.getName();},
//document information
displayAuthorName: function(doc) {this.getHTML().getElementById("author").innerHTML = doc.getAuthor();},
displayLastModification: function(doc) {this.getHTML().getElementById("last_update").innerHTML = doc.getLastModification();},
displayDocumentTitle: function(doc) {this.getHTML().getElementById("document_title").innerHTML = doc.getTitle();},
displayDocumentState: function(doc) {
var stateArea = this.getHTML().getElementById("document_state");
stateArea.innerHTML = doc.getState()[getCurrentUser().getLanguage()];
},
//web page information
displayPageTitle: function() {
var pageTitle = this.getHTML().getElementById("page_title");
pageTitle.innerHTML = this.getTitle();
},
displayPageContent: function() {
var pageContent = this.getHTML().getElementById("page_content");
pageContent.innerHTML = this.getContent();
}
}
getCurrentPage = function() {return currentPage;}
setCurrentPage = function(page) {
currentPage = new Page(page);
//window.location.reload();
}
/*
* user class
*/
var User = function() {
this.name = "unknown";
this.language = "en";
this.storage = "http://www.unhosted-dav.com";
this.identityProvider = "http://www.webfinger.com";
this.setAsCurrentUser();
}
User.prototype = {
getName: function() {return this.name;},
setName: function(newName) {this.name = newName;},
getLanguage: function() {return this.language;},
setLanguage:function(language) {
this.language = language;
getCurrentPage().displayLanguages();
},
getStorageLocation: function() {return this.storage;},
setStorageLocation: function(storage) {this.storage = storage;},
getIdentityProvider: function() {return this.identityProvider;},
setIdentityProvider: function(IDProv) {this.identityProvider = IDProv;},
setAsCurrentUser: function() {
getCurrentPage().displayUserName(this);
getCurrentPage().displayLanguages(this);
setCurrentUser(this);
}
}
getCurrentUser = function() {
var user = JSON.parse(localStorage.getItem("currentUser"));
user.__proto__ = User.prototype;
return user;
}
setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.stringify(user));}
/**
* Documents
*/
/* JSON document */
var JSONDocument = function() {
this.type = "text";
this.author=getCurrentUser().getName();
this.title="Untitled";
this.content="";
this.creation=currentTime();
this.lastModification=currentTime();
this.state=Document.states.draft;
this.setAsCurrentDocument();//temp
}
JSONDocument.prototype = {
//type
getType: function() {return this.type;},
//content
getContent:function() {return this.content;},
setContent:function(content) {this.content=content;},
//title
getTitle:function() {return this.title;},
setTitle:function(title) {this.title=title;},
//author
getAuthor:function() {return this.author;},
setAuthor:function(userName) {this.author=userName;},
//dates
getCreation:function() {return this.creation;},
getLastModification:function() {return this.lastModification;},
setLastModification:function(date) {this.lastModification=date;},
//state
getState:function() {return this.state;},
setState:function(state) {this.state=state;},
setAsCurrentDocument: function() {
setCurrentDocument(this);
}
}
Document.states = {
draft:{"fr":"Brouillon","en":"Draft"},
saved:{"fr":"Enregistré","en":"Saved"},
deleted:{"fr":"Supprimé","en":"Deleted"}
}
getCurrentDocument = function() {
var doc = JSON.parse(localStorage.getItem("currentDocument"));
doc.__proto__ = JSONDocument.prototype;
return doc;
}
setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON.stringify(doc));}
/*
* tools
*/
currentTime = function() {return (new Date()).toUTCString();}
cancel_sharing = function() {alert("cancel");}
translate = function() {alert("translate");}
submit = function() {alert("submit");}
//test = new User();
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<html>
<div id="page_title"> Page web - Web Page </div>
<div id="page_content">
<label>
Contenu de la page
</label>
<div class="input">
<textarea id="input_area" name="input_area" style="width:100%;height:500px">
</textarea>
</div>
</div>
<div id="include">
<span>js/editor.js</span>
</div>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<root>
<title> Page web - Web Page </title>
<content>
<label>
Contenu de la page
</label>
<div class="input">
<textarea id="input_area" name="input_area" style="width:100%;height:500px">
</textarea>
</div>
</content>
<dependencies>
<scriptfile>js/editor.js</scriptfile>
</dependencies>
</root>
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
This the unhosted hive for $protocol://$domain. Please contact superman@$domain for more info about your unhosted account.
</body>
</html>
Options MultiViews
<?php
require_once('../../unhosted/unhosted.php');
function getString($paramName) {
if(!isset($_POST[$paramName])) {
die("Parameter $paramName not specified");
}
return $_POST[$paramName];
}
function getDomain($paramName) {
$domain = getString($paramName);
if(!preg_match('|^[a-z0-9-]+(\.[a-z0-9-]+)*$|i', $domain)) {
die("Parameter $paramName should be a valid domain");
}
return $domain;
}
function getUserAddress($paramName) {
$userAddress = getString($paramName);
if(!preg_match('|^[a-z0-9-]+(\.[a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$|i', $userAddress)) {
die("Parameter $paramName is '$userAddress' but should be a valid user address");
}
return $userAddress;
}
if(count($_POST)) {
$unhostedAccount = new UnhostedAccount(getUserAddress("user_address"), getString("pwd"));
$token = $unhostedAccount->addAPP(getDomain("scope"));
if($token) {
header("Location:".$_POST["redirect_uri"]."?token=".$token);
echo "redirecting you back to the application.\n";
} else {
echo "Wrong password!";
}
} else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="/html5.js"></script><!-- this is the javascript allowing html5 to run in older browsers -->
<title>My Unhosted node</title>
<link rel="stylesheet" href="/css/uncompressed/reset.css" />
<link rel="stylesheet" href="/css/uncompressed/text.css" />
<link rel="stylesheet" href="/general.css" />
<link rel="stylesheet" href="/css/uncompressed/login.css" />
</head>
<header>
<h1><strong><?php echo UnhostedSettings::domain ?> </strong>Unhosted storage node</h1>
</header>
<body>
<div class="content">
<h2>The app '<?=$_GET["client_id"] ?>' wants to read and write the <?=$_GET["scope"]?> data in your unhosted account</h2>
<form method="post" action="">
<label>User address:</label><span class="username"><?=$_GET["user_address"]?></span>
<label for="password">Password:</label>
<div id="passAllow">
<form method="POST" action="?">
<input type="password" name="pwd" value="" />
<input type="submit" name="submit" value="Allow" />
<input type="hidden" value="<?=$_GET["user_address"]?>" name="user_address">
<input type="hidden" value="<?=$_GET["scope"]?>" name="scope">
<input type="hidden" value="<?=$_GET["redirect_uri"]?>" name="redirect_uri">
</form>
</div>
</form>
</div>
</body>
</html>
<?
}
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment