authentication and some experimenting

This commit is contained in:
2024-02-15 21:30:12 +01:00
parent 393f5db892
commit f446953934
11 changed files with 221 additions and 17 deletions

View File

@@ -192,5 +192,121 @@ function showServerErrorScreen(){
}
function authenticateJellyfin(){
console.log("yapppa!")
var serverAddress = atv.localStorage['jellyfin_server_address'];
var username = atv.localStorage['jellyfin_username'];
var password = atv.localStorage['jellyfin_password'];
var xhttp = new XMLHttpRequest();
var url = serverAddress + '/Users/AuthenticateByName';
xhttp.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status === 200) {
var responseJson = JSON.parse(this.responseText);
// console.log("Authentication successful. Response:", responseJson);
// Extracting ServerId and AccessToken
var serverId = responseJson.ServerId;
var accessToken = responseJson.AccessToken;
// Storing ServerId and AccessToken in atv storage
atv.localStorage['jellyfin_serverid'] = serverId;
atv.localStorage['jellyfin_authtoken'] = accessToken;
atv.localStorage['jellyfin_loggedin'] = '1';
showAuthSuccessScreen();
} else {
console.error("Error occurred during authentication. Status:", this.status);
console.error("Response:", this.responseText);
showAuthErrorScreen();
}
}
};
xhttp.onerror = function() {
console.error("An error occurred during the request.");
showAuthErrorScreen();
};
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-Type", "application/json");
// Constructing the Authorization header
var token = "";
var client = "JellyCAT Apple TV";
var version = atv.jcathost.Version;
var deviceId = atv.device.udid;
var device = atv.device.displayName;
var authHeaderValue = 'MediaBrowser Token="' + encodeURIComponent(token) + '", ' +
'Client="' + encodeURIComponent(client) + '", ' +
'Version="' + encodeURIComponent(version) + '", ' +
'DeviceId="' + encodeURIComponent(deviceId) + '", ' +
'Device="' + encodeURIComponent(device) + '"';
xhttp.setRequestHeader("Authorization", authHeaderValue);
var requestBody = JSON.stringify({
"Username": username,
"Pw": password
});
xhttp.send(requestBody);
}
function showAuthErrorScreen(){
var xmlstr = '<?xml version="1.0" encoding="UTF-8"?>' +
'<atv>' +
' <body>' +
' <dialog id="com.jellycat.jellyfin-connect-error-dialog">' +
' <title>Error Authenticating Jellyfin Server:</title>' +
' <description>\n' +
'We could not authenticate the user you provided. Please check the username or password. Error logged.\n\n\n' +
'Please let us know if you believe this is an error\n\nPress MENU to go back</description>' +
' </dialog>' +
' </body>' +
'</atv>';
xmlDoc = atv.parseXML(xmlstr);
atv.loadXML(xmlDoc);
}
function showAuthSuccessScreen(){
var xmlstr =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<atv>' +
'<head>' +
'<script src="http://jcathost.dns/js/jcm.js"/>' +
'<script src="http://jcathost.dns/js/jellyfin-setup.js"/>' +
'</head>' +
'<body>' +
'<optionDialog id="com.jellycat.jellyfin-connect-success-dialog">' +
'<header>' +
'<simpleHeader accessibilityLabel="Dialog with Options">' +
'<title>Success:</title>' +
'</simpleHeader>' +
'</header>' +
'<description>Yay! You\'ve logged in successfully. Feel free to exit settings and dive in!</description>' +
'<menu>' +
'<initialSelection>' +
'<row>0</row>' +
'</initialSelection>' +
'<sections>' +
'<menuSection>' +
'<items>' +
'<oneLineMenuItem id="list_0" accessibilityLabel="Option 1" onSelect="goHome();">' +
'<label>Start</label>' +
'</oneLineMenuItem>' +
'<oneLineMenuItem id="list_1" accessibilityLabel="Option 2" onSelect="atv.unloadPage();">' +
'<label>Go back</label>' +
'</oneLineMenuItem>' +
'</items>' +
'</menuSection>' +
'</sections>' +
'</menu>' +
'</optionDialog>' +
'</body>' +
'</atv>';
xmlDoc = atv.parseXML(xmlstr);
atv.loadXML(xmlDoc);
}
function goHome(){
atvutils.loadURL("https://" + atv.jcathost.SigHost + "/xml/home.xml");
}

52
app/js/search.js Normal file
View File

@@ -0,0 +1,52 @@
// /\_/|
// { ' ' } JellyCAT
// \____\
function checkLogin() {
if (atv.localStorage['jellyfin_loggedin'] === '1') {
renderSearchScreen();
} else {
console.log("No authenticated user.");
renderLoginRequestScreen();
}
}
function renderSearchScreen() {
xmlstr = '<?xml version="1.0" encoding="UTF-8"?>' +
'<atv>' +
' <head>' +
' <script src="http://jcathost.dns/js/jcm.js"/>' +
' <script src="http://jcathost.dns/js/searchfuncs.js"/>' +
' </head>' +
' <body>' +
' <search id="com.jellycat.search">' +
' <header>' +
' <simpleHeader accessibilityLabel="Search">' +
' <title>Search</title>' +
' </simpleHeader>' +
' </header>' +
' <baseURL></baseURL>' +
' </search>' +
' </body>' +
'</atv>';
xmlDoc = atv.parseXML(xmlstr);
atv.loadAndSwapXML(xmlDoc);
}
function renderLoginRequestScreen() {
xmlstr = '<?xml version="1.0" encoding="UTF-8"?>' +
'<atv>' +
' <head>' +
' <script src="http://jcathost.dns/js/jcm.js"/>' +
' <script src="http://jcathost.dns/js/search.js"/>' +
' </head>' +
' <body>' +
' <dialog id="com.jellycat.pleaselogin-dialog">' +
' <title>Not Connected</title>' +
' <description>Please go to the settings tab and add a Jellyfin Server.</description>' +
' </dialog>' +
' </body>' +
'</atv>';
xmlDoc = atv.parseXML(xmlstr);
atv.loadAndSwapXML(xmlDoc);
}

6
app/js/searchfuncs.js Normal file
View File

@@ -0,0 +1,6 @@
// /\_/|
// { ' ' } JellyCAT
// \____\
// the goal here is to grab the input and generate results, but that's going to be hard if we don't want to use the
// GOlang server...

View File

@@ -3,6 +3,7 @@
// \____\
function printSessionStorage() {
console.log("======== Printing ATV Session storage ===========")
var keys = ['test', 'exampleKey'];
@@ -17,8 +18,9 @@ function printSessionStorage() {
}
function printLocalStorage() {
console.log("======== Printing ATV Local storage ===========")
var keys = ['test', 'jellyfin_server_address', 'jellyfin_username', 'jellyfin_password', 'jellyfin_auth'];
var keys = ['test', 'jellyfin_server_address', 'jellyfin_username', 'jellyfin_password', 'jellyfin_serverid', 'jellyfin_authtoken', 'jellyfin_loggedin'];
keys.forEach(function(key) {
var value = atv.localStorage.getItem(key);
@@ -42,4 +44,7 @@ function setTestLocalStorageItem() {
console.log('Test item set in localStorage.');
}
function setFakeLogout() {
console.log("Setting fake Jellyfin logout Key")
atv.localStorage['jellyfin_loggedin'] = '0';
}

View File

@@ -38,7 +38,7 @@
<oneLineMenuItem id="list_5" accessibilityLabel="Option 6" onSelect="console.log('UDID: ' + atv.device.udid);">
<label>Print device UDID (log)</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_6" accessibilityLabel="Option 7" onSelect="console.log('UDID: ' + atv.device.displayName);">
<oneLineMenuItem id="list_6" accessibilityLabel="Option 7" onSelect="console.log('DN: ' + atv.device.displayName);">
<label>Print device DisplayName (log)</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_7" accessibilityLabel="Option 8" onSelect="console.log('Unloading page'); atv.unloadPage();">

View File

@@ -11,16 +11,19 @@
<oneLineMenuItem id="list_0" accessibilityLabel="Set test session storage key" onSelect="setTestSessionStorageItem();">
<label>Set ATV APP session storage key (test)</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_0" accessibilityLabel="Set test local storage key" onSelect="setTestLocalStorageItem();">
<oneLineMenuItem id="list_1" accessibilityLabel="Set test local storage key" onSelect="setTestLocalStorageItem();">
<label>Set ATV APP local storage key (test)</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_1" accessibilityLabel="Print session storage (log)" onSelect="printSessionStorage();">
<oneLineMenuItem id="list_2" accessibilityLabel="Set fake logout local storage key" onSelect="setFakeLogout();">
<label>Set Fake Jellyfin Logged Out key</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_3" accessibilityLabel="Print session storage (log)" onSelect="printSessionStorage();">
<label>Print ATV App session storage (log)</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_2" accessibilityLabel="Print ATV storage (log)" onSelect="printLocalStorage();">
<oneLineMenuItem id="list_4" accessibilityLabel="Print ATV storage (log)" onSelect="printLocalStorage();">
<label>Print ATV App local storage (log)</label>
</oneLineMenuItem>
<oneLineMenuItem id="list_3" accessibilityLabel="Clear ATV Storage and exit" onSelect="console.log('CLEARING ALL APP STORAGE AND EXITING APP'); atv.localStorage.clear(); atv.sessionStorage.clear(); atv.exitApp();">
<oneLineMenuItem id="list_5" accessibilityLabel="Clear ATV Storage and exit" onSelect="console.log('CLEARING ALL APP STORAGE AND EXITING APP'); atv.localStorage.clear(); atv.sessionStorage.clear(); atv.exitApp();">
<label>Clear ATV App Storage and exit App</label>
</oneLineMenuItem>
</items>

View File

@@ -3,7 +3,10 @@
<body>
<dialog id="com.jellycat.help-page">
<title>Help</title>
<description>For assistance, please visit the JellyCAT documentation at https://github.com/SEPPDROID/JellyCAT/. If you encounter any issues, kindly raise them on the GitHub repository at https://github.com/SEPPDROID/JellyCAT/issues.</description>
<description>For assistance, please visit the JellyCAT documentation at https://github.com/SEPPDROID/JellyCAT/. If you encounter any issues, kindly raise them on the GitHub repository at https://github.com/SEPPDROID/JellyCAT/issues.
Press MENU to go back</description>
</dialog>
</body>
</atv>

View File

@@ -8,25 +8,29 @@
<navigation currentIndex="0">
<navigationItem id="nav1">
<title>Home</title>
<url></url>
<url>http://jcathost.dns/xml/homescreen.xml</url>
</navigationItem>
<navigationItem id="nav2">
<title>Favorites</title>
<url></url>
<url>http://jcathost.dns/xml/favoritesscreen.xml</url>
</navigationItem>
<navigationItem id="nav3">
<title>Movies</title>
<url></url>
<url>http://jcathost.dns/xml/movies.xml</url>
</navigationItem>
<navigationItem id="nav4">
<title>TV-Shows</title>
<url></url>
<url>http://jcathost.dns/xml/shows.xml</url>
</navigationItem>
<navigationItem id="nav5">
<title>Search</title>
<url></url>
<title>Music</title>
<url>http://jcathost.dns/xml/music.xml</url>
</navigationItem>
<navigationItem id="nav6">
<title>Search</title>
<url>http://jcathost.dns/xml/search.xml</url>
</navigationItem>
<navigationItem id="nav7">
<title>Settings</title>
<url>http://jcathost.dns/xml/settings.xml</url>
</navigationItem>

16
app/xml/search.xml Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<atv>
<head>
<script src="http://jcathost.dns/js/jcm.js"/>
<script src="http://jcathost.dns/js/search.js"/>
</head>
<body>
<optionList id="fakeUpdater" autoSelectSingleItem="true">
<items>
<oneLineMenuItem id="0" onSelect="checkLogin();">
<label></label>
</oneLineMenuItem>
</items>
</optionList>
</body>
</atv>

View File

@@ -2,7 +2,6 @@
<atv>
<head>
<script src="http://jcathost.dns/js/jcm.js"/>
<script src="http://jcathost.dns/js/about.js"/>
<script src="http://jcathost.dns/js/settingloader.js"/>
</head>
<body>

View File

@@ -26,7 +26,7 @@ func main() {
// Default information store
JellyCAT = JcatDefaults{
Version: "0.1.3revA",
Version: "0.1.3revB",
Name: "JellyCAT Serving stHack",
HostName: config.CertName,
HostIP: config.HijackIP,