1 #!/usr/bin/perl |
|
2 |
|
3 use warnings; |
|
4 use strict; |
|
5 use LWP::UserAgent; |
|
6 use CGI qw(-utf8); |
|
7 use CGI::Carp qw(fatalsToBrowser); |
|
8 use Net::SCP; |
|
9 use Template; |
|
10 use Cwd; |
|
11 use FindBin qw($RealBin); |
|
12 |
|
13 my $cgi = new CGI; |
|
14 |
|
15 if (!$cgi->param(".submit")) { |
|
16 print CGI::header(-type => "text/html", -charset => "utf-8"); |
|
17 |
|
18 my $tt = Template->new({INCLUDE_PATH => "$RealBin/../templates"}) |
|
19 or die "Can't create template object: $Template::ERROR\n"; |
|
20 |
|
21 $tt->process("index.html", { |
|
22 now => time(), |
|
23 error => { firma => "xxx", |
|
24 mail => "so nicht" }, |
|
25 firma => $cgi->param("firma"), |
|
26 }) or die $tt->error(); |
|
27 exit 0; |
|
28 } |
|
29 |
|
30 my ( |
|
31 $uid, $feld, $feld4, $feld1, $feld2, |
|
32 $feld3, $get, $url, $ua, $ub, $req |
|
33 ); |
|
34 |
|
35 my $x = 1; |
|
36 $uid = `uuidgen`; |
|
37 $uid =~ s/-//g; |
|
38 chomp $uid; |
|
39 |
|
40 |
|
41 ####################### |
|
42 # Auswerten der Daten # |
|
43 # des Web-Formulars # |
|
44 ####################### |
|
45 |
|
46 $feld1 = $cgi->param('Firma'); |
|
47 $feld2 = $cgi->param('Mail'); |
|
48 $feld3 = $cgi->param('Test'); |
|
49 $feld4 = $cgi->param('req'); |
|
50 $feld1 =~ s/\&/\<26\>/g; |
|
51 $feld1 =~ s/\=/\<3D\>/g; |
|
52 $feld1 =~ s/\%/\<25\>/g; |
|
53 $feld1 =~ s/\+/\<2B\>/g; |
|
54 $feld2 =~ s/\&/\<26\>/g; |
|
55 $feld2 =~ s/\=/\<3D\>/g; |
|
56 $feld2 =~ s/\%/\<25\>/g; |
|
57 $feld2 =~ s/\+/\<2B\>/g; |
|
58 $feld3 =~ s/\&/\<26\>/g; |
|
59 $feld3 =~ s/\=/\<3D\>/g; |
|
60 $feld3 =~ s/\%/\<25\>/g; |
|
61 $feld3 =~ s/\+/\<2B\>/g; |
|
62 $feld4 =~ s/\&/\<26\>/g; |
|
63 $feld4 =~ s/\=/\<3D\>/g; |
|
64 $feld4 =~ s/\%/\<25\>/g; |
|
65 $feld4 =~ s/\+/\<2B\>/g; |
|
66 $feld4 =~ s/\r\n/\n/g; |
|
67 open( TEST, ">test" ) or die "Kann Handle nicht oeffnen!\n$!"; |
|
68 print TEST ("$feld1 ;:; $feld2 ;:; $feld3 ;:; $feld4"); |
|
69 close TEST; |
|
70 my @Feldnamen = $cgi->param(); |
|
71 |
|
72 ####################### |
|
73 # Senden der Daten # |
|
74 # via HTTP-POST # |
|
75 ####################### |
|
76 |
|
77 $url = 'http://192.168.0.144/cgi-bin/receive'; |
|
78 $ua = LWP::UserAgent->new; |
|
79 $ua->env_proxy; |
|
80 $ua->timeout(20); |
|
81 $ua->show_progress; |
|
82 $req = HTTP::Request->new( "POST", $url ); |
|
83 $req->header( 'Content-Type' => 'text/html' ); |
|
84 $req->accept_decodable; |
|
85 $req->content("ID=$uid&Name=$feld1&Mail=$feld2&Test=$feld3&req=$feld4"); |
|
86 $ua->request($req); |
|
87 |
|
88 open( HTML1, ">/var/www/$uid" . "1.html" ); |
|
89 print HTML1 ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>Download</title></head><body><p>Klicken Sie bitte auf den Link um ihre Datei zu Downloaden oder anzuzeigen.<br>Zum Speichern des Inhaltes klicken Sie den Link mit der rechten Maustaste an und wählen \"Ziel speichern unter...\"</p><p><a style=\"text-decoration: none;\" href=\"/download/$uid\" type=\"application/octet-stream\">$uid</a></p ></body></html>" ); |
|
90 close HTML1; |
|
91 |
|
92 open( HTML, ">/var/www/$uid.html" ); |
|
93 print HTML ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>Download</title><meta http_equiv=\"refresh\" content=\"10;URL=http://192.168.0.138/". $uid . "1.html\"></head><script type=\"text/javascript\"> |
|
94 <!-- |
|
95 var homepage = 'http://192.168.0.138/" . $uid . "1.html'; |
|
96 var sekunden = 10; |
|
97 function countdownWeiterleitung(){ |
|
98 sekunden--; |
|
99 document.getElementById('counter_span').innerHTML = sekunden; |
|
100 if ( !sekunden ) { |
|
101 document.location.href = homepage; |
|
102 } |
|
103 } |
|
104 window.setInterval('countdownWeiterleitung()', 1000); |
|
105 //--> |
|
106 </script><body><p>Ihr Download steht in kürze bereit!<br>Sie werden in <span id=\"counter_span\" class=\"dd\">10</span> sekunden automatisch Weitergeleitet.<br>Sollte die automatische Weiterleitung nicht funktionieren, klicken Sie bitte <a style=\"text-decoration: none;\" href=\"".$uid."1.html\">hier</a>.</p><p>Bitte beachten Sie, dass Ihr Download nur 5 minuten gültig ist.</p></body></html>"); |
|
107 |
|
108 close HTML; |
|
109 |
|
110 # Test |
|
111 |
|
112 ####################### |
|
113 # Erstellen einer # |
|
114 # Feedback-Seite zum # |
|
115 # Test mit Weiter- # |
|
116 # leitung # |
|
117 ####################### |
|
118 |
|
119 print $cgi->header('CGI-Feedback'), |
|
120 $cgi->start_html( |
|
121 -head => $cgi->meta( |
|
122 { |
|
123 -http_equiv => 'REFRESH', |
|
124 -content => "2;URL=http://192.168.0.138/$uid.html" |
|
125 } |
|
126 ), |
|
127 -title => 'CGI-Feedback' |
|
128 ); |
|
129 $cgi->h1( 'CGI-Feedback vom Programm ', $cgi->i('send') ); |
|
130 foreach my $Feld (@Feldnamen) { |
|
131 print $cgi->strong('Feldname: '), |
|
132 $Feld, |
|
133 $cgi->strong(', Inhalt: '), |
|
134 $cgi->param($Feld), "<br>"; |
|
135 } |
|
136 print $cgi->i($uid), $cgi->end_html; |
|
137 |
|
138 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = |
|
139 localtime(time); |
|
140 if ( $min >= 55 ) { |
|
141 $min += 5; |
|
142 $min -= 60; |
|
143 $hour += 1; |
|
144 } |
|
145 else { |
|
146 $min += 5; |
|
147 } |
|
148 open( WRITE, "|sudo at $hour:$min" ) or die; |
|
149 print WRITE "rm /var/www/$uid*\n"; |
|
150 print WRITE "rm /var/www/download/$uid*\n"; |
|
151 close WRITE; |
|
152 __END__ |
|