这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server-php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ FROM php:apache

RUN sed -i 's/^ServerTokens .*/ServerTokens Prod/g' /etc/apache2/conf-available/security.conf
RUN sed -i 's/^ServerSignature .*/ServerSignature Off/g' /etc/apache2/conf-available/security.conf
RUN echo 'expose_php = Off' > /usr/local/etc/php/php.ini
RUN echo 'expose_php = Off' >> /usr/local/etc/php/php.ini

RUN a2enmod ssl && service apache2 restart

COPY ./confs/apache-site.conf /etc/apache2/sites-available/cmh_api.conf
COPY ./confs/cert /usr/local/etc/cmh_cert
RUN a2dissite * && a2ensite cmh_api

RUN chmod 600 /usr/local/etc/cmh_cert/privkey.key && chown www-data:www-data /usr/local/etc/cmh_cert/privkey.key
RUN mkdir /var/tmp/cmh_cache
RUN chown www-data:www-data /var/tmp/cmh_cache/

COPY ./www /var/www/cmh_api/

COPY ./vendor-static.tar.gz /tmp/
Expand Down
11 changes: 11 additions & 0 deletions server-php/www/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@
}

// User inputs
$data = json_decode( file_get_contents("php://input") );

// For POST requests
if ( isset($data->url) ) $request_url = $data->url;
if ( isset($data->host) ) $request_host = $data->host;
if ( isset($data->port) ) $request_port = $data->port;
if ( isset($data->sign) ) $sign = $data->sign;
if ( isset($data->ip) ) $request_ip = $data->ip;

// For GET requests
if (isset($_GET['url'])) $request_url = $_GET['url'];
if (isset($_GET['host'])) $request_host = $_GET['host'];
if (isset($_GET['port'])) $request_port = $_GET['port'];
if (isset($_GET['ip'])) $request_ip = $_GET['ip'];


// Service requested by the user
$service = (object) [
'host' => null,
Expand Down
24 changes: 19 additions & 5 deletions webextension/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ CMH.api = {}
*/
CMH.api.requestFromUrl = async (urlTested, ip) => {
const { host, port } = CMH.common.parseURL(urlTested)

// We won't send "ip=" to the verification server if it is empty

if (ip === "")
arguments = 'api.php?host='+encodeURIComponent(host)+'&port='+port+'&sign'
else
arguments = 'api.php?host='+encodeURIComponent(host)+'&port='+port+'&ip='+ip+'&sign'
{
arguments = {
host: encodeURIComponent(host),
port: port,
sign: true
}
}
else
{
arguments = {
host: encodeURIComponent(host),
port: port,
sign: true,
ip:ip
}
}

const { cert, data:response_data, response } = await CMH.certificatesManager.getCertUrl(CMH.options.settings.checkServerUrl+arguments)
const { cert, data:response_data, response } = await CMH.certificatesManager.getCertUrl(CMH.options.settings.checkServerUrl+"api.php", false, arguments)
if ((cert === null) || (response === null)) {
return { error: 'SERVER_UNREACHABLE' }
}
Expand Down
4 changes: 2 additions & 2 deletions webextension/lib/certificatesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CMH.certificatesManager = {}
* @param {boolean} [httpHeadMethod=false] - Use HTTP HEAD method
* Get the certificate of an URL.
*/
CMH.certificatesManager.getCertUrl = async (urlTested, httpHeadMethod=false) => {
CMH.certificatesManager.getCertUrl = async (urlTested, httpHeadMethod=false, arguments={}) => {
let response = null
let response_data = null
let cert = null
Expand All @@ -34,7 +34,7 @@ CMH.certificatesManager.getCertUrl = async (urlTested, httpHeadMethod=false) =>
if (httpHeadMethod) {
fetchInit = { method: 'HEAD' }
} else {
fetchInit = {}
fetchInit = { method: 'POST', headers: {"Content-Type": "application/json"}, cache: 'no-cache', body: JSON.stringify(arguments) }
}
response = await fetch(urlTested, fetchInit)

Expand Down