Click me!
diff --git a/src/php/handler.php b/src/php/handler.php
index a5d8846..f13c9c5 100644
--- a/src/php/handler.php
+++ b/src/php/handler.php
@@ -1,8 +1,12 @@
upload_folder);
+ if(!$fs->FileExists($id)) {
+ //resolve the hostnames to ips
+ $redis = StaticRedis::$Instance;
+ $sync_hosts = $redis->sMembers(REDIS_PREFIX . 'sync-hosts');
+
+ $sync_hosts_ips = array();
+ foreach($sync_hosts as $host) {
+ $sync_hosts_ips[] = gethostbyname($host);
+ }
+
+ //check the ip of the host submitting the file for sync
+ if(in_array(USER_IP, $sync_hosts_ips)) {
+ $fs->StoreFile("php://input", $id);
+ } else {
+ http_response_code(401);
+ }
+ }
+ } else {
+ http_response_code(400);
+ }
+ }
+
+ public static function SyncFile($id, $filename, $host) : void {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, "https://$host/sync");
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filename));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ "Content-Type: application/octet-stream",
+ "X-File-Id: " . $id
+ ));
+ curl_exec($ch);
+ curl_close ($ch);
}
}
diff --git a/src/php/syncthread.php b/src/php/syncthread.php
new file mode 100644
index 0000000..8818459
--- /dev/null
+++ b/src/php/syncthread.php
@@ -0,0 +1,18 @@
+Id = $id;
+ $this->FilePath = $filepath;
+ $this->Destination = $host;
+ }
+
+ public function run() {
+ Sync::SyncFile($this->Id, $this->FilePath, $this->Destination);
+ }
+ }
+
+?>
\ No newline at end of file
diff --git a/src/php/tracking.php b/src/php/tracking.php
index bb486c4..e3f371b 100644
--- a/src/php/tracking.php
+++ b/src/php/tracking.php
@@ -1,14 +1,6 @@
hIncrBy($file_key, 'views', 1);
$redis->hSet($file_key, 'lastview', time());
}
+
+ $this->SendMatomoEvent();
}
function IsRangeRequest() : bool {
@@ -29,5 +23,20 @@
return False;
}
+
+ function SendMatomoEvent() : void {
+ $msg = "?" . http_build_query(array(
+ "idsite" => 1,
+ "rec" => 1,
+ "apiv" => 1,
+ "_id" => isset($_COOKIE["VC:UID"]) ? $_COOKIE["VC:UID"] : uniqid(),
+ "url" => (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
+ "cip" => _UIP,
+ "ua" => isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "",
+ "urlref" => isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : ""
+ ));
+
+ StaticRedis::$Instance->publish('ga-page-view-matomo', $msg);
+ }
}
?>
\ No newline at end of file
diff --git a/src/php/upload.php b/src/php/upload.php
index 885a742..f62a14d 100644
--- a/src/php/upload.php
+++ b/src/php/upload.php
@@ -53,7 +53,30 @@
}
function SyncFileUpload($id) : void {
+ $redis = StaticRedis::$Instance;
+ $sync_hosts = $redis->sMembers(REDIS_PREFIX . 'sync-hosts');
+ if($sync_hosts !== False) {
+ $fs = new FileStore(Config::$Instance->upload_folder);
+ foreach($sync_hosts as $host) {
+ Sync::SyncFile($id, $fs->GetAbsoluteFilePath($id), $host);
+ }
+
+ /*
+ $sync_threads = array();
+ foreach($sync_hosts as $host) {
+ $new_thread = new SyncThread($id, $fs->GetAbsoluteFilePath($id), $host);
+ $new_thread->start();
+ $sync_threads[] = $new_thread;
+ }
+
+ foreach($sync_threads as $thread) {
+ while($thread->isRunning()) {
+ usleep(100);
+ }
+ $thread->join();
+ }*/
+ }
}
function SaveUpload($bf) : string {