uawdijnntqw1x1x1
IP : 216.73.216.103
Hostname : xhost1.intravision.ru
Kernel : Linux xhost1.intravision.ru 3.16.0-7-amd64 #1 SMP Debian 3.16.59-1 (2018-10-03) x86_64
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
OS : Linux
PATH:
/
var
/
.
/
files
/
need-2-delete
/
mini-borishof.ru1
/
test-drive2
/
generate_newkey.php
/
/
<?php require __DIR__ . '/vendor/autoload.php'; function addTrailingSlash ($path) { return rtrim ($path, '/') . '/'; } function getClient() { $file_secret = 'client_secret_622867803455-lq8ifijafcbk9alh37eb9eat90ft1roe.apps.googleusercontent.com.json'; $configPath = addTrailingSlash (getcwd()); if ( !file_exists( $configPath ."files/". $file_secret ) ) { if(!isset($_FILES['userfile']) || ( isset($_FILES['userfile']) && $_FILES['userfile']['name'] == '' )) { ?> <form enctype="multipart/form-data" method="POST"> Прикрепите json файл, загруженный из созданного сервисе: <br> <input name="userfile" type="file" /><br> <input type="submit" value="Отправить файл." /><br> </form> <? exit; }else{ echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $configPath ."files/". $file_secret)) { echo "Файл корректен и был успешно загружен.\n"; } else { echo "Ошибка загрузки файла!\n"; echo 'Некоторая отладочная информация:'; print_r($_FILES); print "</pre>"; exit; } } } // This get's generated by the script, so don't create it $credentialsPath = $configPath ."files/". 'credentials.json'; $client = new Google_Client(); // Matches the "Application Name" you enter during the "Step 1" wizard $client->setApplicationName( 'API googledrive for miniborishof' ); $client->setScopes( Google_Service_Drive::DRIVE_FILE ); // You need to go through "Step 1" steps to generate this file: https://developers.google.com/sheets/api/quickstart/php $client->setAuthConfig( $configPath ."files/". $file_secret ); $client->setAccessType( 'offline' ); // This must match the "callback URL" that you enter under "OAuth 2.0 client ID" in the Google APIs console at https://console.developers.google.com/apis/credentials //$client->setRedirectUri( 'https://www.mini-borishof.ru/test-drive2/test.php' ); // We have a stored credentials file, try using the data from there first if ( file_exists( $credentialsPath ) ) { $accessToken = json_decode( file_get_contents( $credentialsPath ), true ); //print_r($accessToken); if (array_key_exists('error', $accessToken)) { echo'Ошибка ключа'; unlink($credentialsPath); $authUrl = $client->createAuthUrl(); echo'<a href="'.$authUrl.'" target="_blank">Перейти для получения ключа</a>'; ?> <form method="POST"> <input type="text" name="code"><br> <input type="submit" value="отправить полученный код"> </form> <? exit; }else{ $client->setAccessToken($accessToken); } // If the $accessToken is expired then we'll need to refresh it if ( $client->isAccessTokenExpired() ) { $client->fetchAccessTokenWithRefreshToken( $client->getRefreshToken() ); file_put_contents( $credentialsPath, json_encode( $client->getAccessToken() ) ); } return $client; }else{ // Request authorization from the user $authUrl = $client->createAuthUrl(); if( !isset($_POST['code']) || ( isset($_POST['code']) && $_POST['code'] == '' ) ) { echo'<a href="'.$authUrl.'" target="_blank">Перейти для получения ключа</a>'; ?> <form method="POST"> <input type="text" name="code"><br> <input type="submit" value="отправить полученный код"> </form> <? //header( "Location: $authUrl", true, 302 ); exit; } // The authorization code is sent to the callback URL as a GET parameter. // We use this "authorization code" to generate an "access token". The // "access token" is what's effectively used as a private API key. $authCode = $_POST['code']; $accessToken = $client->fetchAccessTokenWithAuthCode( $authCode ); // Create credentials.json if it doesn't already exist (first run) if ( ! file_exists( dirname( $credentialsPath ) ) ) { mkdir( dirname( $credentialsPath ), 0700, true ); } // Save the $accessToken object to the credentials.json file for re-use file_put_contents( $credentialsPath, json_encode( $accessToken ) ); } if (array_key_exists('error', $accessToken)) { echo'Ошибка ключа'; unlink($credentialsPath); $authUrl = $client->createAuthUrl(); echo'<a href="'.$authUrl.'" target="_blank">Перейти для получения ключа</a>'; ?> <form method="POST"> <input type="text" name="code"><br> <input type="submit" value="отправить полученный код"> </form> <? exit; }else{ $client->setAccessToken($accessToken); } // If the $accessToken is expired then we'll need to refresh it if ( $client->isAccessTokenExpired() ) { $newtoken = $client->getRefreshToken(); $client->fetchAccessTokenWithRefreshToken( $newtoken ); file_put_contents( $credentialsPath, json_encode( $client->getAccessToken() ) ); } return $client; } function create_folder($service,$foldername){ $fileMetadata = new Google_Service_Drive_DriveFile([ 'name' => $foldername, 'mimeType' => 'application/vnd.google-apps.folder' ]); $folder = $service->files->create($fileMetadata, ['fields' => 'id']); return $folder->id; } function copy_newtable($service,$tablename,$folder_id){ $fileMetadata = new Google_Service_Drive_DriveFile([ 'parents' => array($folder_id), 'addParents' => $folder_id, ]); $fileMetadata->setName($tablename); $fileMetadata->setDescription('Это документ ' . 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $fileMetadata->setMimeType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $content = file_get_contents('files/new_table.xlsx');//чистая таблица с заголовками столбцов под запаолнение $file = $service->files->create($fileMetadata, array( 'data' => $content, 'mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'uploadType' => 'multipart', 'fields' => 'id,size,name, webViewLink, mimeType')); return $file; } function downloadFile($client, $table_file,$return = true) { // Determine the file's size and ID $fileId = $table_file->id; $fileSize = intval($table_file->size); // Get the authorized Guzzle HTTP client $http = $client->authorize(); //print_r($http); if(!$return){ $fp = fopen('tmp/client.xlsx', 'w'); }else{ $buff = ''; } $chunkSizeBytes = 1 * 1024 * 1024; $chunkStart = 0; // Iterate over each chunk and write it to our file while ($chunkStart < $fileSize) { $chunkEnd = $chunkStart + $chunkSizeBytes; $response = $http->request( 'GET', sprintf('/drive/v3/files/%s', $fileId), [ 'query' => ['alt' => 'media'], 'headers' => [ 'Range' => sprintf('bytes=%s-%s', $chunkStart, $chunkEnd) ] ] ); $chunkStart = $chunkEnd + 1; if(!$return){ fwrite($fp, $response->getBody()->getContents()); }else{ $buff .= $response->getBody()->getContents(); } } if(!$return){ fclose($fp); }else{ return $buff; } } function update_table($service,$fileId){ $data = file_get_contents('tmp/client.xlsx'); try { $emptyFile = new Google_Service_Drive_DriveFile(); $service->files->update($fileId, $emptyFile, array( 'data' => $data, 'mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'uploadType' => 'multipart' )); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } } $client = getClient(); $client = getClient(); //echo 'Ключ не валидный'; if($client === false){ }else{ $service = new Google_Service_Drive($client); $foldername = 'test3'; $tablename = 'table.xlsx'; $optParams = array( 'pageSize' => 10, 'fields' => 'files(id,size,name, webViewLink, mimeType)', 'q' => "(mimeType = 'application/vnd.google-apps.folder' AND trashed != true) OR (name = '".$tablename."' AND trashed != true)" ); $results = $service->files->listFiles($optParams); if (count($results->getFiles()) == 0) { $folder_id = create_folder($service,$foldername); } else { //print "Files:\n"; foreach ($results->getFiles() as $file) { if($file->getName() == $foldername){ $folder_id = $file->getId(); } if($file->getName() == $tablename){ $table_id = $file->getId(); $table_file = $file; } } } if(!isset($folder_id)){//если папки нет, создаем ее $folder_id = create_folder($service,$foldername); } if(!isset($table_id) && isset($folder_id)){//если таблицы нет, копируем ее из зараннее заготовленной $table_file = copy_newtable($service,$tablename,$folder_id); $table_id = $table_file->id; } echo'Если в вашем аккаунте на гуглдиске появилась папка '.$foldername.' и в ней есть таблица('.$tablename.'), то все прошло успешно.'; }
/var/./files/need-2-delete/mini-borishof.ru1/test-drive2/generate_newkey.php