2016-04-19 03:38:38 +00:00
< ? php
namespace Zotlabs\Module ;
2019-12-03 05:23:02 +00:00
use App ;
2018-06-01 02:42:13 +00:00
use Zotlabs\Lib\Libzot ;
2021-08-25 05:59:48 +00:00
use Zotlabs\Lib\ActivityStreams ;
use Zotlabs\Lib\Activity ;
use Zotlabs\Lib\LDSignatures ;
2021-09-23 22:26:31 +00:00
use Zotlabs\Lib\Crypto ;
2018-06-20 02:33:50 +00:00
use Zotlabs\Web\HTTPSig ;
2019-12-03 05:23:02 +00:00
use Zotlabs\Web\Controller ;
2016-04-19 03:38:38 +00:00
2018-06-01 04:05:09 +00:00
require_once ( 'include/conversation.php' );
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
class Home extends Controller {
2016-04-19 03:38:38 +00:00
function init () {
2018-06-15 03:40:25 +00:00
2021-08-25 05:59:48 +00:00
2019-12-03 05:23:02 +00:00
$ret = [];
2016-04-19 03:38:38 +00:00
call_hooks ( 'home_init' , $ret );
2021-08-25 05:59:48 +00:00
if ( ActivityStreams :: is_as_request ()) {
$x = array_merge ([ '@context' => [
ACTIVITYSTREAMS_JSONLD_REV ,
'https://w3id.org/security/v1' ,
Activity :: ap_schema ()
]], Activity :: encode_site () );
$headers = [];
$headers [ 'Content-Type' ] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
$x [ 'signature' ] = LDSignatures :: sign ( $x ,[ 'channel_address' => z_root (), 'channel_prvkey' => get_config ( 'system' , 'prvkey' ) ]);
$ret = json_encode ( $x , JSON_UNESCAPED_SLASHES );
logger ( 'data: ' . jindent ( $ret ), LOGGER_DATA );
$headers [ 'Date' ] = datetime_convert ( 'UTC' , 'UTC' , 'now' , 'D, d M Y H:i:s \\G\\M\\T' );
$headers [ 'Digest' ] = HTTPSig :: generate_digest_header ( $ret );
$headers [ '(request-target)' ] = strtolower ( $_SERVER [ 'REQUEST_METHOD' ]) . ' ' . $_SERVER [ 'REQUEST_URI' ];
$h = HTTPSig :: create_sig ( $headers , get_config ( 'system' , 'prvkey' ), z_root ());
HTTPSig :: set_headers ( $h );
echo $ret ;
killme ();
}
2019-12-03 05:23:02 +00:00
if ( Libzot :: is_zot_request ()) {
2018-04-23 04:30:14 +00:00
2021-09-21 05:51:28 +00:00
$channel = get_sys_channel ();
$sigdata = HTTPSig :: verify ( file_get_contents ( 'php://input' ), EMPTY_STR , 'zot6' );
if ( $sigdata && $sigdata [ 'signer' ] && $sigdata [ 'header_valid' ]) {
$data = json_encode ( Libzot :: zotinfo ([ 'guid_hash' => $channel [ 'channel_hash' ], 'target_url' => $sigdata [ 'signer' ] ]));
2021-10-28 08:55:09 +00:00
$s = q ( " select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network in ('nomad','zot6') limit 1 " ,
2021-09-21 05:51:28 +00:00
dbesc ( $sigdata [ 'signer' ])
);
if ( $s && $s [ 0 ][ 'hubloc_sitekey' ] && $s [ 0 ][ 'site_crypto' ]) {
$data = json_encode ( Crypto :: encapsulate ( $data , $s [ 0 ][ 'hubloc_sitekey' ], Libzot :: best_algorithm ( $s [ 0 ][ 'site_crypto' ])));
}
}
else {
$data = json_encode ( Libzot :: zotinfo ([ 'guid_hash' => $channel [ 'channel_hash' ] ]));
}
$headers = [
2021-10-28 20:02:31 +00:00
'Content-Type' => 'application/x-nomad+json' ,
2021-09-21 05:51:28 +00:00
'Digest' => HTTPSig :: generate_digest_header ( $data ),
'(request-target)' => strtolower ( $_SERVER [ 'REQUEST_METHOD' ]) . ' ' . $_SERVER [ 'REQUEST_URI' ]
];
$h = HTTPSig :: create_sig ( $headers , get_config ( 'system' , 'prvkey' ), z_root ());
2018-06-20 02:33:50 +00:00
HTTPSig :: set_headers ( $h );
2021-09-21 05:51:28 +00:00
echo $data ;
2018-04-23 04:30:14 +00:00
killme ();
}
2021-09-21 05:51:28 +00:00
2016-04-19 03:38:38 +00:00
$splash = (( argc () > 1 && argv ( 1 ) === 'splash' ) ? true : false );
2019-12-03 05:23:02 +00:00
$channel = App :: get_channel ();
if ( local_channel () && $channel && $channel [ 'xchan_url' ] && ! $splash ) {
2016-04-19 03:38:38 +00:00
$dest = $channel [ 'channel_startpage' ];
2019-12-03 05:23:02 +00:00
if ( ! $dest ) {
2016-04-19 03:38:38 +00:00
$dest = get_pconfig ( local_channel (), 'system' , 'startpage' );
2019-12-03 05:23:02 +00:00
}
if ( ! $dest ) {
2016-04-19 03:38:38 +00:00
$dest = get_config ( 'system' , 'startpage' );
2019-12-03 05:23:02 +00:00
}
if ( ! $dest ) {
2020-02-13 05:36:21 +00:00
$dest = z_root () . '/stream' ;
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
goaway ( $dest );
}
2016-07-15 22:26:36 +00:00
2019-12-03 05:23:02 +00:00
if ( remote_channel () && ( ! $splash ) && $_SESSION [ 'atoken' ]) {
2016-07-15 22:26:36 +00:00
$r = q ( " select * from atoken where atoken_id = %d " ,
intval ( $_SESSION [ 'atoken' ])
);
2019-12-03 05:23:02 +00:00
if ( $r ) {
2016-07-15 22:26:36 +00:00
$x = channelx_by_n ( $r [ 0 ][ 'atoken_uid' ]);
2019-12-03 05:23:02 +00:00
if ( $x ) {
2016-07-15 22:26:36 +00:00
goaway ( z_root () . '/channel/' . $x [ 'channel_address' ]);
}
}
}
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
if ( get_account_id () && ! $splash ) {
2016-04-19 03:38:38 +00:00
goaway ( z_root () . '/new_channel' );
}
}
2021-10-15 05:43:17 +00:00
function get () {
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
$o = EMPTY_STR ;
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
if ( x ( $_SESSION , 'theme' )) {
2016-04-19 03:38:38 +00:00
unset ( $_SESSION [ 'theme' ]);
2019-12-03 05:23:02 +00:00
}
if ( x ( $_SESSION , 'mobile_theme' )) {
2016-04-19 03:38:38 +00:00
unset ( $_SESSION [ 'mobile_theme' ]);
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
$splash = (( argc () > 1 && argv ( 1 ) === 'splash' ) ? true : false );
call_hooks ( 'home_content' , $o );
2019-12-03 05:23:02 +00:00
if ( $o ) {
2016-04-19 03:38:38 +00:00
return $o ;
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
$frontpage = get_config ( 'system' , 'frontpage' );
2019-12-03 05:23:02 +00:00
if ( $frontpage ) {
if ( strpos ( $frontpage , 'include:' ) !== false ) {
2016-04-19 03:38:38 +00:00
$file = trim ( str_replace ( 'include:' , '' , $frontpage ));
2019-12-03 05:23:02 +00:00
if ( file_exists ( $file )) {
App :: $page [ 'template' ] = 'full' ;
App :: $page [ 'title' ] = t ( '$Projectname' );
2016-04-19 03:38:38 +00:00
$o .= file_get_contents ( $file );
return $o ;
}
}
2019-12-03 05:23:02 +00:00
if ( strpos ( $frontpage , 'http' ) !== 0 ) {
2016-04-19 03:38:38 +00:00
$frontpage = z_root () . '/' . $frontpage ;
2019-12-03 05:23:02 +00:00
}
if ( intval ( get_config ( 'system' , 'mirror_frontpage' ))) {
2016-04-19 03:38:38 +00:00
$o = '<html><head><title>' . t ( '$Projectname' ) . '</title></head><body style="margin: 0; padding: 0; border: none;" ><iframe src="' . $frontpage . '" width="100%" height="100%" style="margin: 0; padding: 0; border: none;" ></iframe></body></html>' ;
echo $o ;
killme ();
}
goaway ( $frontpage );
}
$sitename = get_config ( 'system' , 'sitename' );
2019-12-03 05:23:02 +00:00
if ( $sitename ) {
2018-05-15 02:19:25 +00:00
$o .= '<h1 class="home-welcome">' . sprintf ( t ( 'Welcome to %s' ) , $sitename ) . '</h1>' ;
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
$loginbox = get_config ( 'system' , 'login_on_homepage' );
2019-12-03 05:23:02 +00:00
if ( intval ( $loginbox ) || $loginbox === false ) {
2018-05-15 02:19:25 +00:00
$o .= login ( true );
2019-12-03 05:23:02 +00:00
}
2016-04-19 03:38:38 +00:00
return $o ;
}
}