Skip to content

Commit

Permalink
Add new 'http' param for 'from' param
Browse files Browse the repository at this point in the history
  • Loading branch information
xchwarze committed Feb 25, 2023
1 parent e8c36a9 commit e201b45
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Los valores utilizados para la configuración son:
|----------------------|-------------|--------------------------------------------------------------------------------------------------------|
| `folder` | `SI` | Carpeta donde se guardara la herramienta. Si no existe la misma se creara. |
| `url` | `SI` | Web que se usara para realizar los chequeos con las regex. |
| `from` | `NO` | Indica la estrategia usada para el update. Los valores admitidos por el momento son: `web` o `github`. |
| `from` | `NO` | Indica la estrategia usada para el update. Los valores admitidos por el momento son: `web`, `github` o `http`. |
| `local_version` | `NO` | Versión descargada actualmente. Este valor se actualizara con cada update. |
| `re_version` | `NO` | Regex usado para comprobar si hay nuevas versiones en la web de `url`. |
| `re_download` | `NO` | Regex usado para obtener el link de descarga en la web de `url`. |
Expand All @@ -63,6 +63,7 @@ Combinando el uso de `update_url` y `re_download` se consiguen las siguientes es
2. Usando solo `re_download` se obtiene el link de descarga en la web de `url`.
3. Cuando se usan ambos parámetros se concatena el resultado de `re_download` con `update_url`.
Esto es útil para arreglar los links de descarga de GitHub o Sourceforge.
4. También se dispone de un método de detección de nuevas versiones que en lugar de regex usa las cabeceras http con las que responde el servidor.

## Ejemplos

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The values used for configuration are:
|--------------------|-----------|------------------------------------------------------------------------------------------------|
| `folder` | `YES` | Folder where the tool will be saved. If it does not exist, it will be created. |
| `url` | `YES` | Web that will be used to perform the checks with the regex. |
| `from` | `NO` | Indicates the strategy used for the update. Currently supported values are: `web` or `github`. |
| `from` | `NO` | Indicates the strategy used for the update. Currently supported values are: `web`, `github` or `http`. |
| `local_version` | `NO` | Currently downloaded version. This value will be updated with each update. |
| `re_version` | `NO` | Regex used to check for new versions on the web used in `url`. |
| `re_download` | `NO` | Regex used to get the download link on the web used in `url`. |
Expand All @@ -61,6 +61,7 @@ Combining the use of `update_url` and `re_download` the following download strat
2. Using only `re_download` you get the download link on the web from `url`.
3. When using both parameters, the result of `re_download` is concatenated with `update_url`.
This is useful for fixing GitHub or Sourceforge download links.
4. A new version detection method is also available that instead of regex uses the http headers with which the server responds.

## Examples

Expand Down
13 changes: 9 additions & 4 deletions tools.ini
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
[DIE]
folder = Analysis\DIE
folder = Tools\Analysis\DIE
url = horsicq/DIE-engine
from = github
re_download = die_win64_portable_(?:\S+).zip

[Portmon]
folder = Monitor\Portmon
folder = Tools\Monitor\Portmon
url = https://docs.microsoft.com/en-us/sysinternals/downloads/portmon
update_url = https://download.sysinternals.com/files/PortMon.zip
re_version = <h1 [^>]*>Portmon for Windows v(.*?)</h1>

[Process Hacker 3]
folder = Monitor\Process Hacker 3
folder = Tools\Monitor\Process Hacker 3
url = https://processhacker.sourceforge.io/nightly.php
re_version = Build: <span style="font-weight:bold">(.*?)</span>
re_download = href="(.*?releases/download/(?:\S+)/processhacker-(?:\S+)-bin.zip)
[ProcDOT]
folder = Other\ProcDOT
folder = Tools\Other\ProcDOT
url = https://www.procdot.com/downloadprocdotbinaries.htm
update_url = https://www.procdot.com/
update_file_pass = procdot
from = web
re_version = <span class="xr_tl xr_s4" [^>]*>Latest stable build: (.*?)</span>
re_download = href="(.*?/procdot_(?:\S+)_windows.zip)

[FileInsight]
folder = Tools\Other\FileInsight
update_url = https://downloadcenter.mcafee.com/products/mcafee-avert/fileinsight.msi
from = http
Binary file modified updater.exe
Binary file not shown.
40 changes: 34 additions & 6 deletions updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,36 @@ def _scrape_github_api(self, github_repo, update_url, re_download):
'download_url': update_url,
}

def _check_version_from_http(self, headers):
local_version = self.config.get(self.name, 'local_version', fallback='0')

remote_version = None
if 'last-modified' in headers:
remote_version = headers['last-modified']
elif 'content-length' in headers:
print('{0}: using "content-length" as version number...'.format(self.name))
remote_version = headers['content-length']
else:
raise Exception(colorama.Fore.RED + '{0}: no header is found with which to determine if there is an update'.format(self.name))

if not self.force_download and local_version == remote_version:
raise Exception('{0}: {1} is the latest version'.format(self.name, local_version))

print('{0}: updated from {1} --> {2}'.format(self.name, local_version, remote_version))

return remote_version

def _scrape_http(self, update_url):
# get http response
headers={'User-Agent': self.request_user_agent}
http_response = requests.head(update_url, headers=headers)
http_response.raise_for_status()

return {
'download_version': self._check_version_from_http(http_response.headers),
'download_url': update_url,
}

def _unpack(self, file_path):
file_ext = pathlib.Path(file_path).suffix
update_folder = str(file_path).replace(file_ext, '')
Expand Down Expand Up @@ -380,14 +410,12 @@ def _scrape_step(self):
update_url = self.config.get(self.name, 'update_url', fallback=None)
re_download = self.config.get(self.name, 're_download', fallback=None)
re_version = self.config.get(self.name, 're_version', fallback=None)

# case for don't process "Updater" tool
if not tool_url:
raise Exception()

from_url = self.config.get(self.name, 'from', fallback='web')

if from_url == 'github':
return self._scrape_github(tool_url, update_url, re_download)
elif from_url == 'http':
return self._scrape_http(update_url)

return self._scrape_web(tool_url, update_url, re_version, re_download)

Expand Down Expand Up @@ -474,7 +502,7 @@ def cleanup_update_folder(self):
# Implementation
class Setup:
def __init__(self):
self.version = '1.7.2'
self.version = '1.8.0'
self.arguments = {}
self.config = configparser.ConfigParser()
self.default_config = {}
Expand Down
Empty file added updates/.gitkeep
Empty file.

0 comments on commit e201b45

Please sign in to comment.