diff options
author | Mario Vavti <mario@mariovavti.com> | 2016-06-28 11:09:22 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2016-06-28 11:09:22 +0200 |
commit | 9f576369a97009bc93f4f724f85024410c3899df (patch) | |
tree | adc2c68e8729ff783eca9cd259bc5b8fe394d2e6 /Zotlabs/Daemon | |
parent | 911510f9996dc43bd3440884325326b7e99ea12f (diff) | |
parent | 7d7f43c2056fd50ff26aed5df553bf4936ead196 (diff) | |
download | volse-hubzilla-9f576369a97009bc93f4f724f85024410c3899df.tar.gz volse-hubzilla-9f576369a97009bc93f4f724f85024410c3899df.tar.bz2 volse-hubzilla-9f576369a97009bc93f4f724f85024410c3899df.zip |
Merge branch 'dev' into sabre32
Diffstat (limited to 'Zotlabs/Daemon')
-rw-r--r-- | Zotlabs/Daemon/CurlAuth.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Zotlabs/Daemon/CurlAuth.php b/Zotlabs/Daemon/CurlAuth.php new file mode 100644 index 000000000..be12bc779 --- /dev/null +++ b/Zotlabs/Daemon/CurlAuth.php @@ -0,0 +1,55 @@ +<?php + +namespace Zotlabs\Daemon; + +// generate a curl compatible cookie file with an authenticated session for the given channel_id. +// If this file is then used with curl and the destination url is sent through zid() or manually +// manipulated to add a zid, it should allow curl to provide zot magic-auth across domains. + +// Handles expiration of stale cookies currently by deleting them and rewriting the file. + +class CurlAuth { + + static public function run($argc,$argv) { + + if($argc != 2) + killme(); + + \App::$session->start(); + + $_SESSION['authenticated'] = 1; + $_SESSION['uid'] = $argv[1]; + + $x = session_id(); + + $f = 'store/[data]/cookie_' . $argv[1]; + $c = 'store/[data]/cookien_' . $argv[1]; + + $e = file_exists($f); + + $output = ''; + + if($e) { + $lines = file($f); + if($lines) { + foreach($lines as $line) { + if(strlen($line) > 0 && $line[0] != '#' && substr_count($line, "\t") == 6) { + $tokens = explode("\t", $line); + $tokens = array_map('trim', $tokens); + if($tokens[4] > time()) { + $output .= $line . "\n"; + } + } + else + $output .= $line; + } + } + } + $t = time() + (24 * 3600); + file_put_contents($f, $output . 'HttpOnly_' . \App::get_hostname() . "\tFALSE\t/\tTRUE\t$t\tPHPSESSID\t" . $x, (($e) ? FILE_APPEND : 0)); + + file_put_contents($c,$x); + + killme(); + } +}
\ No newline at end of file |