Commit 0c44c92d authored by Dominika Liberda's avatar Dominika Liberda 💽

updated default config, moved example demos to a separate repository

parent 7c4ec8d8
......@@ -42,6 +42,8 @@ Originally made for Junction Stupidhack 2020; Created by [redsPL](https://sakamo
## Variables that we think are cool!
![](https://f.sakamoto.pl/d6584c01-1c48-42b9-935b-d9a89af4e071file_101.jpg)
- $post_data - array, contains data from urlencoded POSTs
- $post_multipart - array, contains URIs to uploaded files from multipart/form-data POSTs
- $get_data - array, contains data from GETs
......
......@@ -9,20 +9,23 @@ cfg[autoindex]=true
cfg[auth_required]=false
cfg[auth_realm]="Laura is cute <3"
cfg[ssl]=true
cfg[ssl]=false
cfg[ssl_port]=8443
cfg[ssl_cert]=''
cfg[ssl_key]=''
cfg[extension]='shs'
cfg[extra_headers]='server: HTTP.sh/0.9'
cfg[extra_headers]='server: HTTP.sh/0.91 (devel)'
cfg[title]='ddd defies development'
cfg[php_enabled]=true
cfg[python_enabled]=true
cfg[php_enabled]=false
cfg[python_enabled]=false
# by default, those logs are placed in the main directory - change it to /var/log/_name_ for production
cfg[log_http]='log_http'
cfg[log_https]='log_https'
cfg[log_misc]='log'
cfg[proxy]=false
cfg[proxy_url]='http://example.com/'
\ No newline at end of file
#!/bin/bash
source templates/head.sh
echo "<form action='listing.shs'>
<input type='text' name='q'>
<input type='submit' value='Search'>
</form>"
#!/bin/bash
cat webroot/allegro/listing_top.txt
query="$(echo "${get_data[q]}" | sed -s "s/ /%20/g;s/+/%20/g")"
query_nice=$(echo ${get_data[q]} | sed -s "s/+/ /g;")
[[ ${get_data[order]} ]] && order=${get_data[order]} || order='p'
echo "Searching for '$query_nice'"
IFS=$'\n'
data=$(curl "https://allegro.pl/listing?string=$query&order=$order" | sed -E 's/<\/article>/\n/g' | grep -ohE "allegro.pl/oferta(.*)")
cost=($(echo "$data" | grep -Eoh "span class=\"[A-Za-z0-9_]{12}\">([0-9]+|[0-9]+ [0-9]+)<span>,<\/span><span class=\"[A-Za-z0-9_]{12}\">[0-9]+" | sed -E 's/span class=\"[A-Za-z0-9_]{12}\">//g;s/<span>//g;s/<\/span><//g'))
img=($(echo "${data}" | sed -E 's/\" [a-z]{3,5}\="/\n/g;s/,/\n/g;s/ [0-9]+w//g;s/" \/>//g' | grep -ohE "[a-z0-9].allegroimg.com/s[0-9]+/[a-z0-9]{6}/[a-z0-9]{28}/(.*)"))
name=($(echo "${data}" | sed -E 's/<\/a>/\n/g' | grep -ohE 'title="">(.*)' | sed -s 's/title="">//g'))
links=($(echo "${data}" | sed -E 's/"(.*)//g'))
for (( i=0; i<${#img[@]}; i++ )) do
#echo "<div><a href='https://${links[$i]}'><img src='https://${img[$i]}'>${cost[$i]}PLN<br><b>${name[$i]}</b></a></div>"
echo "
<!-- ITEM BEGIN -->
<tr>
<td class='cellPhoto'>
<a href='${links[$i]}' class='iImg' title='${name[$i]}'><img src='https://${img[$i]}'></a>
</td>
<td class='cellName'>
<div>
<a href='https://${links[$i]}' class='alleLink iTitle'>
<span>${name[$i]}</span>
</a>
<span class='listingParams'>
</span>
<span>
</span>
</div>
</td>
<td class='cellPrice'>
<span class='iPriceBN'><span>Kup Teraz!</span> ${cost[$i]} zł</span>
</td>
<td class='cellTrans'>
<div>
<span class='iPriceBND'>
<span>z dostawą:</span>
<span class='listingPostagePrice'>??? zł</span>
</span>
</div>
</td>
<td class='cellOffer'>
<span class='iOffer'><span>Popularność:</span> ???</span> </td>
<td class='cellTime alert'>
<span class='iTime'><span>Do końca:</span> <font color='#ff0000'>???</font></span>
</td>
</tr>
<!-- ITEM END -->
"
done
cat webroot/allegro/listing_bottom.txt
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
domainprefix='https://megumin.tech/boards'
meta[title]='bashchan'
meta[css]='style.css'
source templates/head.sh
echo "<body>
<div class='center'>
<a href='./'><img id='branding' src='/img/branding_chinacat.png'><br>
bashchan</a> - a place for all your shitposts
</div>
"
IFS=$'\n'
for i in $(ls -t storage/threads); do
IFS=':'
array=($(cat storage/threads/$i | head -n 1))
echo "<a href='thread.shs?id=$i' class='nolinkdecoration'><div class='post'>"
if [[ ${array[1]} != '' ]]; then
echo "<span class='thread_title'>${array[1]}</span> | "
fi
echo "<span class='poster'>${array[0]}</span><br><img src='$domainprefix/i/${array[3]}' class='pic'>${array[2]}</div></a><hr>"
done
echo "<div class='center'><h2>Submit a new thread</h2>
<form enctype='multipart/form-data' action='post.shs' method='post' id='post'>
<input type='hidden' name='rel' value='new'>
<input type='hidden' name='a' value='broken'>
<input type='text' name='title' class='title' placeholder='Title' required><br>
<textarea name='msg' class='msg' placeholder='Message'></textarea><br>
<input type='file' name='file' class='file' accept='image/*'>
<input type='submit' value='Submit' class='submit'>
</form></center>"
#!/bin/bash
title=$(cat ${post_multipart[2]} | sed -s 's/<//g;s/://g' | tr -d '\n\r')
msg=$(cat ${post_multipart[3]} | sed -E 's/<//g;s/$/<br>/g;s/://g' | tr -d '\n\r')
img=${post_multipart[4]}
img_name=$(basename ${post_multipart[4]})
rel=$(cat ${post_multipart[0]} | sed -E 's/<//g;s/\r//g')
if [[ $title == '' && $rel == '' ]]; then
echo "Empty title?"
return 1
fi
if [[ $(file --mime-type -b $img) == "image/"* ]]; then
mv "$img" "$pwd/i/$img_name"
img_copied_url="i/$img_name"
elif [[ $rel == 'new' ]]; then
echo "No image?"
return 1
elif [[ $msg == '<br>' ]]; then
echo "Post something!"
return 1
fi
if session_verify ${cookies[sh_session]}; then
username=$(session_get_username ${cookies[sh_session]})
else
username='Anon'
fi
if [[ $rel == *"new"* ]]; then
rel=$(($(ls storage/threads/ | wc -l)+1))
touch "storage/threads/$rel"
fi
if [[ -f "storage/threads/$rel" ]]; then
echo "$username:$title:$msg:$img_name" | sed -E "s/\r//g" >> "storage/threads/$rel"
else
echo "No such thread!!"
return 1
fi
meta[redirect]="thread.shs?id=$rel"
source templates/head.sh
echo "Submitted succesfully.<br>
<a href='thread.shs?id=$rel'>Click here if you're not redirected</a>"
.center {
margin-left: auto;
margin-right: auto;
max-width: 100%;
display: block;
text-align: center;
margin-bottom: 30px;
}
.file {
width: 225px
}
.msg {
width: 325px;
height: 125px;
}
.title {
width: 318px;
}
.submit {
width: 95px;
}
.pic {
width: 200px;
}
.thread_title {
color: #f44;
}
.poster {
color: #4f4;
}
.post {
margin: 5px;
background-color: #222;
}
.nolinkdecoration, .nolinkdecoration > div {
color: #ccc;
text-decoration: none;
}
#!/bin/bash
domainprefix='https://megumin.tech/boards'
id=${get_data[id]}
if [[ $id == '' ]]; then
return 1
elif [[ $id == *".."* ]]; then
return 1
fi
meta[css]='style.css'
meta[title]="Thread #$id"
source templates/head.sh
echo "<body>
<div class='center'>
<a href='./'><img id='branding' src='/img/branding_chinacat.png'><br>
bashchan</a> - a place for all your shitposts
</div>
"
IFS=$'\n'
for i in $(cat storage/threads/$id); do
IFS=':'
array=($i)
echo "<div class='post'>"
if [[ ${array[1]} != '' ]]; then
echo "<span class='thread_title'>${array[1]}</span> | "
fi
echo "<span class='poster'>${array[0]}</span><br>"
if [[ -a "$pwd/i/${array[3]}" ]]; then
echo "<a href='$domainprefix/i/${array[3]}'><img src='$domainprefix/i/${array[3]}' class='pic'></a>"
fi
echo "${array[2]}</div>"
done
echo "<form enctype='multipart/form-data' action='post.shs' method='post' id='post'>
<input type='hidden' name='rel' value='$id'>
<input type='hidden' name='a' value='broken'>
<input type='text' name='title' class='title' placeholder='Title'><br>
<textarea name='msg' class='msg' placeholder='Message'></textarea><br>
<input type='file' name='file' class='file' accept='image/*'>
<input type='submit' value='Submit' class='submit'>
</form>
"
#!/bin/bash
meta[title]='HTTP.sh'
meta[author]='Dominika, Laura, Patrycja'
meta[description]='HTTP.sh - a quick and dirty webserver, written in Bash'
meta[keywords]='bash,http,web,server,http.sh'
meta[lang]='en'
source templates/head.sh
echo "<body>
<style>
h1,h2,h3 {
color: #fff
}
.lr {
position: absolute;
right: 5px;
}
</style>"
if [[ ! ${cookies[sh_session]} ]]; then
echo "<div class='lr'><a href='login.shs'>Log in</a> or <a href='register.shs'>Register</a></div>"
else
echo "<div class='lr'>Logged in as ${cookies[username]}| <a href='logout.shs'>Log out</a></div>"
fi
echo "<img src='img/branding_pxplus.png'>
<h2>HTTP.sh - a quick and dirty webserver, written in Bash</h2>
<p>
Although we've seen several attempts to create a Bash web framework, all of them fell flat one way or another.<br>
We've decided to change that. Did we succeed? You be the judge!
</p>
<h3>Download</h3>
<p>
This web server was tested as much as the time allowed, but we can't say for certain that it's bug free.<br>
If you want to check out our (dirty) code, download the current <a href='http://f.sakamoto.pl/httpsh.tar.xz'>tarball</a>.<br><br>
We also can't guarantee that HTTP.sh is <a href='https://xkcd.com/641/'>asbestos free</a>, so <b>proceed with caution.</b>
</p>
<h3>Dependencies</h3>
<ol>
<li>Bash or 100% compatible shell</li>
<li><a href='http://nmap.org/ncat'>Ncat</a> - nc/nc.traditional WILL NOT work</li>
<li>GNU coreutils (dd, base64 and others)</li>
<li>pkill</li>
<li>mktemp</li>
<li>sha1sum, sha256sum</li>
<li>curl (only for a few demos)</li>
<li>certbot (only if you'd like to get a SSL cert)
</ol>
<h3>Demos</h3>
<ol>
<li><a href='boards/'>bashchan</a> (an imageboard)</li>
<li><a href='pastebin/'>bashbin</a> (a pastebin)</li>
<li><a href='yt/'>bashtube</a> (a YouTube frontend)</li>
<li><a href='shortener/'>bashurl</a> (a URL shortener)</li>
<li><a href='upload/'>bashupload</a> (a file uploader)</li>
<li><a href='allegro/'>bashallgero</a> (a frontend for a Polish auction site)</li>
<li><a href='img/'>listing</a> (just a file listing, but it looks mighty cool)</li>
</ol>
<hr>
Made by <a href='https://sakamoto.pl/' id='reds'>reds</a>, <a href='https://selfisekai.rocks/' style='color:#d60270;'>selfisekai</a> and <a href='https://ptrcnull.me/' style='color:#ffb9d3'>ptrcnull</a>. IF YOU LOG IN, THIS SITE WILL STORE COOKIES ON YOUR PERSONAL COMPUTING DEVICE"
#!/bin/bash
if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
login ${post_data[login]} ${post_data[password]}
status=$?
if [[ $status == 0 ]]; then
echo ${get_data[r]} > /dev/stderr
if [[ ${get_data[r]} == '' ]]; then
meta[redirect]='/'
else
meta[redirect]="$(echo ${get_data[r]} | sed -s 's/<//g;s/___/?/')"
fi
fi
fi
source templates/head.sh
if [[ $status == 1 && $reason != '' ]]; then
echo $reason
fi
echo "<h1>Log in...</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Login'>
</form>
(please make sure that you're connecting over SSL)"
#!/bin/bash
logout
meta[redirect]='/'
source templates/head.sh
echo "Logged out successully. Redirecting.."
#!/bin/bash
domainprefix="https://paste.megumin.tech/"
if [[ ${post_data[paste]} ]]; then
filepath=$(mktemp -p $pwd XXX)
filename=$(basename $filepath)
if [[ ${post_data[public]} == "on" ]]; then
echo $filename >> $pwd/list
fi
if session_verify ${cookies[sh_session]}; then
echo "$filename:$(session_get_username ${cookies[sh_session]})" >> storage/pastes
fi
echo -e $(echo "${post_data[paste]}" | sed -E 's/\+/ /g;s/\%/\\x/g') > $filepath
meta[redirect]="$domainprefix$filename"
fi
source templates/head.sh
echo "<body>
<form method='post'>
<input type='submit' value='Send!'>
<input type='checkbox' name='public'>
<label for='public'>Public?</label><br>
<textarea name='paste' rows='25' cols='80'></textarea>
</form>
"
if session_verify ${cookies[sh_session]}; then
echo "<h3>Your pastes:</h3>"
pastes=$(grep -E "$(session_get_username ${cookies[sh_session]})\$" storage/pastes)
if [[ $pastes != '' ]]; then
echo "<ol>"
for i in $pastes; do
IFS=':'
array=($i)
echo "<li><a href='${array[0]}'>${array[0]}</a></li>"
done
echo "</ol>"
else
echo "You currently do not have any pastes."
fi
else
echo "If you log in, we'll be able to show you your paste history here :)"
fi
echo "<h3>Latest public pastes:</h3><ol>"
public=$(tac $pwd/list | head -n 10)
IFS=$'\n'
for i in $public; do
echo "<li><a href='$domainprefix$i'>$i</a></li>"
done
unset IFS
echo "</li>"
#!/bin/bash
if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
register ${post_data[login]} ${post_data[password]}
status=$?
if [[ $status == 0 ]]; then
meta[redirect]='/'
fi
fi
source templates/head.sh
if [[ $status == 1 && $reason != '' ]]; then
echo $reason
fi
echo "<h1>Register</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Register'>
</form>
(please make sure that you're connecting over SSL)"
#!/bin/bash
domainprefix="https://url.megumin.tech/"
not_found=false
if [[ ${get_data[u]} ]]; then
id=${get_data[u]}
if [[ -f storage/shortener/$id ]]; then
meta[redirect]=$(cat storage/shortener/$id)
else
not_found=true
fi
fi
meta[title]="url shortener i guess"
source templates/head.sh
if [[ $not_found == "true" ]]; then
echo "<h1>ID not found</h1>"
else
if [[ ${post_data[url]} ]]; then
if [[ ! -d storage/shortener ]]; then
mkdir storage/shortener
fi
id=$(dd if=/dev/urandom bs=256 count=1 | sha1sum | cut -c 1-8)
link=$(printf $(sed 's/%/\\x/g' <<< ${post_data[url]}))
echo -n $link > storage/shortener/$id
echo "<p>URL created: <a href='$domainprefix?u=$id'>link</a></p>"
else
echo '<h1>Revolutionary URL shortener</h1>
<form method="POST">
<input type="text" name="url" placeholder="URL">
<button type="submit">Submit</button>
</form>';
fi
fi
#!/bin/bash
source templates/head.sh
domainprefix="https://f.megumin.tech/"
if [[ ${post_multipart} != '' ]]; then
for i in ${post_multipart[@]}; do
asdf=$(mktemp -p $(dirname ${r[uri]}) XXX)
relative=$(realpath --relative-to "$(dirname ${r[uri]})" $asdf)
mv "$i" $asdf
rm "$i"
echo "<a href='$domainprefix$relative'>Your uploaded file</a>"
done
else
echo '<form enctype="multipart/form-data" method="POST">
<input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>'
fi
#!/bin/bash
if session_verify ${cookies[sh_session]} && [[ ${get_data[v]} != '' ]]; then
title=$(youtube-dl -e "https://youtube.com/watch?v=${get_data[v]}")
if [[ $(cat storage/faves | grep -F "$title" | grep "$(echo ${cookies[username]} | sed -E "s/\r//")") == '' ]]; then
echo "$(session_get_username ${cookies[sh_session]}):${get_data[v]}:$title" >> storage/faves
fi
fi
source templates/head.sh
echo "<a href='./'>&lt;--- back to main</a><br><h1>Your favourites</h1>"
IFS=$'\n'
for i in $(tac storage/faves); do
IFS=':'
array=($i)
echo "<div><a href='watch.shs?v=${array[1]}'><img src='https://i.ytimg.com/vi/${array[1]}/mqdefault.jpg'><br><b>${array[@]:2:999}</b></a><br></div>";
done
#!/bin/bash
source templates/head.sh
echo "<form action='${r[url]}/search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<h1>All user's favourites</h1>"
IFS=$'\n'
for i in $(tac storage/faves); do
IFS=':'
array=($i)
echo "<div><a href='watch.shs?v=${array[1]}'><img src='https://i.ytimg.com/vi/${array[1]}/mqdefault.jpg'><br><b>${array[@]:2:999}</b></a><br>Favourited by ${array[0]}</div>";
done
#!/bin/bash
meta[title]="youtube but not really"
source templates/head.sh
# GOOD LUCK FIXING IT WHEN GOOGLE BREAKS IT LOL
echo "<form action='${r[url]}/search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
"
if [[ ${get_data[q]} ]]; then
query=${get_data[q]}
query_nice=$(echo ${get_data[q]} | sed -s 's/+/ /g')
echo "<p>Searching for '$query_nice'</p>"
data=''
while [[ $data == '' ]]; do
data=$(curl -s "https://www.youtube.com/results?search_query=$query&hl=en&hs=en")
done
IFS=$'\n'
id=($(echo $data | sed -E 's/<\/a>/\n/g' | grep -ohE 'watch\?v\=[-A-Za-z0-9_]{11}" (.*) rel\="spf-prefetch"' | sed -E 's/watch\?v\=//g;s/" class="yt-uix-tile-link(.*)//g'))
title=($(echo $data | sed -E 's/<\/a>/\n/g' | grep -ohE 'watch\?v\=[-A-Za-z0-9_]{11}" (.*) rel\="spf-prefetch"' | sed -E 's/watch\?v\=[-A-Za-z0-9_]{11}" class\="yt-uix-tile-link(.*)title\="/ /g;s/" rel\="spf-prefetch"//g'))
unset IFS
for (( i=0; i<${#id[@]}; i++ )); do
echo "<a href='/yt/watch.shs?v=${id[$i]}'><img src='https://i.ytimg.com/vi/${id[$i]}/mqdefault.jpg'><br>${title[$i]}</a><br>"
done
else
echo "search for something will 'ya?"
fi
#!/bin/bash
if session_verify ${cookies[sh_session]} && [[ ${get_data[v]} != '' ]]; then
name=$(session_get_username ${cookies[sh_session]})
vid=$(echo -n ${get_data[v]} | sed -E 's/\r//g')
sed -i "/^$name:$vid/d" storage/faves
fi
meta[redirect]='fav.shs'
source templates/head.sh
#!/bin/bash
# fetching recommended disabled for speed
#for i in $(curl https://www.youtube.com/watch?v=${get_data[v]} | grep -ohE "watch\?v\=[A-zaz0-9]{11}" | uniq | cut -c 9-19); do
# echo "<div><img src='http://i.ytimg.com/vi/$i/hqdefault.jpg'><br><audio src='$(youtube-dl -g -f 251 $i)' controls></audio></div>";
#done
if [[ ${get_data[v]} ]]; then
video=$(youtube-dl -J "http://youtube.com/watch?v=${get_data[v]}")
if [[ $video == '' ]]; then
video=$(youtube-dl -J "http://youtube.com/watch?v=${get_data[v]}")