Git Codebase - Sn0wlink IT
Git Codebase
Code:
Download ZIP
🗀 assets
LICENSE
README.md
index.php
index.php
<?php /* Git Public Codebase Description: A public flatfile Git repo browser. Author: David Collins-Cubitt Website: https://sn0wlink.com Email: david@sn0wlink.com Date: March 2026 */ /////////////////////////////////////////////////////////////////////////////// // Config /////////////////////////////////////////////////////////////////////////////// // Site Settings $Site_Title = 'Git Codebase - Sn0wlink IT'; $Site_Description = 'Sn0wlinks public codebase repository for coding projects and codebases'; $Site_Logo = 'https://mirror.sn0wlink.com/img/git-logo-white.svg'; $Copyright_Notice = 'Git Codebase is built by Sn0wlink IT - MIT Licence - FOSS ' . date("Y") . ' - ' . $Site_Title; // Site Logo: Leave blank for no Image $Markdown_Parsdown = 'Parsedown.php'; // // Leave this blank if you do not wish to use markdown parser file from https://github.com/erusev/parsedown $Site_Banner_Text = ''; // Display Important news or text $Site_Banner_Background = '#ffee00'; // Theme $Site_Title_Background = '#002e6b'; $Site_Title_Colour = '#ffffff'; $Site_Main_Colour = '#81a3a3'; $Site_Main_Background_Colour = '#edeff7'; $Site_Title_Font = 'helvetica, arial, sans'; $Site_Main_Font = 'helvetica, arial, sans'; $Site_Favicon = 'https://mirror.sn0wlink.com/img/git-logo.svg'; $Page_Width = '1000px'; // Social $Username = 'Sn0wlink'; $Profile_Photo = 'https://avatars.githubusercontent.com/u/2997878?v=4'; $Website_1 = 'https://sn0wlink.com'; $Website_2 = ''; $Website_3 = ''; $Mastodon_Username = 'Sn0wlink'; $Mastodon_Server = 'mastodon.social'; $About = 'Author of Git Codebase, Electro-Mechanical Engineer with a passion for computing, technology, and photography.'; $Email ='code@sn0wlink.com'; $User_Location = 'Lives in Norfolk, UK'; /////////////////////////////////////////////////////////////////////////////// // Functions /////////////////////////////////////////////////////////////////////////////// // Get Inputs if (ISSET($_GET['loc'])) { // Clean Input $Location_Input = htmlentities($_GET['loc']); $Location_Input = str_replace('../', '', $Location_Input); // Check file path is real and not above root dir $Root_Directory = realpath($_SERVER['DOCUMENT_ROOT']); $Check_Path = realpath($Root_Directory . '/' . $Location_Input); // Check for bad directorys if ($Location_Input == '') { http_response_code(403); exit('Forbidden'); } // Check for bad directorys if ($Check_Path === false || strpos($Check_Path, $Root_Directory) !== 0) { http_response_code(403); exit('Forbidden'); } $Current_Location = $Location_Input; } if (ISSET($_GET['file'])) { // Clean Input $File_Input = htmlentities($_GET['file']); $File_Input = str_replace('../', '', $File_Input); $Root_Directory = realpath($_SERVER['DOCUMENT_ROOT']); $Check_Path = realpath($Root_Directory . '/' . $Current_Location . '/' . $File_Input); // Check for bad directorys if ($File_Input == '') { http_response_code(403); exit('Forbidden'); } // Check for bad directorys if ($Check_Path === false || strpos($Check_Path, $Root_Directory) !== 0) { http_response_code(403); exit('Forbidden'); } $Selected_File = $File_Input; } function Site_Banner() { global $Site_Banner_Text; if ($Site_Banner_Text !== '') { echo " <div class='site_banner'> $Site_Banner_Text </div> "; } } function Open_Graph() { // Because apparently, some people use social media // Ref: https://ogp.me/ global $Site_Logo; global $Site_Description; global $Current_Location; $Open_Graph =''; if (ISSET($_GET['loc'])) { $Open_Graph .= "<meta property='og:title' content='Git Codebase - $Current_Location' />\n"; $Open_Graph .= '<meta property="og:type" content="website">'; $Open_Graph .= "<meta property='og:description' content='$Site_Description'>"; if ($Site_Logo !== '') { $Open_Graph .= "<meta property='og:image' content='$Site_Logo' />\n"; } } return $Open_Graph; } // Build the page content function Build_Page() { $Display = ''; // Display Homepage if (!ISSET($_GET['loc'])) { // Social Header Block $Display .= Display_Social(); // List Repositories $Display .= List_Repos(); return $Display; } // Display Selected Page if (ISSET($_GET['loc'])) { $Display .= Display_Repo(); } return $Display; } // Site Logo function Site_Logo() { global $Site_Logo; $Site_Logo_Image = ''; if ($Site_Logo !== '') { $Site_Logo_Image .= "<img class='site_logo' src='$Site_Logo'>"; } return $Site_Logo_Image; } // Display social header block function Display_Social() { // Define variables global $Username; global $Profile_Photo; global $Website_1; global $Website_2; global $Website_3; global $Mastodon_Username; global $Mastodon_Server; global $About; global $Email; global $User_Location; $Display_Profile_Photo =''; if ($Profile_Photo !== '') { $Display_Profile_Photo = " <div class='profile_photo'> <img class='profile_photo' src='$Profile_Photo'> </div> "; } $Output = " <div class='page_block'> <div class='social_name'>$Username</div> $Display_Profile_Photo <div class='profile_spacer'></div> <div class='social_bio'>$About</div> <div class='social_block'> <div class='social_location'>$User_Location</div> <div class='social_website'><a href='$Website_1'>$Website_1</a></div> <div class='social_email'><a href='mailto:$Email'>$Email</a></div> <a rel='me' href='https://$Mastodon_Server/@$Mastodon_Username'>Mastodon</a> </div> <div class='clear'></div> </div> "; return $Output; } // List Git Repos function List_Repos() { // Define Variables $List_Repo_Out = ''; $Repo_Location = $_SERVER['DOCUMENT_ROOT']; $Count_Repos = 0; $List_Directorys = glob($Repo_Location . '*', GLOB_ONLYDIR); foreach ($List_Directorys as $Git_Folder) { $Count_Repos++; // Most recent commit timestamp from that repo $Last_Modified = trim(shell_exec('git -C ' . escapeshellarg($Git_Folder) . ' log -1 --format=%ah')); $Commit_Message = shell_exec('git -C ' . escapeshellarg($Git_Folder) . ' log -1 --format=%s'); $Commit_Info = "<div class='commit_info'>$Commit_Message - $Last_Modified</div>"; $Git_Folder_Name = str_replace ($Repo_Location, '', $Git_Folder); $List_Repo_Out .= "<hr><a class='repo_link' href='?loc=$Git_Folder_Name'>$Git_Folder_Name</a>$Commit_Info<br><div class='clear'></div>\n"; $Output = " <div class='page_block'> <strong>$Count_Repos Repositories</strong><br> <br> $List_Repo_Out </div> "; } return $Output; } function Display_Repo() { global $Markdown_Parsdown; global $Current_Location; global $Selected_File; $Output = ''; $DIR_List = ''; $Repo_Location = $_SERVER['DOCUMENT_ROOT']; $Repo_Location_Full = $Repo_Location . $Current_Location; // Make 'UP' directory button if (str_contains($Current_Location, '/')) { // Remove last folder from location $UP_Directory_Input = explode('/', $Current_Location); array_pop($UP_Directory_Input); $UP_Directory = ''; foreach($UP_Directory_Input as $Directory) { $UP_Directory .= $Directory . '/'; } // Remove trailing / $UP_Directory = substr($UP_Directory, 0, -1); // Output the Up Folder $DIR_List .= "<a href='?loc=$UP_Directory'>[...] Up Directory</a><br>"; } // Display Directorys $List_Directorys = glob("$Repo_Location_Full/*", GLOB_ONLYDIR); foreach ($List_Directorys as $Directory) { $Directory_Name = str_replace($Repo_Location . $Current_Location . '/', '', $Directory); $DIR_List .= " <hr> <div class='file_list_item'> <a href='?loc=$Current_Location/$Directory_Name'>🗀 $Directory_Name</a> <br> </div> "; } // Display Files $List_Files = array_filter(glob("$Repo_Location_Full/*"), 'is_file'); foreach ($List_Files as $File) { $File_Name = str_replace($Repo_Location . $Current_Location . '/', '', $File); $DIR_List .= " <hr> <div class='file_list_item'> <a href='?loc=$Current_Location&file=$File_Name'>$File_Name</a> <br> </div> "; } if ($DIR_List == '') { $DIR_List .= 'Empty Repository'; } // List Files and Folders $Download_Zip_Link = ''; if (file_exists("$Current_Location.zip")) { $Download_Zip_Link = " Code: <a href='$Current_Location.zip' download='$Current_Location.zip'>Download ZIP</a> "; } $Output .= " <div class='page_block'> <strong>$Current_Location</strong><br><hr> $Download_Zip_Link $DIR_List </div> "; // If there is a Readme file, Display the Readme file! if (file_exists($Repo_Location . $Current_Location . '/README.md')) { if (!ISSET($_GET['file'])) { $Readme_Contents = file_get_contents($Repo_Location . $Current_Location . '/README.md'); // Use Markdown Parsedown if selected if ($Markdown_Parsdown !== '') { include ($Markdown_Parsdown); $Parsedown = new Parsedown(); $Markdown_Output = $Parsedown->text($Readme_Contents); $Readme_Contents = "$Markdown_Output"; } if (($Markdown_Parsdown == '')) { $Readme_Contents = "<pre>$Readme_Contents</pre>"; } $Output .= " <div class='page_block'> <strong>README</strong><br> <hr> $Readme_Contents </div> "; } } // Show the selected file if (ISSET($_GET['file'])) { $Selected_File_Path = $Repo_Location . $Current_Location . '/' . $Selected_File; $Download_File_Path = $Current_Location . '/' . $Selected_File; // Default - Display Contents $File_Contents = htmlspecialchars(file_get_contents($Selected_File_Path)); $File_Contents = '<textarea>' . $File_Contents . "\n\n" . '</textarea>'; // If image Display as image if (exif_imagetype($Selected_File_Path)) { $File_Contents = "<img class='preview' src='$Download_File_Path'>"; } $Output .= " <div class='page_block'> <strong>$Selected_File</strong><br> $File_Contents </div> "; } return $Output; } // Sitemap Generator -- SEO Stuff if (!file_exists('sitemap.txt')) { // Clear File Contents file_put_contents('sitemap.txt', ''); foreach (glob($_SERVER['DOCUMENT_ROOT'] . '*', GLOB_ONLYDIR) as $Git_Repo) { $Git_Repo = str_replace(' ', '%20', $Git_Repo); $Git_Repo = str_replace($_SERVER['DOCUMENT_ROOT'], 'https://' . $_SERVER['HTTP_HOST'] . '/index.php?loc=', $Git_Repo); file_put_contents('sitemap.txt', $Git_Repo . "\n", FILE_APPEND); } } /////////////////////////////////////////////////////////////////////////////// // Page Layout (View) /////////////////////////////////////////////////////////////////////////////// $Page_Content = Build_Page(); $Site_Logo_Image = Site_Logo(); $Site_Banner = Site_Banner(); $Open_Graph = Open_Graph(); echo " <!DOCTYPE html> <html> <head> <title>$Site_Title</title> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <link rel='icon' href='$Site_Favicon' type='image/x-icon'/> <meta name='description' content='$Site_Description'> <meta name='fediverse:creator' content='@$Mastodon_Username@$Mastodon_Server'> $Open_Graph <style> body { font-family: $Site_Main_Font; font-size: 11pt; margin: 0; padding: 0; background-color: $Site_Main_Background_Colour; } hr { border: 1px solid #cbd7dd; } img { max-width: 100%; } pre { max-width: 100%; overflow: auto; } code { background-color: #e3e5e8; border: 2px solid #cbd7dd; display: block; padding: 10px; overflow: auto; } textarea { width: 1000px; height: 400px; max-width: 100%; } div.clear { clear: both; } a { color: #3574c7; text-decoration: none; } a:hover { text-decoration: underline; } img.site_logo { height: 20px; } div.site_banner { background-color: $Site_Banner_Background; animation: marquee 5s linear infinite; padding: 20px; } a.page_title { text-decoration: none; color: $Site_Title_Colour; } div.page_title { font-family: $Site_Title_Font; font-size: 18pt; font-weight: bold; margin: 0; padding: 5px; background-color: $Site_Title_Background; } div.page_content { margin: auto; max-width: $Page_Width; } div.page_block { background-color: #fff; border-width: 1px; border-style: solid; border-color: $Site_Main_Colour; border-radius: 8px; margin: 20px 20px 10px 20px; padding: 30px; } div.social_name { font-size: 18pt; font-weight: bold; margin-bottom: 10px; } img.profile_photo { max-width: 110px; border-radius: 1000px; float: left; margin-right: 10px; } div.social_block { float: left; } div.file_list_item { padding: 3px; } div.file_list_item:hover { background-color: #dce6ec; } div.commit_info { color: #858585; display: inline; float: right; } div.bottom_page_spacer { height: 60px; max-width: 100%; } div.page_footer { font-size: 10pt; color: $Site_Title_Colour; background-color: $Site_Title_Background; text-align: center; position: fixed; bottom: 0; left: 0; width: 100%; padding: 10px; margin: 0; } img.preview { max-width:100%; } </style> </head> <body> $Site_Banner <div class='page_title'> <a class='page_title' href='index.php'>$Site_Logo_Image $Site_Title</a> </div> <div class='page_content'> $Page_Content </div> <div class='bottom_page_spacer'></div> <div class='page_footer'> $Copyright_Notice </div> </body> </html> "; // EOF