From f6e03a291ecb4b73c8aeb0c4c11213f5ad85fab3 Mon Sep 17 00:00:00 2001 From: "Mr. Snowy" Date: Wed, 15 Nov 2023 23:08:02 +0100 Subject: [PATCH] before massive code rewrites, if i need to look at older code --- .gitignore | 4 +- public_html/404.php | 2 +- public_html/compatibility/app.js | 13 +- public_html/compatibility/index.html | 4 +- public_html/compatibility/styles.css | 2 +- public_html/images/NA.png | Bin 0 -> 1457 bytes public_html/images/fpPS4Logo.png | Bin 0 -> 5333 bytes public_html/images/fpPS4Logo1080.png | Bin 0 -> 262354 bytes public_html/images/fpPS4Logo512.png | Bin 0 -> 57827 bytes public_html/index.html | 168 ++++++++++------- public_html/parts/footer.html | 4 +- public_html/robots.txt | 4 + public_html/scripts/api.php | 116 ++++++++++++ public_html/scripts/bot.php | 13 -- public_html/scripts/issue_fetcher.php | 251 ++++++++++++++++++++------ 15 files changed, 439 insertions(+), 142 deletions(-) create mode 100644 public_html/images/NA.png create mode 100644 public_html/images/fpPS4Logo.png create mode 100644 public_html/images/fpPS4Logo1080.png create mode 100644 public_html/images/fpPS4Logo512.png create mode 100644 public_html/scripts/api.php delete mode 100644 public_html/scripts/bot.php diff --git a/.gitignore b/.gitignore index de9a4ee..5c55c2b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ public_html/cgi-bin public_html/.htaccess public_html/ads.txt public_html/images/Thumbs.db -public_html/images/CUSA \ No newline at end of file +public_html/images/CUSA +public_html/images/HOMEBREW +public_html/scripts/HBstore.db \ No newline at end of file diff --git a/public_html/404.php b/public_html/404.php index caaffde..814f13a 100644 --- a/public_html/404.php +++ b/public_html/404.php @@ -2,7 +2,7 @@ 404 :/ - +

404: Not Found :/

diff --git a/public_html/compatibility/app.js b/public_html/compatibility/app.js index c7e481d..5f258ee 100644 --- a/public_html/compatibility/app.js +++ b/public_html/compatibility/app.js @@ -18,6 +18,16 @@ let updatePageValue = false; let noImagesLocked = false; let maxValue; +var urlParams = new URLSearchParams(window.location.search); +var tagParam = urlParams.get('tag'); +if (tagParam) { + tagFilter.push(tagParam); + tagElementForFilter = document.getElementById(tagParam + 'Bar'); + tagParentForFilter = tagElementForFilter.parentElement; + tagParentForFilter.classList.toggle('selected'); +} + + function setCookie(name, value) { var date = new Date(); date.setMonth(date.getMonth() + 1); @@ -101,7 +111,7 @@ avif.onerror = function() { // Page Load document.addEventListener('DOMContentLoaded', function() { - fetch('https://fpps4.net/scripts/search.php?q=&stats') + fetch('https://fpps4.net/scripts/search.php?q=&stats&tag='+ tagFilter) .then(response => response.text()) .then(data => { document.querySelector('#gameWrapper').innerHTML = data; @@ -190,7 +200,6 @@ function UpdateSearchResults() { // Filters function filter() { var ids = ['Nothing', 'Boots', 'Menus', 'Ingame', 'Playable']; - ids.forEach(id => { element = document.getElementById(id + 'Bar'); parent = element.parentElement; diff --git a/public_html/compatibility/index.html b/public_html/compatibility/index.html index ce61a23..abb2383 100644 --- a/public_html/compatibility/index.html +++ b/public_html/compatibility/index.html @@ -8,7 +8,7 @@ - + @@ -17,7 +17,7 @@ - + + + +
+

Game Compatibility List

+

These are the games that have been tested with fpPS4.
Click on an image to view the game's GitHub issue.
The database is updated every 20 minutes.

+
+
Playable
+
+
Menus
+
Ingame
+
+
+
Nothing
+
Boots
+
+
+
+ + +
+ +
+
Oldest
+
No Images
+
Dates
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

0 results in 0ms

+
+
+ +

1

+ +

1

+ +
+
Trademarks and logos displayed on this website are the property of their respective owners.
The use of any third-party trademarks, brand names, product names, and logos is for
informational purposes only and does not imply endorsement or sponsorship.
+
+
+ + + \ No newline at end of file diff --git a/public_html/parts/footer.html b/public_html/parts/footer.html index fb304a9..f90fa46 100644 --- a/public_html/parts/footer.html +++ b/public_html/parts/footer.html @@ -61,7 +61,7 @@
- red-prig github icon + red-prig github icon

red-prig: Developer of fpPS4

@@ -69,6 +69,6 @@

Website by: Mr. Snowy © 2023

- Mr.Snowy github icon + Mr.Snowy github icon
\ No newline at end of file diff --git a/public_html/robots.txt b/public_html/robots.txt index 5371fff..ed34004 100644 --- a/public_html/robots.txt +++ b/public_html/robots.txt @@ -1,3 +1,7 @@ User-agent: * Allow: / + +User-agen: GPTBot +Disallow: / + Sitemap: https://fpps4.net/sitemap.xml \ No newline at end of file diff --git a/public_html/scripts/api.php b/public_html/scripts/api.php new file mode 100644 index 0000000..8b2cc9a --- /dev/null +++ b/public_html/scripts/api.php @@ -0,0 +1,116 @@ + $value) { + +// if ($header === "Token") { + +// if ($value === $validSecret) { +// die('yeey you got in !'); +// } +// } +// } + + +/// makes it so the api is accessible by: headers, browser query and by command line arguments :3 +if ((isset($_GET[$validArgument]) && $_GET[$validArgument] === $validSecret) || (isset($argv[1]) && $argv[1] === $validSecret) || isset($_SERVER['HTTP_AUTHORIZATION']) === $validSecret) { + +/// processing user input +$cusaCodes = isset($_GET['cusa']) ? $_GET['cusa'] : ''; +$homebrews = isset($_GET['homebrew']) ? $_GET['homebrew'] : ''; + +$cusaCodes = filter_var($cusaCodes, FILTER_SANITIZE_STRING); +$homebrews = filter_var($homebrews, FILTER_SANITIZE_STRING); + + + +if ($cusaCodes || $homebrews) { + + /// make connection to database + $host = DATABASE_HOST; + $database = DATABASE_NAME; + $username = DATABASE_USERNAME; + $password = DATABASE_PASSWORD; + + try { + $conn = new PDO("mysql:host=$host;dbname=$database", $username, $password); + } catch (PDOException $e) { + die("The server got itself into trouble, sorry for that."); + } + + + /// variables + $cusacodeArray = array(); + $homebrewArray = array(); + $cusacode = explode(',', $cusaCodes); + $homebrew = explode(',', $homebrews); + + /// handles cusa codes and gets status + if ($cusaCodes) { + foreach ($cusacode as $code) { + $query = "SELECT tags FROM issues WHERE cusacode = :cusacode"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':cusacode', $code, PDO::PARAM_STR); + $stmt->execute(); + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + // print_r($result); // debug + + if ($result) { + $tag = $result["0"]["tags"]; + } else { + $tag = "N/A"; + } + + // echo "$tag"; // debug + $cusacodeArray[] = array( + "id" => $code, + "tag" => $tag + ); + } + } + + if ($homebrews) { + foreach ($homebrew as $code) { + $query = "SELECT tags FROM issues WHERE title = :homebrew"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':homebrew', $code, PDO::PARAM_STR); + $stmt->execute(); + $HBresult = $stmt->fetchAll(PDO::FETCH_ASSOC); + // print_r($HBresult); // debug + + if ($HBresult) { + $tag = $HBresult["0"]["tags"]; + } else { + $tag = "N/A"; + } + + $homebrewArray[] = array( + "title" => $code, + "tag" => $tag + ); + } + } + + $data = array( + "cusacode" => $cusacodeArray, + "homebrew" => $homebrewArray + ); + + /// end + header('Content-Type: application/json'); + $jsonData = json_encode($data); + //$jsonData = json_encode($data, JSON_PRETTY_PRINT); + echo $jsonData; + $conn = null; //exit connection +} + + +} else { + http_response_code(404); + include("/home/{$serverUsername}/domains/fpps4.net/public_html/404.php"); +}?> \ No newline at end of file diff --git a/public_html/scripts/bot.php b/public_html/scripts/bot.php deleted file mode 100644 index b33f9e7..0000000 --- a/public_html/scripts/bot.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/public_html/scripts/issue_fetcher.php b/public_html/scripts/issue_fetcher.php index f718c6e..013498c 100644 --- a/public_html/scripts/issue_fetcher.php +++ b/public_html/scripts/issue_fetcher.php @@ -1,4 +1,6 @@ ["header" => "User-Agent: $homebrewUseragent\r\n"]]); + $response = file_get_contents("https://api.pkg-zone.com/api.php?db_check_hash=true", false, $header); + if ($response !== false) { + $data = json_decode($response); + $hash = $data->hash; + $md5Hash = md5_file("/home/{$serverUsername}/domains/fpps4.net/public_html/scripts/HBstore.db"); // will give warning on first download + if ($hash === $md5Hash) { + echo("the db is the same! response: $hash local: $md5Hash
"); + } else { + echo("the db is diffrent! response: $hash local: $md5Hash downloading db
"); + $fileContent = file_get_contents("https://api.pkg-zone.com/store.db", false, $header); + if ($fileContent !== false) { + file_put_contents("/home/{$serverUsername}/domains/fpps4.net/public_html/scripts/HBstore.db", $fileContent) !== false ? die("DB downloaded and saved successfully.
") : die("Error saving the downloaded DB.
"); + } else { + die("Error downloading the DB from the URL."); + } + } + } else { + echo("Error verifying hash, ignoring for now."); + } + + $dbFile = "/home/{$serverUsername}/domains/fpps4.net/public_html/scripts/HBstore.db"; + try { + $homebrewDB = new PDO("sqlite:$dbFile"); + echo "Connected to the database successfully!
"; + } catch (PDOException $e) { + echo "Connection failed: " . $e->getMessage() . "
"; + } + $conn = new PDO("mysql:host=$host;dbname=$database", $username, $password); $conn->query("DROP TABLE IF EXISTS newIssues"); @@ -36,13 +69,14 @@ try { )"; $sqlSkips = "CREATE TABLE IF NOT EXISTS GameSkips ( - cusaCode VARCHAR(10) PRIMARY KEY + code VARCHAR(130) PRIMARY KEY )"; $conn->exec($sqlOld); $conn->exec($sqlNew); $conn->exec($sqlSkips); echo "Tables created successfully.
"; + // die("Tables created successfully.
"); } catch (PDOException $e) { die("Error creating tables: " . $e->getMessage()); @@ -104,6 +138,15 @@ function insert_issue($issue, $conn) { $cusaCode = "HOMEBREW"; $clean_title = preg_replace('/\s-\s.*$/', '', $title); $clean_title = trim(explode('(Homebrew)', $clean_title)[0]); + $clean_title = trim(explode('Homebrew', $clean_title)[0]); + //$clean_title = trim(explode('Game', $clean_title)[0]); + $clean_title = rtrim($clean_title, ' '); + } else if (in_array("app-system-fw505", array_column($issue['labels'], 'name'))){ + $cusaCode = "SYSTEM APP"; + $clean_title = preg_replace('/\s-\s.*$/', '', $title); + } else if (in_array("app-ps2game", array_column($issue['labels'], 'name'))){ + $cusaCode = "PS2 GAME"; + $clean_title = preg_replace('/\s-\s.*$/', '', $title); } else { $clean_title = preg_replace('/\b' . preg_quote($cusaCode, '/') . '\b/', '', $title); $clean_title = preg_replace('/\s+-\s+/', ' - ', $clean_title); @@ -168,62 +211,95 @@ function extract_cusaCode($title) { } // Images logic -function get_image($cusaCode, $conn, $serverUsername) { - global $tmdbHash; - $key = hex2bin($tmdbHash); - $hashme = $cusaCode . '_00'; - $hash = strtoupper(hash_hmac('sha1', $hashme, $key)); - $url = "https://tmdb.np.dl.playstation.net/tmdb2/{$cusaCode}_00_{$hash}/{$cusaCode}_00.json"; - - $headers = get_headers($url); - if ($headers !== false && strpos($headers[0], '200') !== false) { - $response = file_get_contents($url); - if ($response !== false) { - $data = json_decode($response, true); - if (isset($data['icons']) && is_array($data['icons']) && count($data['icons']) > 0) { - $iconUrl = $data['icons'][0]['icon']; - $httpsIconUrl = str_replace('http://', 'https://', $iconUrl); - $imagick = new Imagick(); - - $avifIconURL = "/home/{$serverUsername}/domains/fpps4.net/public_html/images/CUSA/{$cusaCode}.avif"; - $result = null; - if ($imagick->readImage($httpsIconUrl)) { - $imageFormat = $imagick->getImageFormat(); - if ($imageFormat == 'JPEG' || $imageFormat == 'PNG') { - $imagick->setImageFormat('avif'); - $imagick->setCompressionQuality(75); - $imagick->setImageProperty('avif:effort', '10'); - $imagick->setImageProperty('avif:speed', '8'); - $imagick->thumbnailImage(128, 128, true); - $imagick->setImageProperty('avif:strip', ''); - // Compress and save the image - if ($imagick->writeImage($avifIconURL)) { - $result = $avifIconURL; - } else { - $result = null; - } +function get_image($cusaCode, $homebrewDB) { + global $issue; + global $serverUsername; + global $conn; + global $homebrewUseragent; + //global $homebrewDB; + $iconUrl = ''; + $avifIconURL = ''; + echo " DEBUG: $cusaCode"; + + try { + if (in_array("app-homebrew", array_column($issue['labels'], 'name'))) { + + $query = "SELECT image FROM homebrews WHERE name = :name"; + $statement = $homebrewDB->prepare($query); + $statement->bindParam(':name', $cusaCode); + $statement->execute(); + $result = $statement->fetch(PDO::FETCH_ASSOC); + //var_dump("image link: $result
"); + //echo "image link: $result
" ; +// if ($result !== false) { + if (!empty($result)) { + $iconUrl = $result['image']; + //echo "Image link: $iconUrl
"; + var_dump("image link: $iconUrl
"); + $avifIconURL = "/home/{$serverUsername}/domains/fpps4.net/public_html/images/HOMEBREW/{$cusaCode}.avif"; + $header = stream_context_create(["http" => ["header" => "User-Agent: $homebrewUseragent\r\n"]]); + $httpsIconUrl = str_replace('http://', 'https://', $iconUrl); + $imageData = file_get_contents($httpsIconUrl, false, $header); } else { - $result = null; + echo "No record found for the given name.
"; + throw new Exception(); } - } else { - $result = null; +// } else {throw new Exception();} + } else { + global $tmdbHash; + $key = hex2bin($tmdbHash); + $hashme = $cusaCode . '_00'; + $hash = strtoupper(hash_hmac('sha1', $hashme, $key)); + $url = "https://tmdb.np.dl.playstation.net/tmdb2/{$cusaCode}_00_{$hash}/{$cusaCode}_00.json"; + $userAgent = 'Mozilla/5.0 (PlayStation; PlayStation 4/10.71) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15'; + $PS4header = stream_context_create(["http" => ["header" => "User-Agent: $userAgent\r\n"]]); // ps4 useragent cuz im silly + $headers = get_headers($url, false, $PS4header); + if ($headers !== false && strpos($headers[0], '200') !== false) { + $response = file_get_contents($url, false, $PS4header); + if ($response !== false) { + $data = json_decode($response, true); + if (isset($data['icons']) && is_array($data['icons']) && count($data['icons']) > 0) { + $iconUrl = $data['icons'][0]['icon']; + $avifIconURL = "/home/{$serverUsername}/domains/fpps4.net/public_html/images/CUSA/{$cusaCode}.avif"; + $httpsIconUrl = str_replace('http://', 'https://', $iconUrl); + $imageData = file_get_contents($httpsIconUrl, false, $PS4header); + } else {throw new Exception();} + } else {throw new Exception();} + } else {throw new Exception();} + } + + + $imagick = new Imagick(); + if ($imagick->readImageBlob($imageData)) { + $imageFormat = $imagick->getImageFormat(); + if ($imageFormat == 'JPEG' || $imageFormat == 'PNG') { + $imagick->setImageFormat('avif'); + $imagick->setCompressionQuality(75); + $imagick->setImageProperty('avif:effort', '10'); + $imagick->setImageProperty('avif:speed', '8'); + $imagick->thumbnailImage(128, 128, true); + $imagick->setImageProperty('avif:strip', ''); + $imagick->writeImage($avifIconURL); // save the image } - $imagick->clear(); - $imagick->destroy(); - return $result; } + $imagick->clear(); + $imagick->destroy(); + + } catch (Exception $e) { + echo "

$cusaCode got an error while downloading, $e


"; + $columnName = "code"; + $insertQuery = "INSERT INTO GameSkips ($columnName) VALUES (:value1)"; + $stmt = $conn->prepare($insertQuery); + $stmt->bindParam(':value1', $cusaCode, PDO::PARAM_STR); + if (!$stmt->execute()) { + die("Error inserting issue: " . $stmt->errorInfo()[2]); + } } - } - // Write the skipped $cusaCode to the database - $skippedCode = $conn->quote($cusaCode); - $insertQuery = "INSERT INTO gameSkips (cusaCode) VALUES ($skippedCode)"; - $conn->exec($insertQuery); - return null; } //- Images logic $gh_api_total = 0; -$open_issues_count = get_open_issues_count($gh_api_total); +$open_issues_count = get_open_issues_count(); $total_pages = ceil($open_issues_count / 100); $total_processed = 0; $total_skipped = 0; @@ -231,6 +307,10 @@ $CUSA_total_skipped = 0; $images_downloaded = 0; $images_skiped = 0; $homebrewProcessed = 0; +$systemProcessed = 0; +$ps2Processed = 0; +$HB_images_downloaded = 0; +$HB_images_skiped = 0; for ($page = 1; $page <= $total_pages; $page++) { $issues_data = get_open_issues($page); @@ -258,23 +338,70 @@ for ($page = 1; $page <= $total_pages; $page++) { insert_issue($issue, $conn); if (!file_exists($avifIconURL)) { // check for images - $query = "SELECT cusaCode FROM GameSkips WHERE cusaCode = :cusaCode"; + // ECHO "
DEBUG: I AM GETTING CHECKED. $cusaCode
"; + $query = "SELECT code FROM GameSkips WHERE code = :code"; $stmt = $conn->prepare($query); - $stmt->bindParam(':cusaCode', $cusaCode, PDO::PARAM_STR); + $stmt->bindParam(':code', $cusaCode, PDO::PARAM_STR); $stmt->execute(); + // ECHO "
DEBUG: I HAVE BEEN CHECKED. $cusaCode
"; if ($stmt->rowCount() > 0) { $images_skiped++; continue; + // ECHO "
DEBUG: I HAVE BEEN SKIPPED. $cusaCode
"; } else { - get_image($cusaCode, $conn, $serverUsername); // Download image + get_image($cusaCode, $homebrewDB); // Download image $images_downloaded++; + // ECHO "
DEBUG: I HAVE BEEN DOWNLOADED. $cusaCode
"; } } else { $images_skiped++; } + // HOMEBREW GAMES/APPS } else if (in_array("app-homebrew", array_column($issue['labels'], 'name'))) { + $hb_title = preg_replace('/\s-\s.*$/', '', $title); + $hb_title = trim(explode('(Homebrew)', $hb_title)[0]); + $hb_title = trim(explode('Homebrew', $hb_title)[0]); + //$hb_title = trim(explode('Game', $hb_title)[0]); + $hb_title = rtrim($hb_title, ' '); + + $query = "SELECT title FROM newIssues WHERE title = :title"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':title', $hb_title, PDO::PARAM_STR); + $stmt->execute(); + $checkTitle = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (count($checkTitle) > 0) { + $total_skipped++; + continue; + } + + if (!file_exists("/home/{$serverUsername}/domains/fpps4.net/public_html/images/HOMEBREW/{$hb_title}.avif")) { // check for images + // $query = "SELECT cusaCode FROM GameSkips WHERE homeBrew = :homeBrew"; + $query = "SELECT code FROM GameSkips WHERE code = :code"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':code', $hb_title, PDO::PARAM_STR); + $stmt->execute(); + $check_result = $stmt->fetchAll(PDO::FETCH_ASSOC); + + if (count($check_result) > 0) { + $HB_images_skiped++; + // echo "$hb_title is skipped
"; + } else { + get_image($hb_title, $homebrewDB); // Download image + $HB_images_downloaded++; + // echo "$hb_title getting downloaded
"; + } + } else { + $HB_images_skiped++; + // echo "$hb_title exists
"; + } + + insert_issue($issue, $conn); + $total_processed++; + $homebrewProcessed++; + + } else if (in_array("app-system-fw505", array_column($issue['labels'], 'name'))){ $query = "SELECT title FROM newIssues WHERE title = :title"; $stmt = $conn->prepare($query); $stmt->bindParam(':title', $title, PDO::PARAM_STR); @@ -286,10 +413,26 @@ for ($page = 1; $page <= $total_pages; $page++) { continue; } $total_processed++; - $homebrewProcessed++; + $systemProcessed++; + insert_issue($issue, $conn); + + } else if (in_array("app-ps2game", array_column($issue['labels'], 'name'))){ + $query = "SELECT title FROM newIssues WHERE title = :title"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':title', $title, PDO::PARAM_STR); + $stmt->execute(); + $checkTitle = $stmt->fetchAll(PDO::FETCH_ASSOC); + + if (count($checkTitle) > 0) { + $total_skipped++; + continue; + } + $total_processed++; + $ps2Processed++; insert_issue($issue, $conn); } else { $CUSA_total_skipped++; + //echo "https://github.com/red-prig/fpps4-game-compatibility/issues/" . $issue['number'] . "
"; continue; } } @@ -337,9 +480,13 @@ print "
Total open issues: " . $open_issues_count; print "
Total issues without CUSA: " . $CUSA_total_skipped; print "
Total issues processed: " . $total_processed; print "
Homebrew's processed: " . $homebrewProcessed; +print "
System Apps processed: " . $systemProcessed; +print "
PS2 Games processed: " . $ps2Processed; print "
Total duplicates: " . $total_skipped; print "
Total images downloaded: " . $images_downloaded; print "
Total images skipped: " . $images_skiped; +print "
Total homebrew images downloaded: " . $HB_images_downloaded; +print "
Total homebrew images skipped: " . $HB_images_skiped; print "
Total github api requests: " . $gh_api_total; // Fake 404 page vv -- 2.51.2