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
5 changes: 4 additions & 1 deletion .github/actions/start-hashtopolis/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ runs:
working-directory: .devcontainer
run: docker compose up -d
shell: bash
- name: Install composer dependencies packages
run: docker exec hashtopolis-server-dev composer install --working-dir=/var/www/html/
shell: bash
- name: Wait until entrypoint is finished and Hashtopolis is started
run: bash .github/scripts/await-hashtopolis-startup.sh
shell: bash
shell: bash
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
run: docker exec -u root hashtopolis-server-dev bash -c "chown -R www-data:www-data /var/www/html/src && chmod -R g+w /var/www/html/src"
- name: Run test suite
run: docker exec hashtopolis-server-dev php /var/www/html/ci/run.php -vmaster
- name: Install composer dependencies packages
run: docker exec hashtopolis-server-dev composer install --working-dir=/var/www/html/
- name: Test with pytest
run: docker exec hashtopolis-server-dev pytest /var/www/html/ci/apiv2
- name: Test if pytest is removing all test objects
Expand All @@ -33,4 +31,4 @@ jobs:
run: docker logs hashtopolis-server-dev
- name: Show installed files tree in /var/www/html
if: ${{ always() }}
run: docker exec hashtopolis-server-dev find /var/www/html
run: docker exec hashtopolis-server-dev find /var/www/html
3 changes: 1 addition & 2 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ jobs:
sudo apt-get install -y lftp
sudo apt-get install nodejs
sudo apt-get install npm
sudo npm i openapi-to-md -g
- name: Start Hashtopolis server
uses: ./.github/actions/start-hashtopolis
- name: Download newest apiv2 spec
run: |
wget http://localhost:8080/api/v2/openapi.json -P /tmp/
cat /tmp/openapi.json
openapi-to-md /tmp/openapi.json ./doc/api/
mv /tmp/openapi.json ./doc/
- name: Create function level documentation with phpdocumentor
run: |
wget https://phpdoc.org/phpDocumentor.phar -P /tmp/
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ jobs:
sudo apt-get install -y lftp
sudo apt-get install nodejs
sudo apt-get install npm
sudo npm i openapi-to-md -g
- name: Start Hashtopolis server
uses: ./.github/actions/start-hashtopolis
- name: Download newest apiv2 spec
run: |
wget http://localhost:8080/api/v2/openapi.json -P /tmp/
cat /tmp/openapi.json
openapi-to-md /tmp/openapi.json ./doc/api/
mv /tmp/openapi.json ./doc/
- name: Create function level documentation with phpdocumentor
run: |
wget https://phpdoc.org/phpDocumentor.phar -P /tmp/
Expand Down
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM alpine/git as preprocess
FROM alpine/git AS preprocess

COPY .gi[t] /.git

RUN cd / && git rev-parse --short HEAD > /HEAD; exit 0

# BASE image
# ----BEGIN----
FROM php:8-apache as hashtopolis-server-base
FROM php:8-apache AS hashtopolis-server-base

# Enable possible build args for injecting user commands
ARG CONTAINER_USER_CMD_PRE
Expand Down Expand Up @@ -96,7 +96,7 @@ ENTRYPOINT [ "docker-entrypoint.sh" ]

# DEVELOPMENT Image
# ----BEGIN----
FROM hashtopolis-server-base as hashtopolis-server-dev
FROM hashtopolis-server-base AS hashtopolis-server-dev

# Setting up development requirements, install xdebug
RUN yes | pecl install xdebug-3.4.0beta1 && docker-php-ext-enable xdebug \
Expand Down Expand Up @@ -143,10 +143,13 @@ USER vscode

# PRODUCTION Image
# ----BEGIN----
FROM hashtopolis-server-base as hashtopolis-server-prod
FROM hashtopolis-server-base AS hashtopolis-server-prod

COPY --chown=www-data:www-data ./src/ $HASHTOPOLIS_DOCUMENT_ROOT

# protect install/update directory
RUN echo "Order deny,allow\nDeny from all" > "${HASHTOPOLIS_DOCUMENT_ROOT}/install/.htaccess"

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
&& touch "/usr/local/etc/php/conf.d/custom.ini" \
&& echo "memory_limit = 256m" >> /usr/local/etc/php/conf.d/custom.ini \
Expand Down
5 changes: 3 additions & 2 deletions ci/HashtopolisTestFramework.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use DBA\Factory;
use Composer\Semver\Comparator;

class HashtopolisTestFramework {
const REQUEST_CLIENT = 0;
Expand Down Expand Up @@ -104,11 +105,11 @@ private function isTestIncluded($instance, $version, $testNames, $runType, $upgr
if (!empty($testNames) && !in_array(get_class($instance), $testNames)) {
return false;
}
if (!$upgrade && $version != 'master' && (Util::versionComparison($version, $instance->getMinVersion()) > 0 || $instance->getMinVersion() == 'master')) {
if (!$upgrade && $version != 'master' && (Comparator::lessThan($version, $instance->getMinVersion()) || $instance->getMinVersion() == 'master')) {
echo "Ignoring " . $instance->getTestName() . ": minimum " . $instance->getMinVersion() . " required, but testing $version...\n";
return false;
}
if ($instance->getMaxVersion() != 'master' && (Util::versionComparison($version, $instance->getMaxVersion()) < 0 || $version == 'master')) {
if ($instance->getMaxVersion() != 'master' && (Comparator::greaterThan($version, $instance->getMaxVersion()) || $version == 'master')) {
echo "Ignoring " . $instance->getTestName() . ": maximum " . $instance->getMaxVersion() . " required, but testing $version...\n";
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"slim/psr7": "^1.5",
"slim/slim": "^4.10",
"tuupola/slim-basic-auth": "^3.3",
"tuupola/slim-jwt-auth": "^3.6"
"tuupola/slim-jwt-auth": "^3.6",
"composer/semver": "^3.4"
},
"require-dev": {
"jangregor/phpstan-prophecy": "^1.0.0",
Expand Down
79 changes: 78 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
**Enhancements**

- Updated OpenAPI docs to latest API updates
- Improved version comparison to avoid update script issues

**Bugfixes**

- Fixed missing .htaccess to avoid access to install directory on docker setups


## v0.14.4 -> v0.14.5
Expand Down
39 changes: 12 additions & 27 deletions src/inc/Util.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use DBA\FileDelete;
use DBA\Factory;
use DBA\Speed;
use Composer\Semver\Comparator;

/**
*
Expand Down Expand Up @@ -198,7 +199,7 @@ public static function checkAgentVersion($type, $version, $silent = false) {
}
$binary = Factory::getAgentBinaryFactory()->filter([Factory::FILTER => $qF], true);
if ($binary != null) {
if (Util::versionComparison($binary->getVersion(), $version) == 1) {
if (Comparator::lessThan($binary->getVersion(), $version)) {
if (!$silent) {
echo "update $type version... ";
}
Expand Down Expand Up @@ -941,34 +942,12 @@ public static function getStaticArray($val, $id) {
* @return int
*/
public static function versionComparisonBinary($binary1, $binary2) {
return Util::versionComparison($binary1->getVersion(), $binary2->getVersion());
}

/**
* @param string $version1
* @param string $version2
* @return int 1 if version2 is newer, 0 if equal and -1 if version1 is newer
*/
public static function versionComparison($version1, $version2) {
$version1 = explode(".", $version1);
$version2 = explode(".", $version2);

for ($i = 0; $i < sizeof($version1) && $i < sizeof($version2); $i++) {
$num1 = (int)$version1[$i];
$num2 = (int)$version2[$i];
if ($num1 > $num2) {
return -1;
}
else if ($num1 < $num2) {
return 1;
}
if (Comparator::greaterThan($binary1->getVersion(), $binary2->getVersion())){
return 1;
}
if (sizeof($version1) > sizeof($version2)) {
else if (Comparator::lessThan($binary1->getVersion(), $binary2->getVersion())){
return -1;
}
else if (sizeof($version1) < sizeof($version2)) {
return 1;
}
return 0;
}

Expand All @@ -984,7 +963,13 @@ public static function updateVersionComparison($versionString1, $versionString2)
$version1 = substr($versionString1, 8, strpos($versionString1, "_", 7) - 8);
$version2 = substr($versionString2, 8, strpos($versionString2, "_", 7) - 8);

return Util::versionComparison($version2, $version1);
if(Comparator::greaterThan($version2, $version1)){
return 1;
}
else if(Comparator::lessThan($version2, $version1)){
return -1;
}
return 0;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/inc/api/APICheckClientVersion.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use DBA\AgentBinary;
use DBA\QueryFilter;
use DBA\Factory;
use Composer\Semver\Comparator;

class APICheckClientVersion extends APIBasic {
public function execute($QUERY = array()) {
Expand All @@ -23,7 +24,7 @@ public function execute($QUERY = array()) {
}

$this->updateAgent(PActions::CHECK_CLIENT_VERSION);
if (Util::versionComparison($result->getVersion(), $version) == -1) {
if (Comparator::lessThan($result->getVersion(), $version)) {
DServerLog::log(DServerLog::DEBUG, "Agent " . $this->agent->getId() . " got notified about client update");
$this->sendResponse(array(
PResponseClientUpdate::ACTION => PActions::CHECK_CLIENT_VERSION,
Expand All @@ -42,4 +43,4 @@ public function execute($QUERY = array()) {
);
}
}
}
}
2 changes: 2 additions & 0 deletions src/inc/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

session_start();

require_once(dirname(__FILE__) . "/../../vendor/autoload.php");

require_once(dirname(__FILE__) . "/info.php");

include(dirname(__FILE__) . "/confv2.php");
Expand Down
8 changes: 5 additions & 3 deletions src/inc/utils/AgentBinaryUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
use DBA\QueryFilter;
use DBA\User;
use DBA\Factory;
use Composer\Semver\Comparator;

require_once(__DIR__ . "/../apiv2/common/ErrorHandler.class.php");

require_once __DIR__ . '/../apiv2/common/ErrorHandler.class.php';
class AgentBinaryUtils {
/**
* @param string $type
Expand Down Expand Up @@ -226,9 +228,9 @@ public static function getAgentUpdate($agent, $track) {
if (strlen($latest) == 0) {
throw new HTException("Failed to retrieve latest version!");
}
if (Util::versionComparison($agent->getVersion(), $latest) > 0) {
if (Comparator::lessThan($agent->getVersion(), $latest)) {
return $latest;
}
return false;
}
}
}
5 changes: 3 additions & 2 deletions src/inc/utils/CrackerBinaryUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use DBA\CrackerBinary;
use DBA\QueryFilter;
use DBA\Factory;
use Composer\Semver\Comparator;

class CrackerBinaryUtils {
/**
Expand All @@ -16,7 +17,7 @@ public static function getNewestVersion($crackerBinaryTypeId) {
/** @var $newest CrackerBinary */
$newest = null;
foreach ($binaries as $binary) {
if ($newest == null || Util::versionComparison($binary->getVersion(), $newest->getVersion()) < 0) {
if ($newest == null || Comparator::greaterThan($binary->getVersion(), $newest->getVersion())) {
$newest = $binary;
}
}
Expand All @@ -25,4 +26,4 @@ public static function getNewestVersion($crackerBinaryTypeId) {
}
return $newest;
}
}
}
Loading