log = true; $this->cfg = $cfg; $this->db = $db; $this->cdb = $class_database; } public function __destruct() { // we need to delete the log file here if ($this->log_clean === true) { // VFile::delete($this->log_file); } } public function load($file, $file_type) { if (!file_exists($file)) { return false; } $this->type = $file_type; $this->data['location'] = $file; $this->data['size'] = filesize($file); return true; } public function doTransfer($file_id, $user_key, $file, $srv_id = 0, $send_thumbs = 0, $exclude_id = 0) { $this->log("Determining next " . ($send_thumbs == 1 ? "thumb" : "upload") . " server.\n"); if ($srv_id == 0) { $rs = $this->db->execute(sprintf("SELECT * FROM `db_servers` WHERE %s `status`='1' AND `%s`='1' AND (`total_%s` < `server_limit` AND `current_hop` < `file_hop`) ORDER BY `server_priority` DESC LIMIT 1;", (($send_thumbs >= 1 and $exclude_id > 0) ? "`server_id`!='" . $exclude_id . "' AND " : null), ($send_thumbs >= 1 ? 'upload_' . $this->type[0] . '_thumb' : 'upload_' . $this->type[0] . '_file'), $this->type)); } else { $rs = $this->db->execute(sprintf("SELECT * FROM `db_servers` WHERE `server_id`='%s' LIMIT 1;", $srv_id)); } $this->log("Uploading to server: " . $rs->fields['server_name'] . " (" . (($rs->fields['server_type'] == 's3' or $rs->fields['server_type'] == 'ws') ? $rs->fields['s3_bucketname'] : $rs->fields['ftp_host']) . ")\n"); if ($rs->fields['server_id'] == '') { $this->db->execute("UPDATE `db_servers` SET `current_hop`='0' WHERE `file_hop`=`current_hop` AND `total_" . $this->type . "`<=`server_limit` AND `status`='1';"); $ar = $this->db->Affected_Rows(); $this->log("Trying to reset file hops: " . $ar . " " . ($ar == 1 ? "server" : "servers") . " found." . ($ar == 0 ? " (all servers full or disabled?!)" : null)); $rs = $this->db->execute(sprintf("SELECT * FROM `db_servers` WHERE %s `status`='1' AND `%s`='1' AND (`total_%s` < `server_limit` AND `current_hop` < `file_hop`) ORDER BY `server_priority` DESC LIMIT 1;", (($send_thumbs >= 1 and $exclude_id > 0) ? "`server_id`!='" . $exclude_id . "' AND " : null), ($send_thumbs >= 1 ? 'upload_' . $this->type[0] . '_thumb' : 'upload_' . $this->type[0] . '_file'), $this->type)); } else { $this->db->execute(sprintf("UPDATE `db_%stransfers` SET `state`='1' WHERE `file_key`='%s' LIMIT 1;", $this->type, $file_id)); } $this->log("Server Priority: " . $rs->fields['server_priority']); $this->log("Server Limit: " . $rs->fields['server_limit']); $this->log("Server Total: " . $rs->fields["total_" . $this->type]); $this->log("Server Hop: " . $rs->fields['file_hop']); $this->log("Current Hop: " . $rs->fields['current_hop'] . "\n\n"); if (($rs->fields['server_type'] == 's3' or $rs->fields['server_type'] == 'ws') and ($rs->fields["upload_" . $this->type[0] . "_file"] == 1 or $rs->fields["upload_" . $this->type[0] . "_thumb"] == 1)) { $awsAccessKey = $rs->fields['s3_accesskey']; $awsSecretKey = $rs->fields['s3_secretkey']; $bucketName = $rs->fields['s3_bucketname']; $region = $rs->fields['s3_region']; if ($rs->fields['server_type'] == 's3') { $regarr = VBeServers::region(); $ws = array(); } elseif ($rs->fields['server_type'] == 'ws') { $regarr = array( "us-east-1" => "US East", "us-west-1" => "US West", "eu-central-1" => "EU Central", ); $ws = array( //'endpoint' => 'http://s3.wasabisys.com', //'profile' => 'wasabi', 'region' => $region, 'version' => 'wasabi', ); } $s3 = new S3Client([ 'version' => 'latest', 'region' => $region, 'credentials' => [ 'key' => $awsAccessKey, 'secret' => $awsSecretKey, ], ]); ob_start(); try { $proceed = 0; $result = $s3->listBuckets(); if (is_array($result['Buckets'])) { echo "Successfully logged in using AccessKey and SecretKey\n\n"; if ($s3->doesBucketExist($bucketName)) { $proceed = 1; echo "Using bucket {$bucketName}\n\n\n"; } else { echo "Setting up bucket {$bucketName}\n\n"; $bar = array('Bucket' => $bucketName); $res = $s3->createBucket($bar); if ($res['RequestId']) { $proceed = 1; echo "Bucket {$bucketName} was successfully created\n\n"; echo "Bucket region set to " . $regarr[($region == '' ? 'default' : $region)] . "\n\n"; } else { echo "Bucket {$bucketName} could not be created. Name already used maybe?\n\n"; } } if ($proceed == 1) { $action = 0; $f = array(); $type = $this->type; $url = $this->cfg['media_files_dir']; $ds = md5($this->cfg['global_salt_key'] . $file_id); if ($rs->fields["upload_" . $this->type[0] . "_file"] == 1 and $send_thumbs == 0) { switch ($type) { case "video": $f['360p'] = array( $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.360p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.360p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.360p.webm', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.360p.ogv', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.360p.flv'); $f['mob'] = array( $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.mob.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.mob.mp4'); $f['480p'] = array( $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.480p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.480p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.480p.webm', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.480p.ogv'); $f['720p'] = array( $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.720p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.720p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.720p.webm', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.720p.ogv'); $f['1080p'] = array( $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.1080p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.1080p.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.1080p.webm', $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.1080p.ogv'); break; case "image": $f['jpg'] = array($url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.jpg', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.jpg'); break; case "audio": $f['mp3'] = array($url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.mp3', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.mp3'); $f['mp4'] = array($url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.mp4'); break; case "doc": $f['pdf'] = array($url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.pdf', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.pdf'); break; case "short": $f['short'] = array( $url . '/' . $user_key . '/' . $type[0] . '/' . $file_id . '.short.mp4', $url . '/' . $user_key . '/' . $type[0] . '/' . $ds . '.short.mp4', ); break; } } if ($rs->fields["upload_" . $this->type[0] . "_thumb"] == 1 and $send_thumbs >= 1) { $t = array(); $tcache = VFiles::thumb_cache($this->type, $file_id); for ($i = 0; $i <= $this->cfg['thumbs_nr']; $i++) { $t[] = $url . '/' . $user_key . '/t/' . $file_id . '/' . $i . $tcache . '.jpg'; } $f['tmb'] = $t; } else { echo "upload_" . $this->type[0] . "_thumb -> " . $rs->fields["upload_" . $this->type[0] . "_thumb"]; echo "\n"; echo '$send_thumbs -> ' . $send_thumbs; echo "\n"; } if ($rs->fields["upload_" . $this->type[0] . "_file"] == 1 and $send_thumbs == 0) { $this->db->execute(sprintf("UPDATE `db_%stransfers` SET `upload_server`='%s', `state`='1', `upload_start_time`='%s' WHERE `file_key`='%s' LIMIT 1;", $type, $rs->fields['server_id'], date("Y-m-d H:i:s"), $file_id)); } foreach ($f as $fk => $fv) { if ($fk == 'tmb') { $this->db->execute(sprintf("UPDATE `db_%stransfers` SET `thumb_server`='%s', `state`='1', `thumb_start_time`='%s' WHERE `file_key`='%s' LIMIT 1;", $type, $rs->fields['server_id'], date("Y-m-d H:i:s"), $file_id)); } $this->db->execute(sprintf("UPDATE `db_%sfiles` SET `%s_server`='%s' WHERE `file_key`='%s' LIMIT 1;", $this->type, ($fk != 'tmb' ? 'upload' : 'thumb'), $rs->fields['server_id'], $file_id)); foreach ($fv as $src) { if (file_exists($src)) { $xp = $fk != 'tmb' ? explode('.', $src) : explode('/', $src); $ct = count($xp); $profile = ($fk != 'tmb' and $type == 'video') ? $xp[$ct - 2] . '.' . $xp[$ct - 1] : $xp[$ct - 1]; $result[$profile] = array(); if ($fk == 'tmb') { list($width, $height, $filetype, $attr) = getimagesize($src); } $gs = md5($this->cfg['global_salt_key'] . $file_id); $fid = $file_id; if (strpos($src, $gs) !== false) { $fid = $gs; } echo "location => " . $src . "\n"; echo "size => " . filesize($src) . "\n"; echo ($fk != 'tmb' ? $this->type : "thumb") . " profile => " . $profile . "\n\n"; echo "---------Transfer started " . date("F j, Y, G:i:s") . "\n"; $key = $fk != 'tmb' ? $s3->encodeKey($user_key . '/' . $this->type[0] . '/' . $fid . '.' . $profile) : $s3->encodeKey($user_key . '/t/' . $file_id . '/' . $profile); $result[$profile] = $s3->upload($bucketName, $key, fopen($src, 'r'), $rs->fields['s3_fileperm']); if ($result[$profile]['ObjectURL']) { echo "Success: " . $result[$profile]['ObjectURL'] . "\n\n"; } else { echo "Warning: No ObjectURL returned, but transfer might have gotten through.\n"; } $local_file = $src; echo "Updating local files: \n\n"; echo ($action == 0 ? "Unlinking" : "Renaming") . " file " . $local_file . "\n"; if ($action == 0) { $_png = str_replace('.jpg', '.png', $local_file); if (unlink($local_file)) { if (file_exists($_png)) { echo "PNG unlinked $_png\n"; unlink($_png);} echo "OK\n"; } else { echo "Failed\n"; } } else { if (rename($local_file, $local_file . '.old')) { echo "OK\n"; } else { echo "Failed\n"; } } echo "\n"; echo "Creating new " . $profile . " dummy file \n"; if (file_put_contents($local_file, ($fk == 'tmb' ? $width . 'x' . $height : $file_id))) { echo "OK\n\n"; } echo "---------Transfer ended " . date("F j, Y, G:i:s") . "\n\n\n"; $sql = sprintf("UPDATE `db_%stransfers` SET `%s_end_time`='%s' WHERE `file_key`='%s' LIMIT 1;", $type, ($fk != 'tmb' ? 'upload' : 'thumb'), date("Y-m-d H:i:s"), $file_id); $this->db->execute($sql); } } } echo "Updating database: \n\n"; if ($send_thumbs == 0 or $send_thumbs == 2) { $sql = sprintf("UPDATE `db_%stransfers` SET `state`='2' WHERE `file_key`='%s' LIMIT 1;", $type, $file_id); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; } if ($send_thumbs == 0 or $send_thumbs == 2 or ($send_thumbs == 1 and intval($rs->fields["upload_" . $this->type[0] . "_file"]) != intval($rs->fields["upload_" . $this->type[0] . "_thumb"]))) { $sql = sprintf("UPDATE `db_servers` SET `current_hop`=`current_hop`+1, `total_%s`=`total_%s`+1, `last_used`='%s' WHERE `server_id`='%s' LIMIT 1;", $this->type, $this->type, date("Y-m-d H:i:s"), $rs->fields['server_id']); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; } } } } catch (Exception $e) { echo "Error: " . $e->getMessage(); } $value = ob_get_contents(); ob_end_clean(); $this->log($value); if ($rs->fields["upload_" . $this->type[0] . "_file"] == 1 and $rs->fields["upload_" . $this->type[0] . "_thumb"] == 1) { return; } if (($rs->fields["upload_" . $this->type[0] . "_file"] == 0 and $send_thumbs == 0) or ($rs->fields["upload_" . $this->type[0] . "_thumb"] == 0 and $send_thumbs >= 1)) { $file_type = $this->type; switch ($file_type) { case "video": $file_ext = '.360p.mp4'; break; case "short": $file_ext = '.short.mp4'; break; case "image": $file_ext = '.jpg'; break; case "audio": $file_ext = '.mp3'; break; case "doc": $file_ext = '.pdf'; break; } $tcache = VFiles::thumb_cache($this->type, $file_id); $src = $rs->fields["upload_" . $this->type[0] . "_file"] == 0 ? $this->cfg['media_files_dir'] . '/' . $user_key . '/' . $this->type[0] . '/' . $file_id . $file_ext : $this->cfg['media_files_dir'] . '/' . $user_key . '/t/' . $file_id . '/0' . $tcache . '.jpg'; $xfer = new fileTransfer(); if ($xfer->load($src, $file_type)) { $xfer->log_setup($file_id, true); $xfer->log("Preparing " . ($rs->fields["upload_" . $this->type[0] . "_file"] == 0 ? $this->type : "thumb") . ": " . $src . "\n\n" . $xfer->get_data_string() . "\n"); $xfer->doTransfer($file_id, $user_key, $src, 0, ($rs->fields["upload_" . $this->type[0] . "_file"] == 0 ? 0 : 1), $rs->fields['server_id']); } else { $xfer->log_setup($file_id, true); $xfer->log("Failed to load file: " . $src); } return; } return; } $ftp_host = $rs->fields['ftp_host']; $ftp_port = intval($rs->fields['ftp_port']); $ftp_xfer = $rs->fields['ftp_transfer']; $ftp_pssv = $rs->fields['ftp_passive']; $ftp_user = $rs->fields['ftp_username']; $ftp_pass = $rs->fields['ftp_password']; $ftp_root = $rs->fields['ftp_root']; ob_start(); $ftp = new ftp(true); $ftp->Verbose = false; $ftp->LocalEcho = true; /* set hostname */ if (!$ftp->SetServer($ftp_host, $ftp_port)) { $ftp->quit(); echo "Error: No server\n"; } /* connect to host */ if (!$ftp->connect()) { echo "Error: Cannot connect\n"; } /* send login */ if (!$ftp->login($ftp_user, $ftp_pass)) { $ftp->quit(); echo "Error: Login failed\n"; } /* transfer type */ if (!$ftp->SetType(($ftp_xfer == 'FTP_AUTOASCII' ? FTP_AUTOASCII : ($ftp_xfer == 'FTP_ASCII' ? FTP_ASCII : FTP_BINARY)))) { echo $err = "Error: SetType " . $ftp_xfer . " failed!\n"; } if (!$ftp->Passive(false)) { echo $err = "Error: Passive mode failed!\n"; } /* main folder check */ if (!$ftp->is_exists($ftp_root)) { echo "Error: Main folder not found " . $ftp_root . "\n"; echo "Notice: Attempting to create main folder " . $ftp_root . "\n"; $ftp->mkdir($ftp_root); if (!$ftp->is_exists($ftp_root)) { echo "Error: Main folder could not be created " . $ftp_root . "\n"; $ftp->quit(); } else { echo "Notice: Main folder created " . $ftp_root . "\n"; } } echo "\n\n"; /* user folder check */ $user_dir = $ftp_root . '/' . $user_key; if (!$ftp->is_exists($user_dir)) { echo "Error: User folder not found " . $user_dir . "\n"; echo "Notice: Attempting to create user folder " . $user_dir . "\n"; $ftp->mkdir($user_dir); if (!$ftp->is_exists($user_dir)) { echo "Error: User folder could not be created " . $user_dir . "\n"; $ftp->quit(); } else { echo "Notice: User folder created " . $user_dir . "\n"; } } $ts = $this->db->execute(sprintf("SELECT `thumb_server` FROM `db_%stransfers` WHERE `file_key`='%s' LIMIT 1;", $this->type, $file_id)); $tsrv = $ts->fields['thumb_server']; if ($ftp->is_exists($user_dir)) { if ($rs->fields["upload_" . $this->type[0] . "_file"] == 1) { $ftp->mkdir($user_dir . '/' . $this->type[0]); } if ($rs->fields["upload_" . $this->type[0] . "_thumb"] == 1) { if ($tsrv == 0 or ($tsrv > 0 and $tsrv == $rs->fields['server_id'])) { $ftp->mkdir($user_dir . '/t'); $ftp->mkdir($user_dir . '/t/' . $file_id); } } } if ($rs->fields["upload_" . $this->type[0] . "_file"] == 1 and $send_thumbs == 0) { $ftp->chdir($user_dir . '/' . $this->type[0]); echo "\n\n"; switch ($this->type) { case "video": $a1 = array('1080p', '1080pf', '720p', '720pf', '480p', '480pf', 'mob', 'mobf', '360p', '360pf'); foreach ($a1 as $bp) { if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $bp)) { } if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $bp, 'webm')) { } if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $bp, 'ogv')) { } } break; case "short": $a1 = array('short', 'shortf'); foreach ($a1 as $bp) { if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $bp)) { } } break; case "image": $a1 = array('jpg', 'jpgf'); foreach ($a1 as $bp) { if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $this->type, $bp)) { } } break; case "audio": $a1 = array('mp3', 'mp3f', 'mp4', 'mp4f'); foreach ($a1 as $bp) { if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $this->type, $bp)) { } } break; case "doc": $a1 = array('pdf', 'pdff'); foreach ($a1 as $bp) { if (self::transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $this->type, $bp)) { } } break; } } if ($tsrv > 0 and $tsrv != $rs->fields['server_id'] and $send_thumbs >= 1) { $file_type = $this->type; $tcache = VFiles::thumb_cache($this->type, $file_id); $src = $this->cfg['media_files_dir'] . '/' . $user_key . '/t/' . $file_id . '/0' . $tcache . '.jpg'; $xfer = new fileTransfer(); if ($xfer->load($src, $file_type)) { $xfer->log_setup($file_id, true); $xfer->log("Preparing thumbnail: " . $src . "\n\n" . $xfer->get_data_string() . "\n"); $xfer->doTransfer($file_id, $user_key, $src, $tsrv, 1, $rs->fields['server_id']); } else { $xfer->log_setup($file_id, true); $xfer->log("Failed to load file: " . $src); } echo "\n---------------------------- end ----------------------------\n"; $value = ob_get_contents(); ob_end_clean(); $this->log($value); return; } if ($send_thumbs >= 1) { if ($rs->fields["upload_" . $this->type[0] . "_thumb"] == 1) { $ftp->chdir($user_dir . '/t/' . $file_id); echo "\n\n"; self::transferThumb($ftp, $rs, $user_key, $file_id, $user_dir, 'thumb'); } else { $file_type = $this->type; $tcache = VFiles::thumb_cache($this->type, $file_id); $src = $this->cfg['media_files_dir'] . '/' . $user_key . '/t/' . $file_id . '/0' . $tcache . '.jpg'; $nrs = $this->db->execute(sprintf("SELECT * FROM `db_servers` WHERE `server_id`!='%s' AND `status`='1' AND `upload_%s_thumb`='1' AND (`total_%s` < `server_limit` AND `current_hop` < `file_hop`) ORDER BY `server_priority` DESC LIMIT 1;", $rs->fields['server_id'], $this->type[0], $this->type)); if (!$nrs->fields['server_id']) { echo "Error: No thumb servers found.\n"; $this->db->execute(sprintf("UPDATE `db_servers` SET `current_hop`='0' WHERE `server_id`!='%s' AND `file_hop`=`current_hop` AND `total_%s`<=`server_limit` AND `status`='1';", $rs->fields['server_id'], $this->type)); $ar = $this->db->Affected_Rows(); $this->log("Trying to reset file hops: " . $ar . " " . ($ar == 1 ? "server" : "servers") . " found." . ($ar == 0 ? " (all servers full or disabled?!)" : null)); $nrs = $this->db->execute(sprintf("SELECT * FROM `db_servers` WHERE `server_id`!='%s' AND `status`='1' AND `upload_%s_thumb`='1' AND (`total_%s` < `server_limit` AND `current_hop` < `file_hop`) ORDER BY `server_priority` DESC LIMIT 1;", $rs->fields['server_id'], $this->type[0], $this->type)); } if ($nrs->fields['server_id']) { $xfer = new fileTransfer(); if ($xfer->load($src, $file_type)) { $xfer->log_setup($file_id, true); $xfer->log("Preparing thumbnail: " . $src . "\n\n" . $xfer->get_data_string() . "\n"); $xfer->doTransfer($file_id, $user_key, $src, $nrs->fields['server_id'], 1, $rs->fields['server_id']); } else { $xfer->log_setup($file_id, true); $xfer->log("Failed to load file: " . $src); } } } } echo "\n---------------------------- end ----------------------------\n"; $value = ob_get_contents(); ob_end_clean(); $this->log($value); } public function transferThumb($ftp, $rs, $user_key, $file_id, $user_dir, $br = 'thumb') { $action = 0; //0 = delete local file after transferring; 1 = rename local file after transferring; $tnr = $this->cfg['thumbs_nr']; $sql = sprintf("UPDATE `db_%stransfers` SET `state='1' WHERE `file_key`='%s' LIMIT 1;", $this->type, $file_id); $this->db->execute($sql); for ($i = 0; $i <= $tnr; $i++) { $tcache = VFiles::thumb_cache($this->type, $file_id); $local_file = $this->cfg['media_files_dir'] . '/' . $user_key . '/t/' . $file_id . '/' . $i . $tcache . '.jpg'; $remote_file = $user_dir . '/t/' . $file_id . '/' . $i . $tcache . '.jpg'; if (!file_exists($local_file)) { return; } list($width, $height, $type, $attr) = getimagesize($local_file); $start_time = date("Y-m-d H:i:s"); echo "\n\n" . ucfirst($this->type) . " thumbnail: " . $i . $tcache . ".jpg"; echo "\nTransfer started " . date("F j, Y, G:i:s") . "\n"; if ($ftp->put($local_file, $remote_file)) { $local_size = filesize($local_file); $remote_size = $ftp->filesize($remote_file); echo "Transfer ended " . date("F j, Y, G:i:s"); if ($remote_size == $local_size) { echo "\n\n"; echo "Local file size: " . $local_size . "\n"; echo "Remote file size: " . $remote_size . "\n"; echo "\n\n"; echo "Updating local files: \n\n"; echo ($action == 0 ? "Unlinking" : "Renaming") . " thumb " . $local_file . "\n"; if ($action == 0) { if (unlink($local_file)) { echo "OK\n"; } else { echo "Failed\n"; } } else { if (rename($local_file, $local_file . '.old')) { echo "OK\n"; } else { echo "Failed\n"; } } echo "\n"; echo "Creating new " . $br . " dummy file \n"; if (file_put_contents($local_file, $width . 'x' . $height)) { echo "OK\n\n"; } } else { echo "\n"; echo "Error: File sizes do not match: local (" . $local_size . ") / remote (" . $remote_size . ")"; } } else { echo "Error: The file was not transferred\n"; } if ($br == 'thumb' and $i == 0) { echo "Updating database: \n\n"; $sql = sprintf("UPDATE `db_%sfiles` SET `thumb_server`='%s' WHERE `file_key`='%s' LIMIT 1;", $this->type, $rs->fields['server_id'], $file_id); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; $sql = sprintf("UPDATE `db_%stransfers` SET `thumb_server`='%s', `thumb_start_time`='%s', `thumb_end_time`='%s', `state`='2' WHERE `file_key`='%s' LIMIT 1;", $this->type, $rs->fields['server_id'], $start_time, date("Y-m-d H:i:s"), $file_id); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; if ($rs->fields["upload_" . $this->type[0] . "_file"] == 0 and $rs->fields["upload_" . $this->type[0] . "_thumb"] == 1) { $sql = sprintf("UPDATE `db_servers` SET `current_hop`=`current_hop`+1, `total_%s`=`total_%s`+1, `last_used`='%s' WHERE `server_id`='%s' LIMIT 1;", $this->type, $this->type, date("Y-m-d H:i:s"), $rs->fields['server_id']); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; } } } } /* transfer file */ public function transferFile($ftp, $rs, $user_key, $file_id, $user_dir, $br, $ext = 'mp4') { $action = 0; //0 = delete local file after transferring; 1 = rename local file after transferring; switch ($br) { case "image": case "audio": case "doc": $fk = ($br == 'jpgf' or $br == 'mp3f' or $br == 'mp4f' or $br == 'pdff') ? md5($this->cfg['global_salt_key'] . $file_id) : $file_id; $local_file = $this->cfg['media_files_dir'] . '/' . $user_key . '/' . $this->type[0] . '/' . $fk . '.' . str_replace(array('f', 'pd'), array('', 'pdf'), $br) . '.' . $ext; $remote_file = $user_dir . '/' . $this->type[0] . '/' . $fk . '.' . str_replace(array('f', 'pd'), array('', 'pdf'), $br) . '.' . $ext; break; default: $fk = ($br == '360pf' or $br == '480pf' or $br == '720pf' or $br == '1080pf' or $br == 'mobf') ? md5($this->cfg['global_salt_key'] . $file_id) : $file_id; $local_file = $this->cfg['media_files_dir'] . '/' . $user_key . '/' . $this->type[0] . '/' . $fk . '.' . str_replace('f', '', $br) . '.' . $ext; $remote_file = $user_dir . '/' . $this->type[0] . '/' . $fk . '.' . str_replace('f', '', $br) . '.' . $ext; break; } if (!file_exists($local_file)) { /* echo "\nLocal file not found: ".$local_file; echo "\nProfile: ".$br." - Key: ".$fk; echo "\nID: ".$file_id; echo "\nSalt: ".$this->cfg['global_salt_key'];*/ return; } $start_time = date("Y-m-d H:i:s"); echo "\nFile profile: " . $ext . "/" . $br; echo "\nTransfer started " . date("F j, Y, G:i:s") . "\n"; if ($ftp->put($local_file, $remote_file)) { $local_size = filesize($local_file); $remote_size = $ftp->filesize($remote_file); echo "Transfer ended " . date("F j, Y, G:i:s"); if ($remote_size == $local_size) { echo "\n\n"; echo "Local file size: " . $local_size . "\n"; echo "Remote file size: " . $remote_size . "\n"; echo "\n\n"; if (($br == '360p' and $ext == 'mp4') or $ext == 'jpg' or $ext == 'mp3' or $ext == 'pdf') { echo "Updating database: \n\n"; $sql = sprintf("UPDATE `db_%sfiles` SET `upload_server`='%s' WHERE `file_key`='%s' LIMIT 1;", $this->type, $rs->fields['server_id'], $file_id); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; $sql = sprintf("UPDATE `db_%stransfers` SET `upload_server`='%s', `upload_start_time`='%s', `upload_end_time`='%s', `state`='2' WHERE `file_key`='%s' LIMIT 1;", $this->type, $rs->fields['server_id'], $start_time, date("Y-m-d H:i:s"), $file_id); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; } if ($br == '360pf' and $ext == 'mp4') { echo "Updating database: \n\n"; $sql = sprintf("UPDATE `db_%sfiles` SET `upload_server`='%s' WHERE `file_key`='%s' LIMIT 1;", $this->type, $rs->fields['server_id'], $file_id); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; $sql = sprintf("UPDATE `db_servers` SET `current_hop`=`current_hop`+1, `total_%s`=`total_%s`+1, `last_used`='%s' WHERE `server_id`='%s' LIMIT 1;", $this->type, $this->type, date("Y-m-d H:i:s"), $rs->fields['server_id']); echo $sql . "\n"; $this->db->execute($sql); echo $res = $this->db->Affected_Rows() > 0 ? "OK\n" : "Failed\n"; echo "\n"; } echo "Updating local files: \n\n"; echo ($action == 0 ? "Unlinking" : "Renaming") . " file " . $local_file . "\n"; if ($action == 0) { if (unlink($local_file)) { echo "OK\n"; } else { echo "Failed\n"; } } else { if (rename($local_file, $local_file . '.old')) { echo "OK\n"; } else { echo "Failed\n"; } } echo "\n"; echo "Creating new " . $ext . "/" . $br . " dummy file \n"; if (file_put_contents($local_file, utf8_encode($file_id))) { echo "OK\n\n"; } return true; } else { echo "\n"; echo "Error: File sizes do not match: local (" . $local_size . ") / remote (" . $remote_size . ")"; return false; } } else { echo "Error: The file was not transferred\n"; return false; } } public function get_data_string() { $string = null; foreach ($this->data as $key => $value) { $string .= $key . ' => ' . $value . "\n"; } return $string; } public function get_data() { return $this->data; } public function log_setup($file_id, $log = true) { if ($log === true) { $ddir = 'log_xfer/' . date("Y.m.d") . '/'; $full_path = $this->cfg['logging_dir'] . '/' . $ddir . $path . '.' . $this->type . '_' . $file_id . '.log'; if (!file_exists($full_path)) { @touch($full_path); } if ($ddir != '' and !is_dir($this->cfg['logging_dir'] . '/' . $ddir)) { @mkdir($this->cfg['logging_dir'] . '/' . $ddir); } } $this->log = ($log === true) ? true : false; $this->log_file = $full_path; } public function log($data) { if ($this->log !== false) { if (!file_exists($this->log_file)) { @touch($this->log_file); } VFileinfo::write($this->log_file, $data . "\n", true); } } public function clean() { $this->data = array(); if ($this->log_file) { // VFile::delete($this->log_file); } $this->log_file = ''; } } class fileQueue { private $cfg; private $db; private $cdb; public $type; public function __construct() { global $db, $class_database, $cfg; $this->db = $db; $this->cdb = $class_database; $this->cfg = $cfg; $this->cfg = $this->cdb->getConfigurations("server_path_php,pause_video_transfer,pause_short_transfer,pause_image_transfer,pause_audio_transfer,pause_doc_transfer,conversion_video_que,conversion_short_que,conversion_image_que,conversion_audio_que,conversion_doc_que"); } public function load($t) { $this->type = $t; return true; } public function check() { $found = 0; $file = "transfer.php"; $conv1 = "convert_video.php"; $conv11 = "convert_short.php"; $conv2 = "convert_image.php"; $conv3 = "convert_audio.php"; $conv4 = "convert_doc.php"; $conv5 = "ffmpeg"; $yt = "youtube-dl"; $dl = "download_video.php"; $commands = array(); exec("ps ax", $commands); if (count($commands) > 0) { foreach ($commands as $command) { if (strpos($command, $yt) === false and strpos($command, $conv1) === false and strpos($command, $conv11) === false and strpos($command, $conv2) === false and strpos($command, $conv3) === false and strpos($command, $conv4) === false and strpos($command, $conv5) === false and strpos($command, $dl) === false) { //what ? //$found = 0; } else { $found++; $in = $conv; } if ($found == 0) { if (strpos($command, $file) === false) { //what ? } else { $found++; $in = $file; } } } } if ($found > 0) { echo "Another process is running (" . $in . ").\n"; return false; } /* regular process here */ echo "Made it through all checks, transfer can start (" . $this->type . ").\n"; return true; } public function startTransfer() { // global $class_database; /* transfer state: 0 = idle (waiting to start) 1 = running 2 = completed */ if ($this->cfg["pause_" . $this->type . "_transfer"] == 1) { return; } $sql = sprintf("SELECT `upload_server`, `thumb_server`, `file_key`, `usr_key`, `active` FROM `db_%stransfers` WHERE `upload_start_time`='0000-00-00 00:00:00' AND `upload_end_time`='0000-00-00 00:00:00' AND `state`='0' AND `active`='1' ORDER BY `q_id` DESC LIMIT 1;", $this->type); $res = $this->db->execute($sql); $file_key = $res->fields['file_key']; $usr_key = $res->fields['usr_key']; $srv_id = $res->fields['upload_server']; $tmb_id = $res->fields['thumb_server']; $active = $res->fields['active']; $active = $active == '' ? 1 : $active; $inq = 0; if ($this->cfg["conversion_" . $this->type . "_que"] == 1) { $sql = sprintf("SELECT `q_id` FROM `db_%sque` WHERE `file_key`='%s' AND `state` < 2 LIMIT 1;", $this->type, $file_key); $rs = $this->db->execute($sql); $inq = $rs->fields['q_id']; if (!$inq and $this->type == "video") { $sql = sprintf("SELECT `q_id` FROM `db_%sdl` WHERE `file_key`='%s' AND `state` < 2 LIMIT 1;", $this->type, $file_key); $rs = $this->db->execute($sql); $inq = $rs->fields['q_id']; } } if ($active == 0 or $inq > 0) { return; } $sql = sprintf("SELECT `embed_src` FROM `db_%sfiles` WHERE `file_key`='%s' LIMIT 1;", $this->type, $file_key); $get = $this->db->execute($sql); $src = $get->fields['embed_src']; if ($file_key != '' and $usr_key != '') { if ($src == 'local') { $cmd = sprintf("%s %s/f_modules/m_frontend/m_file/transfer.php %s %s %s %s", $this->cfg['server_path_php'], $this->cfg['main_dir'], $this->type, $file_key, $usr_key, $srv_id); exec(escapeshellcmd($cmd) . ' >/dev/null &'); } $send_thumbs = $src == 'local' ? 1 : 2; $cmd = sprintf("%s %s/f_modules/m_frontend/m_file/transfer.php %s %s %s %s %s", $this->cfg['server_path_php'], $this->cfg['main_dir'], $this->type, $file_key, $usr_key, $tmb_id, $send_thumbs); exec(escapeshellcmd($cmd) . ' >/dev/null &'); } else { $sql = sprintf("SELECT A.`file_key`, A.`upload_server`, B.`usr_key` FROM `db_%sfiles` A, `db_accountuser` B WHERE A.`usr_id`=B.`usr_id` AND A.`upload_server`='0' AND A.`thumb_server`='0' ORDER BY A.`db_id` ASC LIMIT 1;", $this->type); $res = $this->db->execute($sql); $file_key = $res->fields['file_key']; $usr_key = $res->fields['usr_key']; $srv_id = (int) $res->fields['upload_server']; $sql_add = ($srv_id == 0 and $file_key and $usr_key) ? $this->cdb->doInsert('db_' . $this->type . 'transfers', array("upload_server" => $srv_id, "file_key" => $file_key, "usr_key" => $usr_key)) : null; } } public function __destruct() { } } class VbeServers { /* main server details */ public function mainServerDetails($_dsp = '', $entry_id = '', $db_id = '', $server_status = '', $server_name = '', $server_type = '', $server_priority = '', $server_limit = '', $server_filehop = '', $upload_v_file = '', $upload_v_thumb = '', $upload_i_file = '', $upload_i_thumb = '', $upload_a_file = '', $upload_a_thumb = '', $upload_d_file = '', $upload_d_thumb = '', $ftp_transfer = '', $ftp_passive = '', $ftp_host = '', $ftp_port = '', $ftp_user = '', $ftp_pass = '', $ftp_root = '', $base_url = '', $lighttpd_url = '', $lighttpd_secdownload = '', $lighttpd_prefix = '', $lighttpd_key = '', $s3_bucketname = '', $s3_accesskey = '', $s3_secretkey = '', $s3_region = '', $s3_fileperm = '', $cf_enable = '', $cf_dist = '', $cf_priceclass = '', $surl_enable = '', $surl_expire = '', $keypair_id = '', $keypair_file = '', $upload_s_file = '', $upload_s_thumb = '') { global $class_filter; if ($_POST and ($_GET['do'] == 'add' or $_GET['do'] == 'update')) { self::processEntry(); $entryid = (int) $db_id; $backend_servers_type = "backend_servers_type_" . $entryid; $backend_servers_transfer = "backend_servers_transfer_" . $entryid; $backend_servers_passive = "backend_servers_passive_" . $entryid; $backend_s3_region = "backend_s3_region_" . $entryid; $backend_servers_cf_priceclass = "backend_servers_cf_priceclass_" . $entryid; $server_name = $class_filter->clr_str($_POST['frontend_global_name']); $server_type = $class_filter->clr_str($_POST[$backend_servers_type]); $server_priority = intval($_POST['backend_servers_priority']); $server_limit = intval($_POST['backend_servers_limit']); $server_filehop = intval($_POST['backend_servers_hop']); $upload_v_file = intval($_POST['backend_servers_ct_video']); $upload_v_thumb = intval($_POST['backend_servers_ct_vthumb']); $upload_s_file = intval($_POST['backend_servers_ct_short']); $upload_s_thumb = intval($_POST['backend_servers_ct_sthumb']); $upload_i_file = intval($_POST['backend_servers_ct_image']); $upload_i_thumb = intval($_POST['backend_servers_ct_ithumb']); $upload_a_file = intval($_POST['backend_servers_ct_audio']); $upload_a_thumb = intval($_POST['backend_servers_ct_athumb']); $upload_d_file = intval($_POST['backend_servers_ct_doc']); $upload_d_thumb = intval($_POST['backend_servers_ct_dthumb']); $ftp_transfer = $class_filter->clr_str($_POST[$backend_servers_transfer]); $ftp_passive = intval($_POST[$backend_servers_passive]); $ftp_host = $class_filter->clr_str($_POST['backend_servers_host']); $ftp_port = $class_filter->clr_str($_POST['backend_servers_port']); $ftp_user = $class_filter->clr_str($_POST['backend_servers_user']); $ftp_pass = $class_filter->clr_str($_POST['backend_servers_pass']); $ftp_root = $class_filter->clr_str($_POST['backend_servers_root']); $base_url = $class_filter->clr_str($_POST['backend_servers_url']); $lighttpd_url = $class_filter->clr_str($_POST['stream_url']); $lighttpd_secdownload = $class_filter->clr_str($_POST['stream_secure']); $lighttpd_prefix = $class_filter->clr_str($_POST['stream_prefix']); $lighttpd_key = $class_filter->clr_str($_POST['stream_key']); $s3_bucketname = $class_filter->clr_str($_POST['backend_s3_bucketname']); $s3_accesskey = $class_filter->clr_str($_POST['backend_s3_accesskey']); $s3_secretkey = $class_filter->clr_str($_POST['backend_s3_secretkey']); $s3_region = $class_filter->clr_str($_POST[$backend_s3_region]); $s3_fileperm = $class_filter->clr_str($_POST['backend_s3_fileperm']); $cf_enable = $class_filter->clr_str($_POST['backend_servers_cf_enable']); $cf_dist = $class_filter->clr_str($_POST['backend_servers_cf_dist']); $cf_priceclass = $class_filter->clr_str($_POST[$backend_servers_cf_priceclass]); $surl_enable = intval($_POST['backend_servers_surl_enable']); $surl_expire = intval($_POST['backend_servers_surl_time']); $keypair_id = $class_filter->clr_str($_POST['backend_servers_keypair_id']); $keypair_file = $class_filter->clr_str($_POST['backend_servers_keypair_file']); } return self::ServerDetails($_dsp, $entry_id, $db_id, $server_status, $server_name, $server_type, $server_priority, $server_limit, $server_filehop, $upload_v_file, $upload_v_thumb, $upload_i_file, $upload_i_thumb, $upload_a_file, $upload_a_thumb, $upload_d_file, $upload_d_thumb, $ftp_transfer, $ftp_passive, $ftp_host, $ftp_port, $ftp_user, $ftp_pass, $ftp_root, $base_url, '', '', '', '', '', '', '', $lighttpd_url, $lighttpd_secdownload, $lighttpd_prefix, $lighttpd_key, $s3_bucketname, $s3_accesskey, $s3_secretkey, $s3_region, $s3_fileperm, $cf_enable, $cf_dist, $cf_priceclass, $surl_enable, $surl_expire, $keypair_id, $keypair_file, $upload_s_file, $upload_s_thumb); } public function getPostID() { global $class_filter; return $class_filter->clr_str($_POST['hc_id']); } public function region() { return array( "us-east-1" => "US East (N. Virginia)", "us-east-2" => "US East (Ohio)", "us-west-1" => "US West (N. California)", "us-west-2" => "US West (Oregon)", "ca-central-1" => "Canada (Central)", "eu-west-1" => "EU (Ireland)", "eu-west-2" => "EU (London)", "eu-west-3" => "EU (Paris)", "eu-central-1" => "EU (Frankfurt)", "sa-east-1" => "South America (São Paulo)", "ap-south-1" => "Asia Pacific (Mumbai)", "ap-southeast-1" => "Asia Pacific (Singapore)", "ap-southeast-2" => "Asia Pacific (Sydney)", "ap-northeast-1" => "Asia Pacific (Tokyo)", "ap-northeast-2" => "Asia Pacific (Seoul)", "ap-northeast-3" => "Asia Pacific (Osaka-Local)", ); } /* server details edit */ public function ServerDetails($_dsp = '', $entry_id = '', $db_id = '', $server_status = '', $server_name = '', $server_type = '', $server_priority = '', $server_limit = '', $server_filehop = '', $upload_v_file = '', $upload_v_thumb = '', $upload_i_file = '', $upload_i_thumb = '', $upload_a_file = '', $upload_a_thumb = '', $upload_d_file = '', $upload_d_thumb = '', $ftp_transfer = '', $ftp_passive = '', $ftp_host = '', $ftp_port = '', $ftp_user = '', $ftp_pass = '', $ftp_root = '', $base_url = '', $total_video = '', $total_short = '', $total_image = '', $total_audio = '', $total_doc = '', $current_hop = '', $server_last = '', $lighttpd_url = '', $lighttpd_secdownload = '', $lighttpd_prefix = '', $lighttpd_key = '', $s3_bucketname = '', $s3_accesskey = '', $s3_secretkey = '', $s3_region = '', $s3_fileperm = '', $cf_enable = '', $cf_dist = '', $cf_priceclass = '', $surl_enable = '', $surl_expire = '', $keypair_id = '', $keypair_file = '', $upload_s_file = '', $upload_s_thumb = '') { global $class_filter, $language, $cfg; $_init = VbeEntries::entryInit($_dsp, $db_id, $entry_id); $_dsp = $_init[0]; $_btn = $_init[1]; $_btn = $_GET['do'] != 'add' ? VGenerate::simpleDivWrap('left-float', '', VGenerate::basicInput('button', 'save_changes', 'save-entry-button button-grey search-button form-button ' . ($_GET['do'] == 'add' ? 'new-entry' : 'update-entry'), '', $entry_id, '' . ($_GET['do'] == 'add' ? $language['frontend.global.savenew'] : $language['frontend.global.saveupdate']) . ''), 'display: inline-block-off;') : null; $server_type = ($_GET['do'] == 'add' and $_POST) ? $class_filter->clr_str($_POST['backend_servers_type_' . ((int) $db_id)]) : $server_type; $_sel1 = ''; $_sel2 = ''; $_sel3 = ''; $html .= '
'; return $html; } /* pause/resume transfers */ public function xferPause($state) { global $cfg, $db, $class_filter; $sw = $state == 'pause' ? 1 : 0; $type = $class_filter->clr_str($_GET['t']); $res = $db->execute(sprintf("UPDATE `db_settings` SET `cfg_data`='%s' WHERE `cfg_name`='pause_%s_transfer' LIMIT 1;", $sw, $type)); if ($db->Affected_Rows() > 0) { echo VGenerate::declareJS('$(".pause-mode, .resume-mode").parent().toggleClass("no-display");'); } } /* add new transfer */ public function xferAdd() { global $language, $db, $class_filter, $class_database, $cfg; $type = self::xferTypes(); $_btn = null; if ($_POST) { $_file = $class_filter->clr_str($_POST["new_" . $type . "_xfer"]); if ($_file != '') { $sql = sprintf("SELECT A.`file_key`, A.`file_title`, B.`usr_key` FROM `db_%sfiles` A, `db_accountuser` B WHERE A.`file_key`='%s' AND A.`usr_id`=B.`usr_id` LIMIT 1;", $type, $_file); $res = $db->execute($sql); if ($res->fields['file_key']) { $_xkey = $class_database->singleFieldValue('db_' . $type . 'transfers', 'q_id', 'file_key', $res->fields['file_key']); if ($_xkey != '') { $_xfer = ''; echo VGenerate::noticeTpl('', 'Error: Already added to transfer list', ''); } else { $_xfer = $res->fields['file_key']; $_xtitle = $res->fields['file_title']; $_usr = $res->fields['usr_key']; } } else { echo VGenerate::noticeTpl('', 'Error: Invalid title', ''); } } else { echo VGenerate::noticeTpl('', 'Error: Invalid title', ''); } $_vs = intval($_POST["new_" . $type . "_server"]); $_ts = intval($_POST['new_thumb_server']); if ($_xfer != '' and ($_vs > 0 or $_ts > 0)) { $_arr = array("upload_server" => $_vs, "thumb_server" => $_ts, "file_key" => $_xfer, "usr_key" => $_usr); $_ins = $class_database->doInsert('db_' . $type . 'transfers', $_arr); if ($db->Affected_Rows() > 0) { echo VGenerate::noticeTpl('', '', $language['notif.success.request']); } } } $_sel0 = ''; $_sel0 .= ''; $_sel1 = ''; $_sel2 = ''; $html = ''; $html .= VGenerate::declareJS('$(function(){SelectList.init("new_' . $type . '_xfer"); SelectList.init("new_' . $type . '_server"); SelectList.init("new_thumb_server");});'); return $html; } /* get type for transfers */ public function xferTypes() { global $class_filter; $for = $class_filter->clr_str($_GET['s']); switch ($for) { case "backend-menu-entry3-sub14": $type = 'video'; break; case "backend-menu-entry3-sub19": $type = 'short'; break; case "backend-menu-entry3-sub15": $type = 'image'; break; case "backend-menu-entry3-sub16": $type = 'audio'; break; case "backend-menu-entry3-sub17": $type = 'doc'; break; default: $type = 'video'; break; } return $type; } /* video transfer details */ public function xferDetails($_dsp = '', $file_key = '', $entry_id = '', $db_id = '', $state = '', $upload_server = '', $thumb_server = '', $upload_start_time = '', $upload_end_time = '', $thumb_start_time = '', $thumb_end_time = '') { global $class_filter, $language, $db; $_init = VbeEntries::entryInit($_dsp, $db_id, $entry_id); $_dsp = $_init[0]; $_btn = $_init[1]; $_btn = $_GET['do'] != 'add' ? VGenerate::simpleDivWrap('left-float', '', VGenerate::basicInput('button', 'save_changes', 'search-button form-button ' . ($_GET['do'] == 'add' ? 'new-entry' : 'update-entry'), '', $entry_id, ($_GET['do'] == 'add' ? $language['frontend.global.savenew'] : $language['frontend.global.saveupdate']))) : null; $u = $db->execute(sprintf("SELECT `server_type`, `server_name`, `ftp_host`, `s3_bucketname` FROM `db_servers` WHERE `server_id`='%s' LIMIT 1;", $upload_server)); $u1 = $u->fields['server_name']; $u2 = $u->fields['ftp_host']; $sh1 = $u->fields['server_type']; $sn1 = $u->fields['s3_bucketname']; $t = $db->execute(sprintf("SELECT `server_type`, `server_name`, `ftp_host`, `s3_bucketname` FROM `db_servers` WHERE `server_id`='%s' LIMIT 1;", $thumb_server)); $t1 = $t->fields['server_name']; $t2 = $t->fields['ftp_host']; $sh2 = $t->fields['server_type']; $sn2 = $t->fields['s3_bucketname']; $type = self::xferTypes(); $log = $cfg['logging_dir'] . '/xfer/' . date("Y.m.d") . '/' . $type . '_' . $file_key . '.log'; $log_file = $type . '_' . $file_key . '.log'; $log_ht = '' . $log_file . ''; $html = ''; $html .= ''; return $html; } /* show transfer log file */ public function xferLog() { global $class_filter, $cfg, $language, $smarty; $type = self::xferTypes(); $file_key = $class_filter->clr_str($_GET['i']); $log_path = $cfg['logging_dir'] . '/log_xfer/*/.' . $type . '_' . $file_key . '.log'; $html = ''; foreach (glob($log_path) as $filename) { if (file_exists($filename)) { $html .= "$filename size " . filesize($filename) . "Failed to load private key!
"; return; } //Sign the policy with the private key if (!openssl_sign($json, $signed_policy, $key, OPENSSL_ALGO_SHA1)) { echo 'Failed to sign policy: ' . openssl_error_string() . '
'; return; } //Create url safe signed policy $base64_signed_policy = base64_encode($signed_policy); $signature = str_replace(array('+', '=', '/'), array('-', '_', '~'), $base64_signed_policy); //Construct the URL $url = ($channel == 0 ? $resource : null) . '?Expires=' . $expires . '&Signature=' . $signature . '&Key-Pair-Id=' . $keyPairId . ($custom_policy == 1 ? '&Policy=' . self::url_safe_base64_encode($json) : null); return $url; } /* S3 connection check */ public function S3Conn() { global $db, $language, $cfg; $server_id = intval($_GET['i']); $rs = $db->execute(sprintf("SELECT `server_type`, `s3_accesskey`, `s3_secretkey`, `s3_bucketname`, `s3_region` FROM `db_servers` WHERE `server_id`='%s' LIMIT 1;", $server_id)); $server_type = $rs->fields['server_type']; $awsAccessKey = $rs->fields['s3_accesskey']; $awsSecretKey = $rs->fields['s3_secretkey']; $bucketName = $rs->fields['s3_bucketname']; $region = $rs->fields['s3_region']; if ($server_type == 's3') { $regarr = self::region(); $ws = array(); } elseif ($server_type == 'ws') { $regarr = array( "us-east-1" => "US East", "us-west-1" => "US West", "eu-central-1" => "EU Central", ); $ws = array( 'region' => $region, 'version' => 'wasabi', ); } $s3 = new S3Client([ 'version' => 'latest', 'region' => $region, 'credentials' => [ 'key' => $awsAccessKey, 'secret' => $awsSecretKey, ], ]); try { $result = $s3->listBuckets(); if (is_array($result['Buckets'])) { $ht = VGenerate::simpleDivWrap('row', '', str_replace(array('AccessKey', 'SecretKey'), array('AccessKey', 'SecretKey'), $language['backend.s3.logged.in'])); if ($s3->doesBucketExist($bucketName)) { $ht .= VGenerate::simpleDivWrap('row', '', "Bucket {$bucketName} was not created (already exists)"); } else { $ht .= VGenerate::simpleDivWrap('row', '', "Bucket name {$bucketName} is available"); $bar = array('Bucket' => $bucketName); $res = $s3->createBucket($bar); if ($res['RequestId']) { $ht .= VGenerate::simpleDivWrap('row', '', "Bucket {$bucketName} was successfully created"); $ht .= VGenerate::simpleDivWrap('row', '', "Bucket region successfully set to " . $regarr[($region == '' ? 'default' : $region)] . ""); } else { $ht .= VGenerate::simpleDivWrap('row', '', "Bucket {$bucketName} could not be created"); } } foreach ($result['Buckets'] as $bucket) { $ht .= $bucket['Name'] == $bucketName ? VGenerate::simpleDivWrap('row', 'bucket-row' . $server_id, "Bucket {$bucketName} is set up and ready to go (delete bucket)") : null; } } } catch (Exception $e) { $ht .= "Error: " . $e->getMessage(); } $html .= $ht; $js .= '$("a.s3-delete").click(function(){'; //delete s3 bucket $js .= 'var del_confirm = confirm("This will also delete all bucket contents!");'; $js .= 'if(del_confirm){'; $js .= '$(".fancybox-wrap").mask("");'; $js .= '$.post(current_url + menu_section + "?s="+$(".menu-panel-entry-sub-active").attr("id")+"&do=s3-delete&i=' . $server_id . '",'; $js .= 'function(data) {'; $js .= '$("#bucket-row' . $server_id . '").html(data);'; $js .= '$(".fancybox-wrap").unmask();'; $js .= '});'; $js .= 'return false;'; $js .= '}'; $js .= '});'; $html .= VGenerate::declareJS('$(document).ready(function(){' . $js . '});'); return $html; } /* ftp connection check */ public function ftpConn() { global $language, $db; $sid = intval($_GET['i']); $rs = $db->execute(sprintf("SELECT `ftp_host`, `ftp_port`, `ftp_transfer`, `ftp_passive`, `ftp_username`, `ftp_password`, `ftp_root` FROM `db_servers` WHERE `server_id`='%s' LIMIT 1;", $sid)); $ftp_host = $rs->fields['ftp_host']; $ftp_port = intval($rs->fields['ftp_port']); $ftp_xfer = $rs->fields['ftp_transfer']; $ftp_pssv = $rs->fields['ftp_passive']; $ftp_user = $rs->fields['ftp_username']; $ftp_pass = $rs->fields['ftp_password']; $ftp_root = $rs->fields['ftp_root']; $ftp = new ftp(true); $ftp->Verbose = false; $ftp->LocalEcho = false; $html .= "