DIR : /home/kozerus/public_html/ka/owncast.php

/home/kozerus/public_html/ka

<?php

        $dttm=date('Ymd_His');
        $ofile="owncast.txt";


	if ( isset( $_REQUEST['api'] )) { api(''); return(''); };

        header('Content-Type: application/json');
        $request = file_get_contents('php://input');

        $json="_JSON_DATA_";
	$json = json_decode($request, true );


#	if($json = json_decode(file_get_contents("php://input"), true)) {
#		print_r($json); $data = $json;
#		} 
# 	else {
#		print_r($_POST); $data = $_POST;
#		}


#	print( "$dttm json=$json<br>\n" );
#	print( "$json" );


#       $request_data = print_r( $request, true );
#        if( $json = json_decode($request, true)) { $json_data = $json; }
#       if( $json = json_decode(file_get_contents("php://input"), true)) { $json_data = print_r($json, true ); }

#       $fp = file_put_contents( $ofile, "$dttm request_data=\n$request_data\n", FILE_APPEND );
#       $fp = file_put_contents( $ofile, "$dttm json_data=\n$json_data\n", FILE_APPEND );
#	$fh = fopen($file,"a");
#	fwrite($fh, $content);
#	fclose($handle);

	if( isset( $json['type'] )) {
		if ( $json['type'] == "CHAT" ) { webhook_chat($json); return($json); }
		if ( $json['type'] == "NAME_CHANGE" ) { webhook_name_change($json); return($json); }
		if ( $json['type'] == "USER_JOINED" ) { webhook_user_joined($json); return($json); }
		if ( $json['type'] == "USER_PARTED" ) { webhook_user_parted($json); return($json); }
		if ( $json['type'] == "VISIBILITY_UPDATE" ) { webhook_visibility_update($json); return($json); }
		if ( $json['type'] == "STREAM_TITLE_UPDATED" ) { webhook_stream_title_updated($json); return($json); }
		if ( $json['type'] == "STREAM_STARTED" ) { webhook_stream_started($json); return($json); }
		if ( $json['type'] == "STREAM_STOPPED" ) { webhook_stream_stopped($json); return($json); }
		}


function webhook_chat($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$bugs="BUGS_040 webhook_chat type=$type json=$json<br>\n";
#	$fp = file_put_contents( $ofile, "$bugs", FILE_APPEND );


#	$customers = $decoded_json['customers'];
#	foreach($customers as $customer) {
#		$name = $customer['name'];
#		$countries = $customer['countries'];
#		foreach($countries as $country) {
#			echo $name.' visited '.$country['name'].' in '.$country['year'].'.';
#			}
#		}


	$type=$json['type'];
	$user=$json['eventData']['user'];
	$user_id=$json['eventData']['user']['id'];
	$user_displayname=$json['eventData']['user']['displayName'];
	$user_displaycolor=$json['eventData']['user']['displayColor'];
	$user_createdat=$json['eventData']['user']['createdAt'];
	$user_previousnames=$json['eventData']['user']['previousNames'];
	$user_namechangedat=$json['eventData']['user']['nameChangedAt'];
	$user_isbot=$json['eventData']['user']['isBot'];
	$user_authenticated=$json['eventData']['user']['authenticated'];
	$clientid=$json['eventData']['clientId'];
	$body=$json['eventData']['body'];
	$rawbody=$json['eventData']['rawBody'];
	$id=$json['eventData']['id'];
	$visibile=$json['eventData']['visible'];
	$timestamp=$json['eventData']['timestamp'];

	$csv="";
	$csv.="$dttm|$user_id|$user_displayname|$user_createdat|$user_createdat";
	$csv.="$user_previousnames|$user_namechangedat|$user_isbot|$user_authenticated";
	$csv.="$clientid|BODY=$body|$rawbody|$id|$visible|$timestamp\n";
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );
#	print( "$csv<br>\n");


$chat='{
    "type": "CHAT",
    "eventData": {
	"user": {
		"id": "qSRQpeM7R",
		"displayName": "lazyDaisy",
		"displayColor": 182,
		"createdAt": "2021-08-12T07:51:37.470812684Z",
		"previousNames": ["lazyDaisy"],
		"nameChangedAt": "2022-09-19T12:33:59.42313245+02:00",
		"isBot": false,
		"authenticated": false
		},
        "clientId": 2,
        "body": "hello world \u003cimg class=\"emoji\" alt=\":beerparrot:\" title=\":beerparrot:\" src=\"/img/emoji/beerparrot.gif\"\u003e",
        "rawBody": "hello world \u003cimg class=\"emoji\" alt=\":beerparrot:\" title=\":beerparrot:\" src=\"/img/emoji/beerparrot.gif\"\u003e",
        "id": "j-rXteG7R",
        "visible": true,
        "timestamp": "2021-08-12T07:53:12.061982913Z"
    }
}
';
	return( $json );
	}



function webhook_name_change($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$eventdata_type=$json['eventData']['type'];
	$eventdata_id=$json['eventData']['id'];
	$eventdata_timestamp=$json['eventData']['timestamp'];
	$eventdata_user_id=$json['eventData']['user']['id'];
	$eventdata_user_displayname=$json['eventData']['user']['displayName'];
	$eventdata_user_displaycolor=$json['eventData']['user']['displayColor'];
	$eventdata_user_createat=$json['eventData']['user']['createAt'];
	$eventdata_user_previousnames=$json['eventData']['user']['previousNames'];
	$eventdata_user_namechangedat=$json['eventData']['user']['namechangedAt'];
	$eventdata_user_isbot=$json['eventData']['user']['isBot'];
	$eventdata_user_authenticated=$json['eventData']['user']['authenticated'];
	$eventdata_clientid=$json['eventData']['clientId'];
	$eventdata_newname=$json['eventData']['newName'];

	$csv="$dttm|$type|";
	$csv.="$eventdata_type|$eventdata_id|$eventdata_timestamp|";
	$csv.="$eventdata_user_id|$eventdata_user_displayname|$eventdata_user_displaycolor|";
	$csv.="$eventdata_user_createat|$eventdata_user_previousnames|$eventdata_user_namechangedat|";
	$csv.="$eventdata_user_previousnames|$eventdata_user_namechangedat|$eventdata_user_isbot|";
	$csv.="$eventdata_user_authenticated|$eventdata_clientid|$eventdata_newname\n";

#	$csv="BUGS_110 webhook_name_change type=$type json=$json<br>\n";
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );


$name_change='
{
    "type": "NAME_CHANGE",
    "eventData": {
	"type": "NAME_CHANGE",
        "id": "",
        "timestamp": "0001-01-01T00:00:00Z",
        "user": {
		"id": "qSRQpeM7R",
		"displayName": "NotSoLazyDaisy",
		"displayColor": 182,
		"createdAt": "2021-08-12T07:51:37.470812684Z",
		"previousNames": ["lazyDaisy"],
		"nameChangedAt": "2022-09-19T12:33:59.423278816+02:00",
		"isBot": false,
		"authenticated": false
		},
	"clientId": 2,
        "newName": "NotSoLazyDaisy"
		}
	}
';

	return($json);
	}

function webhook_user_joined($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$id=$json['eventData']['id'];
	$timestamp=$json['eventData']['timestamp'];
	$user_id=$json['eventData']['user']['id'];
	$user_displayname=$json['eventData']['user']['displayName'];
	$user_displaycolor=$json['eventData']['user']['displayColor'];
	$user_createdat=$json['eventData']['user']['createdAt'];
	$user_previousnames=$json['eventData']['user']['previousNames'];
	$user_namechangedat=$json['eventData']['user']['nameChangedAt'];
	$user_isbot=$json['eventData']['user']['isBot'];
	$user_authenticated=$json['eventData']['user']['authenticated'];
	$clientid=$json['eventData']['clientId'];

	$bugs="BUGS_180 webhook_user_joined type=$type json=$json<br>\n";
	$csv="$dttm|$type|$id|$timestamp|$user_id|$user_displayname|$user_displaycolor|";
	$csv.="$user_createdat|$user_previousname|$user_namechangedat|$user_isbot|$user_authenticated|$clientid\n";
#	$fp = file_put_contents( $ofile, "$bugs", FILE_APPEND );
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );

$user_joined='{
    "type": "USER_JOINED",
    "eventData": {
        "id": "wAgcTeM7g",
        "timestamp": "2021-08-12T08:19:28.921355401Z",
        "user": {
            "id": "yFgco6M7R",
            "displayName": "laughing-cray",
            "displayColor": 257,
            "createdAt": "2021-08-12T08:19:28.759651178Z",
            "previousNames": ["laughing-cray"],
            "nameChangedAt": "0001-01-01T00:00:00Z",
            "isBot": false,
            "authenticated": false
        },
        "clientId": 2
    }
}
';
	return($json);
	}

function webhook_user_parted($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$id=$json['eventData']['id'];
	$timestamp=$json['eventData']['timestamp'];
	$user_id=$json['eventData']['user']['id'];
	$user_displayname=$json['eventData']['user']['displayName'];
	$user_displaycolor=$json['eventData']['user']['displayColor'];
	$user_createdat=$json['eventData']['user']['createdAt'];
	$user_previousnames=$json['eventData']['user']['previousNames'];
	$user_namechangedat=$json['eventData']['user']['nameChangedAt'];
	$user_isbot=$json['eventData']['user']['isBot'];
	$user_authenticated=$json['eventData']['user']['authenticated'];
	$user_clientid=$json['eventData']['clientId'];


	$bugs="BUGS_220 webhook_user_parted type=$type json=$json<br>\n";

	$csv="$dttm|$type|$id|$timestamp|";
	$csv.="$user_id|$user_displayname|$user_displaycolor|$user_createdat|$user_previousnames|";
	$csv.="$user_namechangedat|$user_isbot|$user_authenticated|$user_clientid\n";
#	$fp = file_put_contents( $ofile, "$bugs", FILE_APPEND );
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );

	return($json);
	}


function webhook_stream_started($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$id=$json['eventData']['id'];
	$name=$json['eventData']['name'];
	$streamtitle=$json['eventData']['streamTitle'];
	$summary=$json['eventData']['summary'];
	$timestamp=$json['eventData']['timestamp'];
#	$csv="BUGS_170 webhook_stream_started type=$type json=$json<br>\n";
	$csv="$dttm|$type|$id|$name|$streamtitle|$summary|$timestamp\n";
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );

$stream_started='{
    "type": "STREAM_STARTED",
    "eventData": {
		"id": "WtokptnVR",
		"name": "Owncast",
		"streamTitle": "",
		"summary": "Welcome to your new Owncast server! This description can be changed in the admin. Visit https://owncast.online/docs/configuration/ to learn more.",
		"timestamp": "2022-09-19T12:30:26.97907142+02:00"
		}
	}
';
	return($json);
	}

function webhook_stream_stopped($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$id=$json['eventData']['id'];
	$name=$json['eventData']['name'];
	$streamtitle=$json['eventData']['streamTitle'];
	$summary=$json['eventData']['summary'];
	$timestamp=$json['eventData']['timestamp'];
#	$csv="BUGS_190 webhook_stream_stopped type=$type json=$json<br>\n";
	$csv="$dttm|$type|$id|$name|$streamtitle|$summary|$timestamp\n";
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );


$stream_stopped='{
    "type": "STREAM_STOPPED",
    "eventData": {
        "id": "YP-aptn4g",
        "name": "Owncast",
        "streamTitle": "",
        "summary": "Welcome to your new Owncast server! This description can be changed in the admin. Visit https://owncast.online/docs/configuration/ to learn more.",
        "timestamp": "2022-09-19T12:40:21.205872269+02:00"
    }
}
';
	return($json);
	}


function webhook_stream_title_updated($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$id=$json['eventData']['id'];
	$name=$json['eventData']['name'];
	$status_lastconnecttime=$json['status']['lastConnectTime'];
	$status_lastdisconnecttime=$json['status']['lastDisconnectTime'];
	$status_versionnumber=$json['status']['versionNumber'];
	$status_streamtitle=$json['status']['streamTitle'];
	$status_viewercount=$json['status']['viewerCount'];
	$status_overallmaxviewercount=$json['status']['overallMaxViewerCount'];
	$status_sessionmaxviewercount=$json['status']['sessionMaxViewerCount'];
	$status_online=$json['status']['online'];

	$streamtitle=$json['eventData']['streamTitle'];
	$summary=$json['eventData']['summary'];
	$timestamp=$json['eventData']['timestamp'];

	$csv="$dttm|$type|$name|";
	$csv.="$status_lastconnectiontime|$status_lastdisconnecttime|$status_versionnumber";
	$csv.="$status_streamtitle|$status_viewercount|$status_overallmaxviewercount|$status_sessionmaxviewercount|";
	$csv.="$status_online|";
	$csv.="$streamtitle|$summary|$timestamp\n";

#	$bugs="BUGS_220 webhook_title_updates type=$type json=$json<br>\n";
#	$fp = file_put_contents( $ofile, "$bugs", FILE_APPEND );
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );


$stream_stream_title_updated='{
	"type": "STREAM_TITLE_UPDATED",
	"eventData": {
		"id": "DmeikEf4Rz",
		"name": "New Owncast Server",
		"status": {
			"lastConnectTime": null,
			"lastDisconnectTime": "2024-10-24T22:35:05Z",
			"versionNumber": "0.1.3",
			"streamTitle": "Test stream title change",
			"viewerCount": 0,
			"overallMaxViewerCount": 7,
			"sessionMaxViewerCount": 2,
			"online": false
			},
		"streamTitle": "Test stream title change",
		"summary": "This is a new live video streaming server powered by Owncast.",
		"timestamp": "2023-03-27T21:50:10.121391094-07:00"
		}
	}
';
	return($json);
	}

function webhook_visibility_update($json) {
        $dttm=date('Ymd_His');
	$ofile="owncast.txt";
	$type=$json['type'];
	$id=$json['eventData']['id'];
	$messageids=$json['eventData']['MessageIDs'];
	$timestamp=$json['eventData']['timestamp'];
	$visible=$json['eventData']['Visible'];
	
#	$csv="BUGS_250 webhook_visibility_updates type=$type json=$json<br>\n";
	$csv="$dttm|$type|$id|$messageids|$timestamp|$visible\n";
	$fp = file_put_contents( $ofile, "$csv", FILE_APPEND );


$visibility_update='{
    "type": "VISIBILITY-UPDATE",
    "eventData": {
        "id": "zqGupt7VR",
        "MessageIDs": [
            "-Zzltt74g",
            "rvd2ppn4g"
        ],
        "timestamp": "2022-09-19T12:44:28.225779601+02:00",
        "Visible": false
    }
}
';

	return($json);
	}


function api($args) {
	$host="http://ka22:8080";
	$token="2hrhyKWQuU3pfgqzn_3ASmqH2XCYvKx3WbauxdLFdoA=";
	$cmd=""; $out=""; 
	$string=""; $body=""; 

$apis="
/api/integrations/chat/system
/api/integrations/chat/system/client
/api/integrations/status
/api/integrations/streamtitle
/api/integrations/chat
/api/integrations/clients
/api/status
/api/chat
/api/admin/viewers
";



	if( isset( $_REQUEST['host'] )) { $host=$_REQUEST['host']; }
	if( isset( $_REQUEST['token'] )) { $token=$_REQUEST['token']; }
	if( isset( $_REQUEST['api'] )) { $api=$_REQUEST['api']; }
	if( isset( $_REQUEST['s'] )) { $string=$_REQUEST['s']; }
	if( isset( $_REQUEST['str'] )) { $string=$_REQUEST['str']; }
	if( isset( $_REQUEST['string'] )) { $string=$_REQUEST['string']; }
	

	if( $api == "/api/integrations/chat/system" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }

		$cmd="curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '{\"body\": \"$body\"}' $hostapi";
		print( "<h1>BUGS_401 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_402 out=$out</h1>\n" );
		return( $out );
		}

	if( $api == "/api/integrations/chat/system/client" ) {	
		$hostapi="$host$api";
		$clientid=""; if( isset($_REQUEST['clientid'])) { $clientid=$_REQUEST['clientid']; }
		$timestamp=""; if( isset( $_REQUEST['timestamp'] )) { $timestamp=$_REQUEST['timestamp']; }
		$type=""; if( isset( $_REQUEST['type'] )) { $type=$_REQUEST['type']; }
		$id=""; if( isset( $_REQUEST['id'] )) { $id=$_REQUEST['id']; }
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }

		$hostapi="$host$api/$clientid";
		$payload="{";
		$payload.="\"timestamp\": \"$timestamp\",";
		$payload.="\"type\": \"$type\",";
		$payload.="\"id\": \"$id\",";
		$payload.="\"body\": \"$body\",";
		$payload.="}";

		$cmd="curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";

#		$cmd="curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '{\"body\": \"$body\"}' $hostapi";
		print( "<h1>BUGS_401 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_402 out=$out</h1>\n" );
		return( $out );
		}

	if( $api == "/api/integrations/status" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="}";
		$cmd="curl -X GET -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_441 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_442 out=$out</h1>\n" );
		return( $out );
		}
	if( $api == "/api/integrations/streamtitle" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="\"message\":\"\"";
		$payload.="}";
		$cmd="curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_451 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_452 out=$out</h1>\n" );
		return( $out );
		}


	if( $api == "/api/integrations/chat" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="\"message\":\"\"";
		$payload.="}";
		$cmd="curl -X GET -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_461 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_462 out=$out</h1>\n" );
		return( $out );
		}

	if( $api == "/api/integrations/clients" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="\"message\":\"\"";
		$payload.="}";
		$cmd="curl -X GET -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_471 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_472 out=$out</h1>\n" );
		return( $out );
		}

	if( $api == "/api/status" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="\"message\":\"\"";
		$payload.="}";
		$cmd="curl -X GET -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_501 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_502 out=$out</h1>\n" );
		return( $out );
		}

	if( $api == "/api/chat" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="\"timestamp\":\"\"";
		$payload.="\"type\":\"\"";
		$payload.="\"id\":\"\"";
		$payload.="\"user\":\"\"";
		$payload.="\"hiddenAt\":\"\"";
		$payload.="\"clientId\":\"\"";
		$payload.="\"body\":\"\"";
		$payload.="}";
		$cmd="curl -X GET -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_511 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_512 out=$out</h1>\n" );
		return( $out );
		}


	if( $api == "/api/admin/viewers" ) {	
		$hostapi="$host$api";
		$body=""; if( isset( $_REQUEST['body'] )) { $body=$_REQUEST['body']; }
		$payload="{";
		$payload.="\"firstSeen\":\"\"";
		$payload.="\"geo\":\"\"";
		$payload.="\"userAgent\":\"\"";
		$payload.="\"ipAddress\":\"\"";
		$payload.="\"clientID\":\"\"";
		$payload.="}";
		$cmd="curl -X GET -H \"Content-Type: application/json\" -H \"Authorization: Bearer $token\" -d '$payload' $hostapi";
		print( "<h1>BUGS_531 api=$api cmd=$cmd</h1>\n" );
		$out=shell_exec($cmd);
		print( "<h1>BUGS_532 out=$out</h1>\n" );
		return( $out );
		}


	print( "<h1>BUGS_390  api api=$api string=$string token=$token</h1>\n" );

	if( $cmd != "" ) { 
		print( "<h1>BUGS_400 cmd=$cmd</h1>\n" );
		$out="_OUT_";
#		$out=shell_exec($cmd);
		print( "<h1>BUGS_381 cmd=$cmd  out=$out</h1>\n" );
		}
	return($args);
	}
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer