2016-04-19 03:38:38 +00:00
< ? php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module ;
2016-04-19 03:38:38 +00:00
2019-12-03 05:23:02 +00:00
use App ;
2022-02-16 04:08:28 +00:00
use Code\Lib\Libzot ;
use Code\Lib\ActivityStreams ;
use Code\Lib\Activity ;
2024-01-03 00:17:40 +00:00
use Code\Lib\JcsEddsa2022 ;
2022-02-16 04:08:28 +00:00
use Code\Lib\Crypto ;
use Code\Web\HTTPSig ;
use Code\Web\Controller ;
use Code\Lib\Channel ;
use Code\Extend\Hook ;
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
2021-12-02 23:02:31 +00:00
class Home extends Controller
{
public function init ()
{
$ret = [];
2022-02-12 08:50:48 +00:00
Hook :: call ( 'home_init' , $ret );
2021-12-02 23:02:31 +00:00
if ( ActivityStreams :: is_as_request ()) {
2022-12-15 21:24:47 +00:00
$x = array_merge ( Activity :: ap_context (), Activity :: encode_site ());
2021-12-02 23:02:31 +00:00
$headers = [];
$headers [ 'Content-Type' ] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
2024-01-05 19:18:21 +00:00
$channel = App :: $sys_channel ;
$x [ 'proof' ] = ( new JcsEddsa2022 ) -> sign ( $x , $channel );
2021-12-02 23:02:31 +00:00
$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 ();
}
2023-01-20 22:35:14 +00:00
if ( Libzot :: is_nomad_request ()) {
2022-01-25 01:26:12 +00:00
$channel = Channel :: get_system ();
2024-02-13 21:27:04 +00:00
/*
2021-12-02 23:02:31 +00:00
$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-12-03 03:01:39 +00:00
$s = q (
2022-06-17 02:46:54 +00:00
" select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') and hubloc_deleted = 0 limit 1 " ,
2021-12-02 23:02:31 +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 {
2024-02-13 21:27:04 +00:00
*/
2021-12-02 23:02:31 +00:00
$data = json_encode ( Libzot :: zotinfo ([ 'guid_hash' => $channel [ 'channel_hash' ]]));
2024-02-13 21:27:04 +00:00
// }
2021-12-02 23:02:31 +00:00
$headers = [
2021-12-06 21:19:19 +00:00
'Content-Type' => 'application/x-nomad+json' ,
2021-12-02 23:02:31 +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 ());
HTTPSig :: set_headers ( $h );
echo $data ;
killme ();
}
$splash = (( argc () > 1 && argv ( 1 ) === 'splash' ) ? true : false );
$channel = App :: get_channel ();
if ( local_channel () && $channel && $channel [ 'xchan_url' ] && ! $splash ) {
$dest = $channel [ 'channel_startpage' ];
if ( ! $dest ) {
$dest = get_pconfig ( local_channel (), 'system' , 'startpage' );
}
if ( ! $dest ) {
$dest = get_config ( 'system' , 'startpage' );
}
if ( ! $dest ) {
$dest = z_root () . '/stream' ;
}
goaway ( $dest );
}
2023-04-27 19:45:34 +00:00
if ( remote_channel () && ( ! $splash )) {
if ( $_SESSION [ 'atoken' ]) {
$r = q (
" select * from atoken where atoken_id = %d " ,
intval ( $_SESSION [ 'atoken' ])
);
if ( $r ) {
$x = Channel :: from_id ( $r [ 0 ][ 'atoken_uid' ]);
if ( $x ) {
goaway ( z_root () . '/channel/' . $x [ 'channel_address' ]);
}
}
}
else {
2023-04-27 20:22:11 +00:00
goaway ( z_root () . '/apps' );
2021-12-02 23:02:31 +00:00
}
}
if ( get_account_id () && ! $splash ) {
goaway ( z_root () . '/new_channel' );
}
}
public function get ()
{
$o = EMPTY_STR ;
if ( x ( $_SESSION , 'theme' )) {
unset ( $_SESSION [ 'theme' ]);
}
if ( x ( $_SESSION , 'mobile_theme' )) {
unset ( $_SESSION [ 'mobile_theme' ]);
}
$splash = (( argc () > 1 && argv ( 1 ) === 'splash' ) ? true : false );
2022-02-12 08:50:48 +00:00
Hook :: call ( 'home_content' , $o );
2021-12-02 23:02:31 +00:00
if ( $o ) {
return $o ;
}
$frontpage = get_config ( 'system' , 'frontpage' );
if ( $frontpage ) {
2022-09-04 01:35:50 +00:00
if ( str_contains ( $frontpage , 'include:' )) {
2021-12-02 23:02:31 +00:00
$file = trim ( str_replace ( 'include:' , '' , $frontpage ));
if ( file_exists ( $file )) {
App :: $page [ 'template' ] = 'full' ;
App :: $page [ 'title' ] = t ( '$Projectname' );
$o .= file_get_contents ( $file );
return $o ;
}
}
2022-09-04 01:35:50 +00:00
if ( ! str_starts_with ( $frontpage , 'http' )) {
2021-12-02 23:02:31 +00:00
$frontpage = z_root () . '/' . $frontpage ;
}
if ( intval ( get_config ( 'system' , 'mirror_frontpage' ))) {
$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' );
if ( $sitename ) {
$o .= '<h1 class="home-welcome">' . sprintf ( t ( 'Welcome to %s' ), $sitename ) . '</h1>' ;
}
$loginbox = get_config ( 'system' , 'login_on_homepage' );
2023-04-27 20:22:11 +00:00
if (( intval ( $loginbox ) || $loginbox === false ) && ! get_observer_hash ()) {
2021-12-02 23:02:31 +00:00
$o .= login ( true );
}
return $o ;
}
2016-04-19 03:38:38 +00:00
}