PDA

View Full Version : QHttp get unparsed php file from WebDav! and same file firefox parse Ok.



patrik08
20th June 2006, 21:17
I have on server a alias dir called /webdav and other real dir called /setting Password protect from ldapserver alias webdav is password protected on same ldap...

a request to /setting/index.php?lastupdate=1414141414 (unixtime) from firefox parse this file ....

the same request from qt QHttp download the plain text index.php and not the attached sqldump ??? why???

I have spend much time & money to make the Http request with qt in place of libcurl and now the same QHttp give me a big invoice :crying:


QHttp download this file as text! firefox no! (get the file sql ...)

<?php
header("Content-Type: text/plain");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Datum in der Vergangenheit
if(!defined('DIR_SEP')) {
define('DIR_SEP', DIRECTORY_SEPARATOR);
}
print(file_get_contents(dirname(__FILE__).DIR_SEP."CURRENT_OBJEKT_3.sql"));
/* .... update command on server ..... */
?>


my qt friend.... action
full file http://ciz.ch/svnciz/_STATIC_LIBS_QT4/src_0/c_network/gui_wget.cpp



http = new QHttp(this);
stopButton->setEnabled(true);
http->setHost(urls.host(),80);
http->setUser( current_user , current_pass );



apache 2 setting only webdaw dir ForceType text/plain


Alias /webdav/ /home/webdav/angry/
<Location /webdav>
DirectoryIndex webdavnone.html
AuthType Basic
AuthLDAPAuthoritative On
AuthName "Explorer"
AuthLDAPURL ldap://195.90.211.54:389/ou=webdav,dc=box,dc=ciz,dc=ch?uid?sub
require valid-user
DAV On
### to show php as text on browser ####
ForceType text/plain
SetEnv redirect-carefully
<Limit PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
require user angry
</Limit>
</Location>

wysota
20th June 2006, 21:36
I'm not sure if I understood you right. You mean you get different file contents depending on whether you access the location from firefox and QHttp? If so, then you have an error in your webserver configuration. QHttp just sends a request for a file, it doesn't do anything *magic*. And what exactly do you mean by "parsing"? QHttp doesn't do any parsing, it just fetches a block of data, it's not a web browser.

jacek
20th June 2006, 21:45
Use a network sniffer (like Ethereal (http://www.ethereal.com/)) to check if QHttp requests differ from those issued by Firefox, but most likely there's something wrong with your Apache configuration.

patrik08
20th June 2006, 22:32
Use a network sniffer (like Ethereal (http://www.ethereal.com/)) to check if QHttp requests differ from those issued by Firefox, but most likely there's something wrong with your Apache configuration.

If i remove the line ( #######ForceType text/plain ) qt parse the php file....:D .
from /webdav alias ...but now problem .... i find parsed php file on my Hard-Drive and can not edit... on disk !!! . :o

[ less +F webdavaccess.log ] i found ipclient GET /setting/index.php HTTP/1.1 "_" "_" no user agent

QT make PUT & GET as same method!

This is a BUG ...

I make a extra alias domain to qt to resolve problem.....


<Location /webdav>
DirectoryIndex webdavnone.html
AuthType Basic
AuthLDAPAuthoritative On
AuthName "Explorer"
AuthLDAPURL ldap://195.90.211.54:389/ou=webdav,dc=box,dc=ciz,dc=ch?uid?sub
require valid-user
DAV On
#######ForceType text/plain
SetEnv redirect-carefully
<Limit PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
require user client
</Limit>
</Location>

patrik08
20th June 2006, 23:24
The same url /setting/index.php is parsed by libcurl and take the sql dump file...

The server take PUT DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK method on port 80 + AuthType Basic to webdav server hardisk....

Webdav is the same protocoll as subversion http://subversion.tigris.org/ commit
and file is evry time served on plain text ... and binary no....


and GET POST port 80 to normal to human browser + AuthType Basic on/off

On libcurl http://curl.haxx.se/ whit this simple code the file index.php is parsed!
& QT plain/text ..... i suppose the server wand a user agent....




/* return file contenets as qstring */
QString Gui_Setting::file_get_contents( QString fullFileName )
{
QString inside = "";
if (fullFileName.contains("https://", Qt::CaseInsensitive)) {
/* not build in on window only mac & linux*/
return inside;
}


xdcookiefile = QString( "%1biscotti.html" ).arg( WORK_CACHEDIR );
xml_export_file = QString( "%1_xml_export.xml" ).arg( WORK_CACHEDIR );
wwwnetfile = QString( "%1wwwfull.html" ).arg( WORK_CACHEDIR );

if (IsNetFile( fullFileName ) )
{
qt_unlink(wwwnetfile);
/*QString xgeturl = fullFileName; http://shop.ecoplanet.ch/info.php */
QByteArray lop = wwwnetfile.toAscii();
char *localfile = lop.data();
QByteArray der = xdcookiefile.toAscii();
char *xwcookiefile = der.data();
QByteArray ba = fullFileName.toAscii();
char *url = ba.data();
qDebug() << "### entra save to "<< localfile;
qDebug() << "### get url "<< url;
CURL *curl_handle;
FILE *outfile;
curl_global_init(CURL_GLOBAL_ALL);
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
outfile = fopen(localfile, "w");

if (outfile!=NULL) {
/* CURLOPT_COOKIE and must have CURLOPT_COOKIEJAR char * (file to write same as php) */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION , 1);
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS , 2);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT , 15 );
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, _USER_AGENT_CURL_APPS );
curl_easy_setopt(curl_handle, CURLOPT_FILE, outfile);

if (curl_easy_perform(curl_handle)==CURLE_OK) {
fclose(outfile);

QFile filecurl(wwwnetfile);
if (filecurl.exists()) {
if (filecurl.open(QFile::ReadOnly | QFile::Text)) {
inside =filecurl.readAll();
filecurl.close();
if (inside.size() > 1) {
curlerrormsg = "";
qt_unlink(wwwnetfile);
}
}
}

} else {
curlerrormsg = "Error time out to get remote file";
}
}
/* return grab result from local file */
return inside;
}




/* ok is a fake normal local file init ..... */
QFile file(fullFileName);
if (file.exists()) {
if (file.open(QFile::ReadOnly | QFile::Text)) {
inside =file.readAll();
file.close();
if (inside.size() > 1) {
curlerrormsg = "";
}
}
}

return inside;
}

wysota
20th June 2006, 23:27
Could you explain what you mean by "parsed" in this context? Did you mean "interpreted"? It's the webserver which interprets php scripts, Qt doesn't have anything to do with it. Maybe you shouldn't enforce text/plain encoding but try with text/html (or see what type does the php script return).

BTW. Please don't post code irrelevant to the problem on the forum.

patrik08
20th June 2006, 23:38
This file is not parsed apache send file as plain text as is...

index.php
php code

<?php
header("Content-Type: text/plain");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Datum in der Vergangenheit
if(!defined('DIR_SEP')) {
define('DIR_SEP', DIRECTORY_SEPARATOR);
}
print(file_get_contents(dirname(__FILE__).DIR_SEP."CURRENT_OBJEKT_3.sql"));
/* other hidden php code update operatian ....*/
?>



and this file is parsed ... server apache module php interpret php module and
read file CURRENT_OBJEKT_3.sql served

index.php result ... php code up ...
file text


CREATE TABLE PAESI (ID INTEGER PRIMARY KEY,NOME TEXT,CODICE TEXT);
INSERT INTO PAESI VALUES ('1','Italy','IT');
INSERT INTO PAESI VALUES ('2','Germany','DE');
INSERT INTO PAESI VALUES ('3','United Kingdom','GB');
INSERT INTO PAESI VALUES ('4','USA','US');
INSERT INTO PAESI VALUES ('6','Switzerland','CH');
INSERT INTO PAESI VALUES ('7','Andorra','AD');
INSERT INTO PAESI VALUES ('8','United Arab Emirates','AE');
INSERT INTO PAESI VALUES ('9','Afghanistan','AF');
INSERT INTO PAESI VALUES ('10','Antigua and Barbuda','AG');
INSERT INTO PAESI VALUES ('11','Anguilla','AI');
INSERT INTO PAESI VALUES ('12','Albania','AL');
INSERT INTO PAESI VALUES ('13','Armenia','AM');
INSERT INTO PAESI VALUES ('14','Netherlands Antilles','AN');

whoops.slo
21st June 2006, 00:03
do you want to download the php file with php code executed (instead of php code you want data that is a resoult of the execution of the php code)? if so try downloading a php file from other server. Just to test if there is a problem with your code or with the configuration on the server.

patrik08
21st June 2006, 02:24
do you want to download the php file with php code executed (instead of php code you want data that is a resoult of the execution of the php code)? if so try downloading a php file from other server. Just to test if there is a problem with your code or with the configuration on the server.

Logical ... i want to make a button to download the executed php to import 4 sqlite3 table and on the same request a class on server switsch to read modus and lock (a lock file 1kb) the web admin section... So other user can not admin this 4 table.... If the QT client close or upload this 4 table (update) ... unlock and delete this 1kb file.. (only unixtime inside).....

[If i connect the qt client direct to mysql from server or odbc ... evry action is long..... and slow ... sqlite update 100 row on 0.01 sec...] -- [the file download on qt start is 3 seconds...] - [the upload is 1 second on mounted webdav disk...]
I must make the download table on http only for window .... why the mounted webdav disk stay much time on cache.... Mac OSX mount read & write the mounted disk on realtime...
On this method qt work fast ... same as Oracle DB....:rolleyes:



If the client not upload this 4 table .... on server a cron job delete this lock file if is older as 3 Hours....

But i solved this qt bug whit RewriteCond and request go to /extraqtsetting/lastupdate/

a not existing folder .... so qt can not make conflict PUT & GET to become webdav existing dir... and i can uncommend "ForceType text/plain" to not become executed php on my...mountet remote webdav hardisk. :cool:




RewriteEngine on
RewriteCond %{REQUEST_URI} !^/*index.php
RewriteCond %{REQUEST_URI} !^/*robots.txt
RewriteCond %{REQUEST_URI} !^/*favicon
RewriteCond %{REQUEST_URI} !^/*editor/
RewriteCond %{REQUEST_URI} !^/*user/
RewriteCond %{REQUEST_URI} !^/*pic/
RewriteCond %{REQUEST_URI} !^/*icons/
RewriteRule ^/*(.+)$ ./index.php?path=$1 [QSA]

jacek
21st June 2006, 13:23
apache 2 setting only webdaw dir ForceType text/plain


Alias /webdav/ /home/webdav/angry/
<Location /webdav>
DirectoryIndex webdavnone.html
AuthType Basic
AuthLDAPAuthoritative On
AuthName "Explorer"
AuthLDAPURL ldap://195.90.211.54:389/ou=webdav,dc=box,dc=ciz,dc=ch?uid?sub
require valid-user
DAV On
### to show php as text on browser ####
ForceType text/plain
SetEnv redirect-carefully
<Limit PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
require user angry
</Limit>
</Location>

IMO this configuration doesn't prohibit the use of GET method. It just requires a specific user for the other methods.

patrik08
21st June 2006, 19:57
IMO this configuration doesn't prohibit the use of GET method. It just requires a specific user for the other methods.

this config is only to alias

Get & Post method is default from apache ....
<Location /webdav>

The problem by qt QHttp.... wenn user & pass is set....
this is 2 request ... first get normal (like 1000 of homepage)
the 2 request qt send PUT user & pass to the request file...

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 PUT
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8 Authorization

jacek
21st June 2006, 20:23
The problem by qt QHttp.... wenn user & pass is set....
this is 2 request ... first get normal (like 1000 of homepage)
the 2 request qt send PUT user & pass to the request file...
But what is exactly wrong with QHttp? Could you prepare a minimal compilable example that illustates the problem and intercept (using some network sniffer) requests sent by QHttp and Firefox and paste them here, so we can compare them?

patrik08
21st June 2006, 22:12
But what is exactly wrong with QHttp? Could you prepare a minimal compilable example that illustates the problem and intercept (using some network sniffer) requests sent by QHttp and Firefox and paste them here, so we can compare them?


Ok i have the sample.....
http://ppk.ciz.ch/mac_build/qhttp_qt.tar.bz2

And now how configure etheral to read only tcp on port 80?

this i read on firefox live ... header .......




GET /setting/ HTTP/1.1
Host: urlx.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.7.12) Gecko/20050919 Firefox/1.0.7
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: de-de,it;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Authorization: Basic dGVee5zdHF0OnbReexbe235lc3Rx

HTTP/1.x 200 OK
Date: Wed, 21 Jun 2006 20:05:59 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 PHP/5.0.4-0.9sarge1 mod_perl/1.999.21 Perl/v5.8.4
X-Powered-By: PHP/5.0.4-0.9sarge1
Cache-Control: no-cache, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 2639
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/plain

jacek
21st June 2006, 22:22
And now how configure etheral to read only tcp on port 80?
Just enter "http" as filter.