From 913a9a6ec8c41033b710a0f0a1f58b0836d6c0aa Mon Sep 17 00:00:00 2001 From: b Date: Wed, 25 Nov 2015 23:56:04 +0000 Subject: [PATCH 1/1] look through directory head header git-svn-id: svn://botcastle1b/yplom/facebug1@1 7dec801f-c475-4e67-ba99-809552d69c55 --- bot.1.pl | 172 +++++++++++++++++++++++++++++++++++++++++++++++++ configure.pl | 67 +++++++++++++++++++ make.sh | 10 +++ makefile.1.mak | 31 +++++++++ settings | 31 +++++++++ 5 files changed, 311 insertions(+) create mode 100644 bot.1.pl create mode 100644 configure.pl create mode 100644 make.sh create mode 100644 makefile.1.mak create mode 100644 settings diff --git a/bot.1.pl b/bot.1.pl new file mode 100644 index 0000000..cc473a5 --- /dev/null +++ b/bot.1.pl @@ -0,0 +1,172 @@ +###PERL; + +use strict; + +###PROXY_LIB; +use proxy_lib qw(url2path path2urldiv getcgi divideurl); +use POSIX qw(strftime); + +my $time = time(); +print strftime("%d.%m.%Y %H:%M:%S", gmtime($time))."\n"; +for (my $ind=0; $ind < scalar @ARGV; ++$ind) { + my %set = {}; + my $basepath=''; + my $configfile; + + unless (open ($configfile, "<", $ARGV[$ind])) { + print "Cannot open $ARGV[$ind]\n"; + next; + } + + while (defined(my $line = <$configfile>)) { + $line =~ s/[\r\n]//g; + $line =~ s/#.*$//; + if ($line =~ /^ *([a-zA-Z0-9_]+) *= *(.*)$/){ + my $name=$1; + my $value=$2; + $value =~ s/ *$//; + $set{$name}=$value; + } + } + close ($configfile); + + if ($set{'id'} =~ /^([0-9]+)$/) { + my $basepath = url2path('https://m.facebook.com/groups/'.$1).'@q/'; + processdir($basepath); + } + else { + print "Invalid ID $ARGV[$ind]\n"; + next; + } +} + +sub processdir { + (my $dirpath) = @_; + my $dir; + my $subpath; + my $subpathfull; + my @stat; + + unless ( opendir ($dir, $dirpath)) { + return; + } + while (defined($subpath = readdir $dir)) { + $subpathfull=$dirpath.$subpath; + if ($subpath =~ /^\.\.?$/) { + next; + } + if (-f $subpathfull) { + processfile($subpathfull); + } + elsif (-d $subpathfull) { + processdir($subpathfull.'/'); + } + } + closedir ($dir); +} + +sub processfile { + (my $headerpath) = @_; + my $basepath; + my $contentpath; + + my %header; + + my $prot; + my $host; + my $port; + my $path; + my $query; + + my %cgi; + + my $id; + + if ($headerpath =~ /^((.+)\@h)$/) { + $headerpath = $1; + $basepath = $2; + $contentpath = $basepath.'@v'; + } + else { + return; + } + + ($prot, $host, $port, $path, $query) = path2urldiv($basepath); + + if($query ne '') { + %cgi=getcgi($query); + $id = $cgi{'id'}; + } + else { + $id=''; + } + + while () { + %header = readheaderfile($headerpath); + if ($header{'status'} =~ /^200 /) { + last; + } + elsif ($header{'status'} =~ /^30[1237] /) { + my $location; + unless (defined($location = $header{'location'})) { + return; + } + if ($location !~ /^[a-z]+:\/\//) { + $location = $prot.'://'.$host.(($port ne '')?(':'.$port):'').$location; + } + ($prot, $host, $port, $path, $query) = divideurl($location); + $basepath = urldiv2path($prot, $host, $port, $path, $query); + $headerpath = $basepath.'@h'; + $contentpath = $basepath.'@v'; + } + else { + return; + } + } + + if ($id =~ /^[0-9]+$/) { + + + print "e\n"; + + + + + } +} + +sub readheaderfile { + (my $headerpath) = @_; + my $headerfile; + my %header; + + my $lastname=''; + + if (open ($headerfile, "<", $headerpath)) { + while (defined(my $line = <$headerfile>)) { + $line =~ s/[\r\n]$//g; + my $headname=''; + my $headval=''; + + if($line =~ /^[ \t]+([^ \t].*)$/){ + if($lastname ne '') { + $header{$lastname}.=$1; + } + } + elsif ($line =~ /^([^:]*):[ \t]*([^ \t](.*[^ \t])?)[ \t]*$/) { + $headname = lc($1); + $headval = $2; + + if ($header{$headname} ne '') { + $header{$headname}.=', '.$headval; + } + else { + $header{$headname}=$headval; + } + $lastname = $headname; + } + } + close ($headerfile); + } + return %header; +} \ No newline at end of file diff --git a/configure.pl b/configure.pl new file mode 100644 index 0000000..148fef2 --- /dev/null +++ b/configure.pl @@ -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 = ) { + $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 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 +make +rm makefile diff --git a/makefile.1.mak b/makefile.1.mak new file mode 100644 index 0000000..f905b36 --- /dev/null +++ b/makefile.1.mak @@ -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 diff --git a/settings b/settings new file mode 100644 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. -- 2.30.2