diff options
-rw-r--r-- | README.md | 40 | ||||
-rw-r--r-- | cron.txt | 8 | ||||
-rw-r--r-- | public_html/browser/get.php | 35 | ||||
-rw-r--r-- | public_html/browser/index.php | 87 | ||||
-rw-r--r-- | store/browser/curl.php | 20 | ||||
-rw-r--r-- | store/browser/db.php | 23 | ||||
-rw-r--r-- | store/browser/update.sh | 3 |
7 files changed, 216 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e5fe92 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Sites Roulette + +My simple application to view user pages on a given server, + +curl.php gets the data from the main page of the server, parses it and writes to the database, thanks to cron you can easily update the database for example once a day. + +it's a very simple script, if you want to run it, you need to personalize some things, like the name of your home directory or regex to download users + +to change: + +- public_html/browser/get.php + + - require_once('/home/grizzly/store/browser/db.php'); + - die(header("Location: https://tilde.team/~grizzly/browser/?member=" . $row['login_name'])); + +- public_html/browser/index.php + + - s/tilde.team/you.website/ + +- store/browser/curl.php + + - require_once ('/home/grizzly/store/browser/db.php'); + - curl_setopt($c, CURLOPT_URL,'https://tilde.team/'); + - preg*match_all('/<li><a href="\/~(.*)\/" class=\"list-group-item col-xs-6 col-sm-4 col-md-2\">~(.\_)<\/a><\/li>/', $data, $matches); + +- store/browser/update.sh + +and add cron.txt content to your cron: `crontab -e` + +--- + +the script was created out of "need", I wanted to browse all user pages and I didn't want to open thousands of tabs, so this is "sites roulette". + +you can modify it, share it freely + +--- + +if you want to change or improve something, clone the repo, add changes, upload to some git server and send me the link, if you are a user of tilde.institute, send me an email with the path to your repo on the server + +=> grizzly/at/nand.sh diff --git a/cron.txt b/cron.txt new file mode 100644 index 0000000..76bebd9 --- /dev/null +++ b/cron.txt @@ -0,0 +1,8 @@ +#minute (0-59), +#| hour (0-23), +#| | day of the month (1-31), +#| | | month of the year (1-12), +#| | | | day of the week (0-6 with 0=Sunday). +#| | | | | commands + +0 0 * * * /home/grizzly/store/browser/update.sh > /dev/null 2>&1 \ No newline at end of file diff --git a/public_html/browser/get.php b/public_html/browser/get.php new file mode 100644 index 0000000..fa346c3 --- /dev/null +++ b/public_html/browser/get.php @@ -0,0 +1,35 @@ +<?php + +require_once('/home/grizzly/store/browser/db.php'); + +$member = $_GET['member']; + +if (isset($_GET["random"]) || !isset($member)) { + $stmt = $db->prepare("SELECT * FROM `websites` ORDER BY RANDOM() LIMIT 1;"); + $stmt->execute(); + $row = $stmt->fetch(); + + die(header("Location: https://tilde.team/~grizzly/browser/?member=" . $row['login_name'])); +} else { + $stmt = $db->prepare("SELECT * FROM `websites` WHERE login_name = :login_name;"); + $stmt->execute(array(':login_name' => $member)); + $row = $stmt->fetch(); // works + + $stmt = $db->prepare("SELECT login_name FROM `websites` WHERE id > :id;"); + $stmt->execute(array(':id' => $row['id'])); + $next = $stmt->fetch(); // works + + $stmt = $db->prepare("SELECT login_name FROM `websites` WHERE id < :id;"); + $stmt->execute(array(':id' => $row['id'])); + $prev = $stmt->fetch(); // always return first record from database, why? +} + +$current = $row["login_name"]; +$next = $next["login_name"] ? $next["login_name"] : null; +$prev = $prev["login_name"] ? $prev["login_name"] : null; + +// echo "current: " . $current . "\n"; +// echo "next: " . $next . "\n"; +// echo "prev: " . $prev . "\n"; + +?> \ No newline at end of file diff --git a/public_html/browser/index.php b/public_html/browser/index.php new file mode 100644 index 0000000..08aecd6 --- /dev/null +++ b/public_html/browser/index.php @@ -0,0 +1,87 @@ +<?php require_once ('get.php'); +?><!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8" /> + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Members websites on tilde.team</title> + </head> + <body> + <div class="app"> + <div class="view"> + <iframe + src="https://tilde.team/~<?=$current?>" + frameborder="0" + ></iframe> + </div> + <div class="control"> + <div> + you are viewing + <a href="https://tilde.team/~<?=$current?>" target="_blank" + ><?=$current?></a + > + site + </div> + <div> + <?php if (isset($prev)) { ?> + <a href="https://tilde.team/~grizzly/browser/?member=<?=$prev?>" + >[previous]</a + > + <?php } ?> + <a href="https://tilde.team/~grizzly/browser/?random">[random]</a> + <?php if (isset($next)) { ?> + <a href="https://tilde.team/~grizzly/browser/?member=<?=$next?>" + >[next]</a + > + <?php } ?> + </div> + <div class="cache">user list cache is updated once a day</div> + </div> + </div> + + <style> + * { + padding: 0; + margin: 0; + box-sizing: border-box; + } + body { + font-family: "lucida sans unicode", "lucida grande", sans-serif; + line-height: 1.7; + font-size: 14px; + background-color: #0e0e0e; + } + .app { + display: flex; + flex-direction: column; + min-height: 100vh; + } + .view { + display: flex; + flex-direction: column; + flex-grow: 1; + border: 5px dotted #3ee77b; + } + iframe { + flex-grow: 1; + background-color: #cecece; + } + .control { + display: flex; + flex-direction: column; + border-top: 5px dotted #3ee77b; + padding: 10px; + color: #3ee77b; + align-items: center; + } + .control a { + color: #99f2b9; + } + .cache { + font-size: 10px; + margin-top: 5px; + } + </style> + </body> +</html> \ No newline at end of file diff --git a/store/browser/curl.php b/store/browser/curl.php new file mode 100644 index 0000000..2692108 --- /dev/null +++ b/store/browser/curl.php @@ -0,0 +1,20 @@ +<?php + +require_once ('/home/grizzly/store/browser/db.php'); + +$c = curl_init(); +curl_setopt($c, CURLOPT_URL,'https://tilde.team/'); +curl_setopt($c, CURLOPT_RETURNTRANSFER, true); +$data = curl_exec($c); +curl_close($c); + +preg_match_all('/<li><a href="\/~(.*)\/" class=\"list-group-item col-xs-6 col-sm-4 col-md-2\">~(.*)<\/a><\/li>/', $data, $matches); + +foreach ($matches[1] as $user) { + $stmt = $db->prepare("INSERT INTO `websites` (login_name) VALUES(:login_name)"); + $stmt->bindParam(':login_name', $user); + $stmt->execute(); +} + + +?> \ No newline at end of file diff --git a/store/browser/db.php b/store/browser/db.php new file mode 100644 index 0000000..bfe73d8 --- /dev/null +++ b/store/browser/db.php @@ -0,0 +1,23 @@ +<?php + +$db = new PDO('sqlite:db_websites.sqlite3'); + +$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +$query = "CREATE TABLE IF NOT EXISTS websites +(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + login_name TEXT +)"; + +$db->exec($query); + +function cleanText($value) { + $value = strip_tags($value); + $value = htmlentities($value, ENT_QUOTES, "UTF-8"); + $value = trim($value); + $value = stripslashes($value); + $value = strval($value); + return $value; +} + +?> \ No newline at end of file diff --git a/store/browser/update.sh b/store/browser/update.sh new file mode 100644 index 0000000..1ea2a64 --- /dev/null +++ b/store/browser/update.sh @@ -0,0 +1,3 @@ +#!/bin/bash +rm /home/grizzly/store/browser/db_websites.sqlite3; +php /home/grizzly/store/browser/curl.php; \ No newline at end of file |