Initial commit

This commit is contained in:
Sebastian Korotkiewicz 2022-03-19 09:17:55 +01:00
commit 53da95395a
Signed by: grizzly
GPG Key ID: 5BDC557B496BDB0D
7 changed files with 216 additions and 0 deletions

40
README.md Normal file
View File

@ -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

8
cron.txt Normal file
View File

@ -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

View File

@ -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";
?>

View File

@ -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>

20
store/browser/curl.php Normal file
View File

@ -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();
}
?>

23
store/browser/db.php Normal file
View File

@ -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;
}
?>

3
store/browser/update.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
rm /home/grizzly/store/browser/db_websites.sqlite3;
php /home/grizzly/store/browser/curl.php;