forked from remotestorage/remotestorage.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved functionality into unhosted.php class
- Loading branch information
root
committed
Apr 29, 2011
1 parent
c2c5275
commit 1861771
Showing
7 changed files
with
120 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
require_once 'unhosted.php'; | ||
|
||
$unhostedAccount = new UnhostedAccount($_GET["user_address"], $_GET["pwd"]); | ||
switch($_GET["action"]) { | ||
case "register_hosted": echo $unhostedAccount->registerHosted();break; | ||
case "register_wallet": echo $unhostedAccount->registerWallet($_GET["dav_base_url"], $_GET["dav_token"]); break; | ||
case "add_app": echo $unhostedAccount->addApp($_GET["scope"]);break; | ||
case "get_wallet": echo $unhostedAccount->getWallet($_GET["scope"]);break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,65 @@ | ||
<?php | ||
require_once('init.php'); | ||
|
||
function registerScope($userAddress, $pwd, $scope) { | ||
list($userName, $userDomain) = explode("@", $userAddress); | ||
$pwdFile = UnhostedSettings::davDir . "$userDomain/$userName/.htpasswd"; | ||
if(file_exists($pwdFile) && sha1($pwd)==file_get_contents($pwdFile)) { | ||
class UnhostedAccount { | ||
private $userAddress, $userName, $userDomain, $pwd; | ||
function __construct($userAddress) { | ||
$this->userAddress = $userAddress; | ||
list($this->userName, $this->userDomain) = explode("@", $userAddress); | ||
$this->pwd = $pwd; | ||
} | ||
private function createUserDir() { | ||
$userDomainDir = UnhostedSettings::davDir . $this->userDomain . '/'; | ||
$userDir = $userDomainDir . strtolower($this->userName); | ||
if(is_dir($userDir)) { | ||
return false; | ||
} | ||
mkdir($userDomainDir); | ||
mkdir($userDir); | ||
file_put_contents($userDir."/.htpasswd", sha1($this->pwd)); | ||
return true; | ||
} | ||
private function createDav($scope) { | ||
$token = base64_encode(mt_rand()); | ||
$davDir = UnhostedSettings::davDir . "$userDomain/$userName/".$scope; | ||
$davDir = UnhostedSettings::davDir . "{$this->userDomain}/{$this->userName}/".$scope; | ||
`if [ ! -d $davDir ] ; then mkdir $davDir ; fi`; | ||
`echo "<LimitExcept OPTIONS HEAD GET>" > $davDir/.htaccess`; | ||
`echo " AuthType Basic" >> $davDir/.htaccess`; | ||
`echo " AuthName \"http://unhosted.org/spec/dav/0.1\"" >> $davDir/.htaccess`; | ||
`echo " Require valid-user" >> $davDir/.htaccess`; | ||
`echo " AuthUserFile $davDir/.htpasswd" >> $davDir/.htaccess`; | ||
`echo "</LimitExcept>" >> $davDir/.htaccess`; | ||
`htpasswd -bc $davDir/.htpasswd {$userAddress} $token`; | ||
`htpasswd -bc $davDir/.htpasswd {{$this->userAddress} $token`; | ||
return $token; | ||
} | ||
return null; | ||
private function createWallet($davBaseUrl, $davToken, $cryptoPwd) { | ||
$wallet = json_encode(array( | ||
"userAddress" => $userAddress, | ||
"davBaseUrl" => $davBaseUrl, | ||
"davAuth" => base64_encode($userAddress .':'. $davToken), | ||
"cryptoPwd" => $cryptoPwd | ||
)); | ||
file_put_content($davDir.'/wallet_'.sha1($this->pwd), $wallet); | ||
return $wallet; | ||
} | ||
public function getWallet($scope) { | ||
$davDir = UnhostedSettings::davDir . "{$this->userDomain}/{$this->userName}/".$scope; | ||
return file_get_content($davDir.'/wallet_'.sha1($this->pwd)); | ||
|
||
} | ||
public function createHostedUser() { | ||
createUserDir(); | ||
$davToken = createDav(UnhostedSettings::homeScope); | ||
return createWallet(UnhostedSettings::homeDavBaseUrl, $davToken, null); | ||
} | ||
public function createWalletAccount($davBaseUrl, $davToken) { | ||
$cryptoPwd = mtrand(); | ||
return createWallet($davBaseUrl, $davToken, $cryptoPwd); | ||
} | ||
public function addApp($scope) { | ||
$pwdFile = UnhostedSettings::davDir . "{$this->userDomain}/{$this->userName}/.htpasswd"; | ||
if(file_exists($pwdFile) && sha1($this->pwd)==file_get_contents($pwdFile)) { | ||
return createDav($scope); | ||
} | ||
return null; | ||
} | ||
} |