Feature #2163
closedMultiple use of '?' in mysql-vhost.sql
Description
Can someone please rewrite the code for mod_mysql_vhost to parse at least two or more occurrences of the questionmark?
in trunk it should be line 142 (now) and in branches it should be following link:
PS:
The destination version could be 1.4.x or later.
Files
Updated by phpmysqlfreak almost 15 years ago
- File mod_mysql_vhost.c mod_mysql_vhost.c added
- % Done changed from 0 to 10
depending on the sources of 1.4.19 - installed on my system - i tried to change some things.
now i get some other errors like following, while testing some testbuilds.
Feb 11 18:01:51 atom019 kernel: lighttpd[1613]: segfault at 0 ip b7519bbf sp bffe9b20 error 6 in libc-2.7.so[b74a7000+138000] Feb 11 18:06:33 atom019 kernel: lighttpd[2515]: segfault at 0 ip b747dbbf sp bfe5c3b0 error 6 in libc-2.7.so[b740b000+138000] Feb 11 18:10:29 atom019 kernel: lighttpd[2558]: segfault at 0 ip b7505bbf sp bff5f510 error 6 in libc-2.7.so[b7493000+138000] Feb 11 18:10:34 atom019 kernel: lighttpd[2572]: segfault at 0 ip b7497bbf sp bfb8b830 error 6 in libc-2.7.so[b7425000+138000] Feb 11 18:19:04 atom019 kernel: lighttpd[2599]: segfault at 0 ip b7458bbf sp bf909600 error 6 in libc-2.7.so[b73e6000+138000] Feb 11 18:19:50 atom019 kernel: lighttpd[2616]: segfault at 0 ip b74adbbf sp bfe44700 error 6 in libc-2.7.so[b743b000+138000] Feb 11 18:26:44 atom019 kernel: lighttpd[2642]: segfault at 0 ip b74e4bbf sp bfc5cf50 error 6 in libc-2.7.so[b7472000+138000] Feb 11 18:32:18 atom019 kernel: lighttpd[2668]: segfault at 0 ip b7475bbf sp bfc30540 error 6 in libc-2.7.so[b7403000+138000] Feb 11 18:35:49 atom019 kernel: lighttpd[2687]: segfault at 0 ip b74ecbbf sp bfe081c0 error 6 in libc-2.7.so[b747a000+138000] Feb 11 18:37:47 atom019 kernel: lighttpd[2706]: segfault at 0 ip b749bbbf sp bfc38f60 error 6 in libc-2.7.so[b7429000+138000] Feb 11 19:05:48 atom019 kernel: lighttpd[2749]: segfault at 0 ip b74b5bbf sp bf856320 error 6 in libc-2.7.so[b7443000+138000]
The attached file has some modifications - first I added mysql_mid between mysql_pre/post. to assemble the complete query i replicated some lines at about line 370.
with some output to the error log i verified, that the string is splittet into 3 parts (for me enough, but normally a dirty version with strrchr) - not 2, like before.
Updated by lonnyk over 14 years ago
I was just looking into this and I'm not sure how this can be used in real life with two '?'.
Keep in mind, the '?' is replaced by the URI (hostname) that is being used to hit the server. So if you had:
mysql-vhost.sql = "SELECT docroot FROM domains WHERE domain='?';"
And my site hit the server the query ran would be:
SELECT docroot FROM domains WHERE domain='lonnylot.com';
I don't see how having that in two separate places would make any sense. Can you please post the query you're running as well as an example MySQL table so I can see why this is needed before adding the feature?
Updated by phpmysqlfreak over 14 years ago
My Setup is the following:
MySQL-Table:
id subdomain domain 2015 www example.tld 2016 www2 example.tld
the mysql-table contains some data more (for ftp-access, etc.), while the username contains the user-id - in all services.
Now I want this module using a query like this:
SELECT CONCAT("/webs/",id) AS docroot FROM users WHERE CONCAT(subdomain,".",domain) = '?' OR CONCAT("web-",id,".",domain) = '?';
One questionmark was not changed, so I tried to change the code. But while running the updated mod, I got the errors mentioned above, so I opened this feature-request.
So one webspace should be accessible by two names:
web-2015.example.tld OR www.example.tld should give the content of /webs/2015/
web-2016.example.tld OR www2.example.tld should give the content of /webs/2016/
Updated by lonnyk over 14 years ago
- File lighttpd_feature_2163.diff lighttpd_feature_2163.diff added
- Status changed from New to Patch Pending
Attached is a diff for this feature against the version in 1.4.26
Let me know what you think.
Updated by phpmysqlfreak over 14 years ago
I applied the patch with following summary:
The query is set to right format. All occurences of "?" are replaced.
Now the server is listening on both applied addresses and my aim was reached fully.
Thank you for your help.
I will follow the function with much care and report bugs, if I find any.
Updated by tronox@hotmail.com over 11 years ago
Seems like the functions from: http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring would do the job of this.
Updated by tronox@hotmail.com over 11 years ago
- File mod_mysql_vhost.c mod_mysql_vhost.c added
- File mod_mysql_vhost.so added
Attached is the source code and a compiles .so file for the mod_mysql_vhost. This one allows for multiple '?' in the SQL query. And if I knew more about c I could even get it to escape the URI just to be safe (left the code in there that I was working on).
Updated by tronox@hotmail.com over 11 years ago
- File mod_mysql_vhost.c mod_mysql_vhost.c added
Further Edited the mod_mysql_vhost.c to allow for user directories to be listed through mysql.
SQL Table & Sample Data:
CREATE TABLE IF NOT EXISTS `vhosts` ( `Uid` int(10) unsigned NOT NULL, `vhost` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `rootdir` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `admin` varchar(255) COLLATE utf8_bin DEFAULT '', `extra_php_config` text COLLATE utf8_bin, UNIQUE KEY `vhostname` (`vhost`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='vhosts'; INSERT INTO `vhosts` (`Uid`, `vhost`, `rootdir`, `admin`, `extra_php_config`) VALUES (5000, 'example.com', '/var/www/vhosts/example.com/subdomains/test', 'admin@example.com', ''), (5000, '~shinrai', '/var/www/vhosts/example.com/subdomains/test', 'admin@example.com', '');
http://localhost/~shinrai/ or http://example.com/ Will serve up the directory '/var/www/vhosts/example.com/subdomains/test'
Updated by tronox@hotmail.com over 11 years ago
Forgot to give the sample SQL for the config:
SELECT rootdir FROM (SELECT IF((SELECT rootdir FROM vhosts WHERE vhost='~@@') IS NOT NULL,(SELECT rootdir FROM vhosts WHERE vhost='~@@'),IF((SELECT rootdir FROM vhosts WHERE vhost='?') IS NOT NULL,(SELECT rootdir FROM vhosts WHERE vhost='?'),(SELECT rootdir FROM vhosts WHERE '?' like vhost))) as rootdir) as a WHERE rootdir IS NOT NULL
Updated by gstrauss about 8 years ago
- Target version changed from 1.4.x to 1.4.42
- % Done changed from 10 to 0
PSA: anyone using tronox (shinrai) patches above, the patches have serious memory leaks upon every request to URI beginning "/~username"
I re-implemented much simplified support for replacing multiple '?' with escaped URI authority in the MySQL query string.
However, the userdir feature (part of some of the contributed patches above) is not included. If it is desirable to add mod_userdir features into mod_mysql_vhost, giving the option to replace use of mod_userdir with mod_mysql_vhost queries, then there should be a new directive in mod_mysql_vhost to enable this feature (and the memory leaks in the contributed patches must be removed).
Updated by gstrauss about 8 years ago
- Status changed from Patch Pending to Fixed
- % Done changed from 0 to 100
Applied in changeset 145ddc2ee72cfed9cedaee85dce69047755aa995.
Also available in: Atom