· 6 years ago · Dec 17, 2019, 06:22 PM
1<?php
2/*
3php?upload[]=<log url>&upload[]=<log url>&title=<log title>&map=<map name>&api=<api key>
4*/
5header("Access-Control-Allow-Origin: *");
6//error_reporting(0);
7function getIP()
8{
9 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
10 $ip = $_SERVER['HTTP_CLIENT_IP'];
11 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
12 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
13 } else {
14 $ip = $_SERVER['REMOTE_ADDR'];
15 }
16 return $ip;
17}
18
19/* ODCZYTANIE JSON */
20$JSON_POST = json_decode(file_get_contents('php://input'), true);
21
22$USER_IP = getIP();
23if (!isset($JSON_POST['api'])) {
24 exit('{"error": "Missing api field.", "success": false}');
25}
26if (!isset($JSON_POST['title'])) {
27 exit('{"error": "Missing title field.", "success": false}');
28}
29if (!isset($JSON_POST['map'])) {
30 exit('{"error": "Missing map field.", "success": false}');
31}
32if (!isset($JSON_POST['ids'])) {
33 exit('{"error": "Missing ids[] field.", "success": false}');
34}
35if (!is_array($JSON_POST['ids'])) {
36 exit('{"error": "ids[] field must contain an array of valid ids.", "success": false}');
37}
38/* BOT WYSYŁA OD RAZU ARRAYLISTE Z LISTĄ ID */
39$log_ids = $JSON_POST['ids'];
40
41/* STARE POZYSKIWANIE ID Z LISTY URL
42$log_ids = array();
43foreach ($upload_urls as $log_url) {
44 $upload_url_parts = explode('/', $log_url);
45 $upload_url_id_array = explode('#', end($upload_url_parts));
46 $upload_url_id = $upload_url_id_array[0];
47 array_push($log_ids, $upload_url_id);
48}*/
49$storage_dir = str_replace(array(
50 '.',
51 ':'
52), '-', $USER_IP) . '/';
53$log_files = array();
54if (!file_exists(substr($storage_dir, 0, -1))) {
55 mkdir(substr($storage_dir, 0, -1));
56}
57foreach ($log_ids as $id) {
58 $log_zip_dir = $storage_dir . $id . '_log.zip';
59 if (!$chk = fopen('http://logs.tf/logs/log_' . $id . '.log.zip', 'r')) {
60 exit('{"error": "Invalid log url submitted.", "success": false}');
61 }
62 else {
63 file_put_contents($log_zip_dir, fopen('http://logs.tf/logs/log_' . $id . '.log.zip', 'r'));
64 //EXAMPLE: ./255-255-255-0/1234567_log.zip
65 $log_zip = new ZipArchive;
66 $log_zip->open($log_zip_dir);
67 $log_zip->extractTo($storage_dir);
68 $log_zip->close();
69 array_push($log_files, $storage_dir . 'log_' . $id . '.log');
70 }
71}
72//array for log file directories is stored in $log_files
73$final_log_dir = $storage_dir . 'LOG_FINAL-' . microtime() . '.log';
74$final_log = fopen($final_log_dir, 'a+');
75foreach ($log_files as $f) {
76 $l = file_get_contents($f) . "\n";
77 fwrite($final_log, $l);
78}
79fclose($final_log);
80$UPLOAD_URL = 'http://logs.tf/upload';
81$post = array(
82 'title' => $JSON_POST['title'],
83 'map' => $JSON_POST['map'],
84 'key' => $JSON_POST['api'],
85 'logfile' => curl_file_create($final_log_dir),
86 'uploader' => "Sharky's Logify v1.3"
87);
88$ch = curl_init($UPLOAD_URL);
89$ch_set = array(
90 CURLOPT_POST => 1,
91 CURLOPT_POSTFIELDS => $post,
92 CURLOPT_FOLLOWLOCATION => 1,
93 CURLOPT_HEADER => 0,
94 CURLOPT_RETURNTRANSFER => 1
95);
96curl_setopt_array($ch, $ch_set);
97$response = curl_exec($ch);
98echo ($response);
99$ffiles = glob($storage_dir . '*');
100foreach ($ffiles as $ffile) {
101 unlink($ffile);
102}
103?>