]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SphinxSearch/scripts/gen_config.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / SphinxSearch / scripts / gen_config.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - the distributed open-source microblogging tool
5  * Copyright (C) 2009, StatusNet, Inc.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
22
23 $longoptions = array('base=', 'network');
24
25 $helptext = <<<END_OF_TRIM_HELP
26 Generates sphinx.conf file based on StatusNet configuration.
27     --base               Base dir to Sphinx install
28                          (default /usr/local)
29     --network            Use status_network global config table
30                          (non-functional at present)
31
32
33 END_OF_TRIM_HELP;
34
35 require_once INSTALLDIR . '/scripts/commandline.inc';
36 require dirname(__FILE__) . '/sphinx-utils.php';
37
38
39 $timestamp = date('r');
40 print <<<END
41 #
42 # Sphinx configuration for StatusNet
43 # Generated {$timestamp}
44 #
45
46 END;
47
48 sphinx_iterate_sites('sphinx_site_template');
49
50 print <<<END
51
52 indexer
53 {
54     mem_limit               = 300M
55 }
56
57 searchd
58 {
59     port                    = 3312
60     log                     = {$base}/log/searchd.log
61     query_log               = {$base}/log/query.log
62     read_timeout            = 5
63     max_children            = 30
64     pid_file                = {$base}/log/searchd.pid
65     max_matches             = 1000
66     seamless_rotate         = 1
67     preopen_indexes         = 0
68     unlink_old              = 1
69 }
70
71 END;
72
73 /**
74  * Build config entries for a single site
75  * @fixme we only seem to have master DB currently available...
76  */
77 function sphinx_site_template($sn)
78 {
79     return
80         sphinx_template($sn,
81             'profile',
82             'SELECT id, UNIX_TIMESTAMP(created) as created_ts, nickname, fullname, location, bio, homepage FROM profile',
83             'SELECT * FROM profile where id = $id') .
84         sphinx_template($sn,
85             'notice',
86             'SELECT id, UNIX_TIMESTAMP(created) as created_ts, content FROM notice',
87             'SELECT * FROM notice where notice.id = $id AND notice.is_local != -2');
88 }
89
90 function sphinx_template($sn, $table, $query, $query_info)
91 {
92     $base = sphinx_base();
93     $dbtype = common_config('db', 'type');
94
95     print <<<END
96
97 #
98 # {$sn->sitename}
99 #
100 source {$sn->dbname}_src_{$table}
101 {
102     type                    = {$dbtype}
103     sql_host                = {$sn->dbhost}
104     sql_user                = {$sn->dbuser}
105     sql_pass                = {$sn->dbpass}
106     sql_db                  = {$sn->dbname}
107     sql_query_pre           = SET NAMES utf8;
108     sql_query               = {$query}
109     sql_query_info          = {$query_info}
110     sql_attr_timestamp      = created_ts
111 }
112
113 index {$sn->dbname}_{$table}
114 {
115     source                  = {$sn->dbname}_src_{$table}
116     path                    = {$base}/data/{$sn->dbname}_{$table}
117     docinfo                 = extern
118     charset_type            = utf-8
119     min_word_len            = 3
120 }
121
122
123 END;
124 }