This repository has been archived by the owner on Jul 19, 2020. It is now read-only.
/
config.py
214 lines (189 loc) · 8.41 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
"""Saku Configuration.
"""
#
# Copyright (c) 2005-2012 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
import re
import sys
import os.path
import ConfigParser
def _get_value(parser, section, key, default, vtype=''):
"""Get config value or default value."""
try:
if vtype == 'int':
return parser.getint(section, key)
elif vtype == 'path':
return os.path.expanduser(parser.get(section, key))
elif vtype == 'boolean':
return parser.getboolean(section, key)
else:
return parser.get(section, key)
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
return default
def _get_version():
"""Get Saku version for useragent and servername.
"""
version = 'Unstable'
version_file = os.path.join(docroot, file_dir, 'version.txt')
if (not re.search(r'^\d', version)) and os.path.isfile(version_file):
try:
f = open(version_file)
version = f.read().strip()
f.close()
except (IOError, OSError):
pass
return 'shinGETsu/0.7 (Saku-Ex/%s)' % version
# External config files.
_extconf = ConfigParser.SafeConfigParser()
_extconf.read(['file/saku.ini',
'/usr/local/etc/saku/saku.ini',
'/etc/saku/saku.ini',
os.path.expanduser('~/.saku/saku.ini')])
# Application types
types = ("thread",)
port = _get_value(_extconf, 'Network', 'port', 8000, 'int')
max_connection = _get_value(_extconf, 'Network', 'max_connection', 20, 'int')
docroot = _get_value(_extconf, 'Path', 'docroot', './www', 'path')
log_dir = _get_value(_extconf, 'Path', 'log_dir', './log', 'path')
run_dir = _get_value(_extconf, 'Path', 'run_dir', '../run', 'path')
file_dir = _get_value(_extconf, 'Path', 'file_dir', '../file', 'path')
cache_dir = _get_value(_extconf, 'Path', 'cache_dir', '../cache', 'path')
template_dir = _get_value(_extconf, 'Path', 'template_dir',
'../template', 'path')
spam_list = _get_value(_extconf, 'Path', 'spam_list',
'../file/spam.txt', 'path')
initnode_list = _get_value(_extconf, 'Path', 'initnode_list',
'../file/initnode.txt', 'path')
node_allow = _get_value(_extconf, 'Path', 'node_allow',
'../file/node_allow.txt', 'path')
node_deny = _get_value(_extconf, 'Path', 'node_deny',
'../file/node_deny.txt', 'path')
apache_docroot = _get_value(_extconf, 'Path', 'apache_docroot',
'/var/local/www/shingetsu', 'path')
admin = _get_value(_extconf, 'Gateway', 'admin', r'^127')
friend = _get_value(_extconf, 'Gateway', 'friend', r'^127')
visitor = _get_value(_extconf, 'Gateway', 'visitor', r'.')
server_name = _get_value(_extconf, 'Gateway', 'server_name', '')
tag_size = _get_value(_extconf, 'Gateway', 'tag_size', 20, 'int')
rss_range = _get_value(_extconf, 'Gateway', 'rss_range', 3*24*60*60, 'int')
top_recent_range = _get_value(_extconf, 'Gateway',
'top_recent_range', 3*24*60*60, 'int')
recent_range = _get_value(_extconf, 'Gateway', 'recent_range',
31*24*60*60, 'int')
record_limit = _get_value(_extconf, 'Gateway', 'record_limit', 2048, 'int')
proxy_destination = _get_value(_extconf, 'Gateway', 'proxy_destination', '')
tmpaddr_span = _get_value(_extconf, 'Gateway', 'tmpaddr_span', 60*60, 'int')
re_admin = re.compile(admin)
re_friend = re.compile(friend)
re_visitor = re.compile(visitor)
template_suffix = '.txt'
tklog = _get_value(_extconf, 'Interface', 'tklog', 100, 'int')
# Seconds; 0 for infinity
save_record = {}
save_size = {} # It is not seconds, but number.
get_range = {}
sync_range = {}
save_removed = {}
for type in types:
ctype = 'Application %s' % type.capitalize()
save_record[type] = \
_get_value(_extconf, ctype, 'save_record', 0, 'int')
save_size[type] = \
_get_value(_extconf, ctype, 'save_size', 1, 'int')
get_range[type] = \
_get_value(_extconf, ctype, 'get_range', 31*24*60*60, 'int')
sync_range[type] = \
_get_value(_extconf, ctype, 'sync_range', 10*24*60*60, 'int')
save_removed[type] = \
_get_value(_extconf, ctype, 'save_removed', 50*24*60*60, 'int')
thread_page_size = _get_value(_extconf,
'Application Thread',
'page_size', 50, 'int')
thumbnail_size = _get_value(_extconf,
'Application Thread',
'thumbnail_size', None, '')
force_thumbnail = _get_value(_extconf,
'Application Thread',
'force_thumbnail', False, 'boolean')
client_cycle = 5*60 # Seconds; Access client.cgi
ping_cycle = 5*60 # Seconds; Check nodes
sync_cycle = 5*60*60 # Seconds; Check cache
init_cycle = 20*60 # Seconds; Check initial node
update_range = 24*60*60 # Seconds
wait_update = 10 # Seconds
time_error = 60 # Seconds
search_timeout = 10*60 # Seconds
timeout = 20 # Seconds; Timeout for TCP
get_timeout = 2*60 # Seconds; Timeout for /get
client_timeout = 30*60 # Seconds; client_timeout < sync_cycle
tk_save_warn = 5*60 # Seconds
retry = 5 # Times; Common setting
retry_join = 2 # Times; Join network
nodes = 5 # Nodes keeping in node list
share_nodes = 5 # Nodes having the file
search_depth = 30 # Search node size
tiedfile_cache_size = 30
broadcast = "../tool/broadcast.py" # Broadcast script path
rss = "1" # RSS version; must be "1"
google = "http://www.google.co.jp/search"
language = "en" # Language code (see RFC3066)
# regexp
robot = r"Google|bot|Yahoo|archiver|Wget|Crawler|Yeti|Baidu"
dnsname = "" # Server name for shinGETsu protocol
query_separator = "/" # Must be "/"
root_path = "/" # path of URI for root
motd = file_dir + "/motd.txt"
node = run_dir + "/node.txt"
search = run_dir + "/search.txt"
update = run_dir + "/update.txt"
recent = run_dir + "/recent.txt"
client_log = run_dir + "/client.txt"
lock = run_dir + "/lock.txt"
search_lock = run_dir + "/touch.txt"
admin_search = run_dir + "/admintouch.txt"
admin_sid = run_dir + "/sid.txt"
pid = run_dir + "/pid.txt"
lookup = run_dir + "/lookup.txt"
taglist = run_dir + "/tag.txt"
sugtag = run_dir + "/sugtag.txt"
tmpaddr_file = run_dir + '/tmpaddr.txt'
read_status = run_dir + '/readstatus.txt'
server = root_path + "server.cgi"
client = root_path + "client.cgi"
gateway = root_path + "gateway.cgi"
thread_cgi = root_path + "thread.cgi"
admin_cgi = root_path + "admin.cgi"
xsl = root_path + "rss1.xsl"
root_index = _get_value(_extconf, 'Gateway', 'root_index', gateway)
application = {"thread": thread_cgi}
use_cookie = True
save_cookie = 7*24*60*60 # Seconds
title_limit = 30 # Charactors
# asis, md5, sha1, sha224, sha256, sha384, or sha512
cache_hash_method = 'asis'
version = _get_version()
init_node = ['node.shingetsu.info:8000/server.cgi',
'pushare.zenno.info:8000/server.cgi']
flags = [] # It is set by script