Ejemplo n.º 1
0
 function get()
 {
     $o .= '<h3>Probe Diagnostic</h3>';
     $o .= '<form action="probe" method="get">';
     $o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . $_GET['addr'] . '" />';
     $o .= '<input type="submit" name="submit" value="Submit" /></form>';
     $o .= '<br /><br />';
     if (x($_GET, 'addr')) {
         $channel = \App::get_channel();
         $addr = trim($_GET['addr']);
         $do_import = intval($_GET['import']) && is_site_admin() ? true : false;
         $j = \Zotlabs\Zot\Finger::run($addr, $channel, false);
         //			$res = zot_finger($addr,$channel,false);
         $o .= '<pre>';
         if (!$j['success']) {
             $o .= sprintf(t('Fetching URL returns error: %1$s'), $res['error'] . "\r\n\r\n");
             $o .= "<strong>https connection failed. Trying again with auto failover to http.</strong>\r\n\r\n";
             $j = \Zotlabs\Zot\Finger::run($addr, $channel, true);
             if (!$j['success']) {
                 $o .= sprintf(t('Fetching URL returns error: %1$s'), $res['error'] . "\r\n\r\n");
             }
         }
         if ($do_import && $j) {
             $x = import_xchan($j);
         }
         if ($j && $j['permissions'] && $j['permissions']['iv']) {
             $j['permissions'] = json_decode(crypto_unencapsulate($j['permissions'], $channel['channel_prvkey']), true);
         }
         $o .= str_replace("\n", '<br />', print_r($j, true));
         $o .= '</pre>';
     }
     return $o;
 }
Ejemplo n.º 2
0
 public static function run($argc, $argv)
 {
     if ($argc != 2) {
         return;
     }
     $url = hex2bin($argv[1]);
     if (!strpos($url, '@')) {
         return;
     }
     $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($url));
     if (!$r) {
         $j = \Zotlabs\Zot\Finger::run($url, null);
         if ($j['success']) {
             $y = import_xchan($j);
         }
     }
     return;
 }
Ejemplo n.º 3
0
 function init()
 {
     $result = array('success' => false);
     $url = $_REQUEST['url'];
     $access_token = $_REQUEST['t'];
     $valid = 0;
     // we probably don't need the realm as we will find out in the probe.
     // What we may want to die is throw an error if you're trying to register in a different realm
     // so this configuration issue can be discovered.
     $realm = $_REQUEST['realm'];
     if (!$realm) {
         $realm = DIRECTORY_REALM;
     }
     if ($realm === DIRECTORY_REALM) {
         $valid = 1;
     } else {
         $token = get_config('system', 'realm_token');
         if ($token && $access_token != $token) {
             $result['message'] = 'This realm requires an access token';
             return;
         }
         $valid = 1;
     }
     $dirmode = intval(get_config('system', 'directory_mode'));
     if ($dirmode == DIRECTORY_MODE_NORMAL) {
         $ret['message'] = t('This site is not a directory server');
         json_return_and_die($ret);
     }
     $m = null;
     if ($url) {
         $m = parse_url($url);
         if (!$m || !@dns_get_record($m['host'], DNS_A + DNS_CNAME + DNS_PTR) && !filter_var($m['host'], FILTER_VALIDATE_IP)) {
             $result['message'] = 'unparseable url';
             json_return_and_die($result);
         }
         $j = \Zotlabs\Zot\Finger::run('[system]@' . $m['host']);
         if ($j['success'] && $j['guid']) {
             $x = import_xchan($j);
             if ($x['success']) {
                 $result['success'] = true;
             }
         }
         if (!$result['success']) {
             $valid = 0;
         }
         q("update site set site_valid = %d where site_url = '%s' limit 1", intval($valid), strtolower($url));
         json_return_and_die($result);
     } else {
         // We can put this in the sql without the condition after 31 august 2015 assuming
         // most directory servers will have updated by then
         // This just makes sure it happens if I forget
         $sql_extra = datetime_convert() > datetime_convert('UTC', 'UTC', '2015-08-31') ? ' and site_valid = 1 ' : '';
         if ($dirmode == DIRECTORY_MODE_STANDALONE) {
             $r = array(array('site_url' => z_root()));
         } else {
             $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s' and site_type = %d {$sql_extra} ", dbesc(get_directory_realm()), intval(SITE_TYPE_ZOT));
         }
         if ($r) {
             $result['success'] = true;
             $result['directories'] = array();
             foreach ($r as $rr) {
                 $result['directories'][] = $rr['site_url'];
             }
             json_return_and_die($result);
         }
     }
     json_return_and_die($result);
 }
Ejemplo n.º 4
0
 function post()
 {
     if (!local_channel()) {
         return;
     }
     $replyto = x($_REQUEST, 'replyto') ? notags(trim($_REQUEST['replyto'])) : '';
     $subject = x($_REQUEST, 'subject') ? notags(trim($_REQUEST['subject'])) : '';
     $body = x($_REQUEST, 'body') ? escape_tags(trim($_REQUEST['body'])) : '';
     $recipient = x($_REQUEST, 'messageto') ? notags(trim($_REQUEST['messageto'])) : '';
     $rstr = x($_REQUEST, 'messagerecip') ? notags(trim($_REQUEST['messagerecip'])) : '';
     $preview = x($_REQUEST, 'preview') ? intval($_REQUEST['preview']) : 0;
     $expires = x($_REQUEST, 'expires') ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['expires']) : NULL_DATE;
     // If we have a raw string for a recipient which hasn't been auto-filled,
     // it means they probably aren't in our address book, hence we don't know
     // if we have permission to send them private messages.
     // finger them and find out before we try and send it.
     if (!$recipient) {
         $channel = \App::get_channel();
         $j = \Zotlabs\Zot\Finger::run($rstr, $channel);
         if (!$j['success']) {
             notice(t('Unable to lookup recipient.') . EOL);
             return;
         }
         logger('message_post: lookup: ' . $url . ' ' . print_r($j, true));
         if (!$j['guid']) {
             notice(t('Unable to communicate with requested channel.'));
             return;
         }
         $x = import_xchan($j);
         if (!$x['success']) {
             notice(t('Cannot verify requested channel.'));
             return;
         }
         $recipient = $x['hash'];
         $their_perms = 0;
         if ($j['permissions']['data']) {
             $permissions = crypto_unencapsulate($j['permissions'], $channel['channel_prvkey']);
             if ($permissions) {
                 $permissions = json_decode($permissions);
             }
             logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
         } else {
             $permissions = $j['permissions'];
         }
         if (!$permissions['post_mail']) {
             notice(t('Selected channel has private message restrictions. Send failed.'));
             // reported issue: let's still save the message and continue. We'll just tell them
             // that nothing useful is likely to happen. They might have spent hours on it.
             //			return;
         }
     }
     //	if(feature_enabled(local_channel(),'richtext')) {
     //		$body = fix_mce_lf($body);
     //	}
     require_once 'include/text.php';
     linkify_tags($a, $body, local_channel());
     if ($preview) {
     }
     if (!$recipient) {
         notice('No recipient found.');
         \App::$argc = 2;
         \App::$argv[1] = 'new';
         return;
     }
     // We have a local_channel, let send_message use the session channel and save a lookup
     $ret = send_message(0, $recipient, $body, $subject, $replyto, $expires);
     if ($ret['success']) {
         xchan_mail_query($ret['mail']);
         build_sync_packet(0, array('conv' => array($ret['conv']), 'mail' => array(encode_mail($ret['mail'], true))));
     } else {
         notice($ret['message']);
     }
     goaway(z_root() . '/mail/combined');
 }
Ejemplo n.º 5
0
 function init()
 {
     $ret = array('success' => false, 'url' => '', 'message' => '');
     logger('mod_magic: invoked', LOGGER_DEBUG);
     logger('mod_magic: args: ' . print_r($_REQUEST, true), LOGGER_DATA);
     $addr = x($_REQUEST, 'addr') ? $_REQUEST['addr'] : '';
     $dest = x($_REQUEST, 'dest') ? $_REQUEST['dest'] : '';
     $test = x($_REQUEST, 'test') ? intval($_REQUEST['test']) : 0;
     $rev = x($_REQUEST, 'rev') ? intval($_REQUEST['rev']) : 0;
     $delegate = x($_REQUEST, 'delegate') ? $_REQUEST['delegate'] : '';
     $parsed = parse_url($dest);
     if (!$parsed) {
         if ($test) {
             $ret['message'] .= 'could not parse ' . $dest . EOL;
             return $ret;
         }
         goaway($dest);
     }
     $basepath = $parsed['scheme'] . '://' . $parsed['host'] . ($parsed['port'] ? ':' . $parsed['port'] : '');
     $x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1", dbesc($basepath));
     if (!$x) {
         /*
          * We have no records for, or prior communications with this hub. 
          * If an address was supplied, let's finger them to create a hub record. 
          * Otherwise we'll use the special address '[system]' which will return
          * either a system channel or the first available normal channel. We don't
          * really care about what channel is returned - we need the hub information 
          * from that response so that we can create signed auth packets destined 
          * for that hub.
          *
          */
         $j = \Zotlabs\Zot\Finger::run($addr ? $addr : '[system]@' . $parsed['host'], null);
         if ($j['success']) {
             import_xchan($j);
             // Now try again
             $x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1", dbesc($basepath));
         }
     }
     if (!$x) {
         if ($rev) {
             goaway($dest);
         } else {
             logger('mod_magic: no channels found for requested hub.' . print_r($_REQUEST, true));
             if ($test) {
                 $ret['message'] .= 'This site has no previous connections with ' . $basepath . EOL;
                 return $ret;
             }
             notice(t('Hub not found.') . EOL);
             return;
         }
     }
     // This is ready-made for a plugin that provides a blacklist or "ask me" before blindly authenticating.
     // By default, we'll proceed without asking.
     $arr = array('channel_id' => local_channel(), 'xchan' => $x[0], 'destination' => $dest, 'proceed' => true);
     call_hooks('magic_auth', $arr);
     $dest = $arr['destination'];
     if (!$arr['proceed']) {
         if ($test) {
             $ret['message'] .= 'cancelled by plugin.' . EOL;
             return $ret;
         }
         goaway($dest);
     }
     if (get_observer_hash() && $x[0]['hubloc_url'] === z_root()) {
         // We are already authenticated on this site and a registered observer.
         // Just redirect.
         if ($test) {
             $ret['success'] = true;
             $ret['message'] .= 'Local site - you are already authenticated.' . EOL;
             return $ret;
         }
         $delegation_success = false;
         if ($delegate) {
             $r = q("select * from channel left join hubloc on channel_hash = hubloc_hash where hubloc_addr = '%s' limit 1", dbesc($delegate));
             if ($r && intval($r[0]['channel_id'])) {
                 $allowed = perm_is_allowed($r[0]['channel_id'], get_observer_hash(), 'delegate');
                 if ($allowed) {
                     $_SESSION['delegate_channel'] = $r[0]['channel_id'];
                     $_SESSION['delegate'] = get_observer_hash();
                     $_SESSION['account_id'] = intval($r[0]['channel_account_id']);
                     change_channel($r[0]['channel_id']);
                     $delegation_success = true;
                 }
             }
         }
         // FIXME: check and honour local delegation
         goaway($dest);
     }
     if (local_channel()) {
         $channel = \App::get_channel();
         $token = random_string();
         $token_sig = base64url_encode(rsa_sign($token, $channel['channel_prvkey']));
         $channel['token'] = $token;
         $channel['token_sig'] = $token_sig;
         \Zotlabs\Zot\Verify::create('auth', $channel['channel_id'], $token, $x[0]['hubloc_url']);
         $target_url = $x[0]['hubloc_callback'] . '/?f=&auth=' . urlencode(channel_reddress($channel)) . '&sec=' . $token . '&dest=' . urlencode($dest) . '&version=' . ZOT_REVISION;
         if ($delegate) {
             $target_url .= '&delegate=' . urlencode($delegate);
         }
         logger('mod_magic: redirecting to: ' . $target_url, LOGGER_DEBUG);
         if ($test) {
             $ret['success'] = true;
             $ret['url'] = $target_url;
             $ret['message'] = 'token ' . $token . ' created for channel ' . $channel['channel_id'] . ' for url ' . $x[0]['hubloc_url'] . EOL;
             return $ret;
         }
         goaway($target_url);
     }
     if ($test) {
         $ret['message'] = 'Not authenticated or invalid arguments to mod_magic' . EOL;
         return $ret;
     }
     goaway($dest);
 }
Ejemplo n.º 6
0
 function get()
 {
     $observer = \App::get_observer();
     $xchan = null;
     $r = null;
     if ($_REQUEST['hash']) {
         $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($_REQUEST['hash']));
     }
     if ($_REQUEST['address']) {
         $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($_REQUEST['address']));
     } elseif (local_channel() && intval($_REQUEST['cid'])) {
         $r = q("SELECT abook.*, xchan.* \n\t\t\t\tFROM abook left join xchan on abook_xchan = xchan_hash\n\t\t\t\tWHERE abook_channel = %d and abook_id = %d LIMIT 1", intval(local_channel()), intval($_REQUEST['cid']));
     } elseif ($_REQUEST['url']) {
         // if somebody re-installed they will have more than one xchan, use the most recent name date as this is
         // the most useful consistently ascending table item we have.
         $r = q("select * from xchan where xchan_url = '%s' order by xchan_name_date desc limit 1", dbesc($_REQUEST['url']));
     }
     if ($r) {
         \App::$poi = $r[0];
     }
     // Here, let's see if we have an xchan. If we don't, how we proceed is determined by what
     // info we do have. If it's a URL, we can offer to visit it directly. If it's a webbie or
     // address, we can and should try to import it. If it's just a hash, we can't continue, but we
     // probably wouldn't have a hash if we don't already have an xchan for this channel.
     if (!\App::$poi) {
         logger('mod_chanview: fallback');
         // This is hackish - construct a zot address from the url
         if ($_REQUEST['url']) {
             if (preg_match('/https?\\:\\/\\/(.*?)(\\/channel\\/|\\/profile\\/)(.*?)$/ism', $_REQUEST['url'], $matches)) {
                 $_REQUEST['address'] = $matches[3] . '@' . $matches[1];
             }
             logger('mod_chanview: constructed address ' . print_r($matches, true));
         }
         if ($_REQUEST['address']) {
             $j = \Zotlabs\Zot\Finger::run($_REQUEST['address'], null);
             if ($j['success']) {
                 import_xchan($j);
                 $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($_REQUEST['address']));
                 if ($r) {
                     \App::$poi = $r[0];
                 }
             }
         }
     }
     if (!\App::$poi) {
         //		We don't know who this is, and we can't figure it out from the URL
         //		On the plus side, there's a good chance we know somebody else at that
         //		hub so sending them there with a Zid will probably work anyway.
         $url = $_REQUEST['url'];
         if ($observer) {
             $url = zid($url);
         }
     }
     if (\App::$poi) {
         $url = \App::$poi['xchan_url'];
         if ($observer) {
             $url = zid($url);
         }
     }
     // let somebody over-ride the iframed viewport presentation
     // or let's just declare this a failed experiment.
     //	if((! local_channel()) || (get_pconfig(local_channel(),'system','chanview_full')))
     goaway($url);
     //	$o = replace_macros(get_markup_template('chanview.tpl'),array(
     //		'$url' => $url,
     //		'$full' => t('toggle full screen mode')
     //	));
     //	return $o;
 }