]> bicyclesonthemoon.info Git - yplom/facebug1/commitdiff
look through directory
authorb <b@7dec801f-c475-4e67-ba99-809552d69c55>
Wed, 25 Nov 2015 23:56:04 +0000 (23:56 +0000)
committerb <b@7dec801f-c475-4e67-ba99-809552d69c55>
Wed, 25 Nov 2015 23:56:04 +0000 (23:56 +0000)
head header

git-svn-id: svn://botcastle1b/yplom/facebug1@1 7dec801f-c475-4e67-ba99-809552d69c55

bot.1.pl [new file with mode: 0644]
configure.pl [new file with mode: 0644]
make.sh [new file with mode: 0644]
makefile.1.mak [new file with mode: 0644]
settings [new file with mode: 0644]

diff --git a/bot.1.pl b/bot.1.pl
new file mode 100644 (file)
index 0000000..cc473a5
--- /dev/null
+++ b/bot.1.pl
@@ -0,0 +1,172 @@
+###PERL;\r
+\r
+use strict;\r
+\r
+###PROXY_LIB;\r
+use proxy_lib qw(url2path path2urldiv getcgi divideurl);\r
+use POSIX qw(strftime);\r
+\r
+my $time = time();\r
+print strftime("%d.%m.%Y %H:%M:%S", gmtime($time))."\n";\r
+for (my $ind=0; $ind < scalar @ARGV; ++$ind) {\r
+       my %set = {};\r
+       my $basepath='';\r
+       my $configfile;\r
+       \r
+       unless (open ($configfile, "<", $ARGV[$ind])) {\r
+               print "Cannot open $ARGV[$ind]\n";\r
+               next;\r
+       }\r
+       \r
+       while (defined(my $line = <$configfile>)) {\r
+               $line =~ s/[\r\n]//g;\r
+               $line =~ s/#.*$//;\r
+               if ($line =~ /^ *([a-zA-Z0-9_]+) *= *(.*)$/){\r
+                       my $name=$1;\r
+                       my $value=$2;\r
+                       $value =~ s/ *$//; \r
+                       $set{$name}=$value;\r
+               }\r
+       }\r
+       close ($configfile);\r
+       \r
+       if ($set{'id'} =~ /^([0-9]+)$/) {\r
+               my $basepath = url2path('https://m.facebook.com/groups/'.$1).'@q/';\r
+               processdir($basepath);\r
+       }\r
+       else {\r
+               print "Invalid ID $ARGV[$ind]\n";\r
+               next;\r
+       }\r
+}\r
+\r
+sub processdir {\r
+       (my $dirpath) = @_;\r
+       my $dir;\r
+       my $subpath;\r
+       my $subpathfull;\r
+       my @stat;\r
+\r
+       unless ( opendir ($dir, $dirpath)) {\r
+               return;\r
+       }\r
+       while (defined($subpath = readdir $dir)) {\r
+               $subpathfull=$dirpath.$subpath;\r
+               if ($subpath =~ /^\.\.?$/) {\r
+                       next;\r
+               }\r
+               if (-f $subpathfull) {\r
+                       processfile($subpathfull);\r
+               }\r
+               elsif (-d $subpathfull) {\r
+                       processdir($subpathfull.'/');\r
+               }\r
+       }\r
+       closedir ($dir);        \r
+}\r
+\r
+sub processfile {\r
+       (my $headerpath) = @_;\r
+       my $basepath;\r
+       my $contentpath;\r
+       \r
+       my %header;\r
+       \r
+       my $prot;\r
+       my $host;\r
+       my $port;\r
+       my $path;\r
+       my $query;\r
+       \r
+       my %cgi;\r
+       \r
+       my $id;\r
+       \r
+       if ($headerpath =~ /^((.+)\@h)$/) {\r
+               $headerpath = $1;\r
+               $basepath = $2;\r
+               $contentpath = $basepath.'@v';\r
+       }\r
+       else {\r
+               return;\r
+       }\r
+       \r
+       ($prot, $host, $port, $path, $query) = path2urldiv($basepath);\r
+       \r
+       if($query ne '') {\r
+               %cgi=getcgi($query);\r
+               $id = $cgi{'id'};\r
+       }\r
+       else {\r
+               $id='';\r
+       }\r
+       \r
+       while () {\r
+               %header = readheaderfile($headerpath); \r
+               if ($header{'status'} =~ /^200 /) {\r
+                       last;\r
+               }\r
+               elsif ($header{'status'} =~ /^30[1237] /) {\r
+                       my $location;\r
+                       unless (defined($location = $header{'location'})) {\r
+                               return;\r
+                       }\r
+                       if ($location !~ /^[a-z]+:\/\//) {\r
+                               $location = $prot.'://'.$host.(($port ne '')?(':'.$port):'').$location;\r
+                       }\r
+                       ($prot, $host, $port, $path, $query) = divideurl($location);\r
+                       $basepath = urldiv2path($prot, $host, $port, $path, $query);\r
+                       $headerpath = $basepath.'@h';\r
+                       $contentpath = $basepath.'@v';\r
+               }\r
+               else {\r
+                       return;\r
+               }\r
+       }\r
+       \r
+       if ($id =~ /^[0-9]+$/) {\r
+               \r
+               \r
+               print "e\n";\r
+               \r
+               \r
+               \r
+               \r
+       }\r
+}\r
+\r
+sub readheaderfile {\r
+       (my $headerpath) = @_;\r
+       my $headerfile;\r
+       my %header;\r
+       \r
+       my $lastname='';\r
+       \r
+       if (open ($headerfile, "<", $headerpath)) {\r
+               while (defined(my $line = <$headerfile>)) {\r
+                       $line =~ s/[\r\n]$//g;\r
+                       my $headname='';\r
+                       my $headval='';\r
+                       \r
+                       if($line =~ /^[ \t]+([^ \t].*)$/){\r
+                               if($lastname ne '') {\r
+                                       $header{$lastname}.=$1;\r
+                               }\r
+                       }\r
+                       elsif ($line =~ /^([^:]*):[ \t]*([^ \t](.*[^ \t])?)[ \t]*$/) {\r
+                               $headname = lc($1);\r
+                               $headval = $2;\r
+                               \r
+                               if ($header{$headname} ne '') {\r
+                                       $header{$headname}.=', '.$headval;\r
+                               }\r
+                               else {\r
+                                       $header{$headname}=$headval;\r
+                               }\r
+                               $lastname = $headname;\r
+                       }\r
+               }\r
+               close ($headerfile);\r
+       }\r
+       return %header;\r
+}
\ No newline at end of file
diff --git a/configure.pl b/configure.pl
new file mode 100644 (file)
index 0000000..148fef2
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+# The proxy software, when run on a server, will use different directories,
+# host names, tcp ports, etc. than the server on which this software was
+# originally written.
+# These things are defined in the file 'settings'.
+# This script is called from the makefile. It reads the settings file and
+# inserts the information in the source files.
+
+unless ($ARGV[0]) {
+       print STDERR "Configfile missing.\n";
+       exit 1;
+}
+
+unless (open $configfile, "<", $ARGV[0]) {
+       print STDERR "Cannot open configfile\n";
+       exit 2;
+}
+
+# Read the config file, line format:
+# some_name = some value # some comment
+while ($line = <$configfile>) {
+       $line =~ s/[\r\n]//g;
+       $line =~ s/#.*$//;
+       if ($line =~ /^ *([a-zA-Z0-9_]+) *= *(.*)$/){
+               $name=$1;
+               $value=$2;
+               $value =~ s/ *$//;
+               $set{$name}=$value;
+       }
+}
+close ($configfile);
+
+# Now generate things to be inserted.
+
+$def{'PROXY_ARCH_PATH'}   = "use constant PROXY_ARCH_PATH    => '".$set{'proxy_data_path'}."archive/';";
+
+$def{'PROXY_LIB'} = "use lib '".$set{'proxy_lib_path'}."';";
+
+$def{'PATH'} = "\$ENV{'PATH'} = '".$set{'path'}."';";
+
+
+$def{'PERL'} = "#!".$set{'perl'};
+
+$def{'CC'} = 'CC='.$set{'gcc'};
+$def{'CF'} = 'CF='.$set{'c_flags'};
+$def{'PL'} = 'PL='.$set{'perl'};
+$def{'MV'} = 'MV='.$set{'mv'};
+$def{'CP'} = 'CM='.$set{'cp'};
+$def{'RM'} = 'RM='.$set{'rm'};
+$def{'OD'} = 'OD='.$set{'bin_path'};
+$def{'CM'} = 'CM='.$set{'chmod'};
+
+
+# Now go through input file, find lines to be replaced. Format:
+# ###SOME_NAME;
+# If found - replace.
+
+while ($line = <STDIN>) {
+       $line =~ s/[\r\n]//g;
+       if ($line =~ /###([a-zA-Z0-9_]+);/) {
+               print "$def{$1}\n";
+       }
+       else {
+               print "$line\n";
+       }
+}
diff --git a/make.sh b/make.sh
new file mode 100644 (file)
index 0000000..f584d54
--- /dev/null
+++ b/make.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# This is the script for making the software. Normally, the makefile is used for
+# this purpose. But the makefile has to be generated first.
+# This script generates the makefile and then uses it and finally removes it.
+
+set -x
+perl configure.pl settings <makefile.1.mak >makefile
+make
+rm makefile
diff --git a/makefile.1.mak b/makefile.1.mak
new file mode 100644 (file)
index 0000000..f905b36
--- /dev/null
@@ -0,0 +1,31 @@
+# makefile is generated from makefile.1.mak.
+
+###CC;
+###CF;
+###PL;
+###CP;
+###MV;
+###RM;
+###CM;
+###OD;
+
+all: moveout copyout remove #config.txt
+
+
+moveout: bot   setuid exec
+       $(MV) bot $(OD)
+
+copyout:   setuid exec
+#       $(CP) access.pl $(OD)
+
+setuid:
+       # $(CM) u+s proxy access
+
+exec: bot
+       $(CM) +x bot
+
+remove:   copyout moveout setuid exec 
+       # $(RM) proxy.c access.c
+
+bot: bot.1.pl   configure.pl settings 
+       $(PL) configure.pl settings <bot.1.pl >bot
diff --git a/settings b/settings
new file mode 100644 (file)
index 0000000..c17f635
--- /dev/null
+++ b/settings
@@ -0,0 +1,31 @@
+#all directory paths must end with '/' and must already exist.
+
+bin_path  = /yplom/bin/facebug1/  
+data_path = /yplom/data/facebug1/ 
+log_path  = /yplom/log/facebug1/  
+tmp_path  = /yplom/tmp/facebug1/  
+#www_path  = /yplom/www/facebug1/  
+
+proxy_bin_path  = /yplom/bin/proxy/ 
+proxy_data_path = /yplom/data/proxy/
+proxy_lib_path  = /yplom/lib/proxy/
+
+path    = /usr/local/bin:/usr/bin:/bin
+perl    = /usr/bin/perl
+curl    = /usr/bin/curl
+chmod   = /bin/chmod
+cp      = /bin/cp
+mv      = /bin/mv
+rm      = /bin/rm
+gcc     = /usr/bin/gcc
+gzip    = /bin/gzip
+c_flags = -g -Wall
+
+log_size_limit    = 65536 # How big can a log file be
+logs_uncompressed =     2 # How many uncompressed old logs to keep
+logs_total        =    10 # How many old logs to keep 
+
+rm_access_crontab =  0 1 * * * # How often to remove leftover unlock info.
+cleararch_crontab = 30 0 * * * # How often to clear the archive from old files.
+oldlogs_crontab   =  0 0 * * * # How often to deal with old logs
+# Not a good idea to launch oldlogs just after cleararch, I think.