Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Apache 2.4. Autoriser la méthode PUT pour un chemin spécifique

Aucune réponse
Avatar
Olivier
--00000000000029f4dc05b232542a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Bonjour,

J'ai des fichiers dans une arboresence /srv/tftp/foo d'une machine sous
Buster
Je souhaite pouvoir "pousser" des fichiers dans cette arborescence avec la
m=C3=A9thode PUT via un serveur Apache 2.4 sur lequel le paquet php est ins=
tall=C3=A9.

Comment proc=C3=A9der proprement ?

J'ai le fichier file_upload.php au contenu suivant:

<?php
//error_log("Current user is ".get_current_user());

$data =3D file_get_contents("php://input");
$output_filename =3D $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];

$code =3D file_put_contents($output_filename, $data);
if (strlen($data) !=3D=3D $code)
error_log("Error code while writing ".$output_filename.": input length
is ".strlen($data)." while output length is ".$code);

?>


J'ai aussi un fichier de config Apache, activ=C3=A9 avec a2enconf :
<VirtualHost *:80>

ServerAdmin webmaster@localhost

Alias /foo /srv/tftp/foo
DocumentRoot /srv/tftp/foo
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /srv/tftp/foo/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
Script PUT /srv/tftp/foo/file_upload.php
</Directory>

</VirtualHost>

J'ai:
curl -T foo.cfg http://192.168.1.1/foo/foo.cfg
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for this URL.</p>
<hr>
<address>Apache/2.4.38 (Raspbian) Server at 192.168.1.1 Port 80</address>
</body></html>

Comment corriger ?

Slts

--00000000000029f4dc05b232542a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Bonjour,</div><div><br></div><div>J&#39;ai des fichie=
rs dans une arboresence /srv/tftp/foo d&#39;une machine sous Buster<br></di=
v><div>Je souhaite pouvoir &quot;pousser&quot; des fichiers dans cette arbo=
rescence avec la m=C3=A9thode PUT via un serveur Apache 2.4 sur lequel le p=
aquet php est install=C3=A9.<br></div><div><br></div><div>Comment proc=C3=
=A9der proprement ?</div><div><br></div><div>J&#39;ai le fichier file_uploa=
d.php au contenu suivant:</div><div><br></div><div>&lt;?php<br>//error_log(=
&quot;Current user is &quot;.get_current_user());<br><br>$data =3D file_get=
_contents(&quot;php://input&quot;);<br>$output_filename =3D $_SERVER[&#39;D=
OCUMENT_ROOT&#39;].$_SERVER[&#39;REQUEST_URI&#39;];<br><br>$code =3D file_p=
ut_contents($output_filename, $data);<br>if (strlen($data) !=3D=3D $code)<b=
r>=C2=A0 =C2=A0error_log(&quot;Error code while writing &quot;.$output_file=
name.&quot;: input length is &quot;.strlen($data).&quot; while output lengt=
h is &quot;.$code);<br><br>?&gt;</div><div><br></div><div><br></div><div>J&=
#39;ai aussi un fichier de config Apache, activ=C3=A9 avec a2enconf :</div>=
<div>&lt;VirtualHost *:80&gt;<br><br>=C2=A0 =C2=A0 ServerAdmin webmaster@lo=
calhost<br><br>=C2=A0 =C2=A0 Alias /foo /srv/tftp/foo<br>=C2=A0 =C2=A0 Docu=
mentRoot /srv/tftp/foo<br>=C2=A0 =C2=A0 ErrorLog ${APACHE_LOG_DIR}/error.lo=
g<br>=C2=A0 =C2=A0 CustomLog ${APACHE_LOG_DIR}/access.log combined<br><br>=
=C2=A0 =C2=A0 &lt;Directory /srv/tftp/foo/&gt;<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 Options Indexes FollowSymLinks MultiViews<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 AllowOverride None<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Require all granted<b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Script PUT /srv/tftp/foo/file_upload.php<br>=
=C2=A0 =C2=A0 &lt;/Directory&gt;<br><br>&lt;/VirtualHost&gt;</div><div><br>=
</div><div>J&#39;ai:</div><div>curl -T foo.cfg <a href=3D"http://192.168.1.=
1/foo/foo.cfg">http://192.168.1.1/foo/foo.cfg</a><br>&lt;!DOCTYPE HTML PUBL=
IC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;<br>&lt;html&gt;&lt;head&gt;<br=
>&lt;title&gt;405 Method Not Allowed&lt;/title&gt;<br>&lt;/head&gt;&lt;body=
&gt;<br>&lt;h1&gt;Method Not Allowed&lt;/h1&gt;<br>&lt;p&gt;The requested m=
ethod PUT is not allowed for this URL.&lt;/p&gt;<br>&lt;hr&gt;<br>&lt;addre=
ss&gt;Apache/2.4.38 (Raspbian) Server at 192.168.1.1 Port 80&lt;/address&gt=
;<br>&lt;/body&gt;&lt;/html&gt;</div><div><br></div><div>Comment corriger ?=
</div><div><br></div><div>Slts<br></div></div>

--00000000000029f4dc05b232542a--

Réponses