Browse Source

android support

raven 9 months ago
parent
commit
1491007aee

+ 152 - 0
README-TERMUX.md

@@ -0,0 +1,152 @@
+# Anarcho-Copy HTML generatörü / Tor-Onion Servisi - Android (root gerektirmez)
+
+Not: Bu generator android işletim sisteminde termux üzerinde test edilmiştir. Kuruluma geçmek için yönergeleri takip edin.
+
+## Gerekli ortamın hazırlanması (android)
+
+İlk önce `termux` programını android cihazına kur, tüm kurulumlar termux ortamında yapılıcaktır.
+
+ - [Termux - Play Store](https://play.google.com/store/apps/details?id=com.termux)
+ - [Termux - F-Droid](https://f-droid.org/en/packages/com.termux/)
+
+
+Daha rahat yazabilmek için [hacker's keyboard](https://play.google.com/store/apps/details?id=org.pocketworkstation.pckeyboard) klavye uygulamasını kullanın.
+
+## Kurulum
+
+Termux terminaline gir ardından gerekli paketleri ve programları kur:
+
+```bash
+$ pkg update && pkg install wget git tor ghostscript imagemagick exiftool sqlite nginx poppler bc
+```
+
+Şimdi kuruluma başlayabilirsin, adımları teker teker uygulan gerekiyor.
+
+Projenin kaynak kodunu gerekli dizine indir:
+
+```bash
+$ mkdir -p $PREFIX/var/www/hidden-service/
+$ chown -R $USER:$USER $PREFIX/var/www/hidden-service/
+$ cd $PREFIX/var/www/hidden-service/
+$ git clone https://git.anarcho-copy.org/www.anarcho-copy.org/hidden_site_generator.git
+```
+
+
+PDF dosyalarını indirip gerekli dizinleri ayarla.
+Telefonunun internet hızına göre bu adım biraz uzun sürecek, çay içip bekle.
+
+```bash
+$ mkdir -p $PREFIX/var/www/public/anarcho-copy.org/free/
+$ chown -R $USER:$USER $PREFIX/var/www/public/anarcho-copy.org/free/
+$ cd $PREFIX/var/www/public/anarcho-copy.org/free/
+$ wget https://anarcho-copy.org/.list
+$ for i in `<.list`; do wget "https://anarcho-copy.org/free/$i"; done
+$ rm .list
+```
+
+ardından generatorun kaynak konundaki config dosyasına termux için pdf yolunu tanıtman gerekir, bunun için   **nano** ile `$PREFIX/var/www/hidden-service/hidden_site_generator/bin/config.sh` dosyasını aç, `CTRL+W` yapıp `pdf_dir` değişkenini bul. Sonrasında ise o satırı aşağıdaki satır ile değiştir:
+
+```bash
+pdf_dir="/data/data/com.termux/files/usr/var/www/public/anarcho-copy.org/free"
+```
+bu kadar.
+
+
+## NGINX
+
+Moduler şekilde konfigure etmek için `$PREFIX/etc/nginx/nginx.conf` dosyasında `http` bloğunun içine aşağıdaki satırı ekle:
+
+```
+include /data/data/com.termux/files/usr/etc/nginx/conf.d/*.conf;
+```
+
+ardından moduler dizini oluştur:
+
+```
+$ mkdir -p $PREFIX/etc/nginx/conf.d/
+```
+
+proje dizinindeki nginx konfigurasyon dosyasını oluşturduğun dizine kopyala ve nginx'i çalıştır.
+```bash
+$ cp $PREFIX/var/www/hidden-service/hidden_site_generator/termux_nginx.conf $PREFIX/etc/nginx/conf.d/
+$ nginx
+```
+
+
+## TOR
+
+Tor onion servisinin anahtar dosyalarının saklanması için gerekli dizini oluştur:
+
+```bash
+$ mkdir -p $PREFIX/var/lib/tor/
+```
+
+ardından `$PREFIX/etc/tor/torrc` dosyasına aşağıdaki satırları ekle:
+
+```
+ HiddenServiceDir /data/data/com.termux/files/usr/var/lib/tor/hidden_service/
+ HiddenServicePort 80 127.0.0.1:8090
+```
+
+son olarak tor servisini çalıştır:
+
+```bash
+$ nohup tor > $PREFIX/var/log/tor.log &
+```
+
+Oluşturulan **onion** adresini görmek için ise: 
+
+```bash
+$ cat $PREFIX/var/lib/tor/hidden_service/hostname 
+```
+
+Onion adresini generatore tanıtmak için aşağıdaki komutu çalıştır (web adresini sayfa üzerinde göstermek için):
+
+```bash
+$ mkdir -p $PREFIX/var/www/hidden-service/hidden_site_generator/web && ln -s $PREFIX/var/lib/tor/hidden_service/hostname $PREFIX/var/www/hidden-service/hidden_site_generator/web/
+```
+
+> Not: Bu rehberde termux sistem servislerine değinilmedi, istersen [uygulayabilirsin](https://github.com/termux/termux-services).
+>
+> Unutma: Eğer tor düğümleri sansürlenen bir coğrafyadaysan obfs4 köprü ayarlarını elle yapman gerekecektir.
+
+
+## Statik Dosyaları Oluştur
+
+Proje dizinine git ve statik dosyaları aşağıdaki argümanlar ile yarat:
+
+```bash
+$  cd $PREFIX/var/www/hidden-service/hidden_site_generator/
+$ ./termux_run.sh -bcg
+```
+
+## Kullanım
+
+```
+usage: ./termux_run.sh [-h] [-n] [-b|-c] [-g] [-r] [-t|-s] | [ -p --delete | --delete-all ]
+-h       help page
+-b       build html.
+-c       create static contents (as image etc.)
+-g       generate the web site as use created files
+-p
+   --delete     (it does not include the static contents)
+   --delete-all (purge all files, it does include the static contents)
+
+```
+
+
+## Proje Dizinleri
+
+```text
+bin/                      :  generatörü inşa eden temel dosyalar.
+src/                      :  kullanılan ek kaynaklar
+var/                      :  veri tabanı (sqlite3)
+i/template                :  html şablonları
+i/contents                :  manual dosyaların bulunduğu dizin
+
+i/contents/css/primer.css :  Github Primer css teması. (henüz uygulanıyor)
+```
+
+### Demo sürüm:
+
+https://build.anarcho-copy.org

+ 3 - 3
bin/config.sh

@@ -6,8 +6,8 @@ robots_config="noindex,nofollow"
 
 #website main title
 site_title="Anarcho-Copy Hidden Site"
-hidden_site=$(echo "http://$(grep -oP "server_name\s+\K\w+" ../web/site.conf 2>/dev/null).onion")
-[ -f ../web/site.conf ] || hidden_site="";
+hidden_site=$(cat ../web/hostname 2>/dev/null)
+[ -f ../web/hostname ] || hidden_site="";
 base_href=$hidden_site ##not using at <!--force_base_href-->
 
 #robots.txt config
@@ -30,7 +30,7 @@ redend="\e[0m";
 data_base="../var/books.db";
 
 #pdfs dir config
-pdf_dir="/var/www/public/anarcho-copy.org/free"
+pdf_dir="/data/data/com.termux/files/usr/var/www/public/anarcho-copy.org/free"
 
 #style
 function print_style() {

+ 2 - 2
i/template/books_index_without_zines_html.sh

@@ -6,14 +6,14 @@ if [ -z "$hidden_site" ]
 then
 cat <<EOF
 <div class="flash flash-error">
-onion servisi çalışmıyor
+onion adresi tanımlanmadı
 </div>
 EOF
 else
 cat <<EOF
 <div class="flash flash-success">
 onion servisi şu adreste çalışıyor:&nbsp;
-<a href="$hidden_site">$hidden_site</a>
+<a href="http://$hidden_site">$hidden_site</a>
 </div>
 EOF
 fi

+ 1 - 1
i/template/copy_page.sh

@@ -16,7 +16,7 @@ cat <<EOT
 <meta name="keywords" content="pdf, $title pdf, $title, $author, indir, $( [[ -n "$keywords" ]] && echo "$keywords" )" />
 <meta name="copyright" content="No Copyright" />
 <meta name="robots" content="$robots_config" />
-<meta name="generator" content="$generator" />x
+<meta name="generator" content="$generator" />
 <meta http-equiv="Content-Style-Type" content="text/css">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 $style

+ 12 - 3
install_requirements.sh

@@ -2,11 +2,13 @@
 # these scripts written in GNU bash; version 5.0.16(1)-release (x86_64-pc-linux-gnu)
 #  and version 5.0.17(1)-release (x86_64-redhat-linux-gnu)
 #  and version 4.4.19(1)-release (x86_64-redhat-linux-gnu)
+#  and version 5.1.0(1)-release (aarch64-linux-android)
 
 function guide() {
-echo "usage: ./`basename $0` [debian | rhel]"
+echo "usage: ./`basename $0` [debian | rhel | termux]"
 echo "use debian option to apt based distros, such as Ubuntu."
-echo -e "use rhel option to dnf based distros, such as Fedora.\n"
+echo -e "use rhel option to dnf based distros, such as Fedora."
+echo -e "use termux option to android termux.\n"
 echo "this generator tested under debian and fedora."
 exit 0;
 }
@@ -18,11 +20,18 @@ apt-get update && \
 	# libio-compress-perl libdigest-sha-perl
 }
 
-rhel(){
+rhel() {
 dnf install \
     ghostscript ImageMagick perl-Image-ExifTool sqlite coreutils nginx poppler-utils podman-docker perl-IO-Compress perl-Digest-SHA bc
 }
 
+termux() {
+pkg update && \
+    pkg install \
+    wget git tor ghostscript imagemagick exiftool sqlite coreutils nginx poppler bc
+}
+
+
 if [ "$#" -lt 1 ]; then
     guide;
 fi

+ 9 - 11
main_nginx.conf

@@ -1,17 +1,15 @@
 ##add this configuration to /etc/nginx/sites-available/
 
 server {
-
-        listen 8080;
-        listen [::]:8080;
+        # server anonymity
+        #   listen only localhost to reject requests from outside
+        listen 127.0.0.1:8080;
+        #   disable server tokens
+        server_tokens  off;
+        #   disable port redirect
+        port_in_redirect off;
+        ##
 
         root /var/www/hidden-service/hidden_site_generator/public;
-
-        index index.html index.htm;
-
-        location / {
-                try_files $uri $uri/ =404;
-        }
-
+        index index.html;
 }
-

+ 15 - 14
src/index.sh

@@ -16,20 +16,20 @@ index_chars="1 2 A B C Ç D E F G Ğ H I İ J K L M N O Ö P Q R S Ş T U Ü V W
 #echo ""
 
 function author_index() {
-sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > /tmp/.list.txt
-sort /tmp/.list.txt | uniq -ci > /tmp/.listed.txt
+sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > .list.txt
+sort .list.txt | uniq -ci > .listed.txt
 while IFS=" " read -r count author
 do
 cat <<EOT
-<a href="/index/#$(cat /tmp/.author_count)">$author</a> ($count),
+<a href="/index/#$(cat .author_count)">$author</a> ($count),
 EOT
- echo "$((  $(cat /tmp/.author_count) + 1 ))" > /tmp/.author_count 
-done < /tmp/.listed.txt
+ echo "$((  $(cat .author_count) + 1 ))" > .author_count
+done < .listed.txt
 }
 
 
 function author_loop() {
-echo "0" > /tmp/.author_count
+echo "0" > .author_count
 for x in $index_chars;
 do
 cat <<EOT
@@ -43,35 +43,35 @@ done;
 ###########################3
 
 function author_table() {
-sqlite3 $db_file "SELECT title,url FROM books WHERE author IS '$1'" > /tmp/.table.txt
+sqlite3 $db_file "SELECT title,url FROM books WHERE author IS '$1'" > .table.txt
 while IFS="|" read -r title url
 do
 cat <<EOT
 <li><a href="/copy/$url/">$title</a></li>
 EOT
-done < /tmp/.table.txt
+done < .table.txt
 }
 
 
 function start_index() {
-sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > /tmp/.list.txt
-sort /tmp/.list.txt | uniq -ci > /tmp/.listed.txt
+sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > .list.txt
+sort .list.txt | uniq -ci > .listed.txt
 while IFS=" " read -r count author
 do
 cat <<EOT
-<li id="$(cat /tmp/.id_count)"><span id="$(echo "$author" | bash $url_slug )">$author ($count)</span>
+<li id="$(cat .id_count)"><span id="$(echo "$author" | bash $url_slug )">$author ($count)</span>
 <ul>
 $(author_table "$author")
 </ul>
 </li>
 EOT
- echo "$((  $(cat /tmp/.id_count) + 1 ))" > /tmp/.id_count 
-done < /tmp/.listed.txt
+ echo "$((  $(cat .id_count) + 1 ))" > .id_count 
+done < .listed.txt
 }
 
 
 function start_loop() {
-echo "0" > /tmp/.id_count
+echo "0" > .id_count
 for x in $index_chars;
 do
 cat <<EOT
@@ -154,3 +154,4 @@ echo -ne "</br></br></div>\n</div>\n</body>\n</html>"
 
 ##END
 
+rm .list.txt .listed.txt .author_count .table.txt .id_count &>/dev/null

+ 7 - 5
src/standalone_html.sh

@@ -15,19 +15,19 @@ index_chars="1 2 A B C Ç D E F G Ğ H I İ J K L M N O Ö P Q R S Ş T U Ü V W
 
 
 function author_table() {
-sqlite3 $db_file "SELECT title,url FROM books WHERE author IS '$1'" > /tmp/.table.txt
+sqlite3 $db_file "SELECT title,url FROM books WHERE author IS '$1'" > .table.txt
 while IFS="|" read -r title url
 do
 cat <<EOT
 <li><a href="$link/free/$url.pdf">$title</a></li>
 EOT
-done < /tmp/.table.txt
+done < .table.txt
 }
 
 
 function start_index() {
-sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > /tmp/.list.txt
-sort /tmp/.list.txt | uniq -ci > /tmp/.listed.txt
+sqlite3 $db_file "SELECT author FROM books WHERE author LIKE '$1%'" > .list.txt
+sort .list.txt | uniq -ci > .listed.txt
 while IFS=" " read -r count author
 do
 id=$(echo "$author" | bash $url_slug);
@@ -41,7 +41,7 @@ $(author_table "$author")
 </li>
 <br/>
 EOT
-done < /tmp/.listed.txt
+done < .listed.txt
 }
 
 
@@ -80,3 +80,5 @@ $(start_loop)
 </ul>
 </div>
 EOT
+
+rm .table.txt .list.txt .listed.txt &>/dev/null

+ 15 - 0
termux_nginx.conf

@@ -0,0 +1,15 @@
+##add this configuration to /data/data/com.termux/files/usr/etc/nginx/conf.d/
+
+server {
+        # server anonymity
+        #   listen only localhost to reject requests from outside
+        listen 127.0.0.1:8090;
+        #   disable server tokens
+        server_tokens  off;
+        #   disable port redirect
+        port_in_redirect off;
+        ##
+        
+        root /data/data/com.termux/files/usr/var/www/hidden-service/hidden_site_generator/public;
+        index index.html;
+}

+ 129 - 0
termux_run.sh

@@ -0,0 +1,129 @@
+#!/bin/bash
+
+cd "$(dirname "$0")";
+. src/ask.sh #import the ask()
+. i/template/tor.html.sh #import tor template page | tor.html()
+. i/template/standalone.sh #import standalone html page | print_standalone()
+. bin/config.sh &> /dev/null #import config
+chmod 770 bin/*
+chmod 770 i/template/*
+chmod 770 src/*
+
+
+#help page
+function purge_guide() {
+cat <<EOF
+-p
+   --delete     (it does not include the static contents)
+   --delete-all (purge all files, it does include the static contents)
+EOF
+}
+function guide() {
+echo "usage: ./`basename $0` [-h] [-n] [-b|-c] [-g] [-r] [-t|-s] | [ -p --delete | --delete-all ]"
+echo "-h       help page"
+echo "-b       build html."
+echo "-c       create static contents (as image etc.)"
+echo "-g       generate the web site as use created files"
+purge_guide;
+}
+
+
+#build html files [-b] option
+function build() {
+rm -rf i/out/*;
+mkdir -p i/out/{copy,pdf};
+mkdir -p .tmp/;
+bin/generate_author_pages.sh -gl
+bin/generate_copy_files.sh -egl
+bin/generate_websites_index.sh && echo "websites index page generated"
+}
+
+
+#create static contents [-c] option
+function create() {
+mkdir -p i/listen/copy
+bin/generate_pdf_files.sh -iem #-c option is delete already created files
+}
+
+
+
+#generate the web site as use created files [-g option]
+function main() {
+mkdir -p public/;
+chmod 0755 public/;
+find public/free -type l -exec unlink {} \; &> /dev/null && echo "symbolic links removed"
+rm -rf public/* &> /dev/null && echo "pages deleted"
+mkdir public/free &> /dev/null && echo "pdf raw dir created"
+cp -r i/out/* public/ && echo "i/out/* files are copied."
+cp -r i/listen/copy/ public/ && echo "i/listen/copy/ dir copied"
+cp -r i/contents/* public/ && echo "i/contents/* are copied"
+ln -s $pdf_dir/* public/free && echo "/var/pdf/ symbolic link created"
+tor.html > public/tor.html && echo "tor.html created"
+print_standalone > public/print.html && echo "print.html created"
+mkdir public/index && echo "index page creating.."
+nohup bash src/index.sh > public/index/index.html &
+find public/ -type f -exec chmod 0644 {} \; &> /dev/null && echo "files permissions setted"
+find public/ -type d -exec chmod 0755 {} \; &> /dev/null && echo "directory permissions setted"
+}
+
+
+
+#purge everything [-p] option
+function purge() {
+function delete_default() {
+rm -rf i/out/* && echo "i/out/* are deleted";
+rm -rf public/* && echo "public/* are deleted";
+rm -rf .tmp/* && echo ".tmp/* are deleted";
+find -path '.tmp/.*' -delete && echo ".tmp/.* are deleted";
+}
+
+function delete_static() {
+rm -rf i/listen/copy/* && echo "i/listen/* are deleted";
+}
+
+ case $purge_arg in
+    --delete)
+    delete_default
+    ;;
+    --delete-all)
+    delete_default
+	if ask "do you want the delete static files?" N; then
+	    delete_static;
+	else
+	    echo "--delete-all option is bypassed"
+	fi
+    ;;
+    *)
+    echo "unknown option: $purge_arg"
+    purge_guide;
+    ;;
+ esac
+
+}
+
+
+while getopts ":hbcgp:" opt; do
+  case ${opt} in
+    h ) guide;
+      ;;
+    b ) build;
+      ;;
+    c ) create;
+      ;;
+    g ) main;
+      ;;
+    p )
+      purge_arg=${OPTARG}
+      purge
+      ;;
+    : )
+      echo "Missing option argument for -$OPTARG [ --default | --all ]"
+      purge_guide
+      ;;
+  esac
+done
+
+
+if [ "$#" -lt 1 ]; then
+    guide;
+fi