Compare commits

...

9 Commits

9 changed files with 98 additions and 79 deletions

View File

@@ -16,13 +16,13 @@ use Domframework\Tcpclient;
*/
class TcpclientTest extends \PHPUnit_Framework_TestCase
{
public function testGoogleIPv4()
public function testFournier38IPv4()
{
$tcpclient = new Tcpclient("www.google.fr", 80);
$tcpclient = new Tcpclient("ipv4.fournier38.fr", 80);
$tcpclient->preferIPv4(true);
$tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
@@ -34,12 +34,12 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function testGoogleIPv4orIpv6()
public function testFournier38IPv4orIpv6()
{
$tcpclient = new Tcpclient("www.google.fr", 80);
$tcpclient = new Tcpclient("ip.fournier38.fr", 80);
$tcpclient->connect();
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
@@ -51,13 +51,13 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function testGoogleSSL()
public function testFournier38SSL()
{
$tcpclient = new Tcpclient("www.google.fr", 443);
$tcpclient = new Tcpclient("ip.fournier38.fr", 443);
$tcpclient->connect();
$tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"Host: ip.fournier38.fr\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");
@@ -69,13 +69,13 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
}
public function testGoogleSSLIPv6()
public function testFournier38SSLIPv6()
{
$tcpclient = new Tcpclient("ipv6.google.com", 443);
$tcpclient = new Tcpclient("ipv6.fournier38.fr", 443);
$tcpclient->connect();
$tcpclient->cryptoEnable(true);
$tcpclient->send("GET / HTTP/1.1\r\n" .
"Host: www.google.fr\r\n" .
"Host: ipv6.fournier38.f\r\n" .
"User-Agent: DomFramework\r\n" .
"Accept: *" . "/*\r\n" .
"\r\n");

View File

@@ -91,7 +91,7 @@ class Form
* Set the debug level
* @param integer $val The debug value
*/
public function debug($val)
public function debug($val): self
{
$this->debug = $val;
return $this;
@@ -101,7 +101,7 @@ class Form
* Set the csrf enable
* @param integer $val The csrf check
*/
public function csrf($val)
public function csrf($val): self
{
$this->csrf = !! $val;
return $this;
@@ -111,7 +111,7 @@ class Form
* Set the method
* @param string $val The method to use
*/
public function method($val)
public function method($val): self
{
$this->method = strtolower($val);
return $this;
@@ -121,7 +121,7 @@ class Form
* Set the csrf token name
* @param integer $val The csrf token name
*/
public function csrfField($val)
public function csrfField($val): self
{
$this->csrfField = $val;
return $this;
@@ -131,7 +131,7 @@ class Form
* Set the titlewidth
* @param integer $val The titlewidth
*/
public function titlewidth($val)
public function titlewidth($val): self
{
$this->titlewidth = $val;
return $this;
@@ -141,7 +141,7 @@ class Form
* Set the fieldwidth
* @param integer $val The fieldwidth
*/
public function fieldwidth($val)
public function fieldwidth($val): self
{
$this->fieldwidth = $val;
return $this;
@@ -151,7 +151,7 @@ class Form
* Set the formClass
* @param integer $val The formClass
*/
public function formClass($val)
public function formClass($val): self
{
$this->formClass = $val;
return $this;
@@ -164,7 +164,7 @@ class Form
* @param string|null $loggingBasemsg The basemsg added at the beginning of
* the log
*/
public function logging($loggingCallable, $loggingBasemsg = "")
public function logging($loggingCallable, $loggingBasemsg = ""): void
{
$this->loggingCallable = $loggingCallable;
$this->loggingBasemsg = $loggingBasemsg;
@@ -175,7 +175,7 @@ class Form
* Can be : Bootstrap3, Bootstrap4 (later Bulma)
* @param string $formTemplate The template to use
*/
public function formTemplate($formTemplate)
public function formTemplate($formTemplate): self
{
if (
! in_array(
@@ -195,7 +195,7 @@ class Form
* @param integer $prio The priority of the message
* @param string $msg The message to store
*/
private function loggingCallable($prio, $msg)
private function loggingCallable($prio, $msg): void
{
if (! is_callable($this->loggingCallable)) {
return;
@@ -236,7 +236,7 @@ class Form
*
* @param array $fields The fields to be displayed
*/
public function fields($fields)
public function fields($fields): void
{
$this->fields = $fields;
}
@@ -246,7 +246,7 @@ class Form
* in fields method
* @param object $field The field to add
*/
public function addfield($field)
public function addfield($field): void
{
$this->fields[] = $field;
}
@@ -256,7 +256,7 @@ class Form
* NEVER read the values from $_POST in your codes or CSRF will not be
* checked
*/
public function values()
public function values(): array
{
$values = [];
if ($this->method === "post") {
@@ -328,7 +328,7 @@ class Form
$method = 'post',
$values = null,
$errors = []
) {
): string {
if (count($this->fields) === 0) {
$this->loggingCallable(
LOG_ERR,
@@ -456,7 +456,7 @@ class Form
* Check the token from the user
* @param string $tokenFromUser The value form the user's token
*/
public function checkToken($tokenFromUser)
public function checkToken($tokenFromUser): void
{
$csrf = new Csrf();
$csrf->field = $this->csrfField;
@@ -468,7 +468,7 @@ class Form
/**
* Return the token generated in form
*/
public function getToken()
public function getToken(): string
{
if ($this->csrfToken === "") {
$csrf = new Csrf();
@@ -485,7 +485,7 @@ class Form
* stored one if the value is null)
* @return array containing the errors
*/
public function verify($values, $fields = [])
public function verify($values, $fields = []): array
{
if (count($fields) === 0) {
if (! isset($_SESSION["domframework"]["form"]["fields"])) {
@@ -529,7 +529,7 @@ class Form
* $spaceuuid = $spaceObj->spaceCreateConceal ($values["spacename"]);
* $route->redirect ("/admin/space/");
*/
public function redirectIfError($values, $errors, $route, $url = "")
public function redirectIfError($values, $errors, $route, $url = ""): void
{
$this->saveValuesErrors($values, $errors);
if ($url === "") {
@@ -548,7 +548,7 @@ class Form
* @param array $values The values of the fields filled by the user
* @param array|null $errors The errors detected by a verify
*/
public function saveValuesErrors($values, $errors = [])
public function saveValuesErrors($values, $errors = []): void
{
if (isset($_SESSION)) {
$_SESSION["domframework"]["form"][$this->formName]["values"] = $values;
@@ -560,7 +560,7 @@ class Form
* Reset the saved values to provide a clean form next page
* Need the session to work
*/
public function saveValuesErrorsReset()
public function saveValuesErrorsReset(): void
{
unset($_SESSION["domframework"]["form"][$this->formName]["values"]);
unset($_SESSION["domframework"]["form"][$this->formName]["errors"]);
@@ -572,7 +572,7 @@ class Form
* @param array $values The values returned if there is no stored values
* @return array The values to use
*/
public function getOldValues($values)
public function getOldValues($values): array
{
if (isset($_SESSION["domframework"]["form"][$this->formName]["values"])) {
$values = $_SESSION["domframework"]["form"][$this->formName]["values"];
@@ -587,7 +587,7 @@ class Form
* @param array $errors The values returned if there is no stored values
* @return array The errors to use
*/
public function getOldErrors($errors)
public function getOldErrors($errors): array
{
if (isset($_SESSION["domframework"]["form"][$this->formName]["errors"])) {
$errors = $_SESSION["domframework"]["form"][$this->formName]["errors"];
@@ -606,14 +606,14 @@ class Form
* @param string $outputFormat The output format of the date
* @return string
*/
public function convertDate($inputDate, $inputFormat, $outputFormat)
public function convertDate($inputDate, $inputFormat, $outputFormat): string
{
$date = \DateTime::CreateFromFormat($inputFormat, $inputDate);
if ($date === false) {
return $inputDate;
}
$errors = $date->getLastErrors();
if ($errors["warning_count"] > 0 || $errors["error_count"] > 0) {
if (is_array($errors) && ($errors["warning_count"] > 0 || $errors["error_count"] > 0)) {
return $inputDate;
}
return $date->format($outputFormat);

View File

@@ -90,7 +90,7 @@ class Formfield
/**
* Form template (Bootstrap3 by default)
*/
private $formTemplate = "Bootstrap3";
public $formTemplate = "Bootstrap3";
/**
* When adding a field, the name and the label are the minimum mandatory
@@ -106,7 +106,7 @@ class Formfield
/**
* Display really the form
*/
public function display()
public function display(): string
{
$func = "field" . $this->formTemplate . $this->type;
return $this->$func();
@@ -117,7 +117,7 @@ class Formfield
* Set the type of the field
* @param string $val The value of the type of the field
*/
public function type($val)
public function type($val): self
{
$this->type = $val;
return $this;
@@ -127,7 +127,7 @@ class Formfield
* Set the hidden of the field
* @param string $val The value of the hidden of the field
*/
public function hidden($val)
public function hidden($val): self
{
$this->hidden = !! $val;
return $this;
@@ -137,7 +137,7 @@ class Formfield
* Set the help of the field
* @param string $val The value of the help of the field
*/
public function help($val)
public function help($val): self
{
$this->help = $val;
return $this;
@@ -147,7 +147,7 @@ class Formfield
* Set the placeholder
* @param string $val The value of the placeholder
*/
public function placeholder($val)
public function placeholder($val): self
{
$this->placeholder = $val;
return $this;
@@ -157,7 +157,7 @@ class Formfield
* Set the multiple
* @param string $val The value of the multiple
*/
public function multiple($val)
public function multiple($val): self
{
$this->multiple = $val;
return $this;
@@ -167,7 +167,7 @@ class Formfield
* Set the group
* @param string $val The value of the group
*/
public function group($val)
public function group($val): self
{
$this->group = $val;
return $this;
@@ -177,7 +177,7 @@ class Formfield
* Set the readonly
* @param string $val The value of the readonly
*/
public function readonly($val)
public function readonly($val): self
{
$this->readonly = !! $val;
return $this;
@@ -187,7 +187,7 @@ class Formfield
* Set the mandatory
* @param string $val The value of the mandatory
*/
public function mandatory($val)
public function mandatory($val): self
{
$this->mandatory = !! $val;
return $this;
@@ -197,7 +197,7 @@ class Formfield
* Set the rows
* @param string $val The value of the rows
*/
public function rows($val)
public function rows($val): self
{
$this->rows = $val;
return $this;
@@ -207,7 +207,7 @@ class Formfield
* Set the cols
* @param string $val The value of the cols
*/
public function cols($val)
public function cols($val): self
{
$this->cols = $val;
return $this;
@@ -219,7 +219,7 @@ class Formfield
/**
* Return the checkbox defined
*/
private function fieldBootstrap3checkbox()
private function fieldBootstrap3checkbox(): string
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
@@ -366,7 +366,7 @@ class Formfield
/**
* Return the hidden field defined
*/
private function fieldBootstrap3hidden()
private function fieldBootstrap3hidden(): string
{
$res = "";
// No $this->label, $this->multiple, $this->readonly, $this->hidden,
@@ -388,7 +388,7 @@ class Formfield
/**
* Return the password field defined
*/
private function fieldBootstrap3password()
private function fieldBootstrap3password(): string
{
$res = "";
// No $this->multiple, $this->rows $this->cols
@@ -472,7 +472,7 @@ class Formfield
/**
* Return the radio field defined
*/
private function fieldBootstrap3radio()
private function fieldBootstrap3radio(): string
{
$res = "";
// No $this->multiple, $this->rows $this->cols $this->placeholder
@@ -574,7 +574,7 @@ class Formfield
/**
* Return the checkbox defined
*/
private function fieldBootstrap3select()
private function fieldBootstrap3select(): string
{
// No $this->placeholder $this->maxlength
$res = "";
@@ -704,7 +704,7 @@ class Formfield
/**
* Return the submit defined
*/
private function fieldBootstrap3submit()
private function fieldBootstrap3submit(): string
{
$res = "";
// No $this->label, $this->multiple, $this->error, $this->rows,
@@ -749,7 +749,7 @@ class Formfield
/**
* Return the textarea defined
*/
private function fieldBootstrap3textarea()
private function fieldBootstrap3textarea(): string
{
$res = "";
// No $this->multiple, $this->titles
@@ -835,7 +835,7 @@ class Formfield
/**
* Return the text defined
*/
private function fieldBootstrap3text()
private function fieldBootstrap3text(): string
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols
@@ -919,7 +919,7 @@ class Formfield
/**
* Return the file defined
*/
private function fieldBootstrap3file()
private function fieldBootstrap3file(): string
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols
@@ -1021,7 +1021,7 @@ class Formfield
/**
* Return the checkbox defined
*/
private function fieldBootstrap4checkbox()
private function fieldBootstrap4checkbox(): string
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
@@ -1176,7 +1176,7 @@ class Formfield
/**
* Return the hidden field defined
*/
private function fieldBootstrap4hidden()
private function fieldBootstrap4hidden(): string
{
$res = "";
// No $this->label, $this->multiple, $this->readonly, $this->hidden,
@@ -1198,7 +1198,7 @@ class Formfield
/**
* Return the password field defined
*/
private function fieldBootstrap4password()
private function fieldBootstrap4password(): string
{
$res = "";
// No $this->multiple, $this->rows $this->cols
@@ -1290,7 +1290,7 @@ class Formfield
/**
* Return the radio field defined
*/
private function fieldBootstrap4radio()
private function fieldBootstrap4radio(): string
{
$res = "";
// No $this->multiple, $this->rows $this->cols $this->placeholder
@@ -1400,7 +1400,7 @@ class Formfield
/**
* Return the checkbox defined
*/
private function fieldBootstrap4select()
private function fieldBootstrap4select(): string
{
// No $this->placeholder $this->maxlength
$res = "";
@@ -1538,7 +1538,7 @@ class Formfield
/**
* Return the submit defined
*/
private function fieldBootstrap4submit()
private function fieldBootstrap4submit(): string
{
$res = "";
// No $this->label, $this->multiple, $this->error, $this->rows,
@@ -1583,7 +1583,7 @@ class Formfield
/**
* Return the textarea defined
*/
private function fieldBootstrap4textarea()
private function fieldBootstrap4textarea(): string
{
$res = "";
// No $this->multiple, $this->titles
@@ -1677,7 +1677,7 @@ class Formfield
/**
* Return the text defined
*/
private function fieldBootstrap4text()
private function fieldBootstrap4text(): string
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols
@@ -1769,7 +1769,7 @@ class Formfield
/**
* Return the file defined
*/
private function fieldBootstrap4file()
private function fieldBootstrap4file(): string
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols

View File

@@ -364,7 +364,7 @@ class Language
$languageCode,
"domframework",
LC_MESSAGES,
dirname(__FILE__) . "/locale"
__DIR__ . "/../locale"
);
$dfDir = dirname(dirname(dirname($dfFile)));
$this->languageActivation($dfFile, $languageCode, LC_MESSAGES, $dfDir);

View File

@@ -437,7 +437,7 @@ class Logger
break;
}
}
openlog($this->syslogPrefix, null, $this->syslogFacility);
openlog($this->syslogPrefix, LOG_PID, $this->syslogFacility);
// Syslog display a #012 when there is a \n : remove it
$message = str_replace("\n", "", $message);
syslog($priority, $message);

View File

@@ -302,7 +302,7 @@ class Mail
PREG_SPLIT_DELIM_CAPTURE
);
// Remove the first 2 dashes : the boundary is stored like in the headers
$boundary = "";
$boundary = $boundaryCR = "";
while (count($boundaryArray) > 0 && substr($boundary, 0, 2) !== "--") {
// Skip the lines until the coundary is found. The boundary start by --
$boundary = array_shift($boundaryArray);
@@ -379,9 +379,9 @@ class Mail
$headersEML = ltrim(substr($content, 0, $pos +
strlen($headerBodySeparator)));
$headersArray = [];
$prevCR = "";
if ($headersEML !== "" && $headersEML !== "--") {
$prev = "";
$prevCR = "";
$headersSplit = preg_split(
"#([\r\n]+)#",
$headersEML,
@@ -527,6 +527,7 @@ class Mail
// multipart/alternative)
$sectionList = $this->sectionList();
$sectionIDtoChange = "";
$boundary = $boundaryCR = "";
foreach ($sectionList as $sectionID) {
$section = $this->sectionGet($sectionID);
if (
@@ -628,10 +629,10 @@ class Mail
"text/html; charset=$charset",
$sectionIDtoChange
);
if (isset($boundary)) {
if ($boundary !== "") {
$part["_boundary"] = $boundary;
}
if (isset($boundaryCR)) {
if ($boundaryCR != "") {
$part["_boundaryCR"] = $boundaryCR;
}
$this->sectionUpdate($sectionIDtoChange, $part);
@@ -654,6 +655,7 @@ class Mail
// multipart/alternative)
$sectionList = $this->sectionList();
$sectionIDtoChange = "";
$boundary = "";
foreach ($sectionList as $sectionID) {
$section = $this->sectionGet($sectionID);
if (
@@ -736,12 +738,9 @@ class Mail
"text/plain; charset=$charset",
$sectionIDtoChange
);
if (isset($boundary)) {
if ($boundary !== "") {
$part["_boundary"] = $boundary;
}
if (isset($boundaryCR)) {
$part["_boundaryCR"] = $boundaryCR;
}
$this->sectionUpdate($sectionIDtoChange, $part);
$this->createMailEML();
}
@@ -939,6 +938,7 @@ class Mail
);
}
// Add the new section to the mixed section
$contentID = "";
$sectionID = $this->sectionAddDefault();
$this->sectionAddChild($sectionIDMixed, $sectionID);
$finfo = new \finfo(FILEINFO_MIME);
@@ -1059,6 +1059,7 @@ class Mail
), $number), 404);
}
$part = $this->sectionGet($attachmentIDs[$number]);
$res = [];
foreach ($part as $key => $val) {
if ($key[0] === "_") {
if (

View File

@@ -106,6 +106,7 @@ class Smtp
if ($errstr === "" && $php_errormsg !== "") {
$errstr = $php_errormsg;
}
$this->smtpStream = null;
throw new \Exception(sprintf(dgettext(
"domframework",
"Can't connect to SMTP server : %s"
@@ -123,7 +124,11 @@ class Smtp
$this->putLine("STARTTLS\r\n");
$context["ssl"]["verify_peer_name"] = $this->starttlsCheck;
$context["ssl"]["verify_peer"] = $this->starttlsCheck;
stream_context_set_option($this->smtpStream, $context);
if (version_compare(PHP_VERSION, '8.3.0') <= 0) {
stream_context_set_option($this->smtpStream, $context);
} else {
stream_context_set_options($this->smtpStream, $context);
}
// The track_errors permit to create the $php_errormsg in case of
// warning
ini_set('track_errors', 1);
@@ -135,6 +140,7 @@ class Smtp
) ===
false
) {
$this->smtpStream = null;
throw new \Exception(sprintf(dgettext(
"domframework",
"Can't activate STARTTLS %s"
@@ -144,6 +150,7 @@ class Smtp
$this->debug("STARTTLS ACTIVATED\n");
}
} elseif ($this->starttls === "encrypt") {
$this->smtpStream = null;
throw new \Exception(dgettext(
"domframework",
"Server doesn't supports STARTTLS"
@@ -166,6 +173,7 @@ class Smtp
$this->putLine("AUTH LOGIN " . base64_encode($this->user) . "\r\n");
$this->putLine(base64_encode($this->password) . "\r\n");
} else {
$this->smtpStream = null;
throw new \Exception(
dgettext(
"domframework",

View File

@@ -246,9 +246,14 @@ class Tcpclient
"capture_peer_cert_chain" => true,
"SNI_enabled" => true,
]];
$optionsMerged = [];
$optionsMerged["ssl"] = array_merge($optionsBase["ssl"], $options);
stream_set_blocking($this->socket, true);
stream_context_set_option($this->socket, $optionsMerged);
if (version_compare(PHP_VERSION, '8.3.0') <= 0) {
stream_context_set_option($this->socket, $optionsMerged);
} else {
stream_context_set_options($this->socket, $optionsMerged);
}
$php_errormsg = "";
ini_set("track_errors", 1);
$rc = @stream_socket_enable_crypto($this->socket, !!$val, $cryptoMethod);

View File

@@ -228,6 +228,7 @@ class Tcpserver
pcntl_signal(SIGTERM, [$this, "sigTERMINT"]);
pcntl_signal(SIGINT, [$this, "sigTERMINT"]);
cli_set_process_title($this->processName . " main");
$sockServer = [];
foreach ($this->addresses as $key => $address) {
$port = $this->ports[$key];
if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
@@ -495,7 +496,11 @@ class Tcpserver
"verify_peer_name" => false,
]];
stream_set_blocking($this->socket, true);
stream_context_set_option($this->socket, $options);
if (version_compare(PHP_VERSION, '8.3.0') <= 0) {
stream_context_set_option($this->socket, $options);
} else {
stream_context_set_options($this->socket, $options);
}
return @stream_socket_enable_crypto($this->socket, !!$val, $cryptoMethod);
}