Homebrew RELEASE Host your own GDrive link + Welcome message + PHP source code

st4tic

Member
OP
Newcomer
Joined
Sep 17, 2019
Messages
5
Trophies
0
Age
113
XP
73
Country
Afghanistan
HBG SHOP / Tinfoil users

For those who might care, I made a very simple(shitty) php webpage to host your own GDrive links + Personnal welcome text(source code on the page).

Just add the COMPLETE link shown in the webpage to the file browser of HBG/Tinfoil and you are done.

Test it here —> http://www.atomikpc.com/static/

**Special thanks to designgears for rearranging my work in an intelligent way.

**Don't forget that this is only a demo used be everyone.
**If you like it, host it yourself or PM me, I will host your personal one for free.
**The links are resetted each 5 minutes on the demo but not if you host it.
**You can manually reset the form if you erase everything then save.
 
Last edited by st4tic,

atomik22

Member
Newcomer
Joined
Dec 18, 2014
Messages
16
Trophies
0
XP
80
Country
Canada
even its simple a application i want since hbg is public
but take out the default link because it links to https://drive.google.com/drive/folders/1W6FWvuK2poMS0sN3-DID************** where you can get NSP files. this is forbidden here
It’s a user who posted this to test I guess.
My default links reappear when saving empty textbox.
I am going to reset it right now. Sorry.

**Added a cron job to reset the links at each 5 minutes on the demo website only.
 
Last edited by atomik22,
D

Deleted User

Guest
Does your site store the gdrive links that people put in? Or does it just generate a link for HBG dynamically?
i think he changes them every day manually because the welcome message is not the same from yesterday.....
 

atomik22

Member
Newcomer
Joined
Dec 18, 2014
Messages
16
Trophies
0
XP
80
Country
Canada
i think he changes them every day manually because the welcome message is not the same from yesterday.....
Not exactly that. There's a lot of user testing it, so they change the links and Welcome msg each time they try. The links are saved in a .json file which is overwritten each time the save button is triggered.
When some "real" links are there for too long, I simply reset the form erasing everything then save.
Don't forget that the link provided is only a demo for you to try.
If you like it, host it yourself and you will be the only one using it.
 
Last edited by atomik22,

Quantumcat

Dead and alive
Member
Joined
Nov 23, 2014
Messages
15,144
Trophies
0
Location
Canberra, Australia
Website
boot9strap.com
XP
11,094
Country
Australia
Not exactly that. There's a lot of user testing it, so they change the links and Welcome msg each time they try. The links are saved in a .json file which is overwritten each time the save button is triggered.
When some "real" links are there for too long, I simply reset the form erasing everything then save.
Is it possible for someone to visit your site and get other people's gdrive links? Sounds like yes - if so you won't be able to share the link here. But if you make it so people can only create links for their own stuff then you'll be able to add it back.
 

atomik22

Member
Newcomer
Joined
Dec 18, 2014
Messages
16
Trophies
0
XP
80
Country
Canada
Here's the source code
Code:
<?
    if(isset($_POST['message'])){
        $message=$_POST['message'];
    }
     
    if(isset($_POST['linksNSP']))
    {
        $splitlinksNSP=explode("\n", $_POST['linksNSP']);
        for($y=0;$y<=sizeof($splitlinksNSP)-1;$y++)
        {
            if($y!=sizeof($splitlinksNSP)-1)
            {
                $linksTotNSP=$linksTotNSP . $splitlinksNSP[$y] . "\",\"";
            }else{
               $linksTotNSP=$linksTotNSP . $splitlinksNSP[$y] ;
            }
        }
    }
 
    if(isset($_POST['links']))
    {
        $splitlinks=explode("\n", $_POST['links']);
        for($i=0;$i<=sizeof($splitlinks)-1;$i++)
        {
            if($i!=sizeof($splitlinks)-1)
            {
                $linksTot=$linksTot . $splitlinks[$i] . "\",\"";
            }else{
                $linksTot=$linksTot . $splitlinks[$i] . "\"],\"success\":\"" . $message . "\"}";
            }
        }
        $final= "{\"files\":[\"" . $linksTotNSP . "\"],\"directories\":[\"" . $linksTot;
        $final=str_replace("\n", "", $final);
        $final=str_replace("\r", "", $final);
        $final=str_replace("[\"\"]", "[]", $final);
        $final=str_replace(",\"\"", "", $final);
        $fp = fopen("index.json", "w");
        fwrite($fp, $final);
        fclose($fp);
        header("Location: " . $_SERVER['PHP_SELF']);
    }
    $fn = fopen("index.json","r");
    $result = fgets($fn);
    fclose($fn);
    $splittedR=explode(":[", $result);
    $splittedNSP=explode('"', $splittedR[1]);
    for($i=1;$i<sizeof($splittedNSP)-2;$i+=2)
    {
        $linksNSP=$linksNSP . $splittedNSP[$i] . "\n";
    }
 
    $splittedFolders=explode('"', $splittedR[2]);
 
    for($i=1;$i<sizeof($splittedFolders);$i+=2)
    {
        if ($splittedFolders[$i]=="success")
        {
            $succes=1;
            $succesText=$splittedFolders[$i+2];
        }else{
            if($succes!=1){
               $links=$links . $splittedFolders[$i] . "\n";
            }
        }
    }
 
    if(trim($succesText)==""){
        $succesText="Put your welcome message here";
    }
     if(trim($links)=="" && trim($linksNSP)==""){
        $links="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx\rhttps://drive.google.com/open?id=yyyyyyyyyyyyyyyy\rhttps://drive.google.com/open?id=zzzzzzzzzzzzzzzz";
        $linksNSP="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx\rhttps://drive.google.com/open?id=yyyyyyyyyyyyyyyy\rhttps://drive.google.com/open?id=zzzzzzzzzzzzzzzz";
    }
?>
<html>
    <head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
        <title>Tinfoil</title>
        <link href="colorbox.css" rel="stylesheet">
    </head>
    <body>
        <form name="allo" method="post">
             <table>
                <tr><td>
            Welcome message</td><td><textarea id="message" name="message" rows="5" cols="70"><?echo $succesText?></textarea></td></tr><tr>
            <td>One GDrive <b>NSP</b> link per row<br>No folder<br>No maximum</td><td><textarea id="linksNSP" name="linksNSP" rows="10" cols="125"><?echo $linksNSP?></textarea></td></tr><tr>
            <td>One GDrive <b>FOLDER</b> link per row<br>No single nsp<br>No maximum</td><td><textarea id="links" name="links" rows="10" cols="125"><?echo $links?></textarea></td></tr><tr>
            <td><input type=Submit id="Envoyer" value="Save" class="btn btn-primary"></td></tr><tr></table>
        </form>
    </body>
</html>
<?
 
    echo "Copy this link in the file browser of HBG Shop/Tinfoil";
    function url(){
  return sprintf(
    "%s://%s%s",
    isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
    $_SERVER['SERVER_NAME'],
    $_SERVER['REQUEST_URI']
  );
}
echo "<br><br><u><b>" . str_replace("index.php","", url()) . "index.json</u></b>";
 
 
?>
<br><br><br><br><br><a href="index.txt">SOURCE CODE</a>

--------------------- MERGED ---------------------------

Is it possible for someone to visit your site and get other people's gdrive links? Sounds like yes - if so you won't be able to share the link here. But if you make it so people can only create links for their own stuff then you'll be able to add it back.
This is only a demo website.
The purpose of all this is to host it yourself so you are the only one using it.
But I can host your own personal one for free if you need it or want to test it alone.
PM me and it will take less than 5 minutes to be up.
 
Last edited by atomik22,
  • Like
Reactions: Quantumcat

designgears

Well-Known Member
Member
Joined
Aug 8, 2016
Messages
291
Trophies
0
XP
671
Country
United States
I know but you have to enter each link individually on the tinfoil interface.
My script group them all under a single url and you can have your own welcome message.

Nope, you can directly authenticate with gdrive now, no need to enter links anymore.
---

also, you can build a php array and then call json_encode on it to convert it to json instead of manually building the json string like a mad man.
---

and again with the https detection, write the link as "://www.domain.tld/index.json", the browser will handle the http/https.
 
Last edited by designgears,

atomik22

Member
Newcomer
Joined
Dec 18, 2014
Messages
16
Trophies
0
XP
80
Country
Canada
Nope, you can directly authenticate with gdrive now, no need to enter links anymore.
---

also, you can build a php array and then call json_encode on it to convert it to json instead of manually building the json string like a mad man.
---

and again with the https detection, write the link as "//www.domain.tld/index.json", the browser will handle the http/https.
I will need to try it again.
Last time I tried, I didn't manage to get it working and didn't find any infos/help on how to.
Maybe later today.
 
Last edited by atomik22,

designgears

Well-Known Member
Member
Joined
Aug 8, 2016
Messages
291
Trophies
0
XP
671
Country
United States
Here ya go, this gets the job done in far less php code, letting php handle the json, added some basic checks with success and error messages.

Far less error prone when you use the php functions instead of string concatenating json yourself.

You were also exploding on single type of line break when there are 3 possibilities.

You had a header redirect back to the page itself after writing the json file and then proceeded to run checks on variables that would always be empty because of the redirect to decide if you needed the example data and made it so the user entered data would never fill the boxes after submitting.

You linked to a non-existent css file.

Your table had an extra <tr> hanging out and some other nitpick stuff. Didn't use placeholder for example data, etc...

Your tinfoil link generation depends on the php file being a specific name, otherwise it would create a bad link for use with tinfoil.

Very easy to break the page with special characters as well...

Learning some basic php functions goes a long way, doing things in some weird early php4 fashion can be dangerous.

Good day.

PHP:
<?

    $tinfoil_array = array();

    if (isset($_POST['message']) && !empty($_POST['message'])) {
        $message = trim($_POST['message']);
        $message = htmlspecialchars($message);
        $tinfoil_array['success'] = $message;
    }

    if (isset($_POST['linksNSP']) && !empty($_POST['linksNSP'])) {
        $linksNSP = trim($_POST['linksNSP']);
        $linksNSP = htmlspecialchars($linksNSP);
        $tinfoil_array['files'] = preg_split('/\r\n|\r|\n/', $linksNSP);
    }

    if (isset($_POST['links']) && !empty($_POST['links'])) {
        $links = trim($_POST['links']);
        $links = htmlspecialchars($links);
        $tinfoil_array['directories'] = preg_split('/\r\n|\r|\n/', $links);
    }

    if (!empty($links) || !empty($linksNSP)) {
        file_put_contents('index.json', json_encode($tinfoil_array, JSON_UNESCAPED_SLASHES));
        echo "<div id='json_success'>Json file updated!</div><br />";
    }

    if (count($_POST) > 0 && empty($_POST['links']) && empty($_POST['linksNSP'])) {
        echo "<div id='json_error'>Json file not updated, no links provided!</div><br />";
    }

?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
        <title>Tinfoil</title>
        <style>
            #link_info {
                font-weight: bold;
                text-decoration: underline;
                clear: both;
            }
            #link_text {
                background-color: yellow;
                clear: both;
                float: left;
            }
            #link_text, #link {
                display: none;
            }
            #json_success {
                background-color: lightgreen;
                clear: both;
            }
            #json_error {
                background-color: lightpink;
                clear: both;
            }
        </style>
    </head>
    <body>
        <form method="post">
            <table>
                <tr>
                    <td width="200">Welcome message</td>
                    <td><textarea id="message" name="message" rows="5" cols="70" placeholder="Put your welcome message here"><?= $message ?></textarea></td>
                </tr>
                <tr>
                    <td>One GDrive <b>NSP</b><br />One per line<br />No folder<br />No maximum</td>
                    <td><textarea id="linksNSP" name="linksNSP" rows="10" cols="125" placeholder="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx&#013;&#010;https://drive.google.com/open?id=yyyyyyyyyyyyyyyy&#013;&#010;https://drive.google.com/open?id=zzzzzzzzzzzzzzzz"><?= $linksNSP ?></textarea></td>
                </tr>
                <tr>
                    <td>One GDrive <b>FOLDER</b><br />One per line<br />No single nsp<br />No maximum</td>
                    <td><textarea id="links" name="links" rows="10" cols="125" placeholder="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx&#013;&#010;https://drive.google.com/open?id=yyyyyyyyyyyyyyyy&#013;&#010;https://drive.google.com/open?id=zzzzzzzzzzzzzzzz"><?= $links ?></textarea></td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Create Json">
                        <input type="reset" value="Reset">
                    </td>
                </tr>
            </table>
        </form>

        <br />

        <div id="link_info">Copy this link in the file browser of HBG Shop/Tinfoil</div>
        <div id="link_text"></div>
        <a href="index.json" id="link"></a>
      
        <script>
            var link = document.getElementById('link').href;
            document.getElementById('link_text').innerHTML = link;
            document.getElementById('link_text').style.display = "block";
        </script>
    </body>
</html>
 
Last edited by designgears,

atomik22

Member
Newcomer
Joined
Dec 18, 2014
Messages
16
Trophies
0
XP
80
Country
Canada
Here ya go, this gets the job done in far less php code, letting php handle the json, added some basic checks with success and error messages.

Far less error prone when you use the php functions instead of string concatenating json yourself.

You were also exploding on single type of line break when there are 3 possibilities.

You had a header redirect back to the page itself after writing the json file and then proceeded to run checks on variables that would always be empty because of the redirect to decide if you needed the example data and made it so the user entered data would never fill the boxes after submitting.

You linked to a non-existent css file.

Your table had an extra <tr> hanging out and some other nitpick stuff. Didn't use placeholder for example data, etc...

Your tinfoil link generation depends on the php file being a specific name, otherwise it would create a bad link for use with tinfoil.

Very easy to break the page with special characters as well...

Learning some basic php functions goes a long way, doing things in some weird early php4 fashion is poop.

Good day.

PHP:
<?

    $tinfoil_array = array();
    $message = $links = $linksNSP = NULL;

    if (isset($_POST['message'])) {
        $message = trim($_POST['message']);
        $message = htmlspecialchars($message);
        $tinfoil_array['success'] = $message;
    }

    if (isset($_POST['linksNSP'])) {
        $linksNSP = trim($_POST['linksNSP']);
        $linksNSP = htmlspecialchars($linksNSP);
        $tinfoil_array['files'] = preg_split('/\r\n|\r|\n/', $linksNSP);
    }

    if (isset($_POST['links'])) {
        $links = trim($_POST['links']);
        $links = htmlspecialchars($links);
        $tinfoil_array['directories'] = preg_split('/\r\n|\r|\n/', $links);
    }

    if (!empty($links) || !empty($linksNSP)) {
        file_put_contents('index.json', json_encode($tinfoil_array, JSON_UNESCAPED_SLASHES));
        echo "<div id='json_success'>Json file updated!</div><br />";
    }

    if (count($_POST) > 0 && empty($_POST['links']) && empty($_POST['linksNSP'])) {
        echo "<div id='json_error'>Json file not updated, no links provided!</div><br />";
    }

?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
        <title>Tinfoil</title>
        <style>
            #link_info {
                font-weight: bold;
                text-decoration: underline;
                clear: both;
            }
            #link_text {
                background-color: yellow;
                clear: both;
                float: left;
            }
            #link_text, #link {
                display: none;
            }
            #json_success {
                background-color: lightgreen;
                clear: both;
            }
            #json_error {
                background-color: lightpink;
                clear: both;
            }
        </style>
    </head>
    <body>
        <form method="post">
            <table>
                <tr>
                    <td width="200">Welcome message</td>
                    <td><textarea id="message" name="message" rows="5" cols="70" placeholder="Put your welcome message here"><?= $message ?></textarea></td>
                </tr>
                <tr>
                    <td>One GDrive <b>NSP</b><br />One per line<br />No folder<br />No maximum</td>
                    <td><textarea id="linksNSP" name="linksNSP" rows="10" cols="125" placeholder="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx&#013;&#010;https://drive.google.com/open?id=yyyyyyyyyyyyyyyy&#013;&#010;https://drive.google.com/open?id=zzzzzzzzzzzzzzzz"><?= $linksNSP ?></textarea></td>
                </tr>
                <tr>
                    <td>One GDrive <b>FOLDER</b><br />One per line<br />No single nsp<br />No maximum</td>
                    <td><textarea id="links" name="links" rows="10" cols="125" placeholder="https://drive.google.com/open?id=xxxxxxxxxxxxxxxx&#013;&#010;https://drive.google.com/open?id=yyyyyyyyyyyyyyyy&#013;&#010;https://drive.google.com/open?id=zzzzzzzzzzzzzzzz"><?= $links ?></textarea></td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Create Json">
                        <input type="reset" value="Reset">
                    </td>
                </tr>
            </table>
        </form>

        <br />

        <div id="link_info">Copy this link in the file browser of HBG Shop/Tinfoil</div>
        <div id="link_text"></div>
        <a href="index.json" id="link"></a>
    
        <script>
            var link = document.getElementById('link').href;
            document.getElementById('link_text').innerHTML = link;
            document.getElementById('link_text').style.display = "block";
        </script>
    </body>
</html>
Really nice and way better than before.
I updated my script and source code with yours and added you in the credits.

Thanks, everyone will benefit from your work
 
Last edited by atomik22,

Reecey

Mario 64 (favorite game of all time)
Member
Joined
Mar 7, 2010
Messages
5,864
Trophies
2
Location
At Home :)
XP
4,455
Country
I could do with an app making so I can turn the damn messages off! because they get on my nerves and you shouldn’t have to be made to see them every time you boot tinfoil up, tbh there should be an option like music so you can turn them off by default.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    BakerMan @ BakerMan: @salazarcosplay yeah cod's still up