#!/usr/bin/perl if ($ARGV[1] =~ /command_line/ || !$ENV{'SERVER_PROTOCOL'}) { $Command_Line = 1; } if ($Command_Line && $ARGV[1] =~ /=/) { $ENV{'QUERY_STRING'} = $ARGV[1]; } # $ARGV[0] is a filename or URL else { $ENV{'QUERY_STRING'} =~ s/\;/%3B/g; } # the query string should NOT have semicolons in it. use Time::HiRes qw(gettimeofday tv_interval); $t0 = gettimeofday(); use CGI qw(:standard !head -oldstyle_urls -utf8); $q = new CGI; %in = $q->Vars; use URI::Escape; use URI::Escape qw(uri_escape_utf8 uri_unescape); use HTML::Entities; use Encode; use utf8; no warnings 'utf8'; # suppress "wide character in print" warnings that end up in the apache error_log binmode(STDOUT, ":raw"); if ($0 =~ /[:\/]/) { $0 =~ /^(.*[:\/])([^:\/]+)$/; chdir ($1); $This_Dir = $1; $This_Script = $2; } else { $This_Script = $0; } $This_Script =~ s/(_input|_form)$//; # This means that $This_Script is ONLY "map", "profile", etc. if ($ENV{'HTTP_COOKIE'} =~ /GV_country=(ru|by)\b/i) { print "Location: https://leafletjs.com/\n\n"; exit; } if ($in{'format'} =~ /^te?xt|gpx/i) { $This_Script = 'convert'; } $Log_Dir = "./log/"; $Output_Dir = ""; $Errors_Dir = "./errors/"; $Forms_Dir = "./forms/"; $Lib_Dir = "./lib/"; $Fonts_Dir = $Lib_Dir."fonts/"; $Background_Cache_Dir = $Log_Dir."backgrounds/"; $Map_Info_File = $Lib_Dir.'map_links.txt'; $Units_Info_File = $Lib_Dir.'units.txt'; $GPSV_Log_File_Success = 'gv_log-success.txt'; $GPSV_Log_File_All = 'gv_log-all.txt'; $DBI_Socket_Argument = (-e '/var/mysql/mysql.sock') ? ';mysql_socket=/var/mysql/mysql.sock' : ''; # Sometimes people erroneously bookmark the output page if ($ENV{'QUERY_STRING'} =~ /^(?:output_?)(\w*)/) { if ($1 !~ /^(output|home|geocode)$/) { $in{'form'} ||= $1; } if ($ENV{'REQUEST_METHOD'} =~ /GET/i) { my $location = ($in{'form'} ne '') ? "${This_Script}?form=$in{'form'}" : $This_Script; if ($in{'form'} eq 'calculators') { $location = 'calculators'; } my $protocol = ($ENV{'SERVER_NAME'} =~ /(www\.)?gpsvisualizer\.com/) ? 'https' : 'http'; my $server = ($ENV{'SERVER_PORT'} ne '80') ? "$protocol://$ENV{'SERVER_NAME'}:$ENV{'SERVER_PORT'}/" : "$protocol://$ENV{'SERVER_NAME'}/"; print "Location: $server$location\n\n"; exit; } } # Some programs use a different output directory; it needs to be set right away foreach ('map','profile','convert','kml_overlay','kml_map') { if ($This_Script =~ /\b($_)2?\b/i || $in{$_}) { $Output_Dir .= $_.'/'; } } # Set a "special" variable for some special cases if ($ENV{'HTTP_REFERER'} =~ /\/stupidedia\//) { $in{'special'} ||= 'stupidedia'; } # Check for a "special" variable and remove it if the appropriate log subdirectory doesn't exist $Special = $in{'special'}; if (!$Special && $in{'form'} =~ /^(data)$/i) { $Special = $in{'form'}; } if ($ENV{'SERVER_NAME'} =~ /\btest\b/ || $ENV{'SCRIPT_NAME'} =~ /\/test\//) { $Special = 'test'; } if ($Special && -e $Log_Dir.$Output_Dir.$Special.'/') { $Output_Dir .= $Special.'/'; $Special_Dir = $Special.'/'; } else { $Special = $in{'special'} = ''; # probably not necessary; does a stray $Special value really cause any problems? } $Defaults_Library = $Lib_Dir."defaults.pl"; $Function_Library = $Lib_Dir."functions.pl"; $Maps_Library = $Lib_Dir."maps.pl"; $File_Input_Library = $Lib_Dir."files.pl"; $Data_Library = $Lib_Dir."data.pl"; $Distance_Library = $Lib_Dir."distance.pl"; $Widgets_Library = $Lib_Dir."widgets.pl"; $SVG_JavaScript_Library = $Lib_Dir."svg_javascript.pl"; $Address_Library = $Lib_Dir."address.pl"; $Elevation_Library = $Lib_Dir."elevation.pl"; $Polygon_Library = $Lib_Dir."polygons.pl"; require $Function_Library; # this one is important! require $Defaults_Library; # may as well, it's not very big foreach my $program ('map','profile','backgrounds','kml_overlay','kml_map','localize','convert') { foreach my $type ('input','output') { $Form{$program}{$type} = $Forms_Dir."$program.$type.html"; } } $GPSV_Data_Dump_File = "$Log_Dir$Output_Dir$Unique_Key--mapdata.gpsv"; ######## EXIT IMMEDIATELY IF IT'S A SPAMMER $in{'data'} =~ s/^[\r\n]+//; if ($in{'email'} =~ /\@((pochta|pisem)\.(com|net)|hot\.com|gpsvisualizer\.com|usa\.com)|^frenk@gmail/i || $in{'email'} =~ /m0\w*ds\@yahoo\.co\.uk|smithe\@googlemail|saadepunjab\@gmail\.com|lauraduve\@web\.de|^peterson\@gmail\.com|^email\@gmail|CanadiansRule\.com|Cheatcc.com|^1800\@/i || $in{'data'} =~ /(^http:|\[URL\]http|\[ ?URL ?=[ "]*http|^please .*visit|^comment|^<[^\?g]|^[^\n\r]*(nice|good|great|excellent|useful|informative) (web ?)?site|^[^\n\r]*(\bA href|viaga?ra|\bwow\b|\bchanel.*handbags|rolex|watches|\bhi \w|mmmmm|poiko))/i || $in{'remote_data'} =~ /(rgergerger)/i || $in{'dynamic_data'} =~ /(rgergerger)/i || $in{'remote_data'} =~ /^\w+$/i || $in{'dynamic_data'} =~ /^\w{1,20}$/i ) { open (SPAM_LOG,">".$Log_Dir.$Output_Dir."$Unique_Key--$Host-spam.txt"); print SPAM_LOG "HOST: $Host\nEMAIL: $in{'email'}\nREMOTE_DATA: $in{'remote_data'}\nDYNAMIC_DATA: $in{'dynamic_data'}\n"; print SPAM_LOG "DATA: $in{'data'}\n\n"; close (SPAM_LOG); &Error_Exit('spam'); } ######## FIGURE OUT WHICH PROGRAMS TO RUN if ($This_Script =~ /\bprofile2?(_input)?\b/i) { $in{'profile'} = 1; $GV{'profile'} = 1; $Operation = 'profile'; } elsif ($This_Script =~ /\bbackgrounds2?(_input)?\b/i || $BG || $in{'bg'}) { require $Lib_Dir."backgrounds.pl"; $in{'bg'} = 1; $BG = 1; $Operation = 'backgrounds'; } elsif ($This_Script =~ /\bkml_overlay2?(_input)?\b/i || $KML_Overlay || $in{'kml_overlay'}) { require $Lib_Dir."backgrounds.pl"; $in{'kml_overlay'} = 1; $KML_Overlay = 1; $Operation = 'kml_overlay'; } elsif ($This_Script =~ /\bkml_map(_input)?\b/i || $KML_Map || $in{'kml_map'}) { require $Lib_Dir."kml_map.pl"; $in{'kml_map'} = 1; $KML_Map = 1; $Operation = 'kml_map'; } elsif ($This_Script =~ /\blocalize2?(_input)?\b/i || $Localize || $in{'localize'}) { $in{'localize'} = 1; $Localize = 1; $Operation = 'localize'; require $Lib_Dir."localize.pl"; } elsif ($This_Script =~ /\bconvert2?(_input)?\b/i || $Convert || $in{'convert'}) { $in{'convert'} = 1; $Convert = 1; $Operation = 'convert'; require $Lib_Dir."convert.pl"; } else { $Operation = 'map'; } ######## FIGURE OUT WHICH FORMS TO USE if (!$in{'form'} && $Operation eq 'map') { if ($in{'format'} eq 'leaflet') { $in{'form'} = 'html'; } elsif ($in{'format'} eq 'google') { $in{'form'} = 'html'; } elsif ($in{'format'} eq 'googleearth') { $in{'form'} = 'googleearth'; } elsif ($in{'format'} =~ /^(jpe?g|png|svg)$/i) { $in{'form'} = 'jpg'; } else { $in{'form'} = 'html'; } } if ($in{'form'} || $Special) { $GV{'form'} = lc($in{'form'}) || $Special; foreach my $a ('map','profile','backgrounds','kml_overlay','kml_map','localize','convert') { foreach my $b ('input','output') { (my $tmp = $Form{$a}{$b}) =~ s/\.(html?)$/.$GV{'form'}.$1/i; if (-e $tmp) { $Form{$a}{$b} = $tmp; } } } } if ($Operation eq 'map' && !$in{'format'} && $in{'form'} =~ /^(google|googleearth|leaflet|svg|jpe?g|png)$/) { $in{'format'} = $1; } ######## SPECIAL CASES if ($ENV{'REMOTE_ADDR'} =~ /(204.210.112.166|71.236.170.233)/i) { # $Hey_You = '

Hey, you at NOAA: what are you plotting? It looks interesting. Please e-mail me: adam@gpsvisualizer.com

'; # $Hey_You = '

Hey, you there, making the maps of the "GTRI Receive Tower": E-mail me at adam@gpsvisualizer.com and I\'ll tell you how to hide your waypoints more effectively.

'; # $Hey_You = '

Hey, you there, making the maps of trails on Kaua\'i (some of my favorite trails, I might add): please contact me, I may have some tips on getting your maps to look exactly like you want.

'; } ######## TRAP EVIL BOT REQUESTS if ($ENV{'HTTP_USER_AGENT'} =~ /(claudebot|\bxaxios\b)/i) { &Error_Exit('403'); } ######## TRAP BOT REQUESTS if ($ENV{'HTTP_USER_AGENT'} =~ /(Mediapartners-Google|bot\b|Slurp|spider|crawl|Yandex|Bingbot|360Spider|Ezooms|archive.org_bot|\bBot\b|\bSpider\b|\bRobot\b)/i) { # && $ENV{'HTTP_USER_AGENT'} !~ /Mediapartners-Google/) { if ($ENV{'QUERY_STRING'} =~ /\b(local_input|data|remote_data|dynamic_data|airport[s12]?|lat[12]?|location[12]?|submitted)=/i) { if ($in{'format'} eq 'google' || $ENV{'QUERY_STRING'} =~ /output_google\b/) { $Form{'map'}{'output'} = $Forms_Dir."map.output.google.html"; } elsif ($in{'format'} eq 'googleearth' || $ENV{'QUERY_STRING'} =~ /output_googleearth\b/) { $Form{'map'}{'output'} = $Forms_Dir."map.output.googleearth.html"; } $Temp_Drawing_File = "null"; if ($GV{'profile'}) { &PrintPage($Form{'profile'}{'output'}); } elsif ($KML_Overlay) { &PrintPage($Form{'kml_overlay'}{'output'}); } else { &PrintPage($Form{'map'}{'output'}); } exit; } } ######## WATCH OUT FOR PEOPLE ABUSING CERTAIN FEATURES if ($ENV{'HTTP_REFERER'} =~ /forum\.velovert\.com/i) { delete $in{'return_image'}; } if ($ENV{'HTTP_REFERER'} =~ /\.free\.fr\//i) { delete $in{'return_image'}; delete $in{'remote_data'}; } ######## LOOK FOR "DISTANCE" OR "SINGLE POINT" REQUESTS $Distance_Mode = undef; if ($in{'data'} =~ /^\W*airports\W*[\r\n]/si) { ($in{'airports'} = $in{'data'}) =~ s/^\W*airports\W*//; delete $in{'data'}; } foreach (qw(lat lon coords airport airports address location locations )) { if (($in{$_} || $in{"${_}1"} || $in{"${_}2"}) && !$KML_Overlay && !$KML_Map) { $Distance_Mode = 1; } } foreach my $l (qw(l l1 l2)) { foreach my $k (qw(lat lon coords airport address location )) { if ($in{"$l.$k"} && !$KML_Overlay && !$KML_Map) { $Distance_Mode = 1; } } } if ($Distance_Mode && !$KML_Overlay && !$KML_Map) { require $Distance_Library; # We do this before Set_Defaults and Set_Global_Variables because we need to set some special defaults, # but we don't want to alter them if some parts of %in are already set specially &Make_Data_From_Coordinates; # creates @Waypoints and @Tracks } ######## SET DEFAULT VALUES FOR THE VARIABLES ($Query_String,%Default) = &Set_Defaults($Special,$GV{'form'},$Operation); ######## PRINT THE FORM IF NO INPUT &Read_Cookies_From_Browser; if (!@Tracks && !@Waypoints && !$Distance_Mode && (!$in{'submitted'} && !$in{'uploaded_file_1'}) && !$in{'data'} && !$in{'remote_data'} && !$in{'dynamic_data'} && !$in{'local_input'} && !$Command_Line) { if ($Operation eq 'profile') { &PrintPage($Form{'profile'}{'input'}); } elsif ($Operation eq 'backgrounds') { &PrintPage($Form{'backgrounds'}{'input'}); } elsif ($Operation eq 'kml_overlay') { require $Maps_Library; $Map_Menu = &Build_Map_Menu($Map_Info_File,'kml'); &PrintPage($Form{'kml_overlay'}{'input'}); } elsif ($Operation eq 'kml_map') { #&PrintPage($Form{'kml_map'}{'input'}); my $server = ($ENV{'SERVER_PORT'} ne '80') ? "http://$ENV{'SERVER_NAME'}:$ENV{'SERVER_PORT'}/" : "http://$ENV{'SERVER_NAME'}/"; print "Location: ${server}map_input?format=jpg\n\n"; } elsif ($Operation eq 'localize') { &PrintPage($Form{'localize'}{'input'}); } elsif ($Operation eq 'convert') { &PrintPage($Form{'convert'}{'input'}); } else { require $Maps_Library; $Map_Menu = &Build_Map_Menu($Map_Info_File,$GV{'form'}); &PrintPage($Form{'map'}{'input'}); } # my $t1 = gettimeofday(); my $elapsed = $t1-$t0; print "\n$elapsed\n"; exit; } ######## THERE WAS INPUT, SO LOAD SOME MORE CODE require $Data_Library; $Units = &GetUnitFormatting($Units_Info_File); if ($Operation ne 'convert') { require $Maps_Library; require $Widgets_Library; } require $File_Input_Library; # Get uploaded files my $file_index = 0; for $i (0..30) { if ( !param('uploaded_file_'.($i+1)) ) { next; } else { my @ulf = multi_param('uploaded_file_'.($i+1)); foreach my $f (@ulf) { $Files[$file_index++] = $f; } # $Files[$file_index++] = param('uploaded_file_'.($i+1)); } } #if (1==1) { # open(ZZZ,">>/hdd/storage/gv_user_files/zzz.txt"); print ZZZ "$Unique_Key: \$This_Dir = '$This_Dir', \$Output_Dir = '$Output_Dir', \$This_Script = '$This_Script', \$Operation = '$Operation', \$Special = '$Special'\n"; close(ZZZ); #} ######## SET (AND ADJUST) THE GLOBAL VARIABLES &Set_Global_Variables; ######## LOG SOME BASIC INFO &Log_Request(); ######## DON'T EVEN ANALYZE THE INPUT DATA IF WE'RE IN BACKGROUND-ONLY OR LOCALIZE MODE if ($BG) { &GetBackgrounds; exit; } elsif ($KML_Overlay) { &GetKMLOverlay; exit; } elsif ($KML_Map) { &GetKMLMap; exit; } elsif ($Localize) { &LocalizeSVG($GV{'localize_mode'},$GV{'localized_name'},$GV{'delete_js'},$GV{'rasterize_bold'},$GV{'local_input'}); exit; } ######## CAN'T CONTINUE WITHOUT FILES if (!@Tracks && !@Waypoints && !@Files && !$GV{'data'} && !$GV{'remote_data'} && !$GV{'dynamic_data'} && (!$GV{'local_input'} || ($GV{'local_input'} && !-e $Log_Dir.$GV{'local_input'} && !-e $Log_Dir.$GV{'local_input'}.'--mapdata.gpsv' && !-e $Log_Dir."map/".$GV{'local_input'} && !-e $Log_Dir."map/".$GV{'local_input'}.'--mapdata.gpsv')) && !$Command_Line) { &Error_Exit('no_files'); } if ($GV{'email'} =~ /^\w[^@]*?@([\w-]+\.)+\w\w+\s*$/) { open (EMAIL,">".$Log_Dir.$Output_Dir."$Unique_Key--email.txt"); print EMAIL "$GV{'email'}\n($Host)\n"; close (EMAIL); #use Data::Dumper; #open (DEBUG,">>debug.txt"); #print DEBUG "$Unique_Key--email.txt ($GV{'email'}, $ENV{'REMOTE_ADDR'}):\n"; #use Data::Dumper; print DEBUG "\%in = ",Dumper(\%in),"\n"; #use Data::Dumper; print DEBUG "\%GV = ",Dumper(\%GV),"\n"; #close (DEBUG); } ######## SET UP THE FILE NAME if ($Operation eq 'profile') { $Temp_Drawing_File = "$Unique_Key-profile.$GV{'format'}"; } elsif ($GV{'format'} =~ /^google.?earth/i) { $Temp_Drawing_File = "$Unique_Key-map.kml"; } elsif ($GV{'format'} =~ /^google/i) { $Temp_Drawing_File = "$Unique_Key-map.html"; } elsif ($GV{'format'} =~ /^leaflet/i) { $Temp_Drawing_File = "$Unique_Key-map.html"; } else { $Temp_Drawing_File = "$Unique_Key-map.$GV{'format'}"; } ######## CHECK THE CACHE FOR A PREVIOUSLY-DRAWN MAP if ( ($GV{'local_input'} || ($GV{'data'} && ($Query_String =~ /&form\.data\b/ || $ENV{'REQUEST_METHOD'} eq 'GET')) # If data ($in{'data'}) was transmitted via POST, it is only cacheable if all the data got dumped into the $Query_String variable where we can keep track of it || ($GV{'remote_data'} && $GV{'cache'}) || ($Distance_Mode && $GV{'cache'}) ) && !@Files && $Operation ne 'convert' # it's never cacheable if something was uploaded ) { if ($GV{'cache'}) { $Cacheable = 1; $Cached_Page_Metadata = &Check_Cached_Data; if ($Cached_Page_Metadata) { &GV_Output; # dump the cached info and get the hell out of there exit; } } } #open (DEBUG,">>debug.txt"); print DEBUG time(),": starting to read data\n"; close (DEBUG); ######## USE AN EXTERNAL SUBROUTINE TO GET THE DATA AND CALCULATE INFO &Get_Data_And_Parameters; ######## IF WE'RE IN "CONVERT" MODE, GO NO FURTHER if ($Operation eq 'convert') { if ($GV{'convert_format'} =~ /gpx/i && @Tracks) { $Wikiloc_Export_Link = &Build_Wikiloc_Link; } &ConvertData; my $metadata = &Build_Metadata; open (METADATA,">$Log_Dir$Output_Dir$Unique_Key--metadata.xml"); print METADATA $metadata; close (METADATA); exit; } ######## MAP OR PROFILE MODE; CONTINUE ### DRAW THE IMPORTANT STUFF require $Lib_Dir."drawing.pl"; &SetupDrawing; print STDERR localtime(time).": Drawing the map or profile...\n" if $Command_Line; if ($GV{'profile'}) { &DrawProfile; } else { &DrawMap; } if ($GV{'format'} eq 'google' || $GV{'format'} eq 'leaflet') { $GoogleLeafletHTML = &BuildHTMLMap(); } elsif ($GV{'format'} eq 'googleearth') { $GoogleKML = &BuildGoogleEarthMap(); } elsif ($GV{'format'} eq 'svg') { &SVGExtras; } print STDERR localtime(time).": Map or profile drawn.\n\n" if $Command_Line; ### ADD DIAGNOSTIC COMMENTS # (this creates $KML_Overlay_Link, $KML_Map_Link, and possibly %EXIF_Data) &Create_Comments_And_Links; ### CREATE BOX WITH STATISTICS ABOUT THE MAP $Map_Stats_Box = &Map_Statistics; $Map_Statistics_HTML = "

Map Statistics

\n"; $Map_Statistics_HTML = "
\n".$Map_Stats_Box."
\n"; print STDERR localtime(time).": Saving the output...\n" if $Command_Line; ### SAVE THE DRAWING my $output_file = $Log_Dir.$Output_Dir.$Temp_Drawing_File; if ($GV{'format'} eq 'svg') { # Put the output into a variable for output $XML_Output = $Drawing->xmlify; # Put the file in a temporary location open (OUTPUT,">$output_file"); print OUTPUT chr(0xFEFF) if (&ContainsUTF8($XML_Output)); # UTF-8 byte-order marker print OUTPUT $XML_Output; close (OUTPUT); } elsif ($GV{'format'} eq 'jpg') { my $quality = ($GV{'profile'}) ? 100 : 90; my $jpg_output = $Drawing->jpeg($quality); open (OUTPUT,">$output_file"); binmode OUTPUT; print OUTPUT $jpg_output; close (OUTPUT); } elsif ($GV{'format'} eq 'png') { $Drawing->saveAlpha(1); my $png_output = $Drawing->png(); open (OUTPUT,">$output_file"); binmode OUTPUT; print OUTPUT $png_output; close (OUTPUT); } elsif ($GV{'format'} eq 'google' || $GV{'format'} eq 'leaflet') { open (OUTPUT,">$output_file"); print OUTPUT chr(0xFEFF) if (&ContainsUTF8($GoogleLeafletHTML)); # UTF-8 byte-order marker print OUTPUT $GoogleLeafletHTML; close (OUTPUT); } elsif ($GV{'format'} eq 'googleearth') { open (OUTPUT,">$output_file"); print OUTPUT chr(0xFEFF) if (&ContainsUTF8($GoogleKML)); # UTF-8 byte-order marker print OUTPUT $GoogleKML; close (OUTPUT); $File_Icon = "kml_icon.gif"; } if ($GV{'format'} eq 'jpg' || $GV{'format'} eq 'png') { &Write_EXIF_Data($output_file); } print STDERR localtime(time).": Output saved.\n\n" if $Command_Line; ######## PREPARE FINAL HTML $Page_Title = ($GV{'profile'}) ? "GPS Visualizer profile" : "GPS Visualizer map"; # $Page_Title .= ($GV{'drawing_title'}) ? ": $GV{'drawing_title'}" : ""; $Special_Parameter = ($Special) ? "special=$Special&" : ''; $Form_Parameter = ($GV{'form'}) ? "form=$GV{'form'}&" : ''; if ($GV{'format'} eq 'googleearth' && $GV{'googleearth_zip'}) { # zip $Temp_Drawing_File and change the $Temp_Drawing_File variable to point to the zipped file $Temp_Drawing_File = &CompressKML($Log_Dir.$Output_Dir,$Temp_Drawing_File); $File_Icon = "kmz_icon.gif"; } my $metadata = &Build_Metadata; open (METADATA,">$Log_Dir$Output_Dir$Unique_Key--metadata.xml"); print METADATA $metadata; close (METADATA); if (@Tracks || @Waypoints) { &Log_Request(1); } if ($GPSV_Data_Dump) { open (DUMP,">$GPSV_Data_Dump_File"); print DUMP $GPSV_Data_Dump; close (DUMP); $Wikiloc_Export_Link = &Build_Wikiloc_Link unless !@Tracks; } # Cache URL-driven requests, if applicable if ($Cacheable) { &Cache_Data; } ######## RE-BUILD QUERY STRING IN CASE ANYTHING CHANGED ($Query_String,undef) = &Set_Defaults($Special,$GV{'form'},$Operation); print STDERR localtime(time).": Preparing final output...\n" if $Command_Line; &GV_Output; print STDERR localtime(time).": Done.\n" if $Command_Line; ################################################################################ sub Build_GlobalMotion_Link { # $GlobalMotion_Export_Link my $link; $link = "https://www.globalmotion.com/wiki/Special:EditMap?import=gv&url=".uri_escape("$Output_Dir$Unique_Key"); $link .= ($GV{'drawing_title'}) ? "&maptitle=".uri_escape($GV{'drawing_title'}) : ""; # $link = '/misc/link.cgi?url='.uri_escape_utf8($link); $link =<NEW: Create an article based on this map at GlobalMotion.com

ENDOFTEXT return ($link); } ################################################################################ sub Build_EveryTrail_Link { # $EveryTrail_Export_Link my $link; $link = "http://www.everytrail.com/save_gv_trip.php?partner_id=1002&url=".uri_escape_utf8("$Output_Dir$Unique_Key"); $link .= ($GV{'drawing_title'}) ? "&maptitle=".uri_escape_utf8($GV{'drawing_title'}) : ""; # $link = '/misc/link.cgi?url='.uri_escape_utf8($link); $link =< Save this map, add photos, & share with others @ EveryTrail.com ENDOFTEXT return ($link); } ################################################################################ sub Build_Wikiloc_Link { # $Wikiloc_Export_Link my $link; $link = "/share.php?partner=wikiloc&id=".uri_escape_utf8("$Output_Dir$Unique_Key"); $link =<
Save this map & share with others @ Wikiloc.com
ENDOFTEXT return ($link); } ################################################################################ sub Log_Request { my ($success) = @_; my $log_file = ($success) ? $GPSV_Log_File_Success : $GPSV_Log_File_All; (my $log_time = $Now) =~ s/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/$1-$2-$3 $4:$5:$6/; (my $url = "http://$ENV{'HTTP_HOST'}$ENV{'SCRIPT_NAME'}?$Query_String") =~ s/form:data=[^&]*/form:data=/; open (GPSV_LOG,">>$log_file"); my $format = ($Operation eq 'convert') ? $in{'convert_format'} : $in{'format'}; if ($success) { print GPSV_LOG "$log_time\t$Host\t$Output_Dir$Unique_Key\t$Operation\t$format\t$Special\t".(scalar @Tracks)."\t".(scalar @Waypoints)."\n"; } else { print GPSV_LOG "$log_time\t$Host\t$Output_Dir$Unique_Key\t$Operation\t$format\t$Special\t$url\n"; } close (GPSV_LOG); } ################################################################################ sub GV_Output { my $content_type,$binary; if ($GV{'return_image'} || $GV{'return_file'}) { if ($GV{'format'} eq 'svg') { $content_type = "image/svg+xml"; } elsif ($GV{'format'} eq 'jpg') { $content_type = "image/jpeg"; $binary = 1; } elsif ($GV{'format'} eq 'png') { $content_type = "image/png"; $binary = 1; } elsif ($GV{'format'} eq 'google' || $GV{'format'} eq 'leaflet') { $content_type = "text/html"; } elsif ($GV{'format'} eq 'googleearth' && $Temp_Drawing_File =~ /kmz$/i) { $content_type = "application/vnd.google-earth.kmz"; $binary = 1; } elsif ($GV{'format'} eq 'googleearth') { $content_type = "application/vnd.google-earth.kml+xml"; } if ($GV{'gzip_output'}) { system "gzip $Log_Dir$Output_Dir$Temp_Drawing_File"; if (-e "$Log_Dir$Output_Dir$Temp_Drawing_File.gz") { if ($ENV{'HTTP_ACCEPT_ENCODING'} =~ /gzip/i) { print "Content-Type: $content_type\n"; print "Content-Encoding: gzip\n\n"; } else { print "Content-Type: application/x-gzip\n"; print "Content-Disposition: attachment; filename=\"$Temp_Drawing_File.gz\"\n\n"; } binmode(STDOUT, ":raw"); open(FILE,"$Log_Dir$Output_Dir$Temp_Drawing_File.gz"); seek(FILE,0,2); my $eof_position = tell(FILE); seek(FILE,0,0); read(FILE,my $gzipped_file,$eof_position); print $gzipped_file; close (FILE); exit; } } if ($binary) { binmode(STDOUT, ":raw"); } print "Content-type: $content_type\n\n" unless $Command_Line; open(FILE,$Log_Dir.$Output_Dir.$Temp_Drawing_File); seek(FILE,0,2); my $eof_position = tell(FILE); seek(FILE,0,0); read(FILE,my $output,$eof_position); print $output; close (FILE); exit; } elsif ($GV{'return_redirect'}) { if ($ENV{'HTTP_HOST'}) { print "Location: http://$ENV{'HTTP_HOST'}/display/$Output_Dir$Temp_Drawing_File\n\n"; } else { # command line print STDERR localtime(time).": Done.\n" if $Command_Line; print "Output file: ${This_Dir}log/${Output_Dir}${Temp_Drawing_File}\n\n"; } exit; } elsif ($GV{'return_url'}) { # I believe the best way to do this will be to create a special URL that contains a path to a drawing. # So basically, the existence of "display_file" (or something) will create all the variables that # the output page needs, and it will drop straight into something like the "else" below. # Of course, the output page has things like the BBOX and altitude range on it. Those will need to be read # from the metadata file. Can we maybe just give a time and process ID and get the metadata file from that, # and then read the file name from the $metadata->{'file'} variable? print "Content-type: text/plain\n\nThe 'return_url' feature is not implemented yet.\n"; # print "Content-type: text/plain\n\n"; print "Location: http://$ENV{'SERVER_NAME'}/map_input?display_file=$GV{'display_file'}\n\n"; exit; } else { if ($GV{'profile'}) { &PrintPage($Form{'profile'}{'output'}); } else { &PrintPage($Form{'map'}{'output'}); } } }