mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
php: simplify server configuration
This commit is contained in:
@ -49,41 +49,6 @@ function getHttpOrigin()
|
||||
return $origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set headers that prevent caching in all the browsers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function nocacheHeaders()
|
||||
{
|
||||
$headers = [
|
||||
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
|
||||
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
|
||||
'Pragma' => 'no-cache',
|
||||
];
|
||||
$headers['Last-Modified'] = false;
|
||||
|
||||
unset($headers['Last-Modified']);
|
||||
|
||||
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
|
||||
if (function_exists('header_remove')) {
|
||||
@header_remove('Last-Modified');
|
||||
} else {
|
||||
// In PHP 5.2, send an empty Last-Modified header, but only as a
|
||||
// last resort to override a header already sent. #WP23021
|
||||
foreach (headers_list() as $header) {
|
||||
if (0 === mb_stripos($header, 'Last-Modified')) {
|
||||
$headers['Last-Modified'] = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($headers as $name => $field_value) {
|
||||
@header("{$name}: {$field_value}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save copy as...
|
||||
*
|
||||
@ -208,7 +173,15 @@ function track()
|
||||
return $data;
|
||||
}
|
||||
|
||||
global $_trackerStatus;
|
||||
$_trackerStatus = [
|
||||
0 => 'NotFound',
|
||||
1 => 'Editing',
|
||||
2 => 'MustSave',
|
||||
3 => 'Corrupted',
|
||||
4 => 'Closed',
|
||||
6 => 'MustForceSave',
|
||||
7 => 'CorruptedForceSave',
|
||||
];
|
||||
$status = $_trackerStatus[$data->status]; // get status from the request body
|
||||
|
||||
$userAddress = $_GET["userAddress"];
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace OnlineEditorsExamplePhp;
|
||||
|
||||
use OnlineEditorsExamplePhp\Views\DocEditorView;
|
||||
|
||||
require_once dirname(__FILE__) . '/functions.php';
|
||||
require_once dirname(__FILE__) . '/vendor/autoload.php';
|
||||
|
||||
$docEditorView = new DocEditorView($_REQUEST);
|
||||
$docEditorView->render();
|
||||
@ -17,10 +17,140 @@
|
||||
|
||||
namespace OnlineEditorsExamplePhp;
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/ajax.php';
|
||||
require_once __DIR__ . '/functions.php';
|
||||
require_once __DIR__ . '/trackmanager.php';
|
||||
|
||||
use OnlineEditorsExamplePhp\Common\HTTPStatus;
|
||||
use OnlineEditorsExamplePhp\Common\URL;
|
||||
use OnlineEditorsExamplePhp\Configuration\ConfigurationManager;
|
||||
use OnlineEditorsExamplePhp\Views\DocEditorView;
|
||||
use OnlineEditorsExamplePhp\Views\IndexView;
|
||||
|
||||
require_once dirname(__FILE__) . '/functions.php';
|
||||
require_once dirname(__FILE__) . '/vendor/autoload.php';
|
||||
function configure() {
|
||||
$config_manager = new ConfigurationManager();
|
||||
if ($config_manager->ssl_verify_peer_mode_enabled()) {
|
||||
// Ignore self-signed certificate.
|
||||
stream_context_set_default([
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$indexView = new IndexView($_REQUEST);
|
||||
$indexView->render();
|
||||
function routers() {
|
||||
// TODO: delete fallback.
|
||||
// In theory, the content type of the response should be declared inside the
|
||||
// router function. However, this statement isn't true for all routers, and
|
||||
// it's also not true for all branches in all routers. Therefore, we are
|
||||
// setting the default content type for all routers here.
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
header('Cache-Control: no-cache, must-revalidate, max-age=0');
|
||||
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
|
||||
header('Pragma: no-cache');
|
||||
@header_remove('Last-Modified');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('X-Robots-Tag: noindex');
|
||||
|
||||
$url = new URL($_SERVER['REQUEST_URI']);
|
||||
sendlog($url->string(), 'webedior-ajax.log');
|
||||
|
||||
$path = $url->path();
|
||||
if (!$path || $path === '/') {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
$view = new IndexView($_REQUEST);
|
||||
$view->render();
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/editor')) {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
$view = new DocEditorView($_REQUEST);
|
||||
$view->render();
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/assets')) {
|
||||
$response = assets();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/convert')) {
|
||||
$response = convert();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/csv')) {
|
||||
$response = csv();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/delete')) {
|
||||
$response = delete();
|
||||
$response['status'] = isset($response['error']) ? 'error' : 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/download')) {
|
||||
$response = download();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/files')) {
|
||||
$response = files();
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/history')) {
|
||||
$response = historyDownload();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/reference')) {
|
||||
$response = reference();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/rename')) {
|
||||
$response = renamefile();
|
||||
$content = json_encode($response);
|
||||
echo $content;
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/restore')) {
|
||||
$response = restore();
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/saveas')) {
|
||||
$response = saveas();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/track')) {
|
||||
$response = track();
|
||||
$response['status'] = 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/upload')) {
|
||||
$response = upload();
|
||||
$response['status'] = isset($response['error']) ? 'error' : 'success';
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
|
||||
http_response_code(HTTPStatus::not_found->value);
|
||||
}
|
||||
|
||||
configure();
|
||||
routers();
|
||||
|
||||
@ -1,124 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace OnlineEditorsExamplePhp;
|
||||
|
||||
use OnlineEditorsExamplePhp\Configuration\ConfigurationManager;
|
||||
|
||||
/**
|
||||
* WebEditor AJAX Process Execution.
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/ajax.php';
|
||||
require_once dirname(__FILE__) . '/functions.php';
|
||||
require_once dirname(__FILE__) . '/trackmanager.php';
|
||||
require_once dirname(__FILE__) . '/vendor/autoload.php';
|
||||
|
||||
$config_manager = new ConfigurationManager();
|
||||
|
||||
// define tracker status
|
||||
$_trackerStatus = [
|
||||
0 => 'NotFound',
|
||||
1 => 'Editing',
|
||||
2 => 'MustSave',
|
||||
3 => 'Corrupted',
|
||||
4 => 'Closed',
|
||||
6 => 'MustForceSave',
|
||||
7 => 'CorruptedForceSave',
|
||||
];
|
||||
|
||||
// ignore self-signed certificate
|
||||
if ($config_manager->ssl_verify_peer_mode_enabled()) {
|
||||
stream_context_set_default([
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// check if type value exists
|
||||
if (isset($_GET["type"]) && !empty($_GET["type"])) {
|
||||
@header('Content-Type: application/json; charset==utf-8');
|
||||
@header('X-Robots-Tag: noindex');
|
||||
@header('X-Content-Type-Options: nosniff');
|
||||
|
||||
// set headers that prevent caching in all the browsers
|
||||
nocacheHeaders();
|
||||
|
||||
// write the request result to the log file
|
||||
sendlog(serialize($_GET), "webedior-ajax.log");
|
||||
|
||||
$type = $_GET["type"];
|
||||
|
||||
// switch case for type value
|
||||
switch ($type) {
|
||||
case "upload":
|
||||
$response_array = upload();
|
||||
$response_array['status'] = isset($response_array['error']) ? 'error' : 'success';
|
||||
die(json_encode($response_array));
|
||||
case "download":
|
||||
$response_array = download();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "history":
|
||||
$response_array = historyDownload();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "convert":
|
||||
$response_array = convert();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "track":
|
||||
$response_array = track();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "delete":
|
||||
$response_array = delete();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "assets":
|
||||
$response_array = assets();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "csv":
|
||||
$response_array = csv();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "reference":
|
||||
$response_array = reference();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "files":
|
||||
$response_array = files();
|
||||
die(json_encode($response_array));
|
||||
case "saveas":
|
||||
$response_array = saveas();
|
||||
$response_array['status'] = 'success';
|
||||
die(json_encode($response_array));
|
||||
case "rename":
|
||||
$response_array = renamefile();
|
||||
die(json_encode($response_array));
|
||||
case 'restore':
|
||||
$response_array = restore();
|
||||
die(json_encode($response_array));
|
||||
default:
|
||||
$response_array['status'] = 'error';
|
||||
$response_array['error'] = '404 Method not found';
|
||||
die(json_encode($response_array));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user