Browse Source

use common Valid library methods to check URL and addresses

main
ghost 1 year ago
parent
commit
43c617e893
  1. 6
      src/crontab/export/feed.php
  2. 13
      src/crontab/export/push.php
  3. 28
      src/crontab/import/feed.php
  4. 256
      src/library/valid.php
  5. 22
      src/public/action.php
  6. 29
      src/public/api/push.php
  7. 8
      src/public/download.php
  8. 95
      src/public/edit.php
  9. 2
      src/public/faq.php
  10. 2
      src/public/index.php
  11. 2
      src/public/magnet.php
  12. 2
      src/public/node.php
  13. 2
      src/public/welcome.php

6
src/crontab/export/feed.php

@ -269,7 +269,7 @@ try @@ -269,7 +269,7 @@ try
$uri = $db->getUri($addressTracker->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -295,7 +295,7 @@ try @@ -295,7 +295,7 @@ try
$uri = $db->getUri($acceptableSource->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -321,7 +321,7 @@ try @@ -321,7 +321,7 @@ try
$uri = $db->getUri($eXactSource->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}

13
src/crontab/export/push.php

@ -103,7 +103,7 @@ if (API_EXPORT_PUSH_ENABLED) @@ -103,7 +103,7 @@ if (API_EXPORT_PUSH_ENABLED)
$uri = $db->getUri($addressTracker->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -129,7 +129,7 @@ if (API_EXPORT_PUSH_ENABLED) @@ -129,7 +129,7 @@ if (API_EXPORT_PUSH_ENABLED)
$uri = $db->getUri($acceptableSource->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -155,7 +155,7 @@ if (API_EXPORT_PUSH_ENABLED) @@ -155,7 +155,7 @@ if (API_EXPORT_PUSH_ENABLED)
$uri = $db->getUri($eXactSource->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -310,12 +310,9 @@ if (API_EXPORT_PUSH_ENABLED) @@ -310,12 +310,9 @@ if (API_EXPORT_PUSH_ENABLED)
}
// Skip sending to non-condition addresses
if ($pushUrl = Yggverse\Parser\Url::parse($manifest->import->push))
if (!Valid::url($manifest->import->push))
{
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $pushUrl->host->name)))
{
continue;
}
continue;
}
else

28
src/crontab/import/feed.php

@ -35,31 +35,19 @@ try @@ -35,31 +35,19 @@ try
file_get_contents(__DIR__ . '/../../config/nodes.json')
) as $node)
{
// Skip reading to non-condition addresses
if ($manifestUrl = Yggverse\Parser\Url::parse($node->manifest))
{
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $manifestUrl->host->name)))
{
continue;
}
}
else
// Skip non-condition addresses
if (!Valid::url($node->manifest))
{
continue;
}
// Skip reading current host
if ($thisUrl = Yggverse\Parser\Url::parse(WEBSITE_URL))
{
if ($manifestUrl->host->name == $thisUrl->host->name) // @TODO some mirrors could be available, improve condition
{
continue;
}
}
// Skip current host
$thisUrl = Yggverse\Parser\Url::parse(WEBSITE_URL);
$manifestUrl = Yggverse\Parser\Url::parse($node->manifest);
else
if (empty($manifestUrl->host->name) ||
empty($manifestUrl->host->name) ||
$manifestUrl->host->name == $thisUrl->host->name) // @TODO some mirrors could be available, improve condition
{
continue;
}

256
src/library/valid.php

@ -5,18 +5,102 @@ class Valid @@ -5,18 +5,102 @@ class Valid
private static $_error = [];
// Common
public static function getError()
public static function getError() : array
{
return self::$_error;
}
public static function setError(array $value)
public static function setError(array $value) : void
{
self::$_error = $value;
}
public static function host(mixed $value) : bool
{
if (!is_string($value))
{
array_push(
self::$_error,
_('Invalid host data type')
);
return false;
}
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
{
array_push(
self::$_error,
sprintf(
_('Host "%s" not match condition "%s"'),
$value,
YGGDRASIL_HOST_REGEX
)
);
return false;
}
return true;
}
public static function url(mixed $value) : bool
{
if (!is_string($value))
{
array_push(
self::$_error,
_('Invalid URL data type')
);
return false;
}
if (!$url = Yggverse\Parser\Url::parse($value))
{
array_push(
self::$_error,
sprintf(
_('URL "%s" invalid'),
$value
)
);
return false;
}
if (empty($url->host->name))
{
array_push(
self::$_error,
sprintf(
_('Could not init host name for URL "%s"'),
$value
)
);
return false;
}
if (!self::host($url->host->name))
{
array_push(
self::$_error,
sprintf(
_('URL host "%s" not supported'),
$value,
$url->host->name
)
);
return false;
}
return true;
}
// User
public static function user(mixed $value)
public static function user(mixed $value) : bool
{
if (!is_object($value))
{
@ -48,7 +132,7 @@ class Valid @@ -48,7 +132,7 @@ class Valid
return true;
}
public static function userId(mixed $value)
public static function userId(mixed $value) : bool
{
if (!is_int($value))
{
@ -63,7 +147,7 @@ class Valid @@ -63,7 +147,7 @@ class Valid
return true;
}
public static function userAddress(mixed $value)
public static function userAddress(mixed $value) : bool
{
if (!is_string($value))
{
@ -75,13 +159,13 @@ class Valid @@ -75,13 +159,13 @@ class Valid
return false;
}
if (!preg_match(YGGDRASIL_HOST_REGEX, $value))
if (!self::host($value))
{
array_push(
self::$_error,
sprintf(
_('User address format does not match condition "%s"'),
YGGDRASIL_HOST_REGEX
_('User address "%s" not supported'),
$value
)
);
@ -91,7 +175,7 @@ class Valid @@ -91,7 +175,7 @@ class Valid
return true;
}
public static function userTimeAdded(mixed $value)
public static function userTimeAdded(mixed $value) : bool
{
if (!is_int($value))
{
@ -116,7 +200,7 @@ class Valid @@ -116,7 +200,7 @@ class Valid
return true;
}
public static function userTimeUpdated(mixed $value)
public static function userTimeUpdated(mixed $value) : bool
{
if (!(is_int($value) || is_bool($value)))
{
@ -141,7 +225,7 @@ class Valid @@ -141,7 +225,7 @@ class Valid
return true;
}
public static function userApproved(mixed $value)
public static function userApproved(mixed $value) : bool
{
if (!is_bool($value))
{
@ -156,7 +240,7 @@ class Valid @@ -156,7 +240,7 @@ class Valid
return true;
}
public static function userPublic(mixed $value)
public static function userPublic(mixed $value) : bool
{
if (!is_bool($value))
{
@ -172,7 +256,7 @@ class Valid @@ -172,7 +256,7 @@ class Valid
}
// Magnet
public static function magnet(mixed $data)
public static function magnet(mixed $data) : bool
{
if (!is_object($data))
{
@ -224,7 +308,7 @@ class Valid @@ -224,7 +308,7 @@ class Valid
return true;
}
public static function magnetId(mixed $value)
public static function magnetId(mixed $value) : bool
{
if (!is_int($value))
{
@ -239,7 +323,7 @@ class Valid @@ -239,7 +323,7 @@ class Valid
return true;
}
public static function magnetTitle(mixed $value)
public static function magnetTitle(mixed $value) : bool
{
if (!is_string($value))
{
@ -282,7 +366,7 @@ class Valid @@ -282,7 +366,7 @@ class Valid
return true;
}
public static function magnetPreview(mixed $value)
public static function magnetPreview(mixed $value) : bool
{
if (!is_string($value))
{
@ -325,7 +409,7 @@ class Valid @@ -325,7 +409,7 @@ class Valid
return true;
}
public static function magnetDescription(mixed $value)
public static function magnetDescription(mixed $value) : bool
{
if (!is_string($value))
{
@ -368,7 +452,7 @@ class Valid @@ -368,7 +452,7 @@ class Valid
return true;
}
public static function magnetComments(mixed $value)
public static function magnetComments(mixed $value) : bool
{
if (!is_bool($value))
{
@ -383,7 +467,7 @@ class Valid @@ -383,7 +467,7 @@ class Valid
return true;
}
public static function magnetPublic(mixed $value)
public static function magnetPublic(mixed $value) : bool
{
if (!is_bool($value))
{
@ -398,7 +482,7 @@ class Valid @@ -398,7 +482,7 @@ class Valid
return true;
}
public static function magnetApproved(mixed $value)
public static function magnetApproved(mixed $value) : bool
{
if (!is_bool($value))
{
@ -413,7 +497,7 @@ class Valid @@ -413,7 +497,7 @@ class Valid
return true;
}
public static function magnetSensitive(mixed $value)
public static function magnetSensitive(mixed $value) : bool
{
if (!is_bool($value))
{
@ -428,7 +512,7 @@ class Valid @@ -428,7 +512,7 @@ class Valid
return true;
}
public static function magnetTimeAdded(mixed $value)
public static function magnetTimeAdded(mixed $value) : bool
{
if (!is_int($value))
{
@ -453,7 +537,7 @@ class Valid @@ -453,7 +537,7 @@ class Valid
return true;
}
public static function magnetTimeUpdated(mixed $value)
public static function magnetTimeUpdated(mixed $value) : bool
{
if (!(is_int($value) || is_bool($value)))
{
@ -478,7 +562,7 @@ class Valid @@ -478,7 +562,7 @@ class Valid
return true;
}
public static function magnetDn(mixed $value)
public static function magnetDn(mixed $value) : bool
{
if (!is_string($value))
{
@ -521,7 +605,7 @@ class Valid @@ -521,7 +605,7 @@ class Valid
return true;
}
public static function magnetXl(mixed $value)
public static function magnetXl(mixed $value) : bool
{
if (!(is_int($value) || is_float($value)))
{
@ -536,7 +620,7 @@ class Valid @@ -536,7 +620,7 @@ class Valid
return true;
}
public static function magnetKt(mixed $value)
public static function magnetKt(mixed $value) : bool
{
if (!is_object($value))
{
@ -611,7 +695,7 @@ class Valid @@ -611,7 +695,7 @@ class Valid
return true;
}
public static function magnetXt(mixed $value)
public static function magnetXt(mixed $value) : bool
{
if (!is_object($value))
{
@ -689,7 +773,7 @@ class Valid @@ -689,7 +773,7 @@ class Valid
return true;
}
public static function magnetTr(mixed $value)
public static function magnetTr(mixed $value) : bool
{
if (!is_object($value))
{
@ -705,33 +789,13 @@ class Valid @@ -705,33 +789,13 @@ class Valid
foreach ($value as $tr)
{
if (!$url = Yggverse\Parser\Url::parse($tr))
{
array_push(
self::$_error,
_('Invalid magnet address tracker URL')
);
return false;
}
if (empty($url->host->name))
{
array_push(
self::$_error,
_('Invalid magnet address tracker host name')
);
return false;
}
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
if (!self::url($tr))
{
array_push(
self::$_error,
sprintf(
_('Magnet address tracker format does not match condition "%s"'),
YGGDRASIL_HOST_REGEX
_('Invalid magnet address tracker URL "%s"'),
$tr
)
);
@ -759,7 +823,7 @@ class Valid @@ -759,7 +823,7 @@ class Valid
return true;
}
public static function magnetAs(mixed $value)
public static function magnetAs(mixed $value) : bool
{
if (!is_object($value))
{
@ -775,33 +839,13 @@ class Valid @@ -775,33 +839,13 @@ class Valid
foreach ($value as $as)
{
if (!$url = Yggverse\Parser\Url::parse($as))
{
array_push(
self::$_error,
_('Invalid magnet acceptable source URL')
);
return false;
}
if (empty($url->host->name))
{
array_push(
self::$_error,
_('Invalid magnet acceptable source host name')
);
return false;
}
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
if (!self::url($as))
{
array_push(
self::$_error,
sprintf(
_('Magnet acceptable source format does not match condition "%s"'),
YGGDRASIL_HOST_REGEX
_('Invalid magnet acceptable source URL "%s"'),
$as
)
);
@ -829,7 +873,7 @@ class Valid @@ -829,7 +873,7 @@ class Valid
return true;
}
public static function magnetWs(mixed $value)
public static function magnetWs(mixed $value) : bool
{
if (!is_object($value))
{
@ -845,33 +889,13 @@ class Valid @@ -845,33 +889,13 @@ class Valid
foreach ($value as $ws)
{
if (!$url = Yggverse\Parser\Url::parse($ws))
{
array_push(
self::$_error,
_('Invalid magnet web seed URL')
);
return false;
}
if (empty($url->host->name))
{
array_push(
self::$_error,
_('Invalid magnet web seed host name')
);
return false;
}
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
if (!self::url($ws))
{
array_push(
self::$_error,
sprintf(
_('Magnet web seed format does not match condition "%s"'),
YGGDRASIL_HOST_REGEX
_('Invalid magnet web seed URL "%s"'),
$ws
)
);
@ -900,7 +924,7 @@ class Valid @@ -900,7 +924,7 @@ class Valid
}
// Magnet comment
public static function magnetComment(mixed $value)
public static function magnetComment(mixed $value) : bool
{
if (!is_object($value))
{
@ -933,7 +957,7 @@ class Valid @@ -933,7 +957,7 @@ class Valid
return true;
}
public static function magnetCommentId(mixed $value)
public static function magnetCommentId(mixed $value) : bool
{
if (!is_int($value))
{
@ -948,7 +972,7 @@ class Valid @@ -948,7 +972,7 @@ class Valid
return true;
}
public static function magnetCommentIdParent(mixed $value)
public static function magnetCommentIdParent(mixed $value) : bool
{
if (!(is_bool($value) || is_int($value)))
{
@ -968,7 +992,7 @@ class Valid @@ -968,7 +992,7 @@ class Valid
return true;
}
public static function magnetCommentTimeAdded(mixed $value)
public static function magnetCommentTimeAdded(mixed $value) : bool
{
if (!is_int($value))
{
@ -993,7 +1017,7 @@ class Valid @@ -993,7 +1017,7 @@ class Valid
return true;
}
public static function magnetCommentApproved(mixed $value)
public static function magnetCommentApproved(mixed $value) : bool
{
if (!is_bool($value))
{
@ -1008,7 +1032,7 @@ class Valid @@ -1008,7 +1032,7 @@ class Valid
return true;
}
public static function magnetCommentPublic(mixed $value)
public static function magnetCommentPublic(mixed $value) : bool
{
if (!is_bool($value))
{
@ -1023,7 +1047,7 @@ class Valid @@ -1023,7 +1047,7 @@ class Valid
return true;
}
public static function magnetCommentValue(mixed $value)
public static function magnetCommentValue(mixed $value) : bool
{
if (!is_string($value))
{
@ -1054,7 +1078,7 @@ class Valid @@ -1054,7 +1078,7 @@ class Valid
}
// Magnet download
public static function magnetDownload(mixed $value)
public static function magnetDownload(mixed $value) : bool
{
if (!is_object($value))
{
@ -1083,7 +1107,7 @@ class Valid @@ -1083,7 +1107,7 @@ class Valid
return true;
}
public static function magnetDownloadId(mixed $value)
public static function magnetDownloadId(mixed $value) : bool
{
if (!is_int($value))
{
@ -1098,7 +1122,7 @@ class Valid @@ -1098,7 +1122,7 @@ class Valid
return true;
}
public static function magnetDownloadTimeAdded(mixed $value)
public static function magnetDownloadTimeAdded(mixed $value) : bool
{
if (!is_int($value))
{
@ -1124,7 +1148,7 @@ class Valid @@ -1124,7 +1148,7 @@ class Valid
}
// Magnet star
public static function magnetStar(mixed $value)
public static function magnetStar(mixed $value) : bool
{
if (!is_object($value))
{
@ -1154,7 +1178,7 @@ class Valid @@ -1154,7 +1178,7 @@ class Valid
return true;
}
public static function magnetStarId(mixed $value)
public static function magnetStarId(mixed $value) : bool
{
if (!is_int($value))
{
@ -1169,7 +1193,7 @@ class Valid @@ -1169,7 +1193,7 @@ class Valid
return true;
}
public static function magnetStarValue(mixed $value)
public static function magnetStarValue(mixed $value) : bool
{
if (!is_bool($value))
{
@ -1184,7 +1208,7 @@ class Valid @@ -1184,7 +1208,7 @@ class Valid
return true;
}
public static function magnetStarTimeAdded(mixed $value)
public static function magnetStarTimeAdded(mixed $value) : bool
{
if (!is_int($value))
{
@ -1210,7 +1234,7 @@ class Valid @@ -1210,7 +1234,7 @@ class Valid
}
// Magnet view
public static function magnetView(mixed $value)
public static function magnetView(mixed $value) : bool
{
if (!is_object($value))
{
@ -1239,7 +1263,7 @@ class Valid @@ -1239,7 +1263,7 @@ class Valid
return true;
}
public static function magnetViewId(mixed $value)
public static function magnetViewId(mixed $value) : bool
{
if (!is_int($value))
{
@ -1254,7 +1278,7 @@ class Valid @@ -1254,7 +1278,7 @@ class Valid
return true;
}
public static function magnetViewTimeAdded(mixed $value)
public static function magnetViewTimeAdded(mixed $value) : bool
{
if (!is_int($value))
{

22
src/public/action.php

@ -21,7 +21,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -21,7 +21,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'jidenticon':
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
@ -79,7 +79,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -79,7 +79,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'approved':
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
@ -168,7 +168,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -168,7 +168,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'new':
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
@ -293,7 +293,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -293,7 +293,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'star':
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
@ -393,7 +393,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -393,7 +393,7 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'new':
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
@ -491,9 +491,9 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -491,9 +491,9 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'tr':
foreach ($value as $tr)
{
if ($url = Yggverse\Parser\Url::parse($tr))
if (Valid::url($tr))
{
if (preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
if ($url = Yggverse\Parser\Url::parse($tr))
{
$db->initMagnetToAddressTrackerId(
$magnetId,
@ -517,9 +517,9 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -517,9 +517,9 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'as':
foreach ($value as $as)
{
if ($url = Yggverse\Parser\Url::parse($as))
if (Valid::url($as))
{
if (preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
if ($url = Yggverse\Parser\Url::parse($as))
{
$db->initMagnetToAcceptableSourceId(
$magnetId,
@ -537,9 +537,9 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) @@ -537,9 +537,9 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false)
case 'xs':
foreach ($value as $xs)
{
if ($url = Yggverse\Parser\Url::parse($xs))
if (Valid::url($xs))
{
if (preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
if ($url = Yggverse\Parser\Url::parse($xs))
{
$db->initMagnetToExactSourceId(
$magnetId,

29
src/public/api/push.php

@ -16,29 +16,24 @@ $connectionWhiteList = []; @@ -16,29 +16,24 @@ $connectionWhiteList = [];
foreach (json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')) as $node)
{
// Skip non-condition addresses
if ($manifestUrl = Yggverse\Parser\Url::parse($node->manifest))
if (!Valid::url($node->manifest))
{
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $manifestUrl->host->name)))
{
continue;
}
}
$response =
[
'status' => false,
'message' => Valid::getError()
];
else
{
continue;
}
// Skip current host
if ($thisUrl = Yggverse\Parser\Url::parse(WEBSITE_URL))
{
if ($manifestUrl->host->name == $thisUrl->host->name) // @TODO some mirrors could be available, improve condition
{
continue;
}
}
$thisUrl = Yggverse\Parser\Url::parse(WEBSITE_URL);
$manifestUrl = Yggverse\Parser\Url::parse($node->manifest);
else
if (empty($manifestUrl->host->name) ||
empty($manifestUrl->host->name) ||
$manifestUrl->host->name == $thisUrl->host->name) // @TODO some mirrors could be available, improve condition
{
continue;
}
@ -67,7 +62,7 @@ else if (!API_IMPORT_PUSH_ENABLED) @@ -67,7 +62,7 @@ else if (!API_IMPORT_PUSH_ENABLED)
}
// Yggdrasil connections only
else if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
else if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response =
[

8
src/public/download.php

@ -17,7 +17,7 @@ $response = (object) @@ -17,7 +17,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
@ -146,7 +146,7 @@ else @@ -146,7 +146,7 @@ else
$uri = $db->getUri($addressTracker->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -176,7 +176,7 @@ else @@ -176,7 +176,7 @@ else
$uri = $db->getUri($acceptableSource->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}
@ -206,7 +206,7 @@ else @@ -206,7 +206,7 @@ else
$uri = $db->getUri($eXactSource->uriId);
// Yggdrasil host only
if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value)))
if (!Valid::host($host->value))
{
continue;
}

95
src/public/edit.php

@ -126,7 +126,7 @@ $response = (object) @@ -126,7 +126,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required to enable resource features');
@ -373,27 +373,22 @@ else { @@ -373,27 +373,22 @@ else {
foreach (explode(PHP_EOL, str_replace(['#', ',', ' '], PHP_EOL, $_POST['tr'])) as $tr)
{
$tr = trim($tr);
if (!empty($tr))
if (Valid::url($tr))
{
if ($url = Yggverse\Parser\Url::parse($tr))
{
if (preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
{
$db->initMagnetToAddressTrackerId(
$magnet->magnetId,
$db->initAddressTrackerId(
$db->initSchemeId($url->host->scheme),
$db->initHostId($url->host->name),
$db->initPortId($url->host->port),
$db->initUriId($url->page->uri)
)
);
$response->form->tr->valid->success = true;
$response->form->tr->valid->message = false;
}
$db->initMagnetToAddressTrackerId(
$magnet->magnetId,
$db->initAddressTrackerId(
$db->initSchemeId($url->host->scheme),
$db->initHostId($url->host->name),
$db->initPortId($url->host->port),
$db->initUriId($url->page->uri)
)
);
$response->form->tr->valid->success = true;
$response->form->tr->valid->message = false;
}
}
}
@ -409,27 +404,22 @@ else { @@ -409,27 +404,22 @@ else {
foreach (explode(PHP_EOL, str_replace(['#', ',', ' '], PHP_EOL, $_POST['as'])) as $as)
{
$as = trim($as);
if (!empty($as))
if (Valid::url($as))
{
if ($url = Yggverse\Parser\Url::parse($as))
{
if (preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
{
$db->initMagnetToAcceptableSourceId(
$magnet->magnetId,
$db->initAcceptableSourceId(
$db->initSchemeId($url->host->scheme),
$db->initHostId($url->host->name),
$db->initPortId($url->host->port),
$db->initUriId($url->page->uri)
)
);
$response->form->as->valid->success = true;
$response->form->as->valid->message = false;
}
$db->initMagnetToAcceptableSourceId(
$magnet->magnetId,
$db->initAcceptableSourceId(
$db->initSchemeId($url->host->scheme),
$db->initHostId($url->host->name),
$db->initPortId($url->host->port),
$db->initUriId($url->page->uri)
)
);
$response->form->as->valid->success = true;
$response->form->as->valid->message = false;
}
}
}
@ -445,27 +435,22 @@ else { @@ -445,27 +435,22 @@ else {
foreach (explode(PHP_EOL, str_replace(['#', ',', ' '], PHP_EOL, $_POST['xs'])) as $xs)
{
$xs = trim($xs);
if (!empty($xs))
if (Valid::url($xs))
{
if ($url = Yggverse\Parser\Url::parse($xs))
{
if (preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $url->host->name)))
{
$db->initMagnetToExactSourceId(
$magnet->magnetId,
$db->initExactSourceId(
$db->initSchemeId($url->host->scheme),
$db->initHostId($url->host->name),
$db->initPortId($url->host->port),
$db->initUriId($url->page->uri)
)
);
$response->form->xs->valid->success = true;
$response->form->xs->valid->message = false;
}
$db->initMagnetToExactSourceId(
$magnet->magnetId,
$db->initExactSourceId(
$db->initSchemeId($url->host->scheme),
$db->initHostId($url->host->name),
$db->initPortId($url->host->port),
$db->initUriId($url->page->uri)
)
);
$response->form->xs->valid->success = true;
$response->form->xs->valid->message = false;
}
}
}

2
src/public/faq.php

@ -12,7 +12,7 @@ $response = (object) @@ -12,7 +12,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');

2
src/public/index.php

@ -23,7 +23,7 @@ $response = (object) @@ -23,7 +23,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required to enable resource features');

2
src/public/magnet.php

@ -13,7 +13,7 @@ $response = (object) @@ -13,7 +13,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required to enable resource features');

2
src/public/node.php

@ -12,7 +12,7 @@ $response = (object) @@ -12,7 +12,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');

2
src/public/welcome.php

@ -12,7 +12,7 @@ $response = (object) @@ -12,7 +12,7 @@ $response = (object)
];
// Yggdrasil connections only
if (!preg_match(YGGDRASIL_HOST_REGEX, $_SERVER['REMOTE_ADDR']))
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');

Loading…
Cancel
Save