From 740728a70d98383173c939be354c2854794a7096 Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 26 Sep 2019 19:15:25 -0400 Subject: [PATCH 01/12] Update notation for composer 2.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ddf5320..0155cba 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ { "type":"package", "package": { - "name": "julianxhokaxhiu/DotNotation", + "name": "julianxhokaxhiu/dotnotation", "version": "master", "source": { "url": "https://gist.github.com/a6098de64195f604f56a.git", @@ -40,7 +40,7 @@ ], "require": { "mikecao/flight": "1.*", - "julianxhokaxhiu/DotNotation": "dev-master", + "julianxhokaxhiu/dotnotation": "dev-master", "ext-zip": "*" }, "autoload": { -- GitLab From be2ff1318be47b7450cf770b2f877f2a3a35efca Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 26 Sep 2019 20:43:42 -0400 Subject: [PATCH 02/12] Update regex ...to allow for more than "cm" and "lineage" as the ROM names. --- src/Helpers/Build.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 268b989..655b58f 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -65,7 +65,7 @@ LINEAGE => [SIGNED] (ex. signed) ) */ - preg_match_all( '/(cm|lineage)-([0-9\.]+)-([\d_]+)?-([\w+]+)-([A-Za-z0-9]+)?-?([\w+]+)?/', $fileName, $tokens ); + preg_match_all( '/([A-Za-z]+)?-([0-9\.]+)-([\d_]+)?-([\w+]+)-([A-Za-z0-9]+)?-?([\w+]+)?/', $fileName, $tokens ); $tokens = $this->removeTrailingDashes( $tokens ); -- GitLab From c9325f2faf0e84a8468d458717a92f90aec1cf86 Mon Sep 17 00:00:00 2001 From: Tom Kranz Date: Wed, 30 Oct 2019 15:36:06 +0100 Subject: [PATCH 03/12] Use Forwarded HTTP Extension to determine protocol and host --- index.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.php b/index.php index e851cd7..c043bed 100644 --- a/index.php +++ b/index.php @@ -26,6 +26,22 @@ use \JX\CmOta\CmOta; + if ( isset($_SERVER['HTTP_FORWARDED']) ) { + $fwd_ar = explode(';', $_SERVER['HTTP_FORWARDED']); + for ( $i = 0; $i < count($fwd_ar); $i++ ) { + $kv = explode('=', $fwd_ar[$i]); + if ( count($kv) > 1 ) { + $forwarded[strtoupper($kv[0])] = $kv[1]; + } + } + if ( array_key_exists('HOST', $forwarded) ) { + $_SERVER['HTTP_HOST'] = $forwarded['HOST']; + } + if ( array_key_exists('PROTO', $forwarded) && strtoupper($forwarded['PROTO']) === 'HTTPS') { + $_SERVER['HTTPS'] = 'on'; + } + } + if( isset($_SERVER['HTTPS'] ) ) $protocol = 'https://'; else -- GitLab From 3dae36a179e51ea792f231f1c99c2e7c68121ee4 Mon Sep 17 00:00:00 2001 From: miax Date: Sun, 29 Mar 2020 20:57:46 +0200 Subject: [PATCH 04/12] Add detection of HTTP_X_FORWARDED_* headers --- index.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index c043bed..1e60bbc 100644 --- a/index.php +++ b/index.php @@ -40,9 +40,16 @@ if ( array_key_exists('PROTO', $forwarded) && strtoupper($forwarded['PROTO']) === 'HTTPS') { $_SERVER['HTTPS'] = 'on'; } + } else { + if ( isset($_SERVER['HTTP_X_FORWARDED_HOST']) ) { + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; + } + if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtoupper($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'HTTPS' ) { + $_SERVER['HTTPS'] = 'on'; + } } - if( isset($_SERVER['HTTPS'] ) ) + if( isset($_SERVER['HTTPS']) ) $protocol = 'https://'; else $protocol = 'http://'; -- GitLab From 753b6739fe7e5d2c48b3f3767e5721ae3f934a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnau=20V=C3=A0zquez=20Palma?= Date: Sat, 20 Jun 2020 23:52:26 +0200 Subject: [PATCH 05/12] Bring Dockerfile and composer up to date --- .gitignore | 1 + Dockerfile | 52 ++++++++++++++++++++------------------------------ composer.json | 6 +++--- conf/perf.conf | 2 ++ 4 files changed, 27 insertions(+), 34 deletions(-) create mode 100644 conf/perf.conf diff --git a/.gitignore b/.gitignore index ff72e2d..27d28a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /composer.lock /vendor +.idea diff --git a/Dockerfile b/Dockerfile index 5b427f1..2538875 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,51 +1,41 @@ -FROM php:7.1-apache +FROM php:7.2-apache MAINTAINER Julian Xhokaxhiu # internal variables ENV HTML_DIR /var/www/html ENV FULL_BUILDS_DIR $HTML_DIR/builds/full +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y --fix-missing \ + apt-utils \ + gnupg + +RUN apt-get update \ + && apt-get install -y git zlib1g-dev libzip-dev\ + && docker-php-ext-install zip\ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false zlib1g-dev libzip-dev + +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + # set the working directory WORKDIR $HTML_DIR +# add all the project files +COPY . $HTML_DIR # enable mod_rewrite RUN a2enmod rewrite - -# install the PHP extensions we need -RUN apt-get update \ - && buildDeps=" \ - zlib1g-dev \ - " \ - && apt-get install -y git $buildDeps --no-install-recommends \ - && rm -r /var/lib/apt/lists/* \ - \ - && docker-php-ext-install zip \ - \ - && pecl install apcu \ - && docker-php-ext-enable apcu \ - \ - && docker-php-source delete \ - && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $buildDeps - -# set recommended settings for APCu -# see http://php.net/manual/en/apcu.configuration.php -RUN { \ - echo 'apc.ttl=7200'; \ - } > /usr/local/etc/php/conf.d/opcache-recommended.ini +COPY conf/perf.conf /etc/apache2/conf-available/perf.conf +RUN a2enconf perf # install latest version of composer -ADD https://getcomposer.org/composer.phar /usr/local/bin/composer -RUN chmod 0755 /usr/local/bin/composer - -# add all the project files -COPY . $HTML_DIR +# Install composer from the official image +COPY --from=composer /usr/bin/composer /usr/bin/composer +# Run composer install to install the dependencies +RUN composer install --optimize-autoloader --no-interaction --no-progress # enable indexing for Apache RUN sed -i "1s;^;Options +Indexes\n\n;" .htaccess -# install dependencies -RUN composer install --no-plugins --no-scripts - # fix permissions RUN chmod -R 0775 /var/www/html \ && chown -R www-data:www-data /var/www/html diff --git a/composer.json b/composer.json index e84f688..313441b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "julianxhokaxhiu/lineage-ota", "description": "A simple OTA REST Server for LineageOS OTA Updater System Application", - "version": "2.8.0", + "version": "2.8.1", "type": "project", "keywords": [ "android", @@ -26,7 +26,7 @@ "type":"package", "package": { "name": "julianxhokaxhiu/dotnotation", - "version": "master", + "version": "dev-master", "source": { "url": "https://gist.github.com/a6098de64195f604f56a.git", "type": "git", @@ -42,7 +42,7 @@ "mikecao/flight": "1.*", "julianxhokaxhiu/dotnotation": "dev-master", "ext-zip": "*", - "monolog/monolog": "2.0.*" + "monolog/monolog": "1.23.*" }, "autoload": { "psr-4": { diff --git a/conf/perf.conf b/conf/perf.conf new file mode 100644 index 0000000..9d94c96 --- /dev/null +++ b/conf/perf.conf @@ -0,0 +1,2 @@ +ServerLimit 1024 +MaxClients 1024 \ No newline at end of file -- GitLab From 827cf05995b3c0deab011680354605eae15fcc8c Mon Sep 17 00:00:00 2001 From: akhil Date: Wed, 10 Feb 2021 19:48:24 +0530 Subject: [PATCH 06/12] added 2.0 changes and checked for conflicts --- Dockerfile | 34 ++++++++++++-- LICENSE | 2 +- README.md | 35 +++++---------- composer.json | 6 +-- index.php | 29 +++++++++++- src/CmOta.php | 2 +- src/Helpers/Build.php | 7 ++- src/Helpers/Builds.php | 100 +++++++++++++++++++---------------------- 8 files changed, 123 insertions(+), 92 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2538875..961186f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,15 +27,41 @@ RUN a2enmod rewrite COPY conf/perf.conf /etc/apache2/conf-available/perf.conf RUN a2enconf perf +# install the PHP extensions we need +RUN apt-get update \ + && apt-get install nano \ + && buildDeps=" \ + zlib1g-dev \ + " \ + && apt-get install -y git $buildDeps --no-install-recommends \ + && rm -r /var/lib/apt/lists/* \ + \ + && docker-php-ext-install zip \ + \ + && pecl install apcu \ + && docker-php-ext-enable apcu \ + \ + && docker-php-source delete \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $buildDeps +# set recommended settings for APCu +# see http://php.net/manual/en/apcu.configuration.php +RUN { \ + echo 'apc.ttl=7200'; \ + } > /usr/local/etc/php/conf.d/opcache-recommended.ini + # install latest version of composer -# Install composer from the official image -COPY --from=composer /usr/bin/composer /usr/bin/composer -# Run composer install to install the dependencies -RUN composer install --optimize-autoloader --no-interaction --no-progress +ADD https://getcomposer.org/composer.phar /usr/local/bin/composer +RUN chmod 0755 /usr/local/bin/composer + +# add all the project files +COPY . $HTML_DIR # enable indexing for Apache RUN sed -i "1s;^;Options +Indexes\n\n;" .htaccess +# install dependencies +RUN composer install --no-plugins --no-scripts + # fix permissions RUN chmod -R 0775 /var/www/html \ && chown -R www-data:www-data /var/www/html diff --git a/LICENSE b/LICENSE index cfc5daf..231b13a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Julian Xhokaxhiu +Copyright (c) 2020 Julian Xhokaxhiu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 2e647c1..7645b22 100644 --- a/README.md +++ b/README.md @@ -14,29 +14,6 @@ Got a question? Not sure where it should be made? See [CONTRIBUTING](CONTRIBUTIN ## How to use -### Test - -``` -$ sudo docker build -t e/lineageota . \ - && sudo docker run \ - -d \ - -p 80:80 \ - --rm \ - -v "${PWD}/builds/full:/var/www/html/builds/full" \ - --name lineageota \ - e/lineageota -``` - -Access to API via http://localhost/api/v1/\/\ - -Get logs with - -``` -$ sudo docker exec -ti lineageota tail -f LineageOTA.log -``` - -You can also use this server with a device connected to the same network, specifying the correct IP (see below). - ### Composer ```shell @@ -44,7 +21,7 @@ $ cd /var/www/html # Default Apache WWW directory, feel free to choose your own $ composer create-project julianxhokaxhiu/lineage-ota LineageOTA ``` -then finally visit http://localhost/LineageOTA to see the REST Server up and running. +then finally visit http://localhost/LineageOTA to see the REST Server up and running. Please note that this is only for a quick test, when you plan to use that type of setup for production (your users), make sure to also provide HTTPS support. > If you get anything else then a list of files, contained inside the `builds` directory, this means something is wrong in your environment. Double check it, before creating an issue report here. @@ -124,10 +101,12 @@ In order to integrate this in your LineageOS based ROM, you need to add the [`li ```properties # ... -lineage.updater.uri=http://my.ota.uri/api/v1/{device}/{type}/{incr} +lineage.updater.uri=https://my.ota.uri/api/v1/{device}/{type}/{incr} # ... ``` +Make always sure to provide a HTTPS based uri, otherwise the updater will reject to connect with your server! This is caused by the security policies newer versions of Android (at least 10+) include, as any app wanting to use non-secured connections must explicitly enable this during the compilation. The LineageOS Updater does not support that. + > Since https://review.lineageos.org/#/c/191274/ is merged, the property `cm.updater.uri` is renamed to `lineage.updater.uri`. Make sure to update your entry. > As of [5252d60](https://github.com/LineageOS/android_packages_apps_Updater/commit/5252d606716c3f8d81617babc1293c122359a94d): @@ -147,6 +126,12 @@ In order to integrate this in your [CyanogenMod](https://github.com/lineageos/an ## Changelog +### v2.9.0 +- Add PHP 7.4 compatibility: Prevent null array access on `isValid()` ( thanks to @McNutnut ) +- Update RegEx pattern to match more roms than just CM/LineageOS ( thanks to @toolstack ) +- Use Forwarded HTTP Extension to determine protocol and host ( thanks to @TpmKranz ) +- Add detection of HTTP_X_FORWARDED_* headers ( thanks to @ionphractal ) + ### v2.8.0 - Use md5sum files if available ( thanks to @jplitza ) diff --git a/composer.json b/composer.json index 313441b..6d66bce 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "julianxhokaxhiu/lineage-ota", "description": "A simple OTA REST Server for LineageOS OTA Updater System Application", - "version": "2.8.1", + "version": "2.9.0", "type": "project", "keywords": [ "android", @@ -26,7 +26,7 @@ "type":"package", "package": { "name": "julianxhokaxhiu/dotnotation", - "version": "dev-master", + "version": "master", "source": { "url": "https://gist.github.com/a6098de64195f604f56a.git", "type": "git", @@ -42,7 +42,7 @@ "mikecao/flight": "1.*", "julianxhokaxhiu/dotnotation": "dev-master", "ext-zip": "*", - "monolog/monolog": "1.23.*" + "monolog/monolog": "2.2.*" }, "autoload": { "psr-4": { diff --git a/index.php b/index.php index fbcef56..0a22afb 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ /* The MIT License (MIT) - Copyright (c) 2016 Julian Xhokaxhiu + Copyright (c) 2020 Julian Xhokaxhiu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -28,8 +28,33 @@ use Monolog\Logger; use Monolog\Handler\StreamHandler; - $protocol = 'https://'; + if ( isset($_SERVER['HTTP_FORWARDED']) ) { + $fwd_ar = explode(';', $_SERVER['HTTP_FORWARDED']); + for ( $i = 0; $i < count($fwd_ar); $i++ ) { + $kv = explode('=', $fwd_ar[$i]); + if ( count($kv) > 1 ) { + $forwarded[strtoupper($kv[0])] = $kv[1]; + } + } + if ( array_key_exists('HOST', $forwarded) ) { + $_SERVER['HTTP_HOST'] = $forwarded['HOST']; + } + if ( array_key_exists('PROTO', $forwarded) && strtoupper($forwarded['PROTO']) === 'HTTPS') { + $_SERVER['HTTPS'] = 'on'; + } + } else { + if ( isset($_SERVER['HTTP_X_FORWARDED_HOST']) ) { + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; + } + if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtoupper($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'HTTPS' ) { + $_SERVER['HTTPS'] = 'on'; + } + } + if( isset($_SERVER['HTTPS']) ) + $protocol = 'https://'; + else + $protocol = 'http://'; $logger = new Logger('main'); $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::WARNING)); diff --git a/src/CmOta.php b/src/CmOta.php index e3fb532..296c1b9 100644 --- a/src/CmOta.php +++ b/src/CmOta.php @@ -2,7 +2,7 @@ /* The MIT License (MIT) - Copyright (c) 2016 Julian Xhokaxhiu + Copyright (c) 2020 Julian Xhokaxhiu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 68574e2..091f319 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -2,7 +2,7 @@ /* The MIT License (MIT) - Copyright (c) 2016 Julian Xhokaxhiu + Copyright (c) 2020 Julian Xhokaxhiu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -50,7 +50,7 @@ * @param type $physicalPath The current path where the build lives */ public function __construct($fileName, $physicalPath, $logger) { - $this->logger = $logger; + $this->logger = $logger; /* $tokens Schema: @@ -106,6 +106,8 @@ * @return boolean True if valid, False if not. */ public function isValid($params){ + if ( $params === NULL ) return true; // Assume valid if no parameters + $ret = false; if ( $params['device'] == $this->model ) { @@ -276,6 +278,7 @@ $this->filePath.'.prop' : 'zip://'.$this->filePath.'#system/build.prop'; } + /* Utility / Internal */ /** * Remove trailing dashes diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index f500f90..617944a 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -2,7 +2,7 @@ /* The MIT License (MIT) - Copyright (c) 2016 Julian Xhokaxhiu + Copyright (c) 2020 Julian Xhokaxhiu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in @@ -29,18 +29,20 @@ class Builds { - // This will contain the build list based on the current request + // This will contain the build list based on the current request private $builds = array(); - private $postData = array(); - private $logger = null; - private $currentBuild = null; - - /** - * Constructor of the Builds class. - */ - public function __construct($logger) { - $this->logger = $logger; + private $postData = array(); + + private $logger = null; + + private $currentBuild = null; + + /** + * Constructor of the Builds class. + */ + public function __construct($logger) { + $this->logger = $logger; // Set required paths for properly builds Urls later Flight::cfg()->set( 'buildsPath', Flight::cfg()->get('basePath') . '/builds/full' ); Flight::cfg()->set( 'deltasPath', Flight::cfg()->get('basePath') . '/builds/delta' ); @@ -52,22 +54,22 @@ $this->getBuilds(); } - /** - * Return a valid response list of builds available based on the current request - * @return array An array preformatted with builds - */ + /** + * Return a valid response list of builds available based on the current request + * @return array An array preformatted with builds + */ public function get() { $ret = array(); foreach ( $this->builds as $build ) { - if (!is_null($this->currentBuild) && strcmp($this->currentBuild->getAndroidVersion(), $build->getAndroidVersion()) != 0) { - $this->logger->info($build->getIncremental().' ignored as Android version is not the same'); - continue; - } - - $this->logger->info($build->getIncremental().' is a new update'); - + $this->logger->info($build->getIncremental().' ignored as Android version is not the same'); + continue; + } + + $this->logger->info($build->getIncremental().' is a new update'); + + array_push( $ret, array( // CyanogenMod 'incremental' => $build->getIncremental(), @@ -92,21 +94,21 @@ return $ret; } - /** - * Set a custom set of POST data. Useful to hack the flow in case the data doesn't come within the body of the HTTP request - * @param array An array structured as POST data - * @return void - */ - public function setPostData( $customData ){ - $this->postData = $customData; - $this->builds = array(); - $this->getBuilds(); - } - - /** - * Return a valid response of the delta build (if available) based on the current request - * @return array An array preformatted with the delta build - */ + /** + * Set a custom set of POST data. Useful to hack the flow in case the data doesn't come within the body of the HTTP request + * @param array An array structured as POST data + * @return void + */ + public function setPostData( $customData ){ + $this->postData = $customData; + $this->builds = array(); + $this->getBuilds(); + } + + /** + * Return a valid response of the delta build (if available) based on the current request + * @return array An array preformatted with the delta build + */ public function getDelta() { $ret = false; @@ -134,7 +136,7 @@ return $ret; } - /* Utility / Internal */ + /* Utility / Internal */ private function getBuilds() { // Get physical paths of where the files resides @@ -150,15 +152,9 @@ array_push( $dirs, $path ); foreach ( $dirs as $dir ) { // Get the file list and parse it - $files = preg_grep( '/^([^.Thumbs])/', scandir( $dir ) ); + $files = scandir( $dir ); if ( count( $files ) > 0 ) { foreach ( $files as $file ) { - - $filename = pathinfo($file, PATHINFO_FILENAME); - if ( preg_match("/latest/i", $filename) ) { - continue; - } - $extension = pathinfo($file, PATHINFO_EXTENSION); if ( $extension == 'zip' ) { @@ -170,27 +166,23 @@ // If not found there, we have to find it with the old fashion method... if ( $build === FALSE ) { - $build = new Build( $file, $dir, $this->logger); + $build = new Build( $file, $dir, $this->logger ); // ...and then save it for 72h until it expires again apcu_store( $file, $build, 72*60*60 ); } } else - $build = new Build( $file, $dir, $this->logger); + $build = new Build( $file, $dir, $this->logger ); if ( $build->isValid( $this->postData['params'] ) ) { array_push( $this->builds , $build ); - if (strcmp($this->postData['params']['source_incremental'], $build->getIncremental()) == 0) { - $this->currentBuild = $build; - $this->logger->info($build->getIncremental().' is the current build'); - } + $this->currentBuild = $build; + $this->logger->info($build->getIncremental().' is the current build'); + } } } } } } - - if (!empty($this->postData['params']['source_incremental']) && is_null($this->currentBuild)) - $this->currentBuild = $this->builds[1]; } } -- GitLab From 906c75f3590f80b107b1eae4f5c97ec0ebe5feda Mon Sep 17 00:00:00 2001 From: akhil Date: Wed, 17 Feb 2021 15:07:42 +0530 Subject: [PATCH 07/12] Added line to save prop file in case it doesn't exist --- src/Helpers/Build.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 091f319..979f5e5 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -79,7 +79,11 @@ // Try to load the build.prop from two possible paths: // - builds/CURRENT_ZIP_FILE.zip/system/build.prop // - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist ) - $this->buildProp = explode( "\n", @file_get_contents($this->getPropFilePath())); + $prop_contents = @file_get_contents($this->getPropFilePath()); + if(!file_exists($this->filePath.'.prop')) { + file_put_contents($this->filePath . 'prop', $prop_contents) + } + $this->buildProp = explode( "\n", $prop_contents); // Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given $this->timestamp = intval( $this->getBuildPropValue( 'ro.build.date.utc' ) ?? filemtime($this->filePath) ); $this->incremental = $this->getBuildPropValue( 'ro.build.version.incremental' ) ?? ''; -- GitLab From 845985b969f82b0402c3de41c47402c47dbb9879 Mon Sep 17 00:00:00 2001 From: akhil Date: Thu, 18 Feb 2021 17:20:45 +0530 Subject: [PATCH 08/12] Formatting --- Dockerfile | 5 +---- src/Helpers/Build.php | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 961186f..ff15a22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.2-apache +FROM php:7.4-apache MAINTAINER Julian Xhokaxhiu # internal variables @@ -65,6 +65,3 @@ RUN composer install --no-plugins --no-scripts # fix permissions RUN chmod -R 0775 /var/www/html \ && chown -R www-data:www-data /var/www/html - -# create volumes -VOLUME $FULL_BUILDS_DIR \ No newline at end of file diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 979f5e5..6c1ef20 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -81,7 +81,7 @@ // - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist ) $prop_contents = @file_get_contents($this->getPropFilePath()); if(!file_exists($this->filePath.'.prop')) { - file_put_contents($this->filePath . 'prop', $prop_contents) + file_put_contents($this->filePath . 'prop', $prop_contents); } $this->buildProp = explode( "\n", $prop_contents); // Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given -- GitLab From 40a021d7922dc1ed38e3fe6b9ac3963504e03c84 Mon Sep 17 00:00:00 2001 From: akhil Date: Thu, 18 Feb 2021 17:22:31 +0530 Subject: [PATCH 09/12] Re-added php-7.2 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ff15a22..290b03e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.4-apache +FROM php:7.2-apache MAINTAINER Julian Xhokaxhiu # internal variables -- GitLab From 1f230c389c87b71a3f2a602ab00b697a5abe9019 Mon Sep 17 00:00:00 2001 From: Akhil Date: Thu, 18 Feb 2021 13:39:25 +0000 Subject: [PATCH 10/12] Update Build.php(unnecessary addition) --- src/Helpers/Build.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 6c1ef20..091f319 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -79,11 +79,7 @@ // Try to load the build.prop from two possible paths: // - builds/CURRENT_ZIP_FILE.zip/system/build.prop // - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist ) - $prop_contents = @file_get_contents($this->getPropFilePath()); - if(!file_exists($this->filePath.'.prop')) { - file_put_contents($this->filePath . 'prop', $prop_contents); - } - $this->buildProp = explode( "\n", $prop_contents); + $this->buildProp = explode( "\n", @file_get_contents($this->getPropFilePath())); // Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given $this->timestamp = intval( $this->getBuildPropValue( 'ro.build.date.utc' ) ?? filemtime($this->filePath) ); $this->incremental = $this->getBuildPropValue( 'ro.build.version.incremental' ) ?? ''; -- GitLab From 9e4d359a9a1495d52ad209fad7a26476eec17d50 Mon Sep 17 00:00:00 2001 From: akhil Date: Thu, 18 Feb 2021 19:47:02 +0530 Subject: [PATCH 11/12] Added build prop save after build prop get --- src/Helpers/Build.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 091f319..3794de9 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -81,6 +81,9 @@ // - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist ) $this->buildProp = explode( "\n", @file_get_contents($this->getPropFilePath())); // Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given + if(!file_exists($this->filePath.'.prop')) { + file_put_contents($this->filePath . '.prop', implode("\n", $this->buildProp)); + } $this->timestamp = intval( $this->getBuildPropValue( 'ro.build.date.utc' ) ?? filemtime($this->filePath) ); $this->incremental = $this->getBuildPropValue( 'ro.build.version.incremental' ) ?? ''; $this->apiLevel = $this->getBuildPropValue( 'ro.build.version.sdk' ) ?? ''; -- GitLab From f775adc10442aab90315e77372f8f464a05c8dc3 Mon Sep 17 00:00:00 2001 From: akhil Date: Thu, 18 Feb 2021 20:54:09 +0530 Subject: [PATCH 12/12] Added properties to variable --- src/Helpers/Build.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 3794de9..b802e42 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -81,19 +81,44 @@ // - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist ) $this->buildProp = explode( "\n", @file_get_contents($this->getPropFilePath())); // Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given - if(!file_exists($this->filePath.'.prop')) { - file_put_contents($this->filePath . '.prop', implode("\n", $this->buildProp)); - } + $prop = ""; $this->timestamp = intval( $this->getBuildPropValue( 'ro.build.date.utc' ) ?? filemtime($this->filePath) ); + $prop.='ro.build.date.utc='. $this->timestamp . "\n"; $this->incremental = $this->getBuildPropValue( 'ro.build.version.incremental' ) ?? ''; + $prop.='ro.build.version.incremental='. $this->incremental . "\n"; $this->apiLevel = $this->getBuildPropValue( 'ro.build.version.sdk' ) ?? ''; - $this->model = $this->getBuildPropValue( 'ro.lineage.device' ) ?? $this->getBuildPropValue( 'ro.cm.device' ) ?? ( $tokens[1] == 'cm' ? $tokens[6] : $tokens[5] ); + $prop.='ro.build.version.sdk='. $this->apiLevel . "\n"; + if ($this->getBuildPropValue( 'ro.lineage.device' )){ + $this->model = $this->getBuildPropValue( 'ro.lineage.device' ); + $prop.='ro.lineage.device='.$this->model."\n"; + } + else if( $this->getBuildPropValue( 'ro.cm.device' )) { + $this->model = $this->getBuildPropValue( 'ro.cm.device' ); + $prop.='ro.cm.device='.$this->model."\n"; + } + else if ( $tokens[1] == 'cm') { + $this->model = $tokens[6]; + } else { + $this->model = $tokens[5]; + } $this->version = $tokens[2]; - $this->displayVersion = $this->getBuildPropValue( 'ro.cm.display.version' ) ?? $this->getBuildPropValue( 'ro.lineage.display.version' ) ?? ''; + if( $this->getBuildPropValue( 'ro.cm.display.version' )){ + $this->displayVersion = $this->getBuildPropValue( 'ro.cm.display.version' ); + $prop.='ro.cm.display.version='.$this->displayVersion."\n"; + } + else if( $this->getBuildPropValue( 'ro.lineage.display.version' )){ + $this->displayVersion = $this->getBuildPropValue( 'ro.lineage.display.version' ); + $prop.='ro.lineage.display.version='.$this->displayVersion."\n"; + } else { + $this->displayVersion= ''; + } $this->androidVersion = $this->getBuildPropValue( 'ro.build.version.release' ) ?? ''; + $prop.='ro.build.version.release='.$this->androidVersion."\n"; + if(!file_exists($this->filePath.'.prop')) { + file_put_contents($this->filePath . '.prop', $prop); + } $this->uid = hash( 'sha256', $this->timestamp.$this->model.$this->apiLevel, false ); $this->size = filesize($this->filePath); - $position = strrpos( $physicalPath, '/builds/full' ); if ( $position === FALSE ) $this->url = $this->_getUrl( '', Flight::cfg()->get('buildsPath') ); -- GitLab