From 9a6a60a9c1c7f781790849173e309ac0664d7b35 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Thu, 8 Jul 2010 07:03:25 -0700 Subject: [PATCH] mucho progress on notifier, email style dfrn url's --- boot.php | 47 +++++++++++++++++- include/Scrape.php | 24 ++++++++++ include/main.js | 12 +++++ include/notifier.php | 111 ++++++++++++++++++++++++++++++++----------- mod/dfrn_notify.php | 4 +- mod/dfrn_request.php | 9 ++++ mod/home.php | 2 + mod/item.php | 4 +- mod/profile.php | 2 + 9 files changed, 181 insertions(+), 34 deletions(-) create mode 100644 include/main.js diff --git a/boot.php b/boot.php index 9f825ddfdf..fab44a7a45 100644 --- a/boot.php +++ b/boot.php @@ -311,4 +311,49 @@ function notice($s) { $_SESSION['sysmsg'] .= $s; -}} \ No newline at end of file +}} + + +if(! function_exists('xmlify')) { +function xmlify($str) { + $buffer = ''; + + for($x = 0; $x < strlen($str); $x ++) { + $char = $str[$x]; + + switch( $char ) { + + case "\r" : + break; + case "&" : + $buffer .= '&'; + break; + case "'" : + $buffer .= '''; + break; + + case "\"" : + $buffer .= '"'; + break; + case '<' : + $buffer .= '<'; + break; + case '>' : + $buffer .= '>'; + break; + case "\n" : + $buffer .= ' '; + break; + default : + $buffer .= $char; + break; + } + } + $buffer = trim($buffer); + return($buffer); +}} + + +function hex2bin($s) { + return(pack("H*",$s)); +} \ No newline at end of file diff --git a/include/Scrape.php b/include/Scrape.php index cc50151657..b4a5dd8496 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -76,5 +76,29 @@ function validate_dfrn($a) { return $errors; }} +if(! function_exists('scrape_meta')) { +function scrape_meta($url) { + $ret = array(); + $s = fetch_url($url); + if(! $s) + return $ret; + + $dom = HTML5_Parser::parse($s); + + if(! $dom) + return $ret; + + $items = $dom->getElementsByTagName('meta'); + + // get DFRN link elements + + foreach($items as $item) { + $x = $item->getAttribute('name'); + if(substr($x,0,5) == "dfrn-") + $ret[$x] = $item->getAttribute('content'); + } + + return $ret; +}} diff --git a/include/main.js b/include/main.js new file mode 100644 index 0000000000..4fb92c774a --- /dev/null +++ b/include/main.js @@ -0,0 +1,12 @@ + + function openClose(theID) { + if(document.getElementById(theID).style.display == "block") { + document.getElementById(theID).style.display = "none" + } + else { + document.getElementById(theID).style.display = "block" + } + } + function openMenu(theID) { + document.getElementById(theID).style.display = "block" + } diff --git a/include/notifier.php b/include/notifier.php index d1f26cdc2c..e67ef06e31 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -1,6 +1,5 @@ $a->get_baseurl(), - '$feed_title' => 'Wall Item', - '$feed_updated' => datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z') , - '$name' => $item['name'], - '$profile_page' => $item['url'], - '$thumb' => $item['thumb'], - '$item_id' => $item['hash'] . '-' . $item['id'], - '$title' => '', - '$link' => $a->get_baseurl() . '/item/' . $item['id'], - '$updated' => datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z'), - '$summary' => '', - '$content' => $item['body'] + '$feed_id' => xmlify($baseurl), + '$feed_title' => xmlify('Wall Item'), + '$feed_updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')) , + '$name' => xmlify($item['name']), + '$profile_page' => xmlify($item['url']), + '$thumb' => xmlify($item['thumb']), + '$item_id' => xmlify($item['hash'] . '-' . $item['id']), + '$title' => xmlify(''), + '$link' => xmlify($baseurl . '/item/' . $item['id']), + '$updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')), + '$summary' => xmlify(''), + '$content' => xmlify($item['body']) )); print_r($atom); @@ -75,19 +87,60 @@ print_r($atom); // expand list of recipients - // grab the contact records +dbg(3); - // foreach recipient - // if no dfrn-id continue - - // fetch_url dfrn-notify - - // decrypt challenge - - // post result - - // continue + $recipients = array_unique($recipients); +print_r($recipients); + $recip_str = implode(', ', $recipients); + $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ", + dbesc($recip_str) + ); + if(! count($r)) killme(); + // delivery loop + + foreach($r as $rr) { + if($rr['self']) + continue; + + if(! strlen($rr['dfrn-id'])) + continue; + $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id']; +print_r($url); + $xml = fetch_url($url); +echo $xml; + +print_r($xml); + if(! $xml) + continue; + + $res = simplexml_load_string($xml); +print_r($res); +var_dump($res); + + if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id'])) + continue; + + $postvars = array(); + + $postvars['dfrn_id'] = $rr['dfrn-id']; + $challenge = hex2bin($res->challenge); +echo "dfrn-id:" . $res->dfrn_id . "\r\n"; +echo "challenge:" . $res->challenge . "\r\n"; +echo "pubkey:" . $rr['pubkey'] . "\r\n"; + + openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']); + + $postvars['data'] = $atom; + +print_r($postvars); + $xml = fetch_url($url,$postvars); + + + } + + killme(); + diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index c078afe38b..2d9d06fd1c 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -66,8 +66,8 @@ function dfrn_notify_content(&$a) { $challenge = ''; openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']); - - echo '' .$status . '' . $_GET['dfrn_id'] . '' + $challenge = bin2hex($challenge); + echo '' .$status . '' . $_GET['dfrn_id'] . '' . '' . $challenge . '' . "\r\n" ; session_write_close(); exit; diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index b6ae4346d2..7fb55c4bfe 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -166,6 +166,15 @@ function dfrn_request_post(&$a) { return; } + if(strstr($url,'@')) { + $username = substr($url,0,strpos($url,'@')); + $hostname = substr($url,strpos($url,'@') + 1); + require_once('Scrape.php'); + + $parms = scrape_meta('http://' . $url); + if((x($parms,'dfrn-template')) && strstr($parms['dfrn-template'],'%s')) + $url = sprintf($parms['dfrn-template'],$username); + } $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", intval($uid), diff --git a/mod/home.php b/mod/home.php index 44f2a9888b..a60e96ccbc 100644 --- a/mod/home.php +++ b/mod/home.php @@ -9,6 +9,8 @@ function home_init(&$a) { else goaway( $a->get_baseurl() . "/profile/" . $_SESSION['uid'] ); } + $a->page['htmlhead'] .= "get_baseurl() . "/profile/%s" . "\" />\r\n"; + }} diff --git a/mod/item.php b/mod/item.php index 23917161b4..4314719fb5 100644 --- a/mod/item.php +++ b/mod/item.php @@ -58,8 +58,8 @@ function item_post(&$a) { intval($post_id)); } - - proc_close(proc_open("php include/notifier.php $post_id > notify.log &", + $url = bin2hex($a->get_baseurl()); + proc_close(proc_open("php include/notifier.php $url $post_id > notify.log &", array(),$foo)); // notifier($a,$post_id,$parent); diff --git a/mod/profile.php b/mod/profile.php index 1caa3478f9..e5bc92f5b2 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -58,10 +58,12 @@ function profile_init(&$a) { } profile_load($a,$which); + $a->page['htmlhead'] .= "get_baseurl() . "/profile/%s" . "\" />\r\n"; $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); foreach($dfrn_pages as $dfrn) $a->page['htmlhead'] .= "get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n"; + } function item_display(&$a, $item,$template,$comment) {