DotaNoobs main site.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

488 lines
12 KiB

  1. import os
  2. import re
  3. from time import strftime, gmtime
  4. from hashlib import sha256
  5. from peewee import *
  6. from app import app, cache, db
  7. board_db = MySQLDatabase(app.config['FORUM_NAME'], **{'passwd': app.config['FORUM_PASSWORD'],
  8. 'host': app.config['FORUM_HOST'], 'user': app.config['FORUM_USERNAME']})
  9. def registerUserForumId(user, username, password):
  10. try:
  11. u = Users.filter(name=username).get()
  12. hashpass = sha256(password+app.config['FORUM_SALT']+u.pss).hexdigest()
  13. if hashpass == u.password:
  14. user.forum_id = u.id
  15. db.session.commit()
  16. return {"forum_name":u.name, "forum_id":u.id}
  17. except DoesNotExist:
  18. pass
  19. return False
  20. @cache.memoize(60*5)
  21. def latest_news(num=3):
  22. latest_news = []
  23. try:
  24. board_db.connect()
  25. news_forum = Forums.get(fn.Lower(Forums.title) % '%news%')
  26. for thread in Threads.select().where(
  27. Threads.forum == news_forum.id).order_by(Threads.date.desc()).limit(num):
  28. # Last revision of the first post
  29. post = Posts.select().where(Posts.thread == thread.id).get()
  30. raw_text = PostsText.select().where(PostsText.pid == post.id).order_by(PostsText.revision.desc()).limit(1).get()
  31. #remove BBCode
  32. text = re.sub(r"\[(\/)?(\w+)\]", '', raw_text.text)
  33. timestamp = thread.date
  34. date = strftime('%B %d, %Y %H:%M:%S UTC', gmtime(timestamp))
  35. if not timestamp:
  36. post = Posts.select().where(Posts.thread == thread.id).get()
  37. timestamp = post and post.date
  38. url = 'http://board.dotanoobs.com/?page=thread&id=%d' % thread.id
  39. latest_news.append({'title':thread.title, 'text':text, 'date':date, 'timestamp':timestamp, 'url':url})
  40. except Exception as e:
  41. latest_news.append({'title':'Error with forum db', 'text':e, 'url':''})
  42. finally:
  43. board_db.close()
  44. return latest_news
  45. class UnknownFieldType(object):
  46. pass
  47. class BaseModel(Model):
  48. class Meta:
  49. database = board_db
  50. class Badges(BaseModel):
  51. color = IntegerField()
  52. name = CharField()
  53. owner = IntegerField()
  54. class Meta:
  55. db_table = 'badges'
  56. class Blockedlayouts(BaseModel):
  57. blockee = IntegerField()
  58. user = IntegerField()
  59. class Meta:
  60. db_table = 'blockedlayouts'
  61. class Categories(BaseModel):
  62. corder = IntegerField()
  63. name = CharField()
  64. class Meta:
  65. db_table = 'categories'
  66. class Enabledplugins(BaseModel):
  67. plugin = CharField()
  68. class Meta:
  69. db_table = 'enabledplugins'
  70. class Forummods(BaseModel):
  71. forum = IntegerField()
  72. user = IntegerField()
  73. class Meta:
  74. db_table = 'forummods'
  75. class Forums(BaseModel):
  76. catid = IntegerField()
  77. description = TextField(null=True)
  78. forder = IntegerField()
  79. hidden = IntegerField()
  80. lastpostdate = IntegerField()
  81. lastpostid = IntegerField()
  82. lastpostuser = IntegerField()
  83. minpower = IntegerField()
  84. minpowerreply = IntegerField()
  85. minpowerthread = IntegerField()
  86. numposts = IntegerField()
  87. numthreads = IntegerField()
  88. title = CharField()
  89. class Meta:
  90. db_table = 'forums'
  91. class Guests(BaseModel):
  92. bot = IntegerField()
  93. date = IntegerField()
  94. ip = CharField()
  95. lastforum = IntegerField()
  96. lasturl = CharField()
  97. useragent = CharField()
  98. class Meta:
  99. db_table = 'guests'
  100. class Ignoredforums(BaseModel):
  101. fid = IntegerField()
  102. uid = IntegerField()
  103. class Meta:
  104. db_table = 'ignoredforums'
  105. class Ip2C(BaseModel):
  106. cc = CharField(null=True)
  107. ip_from = BigIntegerField()
  108. ip_to = BigIntegerField()
  109. class Meta:
  110. db_table = 'ip2c'
  111. class Ipbans(BaseModel):
  112. date = IntegerField()
  113. ip = CharField()
  114. reason = CharField()
  115. class Meta:
  116. db_table = 'ipbans'
  117. class Log(BaseModel):
  118. date = IntegerField()
  119. forum = IntegerField()
  120. forum2 = IntegerField()
  121. ip = CharField()
  122. pm = IntegerField()
  123. post = IntegerField()
  124. text = CharField()
  125. thread = IntegerField()
  126. type = CharField()
  127. user = IntegerField()
  128. user2 = IntegerField()
  129. class Meta:
  130. db_table = 'log'
  131. class Misc(BaseModel):
  132. hotcount = IntegerField()
  133. maxpostsday = IntegerField()
  134. maxpostsdaydate = IntegerField()
  135. maxpostshour = IntegerField()
  136. maxpostshourdate = IntegerField()
  137. maxusers = IntegerField()
  138. maxusersdate = IntegerField()
  139. maxuserstext = TextField(null=True)
  140. milestone = TextField(null=True)
  141. version = IntegerField()
  142. views = IntegerField()
  143. class Meta:
  144. db_table = 'misc'
  145. class Moodavatars(BaseModel):
  146. mid = IntegerField()
  147. name = CharField()
  148. uid = IntegerField()
  149. class Meta:
  150. db_table = 'moodavatars'
  151. class Notifications(BaseModel):
  152. description = TextField(null=True)
  153. link = IntegerField()
  154. linklocation = CharField()
  155. time = IntegerField()
  156. title = CharField()
  157. type = CharField()
  158. uid = IntegerField()
  159. class Meta:
  160. db_table = 'notifications'
  161. class Pmsgs(BaseModel):
  162. date = IntegerField()
  163. deleted = IntegerField()
  164. drafting = IntegerField()
  165. ip = CharField()
  166. msgread = IntegerField()
  167. userfrom = IntegerField()
  168. userto = IntegerField()
  169. class Meta:
  170. db_table = 'pmsgs'
  171. class PmsgsText(BaseModel):
  172. pid = IntegerField()
  173. text = TextField(null=True)
  174. title = CharField()
  175. class Meta:
  176. db_table = 'pmsgs_text'
  177. class Poll(BaseModel):
  178. briefing = TextField(null=True)
  179. closed = IntegerField()
  180. doublevote = IntegerField()
  181. question = CharField()
  182. class Meta:
  183. db_table = 'poll'
  184. class PollChoices(BaseModel):
  185. choice = CharField()
  186. color = CharField()
  187. poll = IntegerField()
  188. class Meta:
  189. db_table = 'poll_choices'
  190. class Pollvotes(BaseModel):
  191. choiceid = IntegerField()
  192. poll = IntegerField()
  193. user = IntegerField()
  194. class Meta:
  195. db_table = 'pollvotes'
  196. class Postplusones(BaseModel):
  197. post = IntegerField()
  198. user = IntegerField()
  199. class Meta:
  200. db_table = 'postplusones'
  201. class Posts(BaseModel):
  202. currentrevision = IntegerField()
  203. date = IntegerField()
  204. deleted = IntegerField()
  205. deletedby = IntegerField()
  206. ip = CharField()
  207. mood = IntegerField()
  208. num = IntegerField()
  209. options = IntegerField()
  210. postplusones = IntegerField()
  211. reason = CharField()
  212. thread = IntegerField()
  213. user = IntegerField()
  214. class Meta:
  215. db_table = 'posts'
  216. class PostsText(BaseModel):
  217. date = IntegerField()
  218. pid = IntegerField(primary_key=True)
  219. revision = IntegerField()
  220. text = TextField(null=True)
  221. user = IntegerField()
  222. class Meta:
  223. db_table = 'posts_text'
  224. class Proxybans(BaseModel):
  225. ip = CharField()
  226. class Meta:
  227. db_table = 'proxybans'
  228. class Queryerrors(BaseModel):
  229. cookie = TextField(null=True)
  230. error = TextField(null=True)
  231. get = TextField(null=True)
  232. ip = CharField()
  233. post = TextField(null=True)
  234. query = TextField(null=True)
  235. time = IntegerField()
  236. user = IntegerField()
  237. class Meta:
  238. db_table = 'queryerrors'
  239. class Reports(BaseModel):
  240. hidden = IntegerField()
  241. ip = CharField()
  242. request = TextField(null=True)
  243. severity = IntegerField()
  244. text = CharField()
  245. time = IntegerField()
  246. user = IntegerField()
  247. class Meta:
  248. db_table = 'reports'
  249. class Sessions(BaseModel):
  250. autoexpire = IntegerField()
  251. expiration = IntegerField()
  252. id = CharField()
  253. iplock = IntegerField()
  254. iplockaddr = CharField()
  255. lastip = CharField()
  256. lasttime = IntegerField()
  257. lasturl = CharField()
  258. user = IntegerField()
  259. class Meta:
  260. db_table = 'sessions'
  261. class Settings(BaseModel):
  262. name = CharField()
  263. plugin = CharField()
  264. value = TextField(null=True)
  265. class Meta:
  266. db_table = 'settings'
  267. class Smilies(BaseModel):
  268. code = CharField()
  269. image = CharField()
  270. class Meta:
  271. db_table = 'smilies'
  272. class Threads(BaseModel):
  273. closed = IntegerField()
  274. date = IntegerField()
  275. firstpostid = IntegerField()
  276. forum = IntegerField()
  277. icon = CharField()
  278. lastpostdate = IntegerField()
  279. lastposter = IntegerField()
  280. lastpostid = IntegerField()
  281. poll = IntegerField()
  282. replies = IntegerField()
  283. sticky = IntegerField()
  284. title = CharField()
  285. user = IntegerField()
  286. views = IntegerField()
  287. class Meta:
  288. db_table = 'threads'
  289. class Threadsread(BaseModel):
  290. date = IntegerField()
  291. thread = IntegerField()
  292. class Meta:
  293. db_table = 'threadsread'
  294. class Uploader(BaseModel):
  295. category = IntegerField()
  296. date = IntegerField()
  297. description = CharField()
  298. downloads = IntegerField()
  299. filename = CharField()
  300. private = IntegerField()
  301. user = IntegerField()
  302. class Meta:
  303. db_table = 'uploader'
  304. class UploaderCategories(BaseModel):
  305. description = TextField(null=True)
  306. name = CharField()
  307. ord = IntegerField()
  308. class Meta:
  309. db_table = 'uploader_categories'
  310. class Usercomments(BaseModel):
  311. cid = IntegerField()
  312. date = IntegerField()
  313. text = TextField(null=True)
  314. uid = IntegerField()
  315. class Meta:
  316. db_table = 'usercomments'
  317. class Usergroups(BaseModel):
  318. inherits = IntegerField()
  319. permissions = TextField(null=True)
  320. title = CharField()
  321. class Meta:
  322. db_table = 'usergroups'
  323. class Userpermissions(BaseModel):
  324. permissions = TextField(null=True)
  325. uid = IntegerField()
  326. class Meta:
  327. db_table = 'userpermissions'
  328. class Users(BaseModel):
  329. bio = TextField(null=True)
  330. birthday = IntegerField()
  331. blocklayouts = IntegerField()
  332. color = CharField()
  333. dateformat = CharField()
  334. displayname = CharField()
  335. email = CharField()
  336. fontsize = IntegerField()
  337. forbiddens = CharField()
  338. globalblock = IntegerField()
  339. hascolor = IntegerField()
  340. homepagename = CharField()
  341. homepageurl = CharField()
  342. karma = IntegerField()
  343. lastactivity = IntegerField()
  344. lastforum = IntegerField()
  345. lastip = CharField()
  346. lastknownbrowser = TextField(null=True)
  347. lastposttime = IntegerField()
  348. lasturl = CharField()
  349. location = CharField()
  350. loggedin = IntegerField()
  351. lostkey = CharField()
  352. lostkeytimer = IntegerField()
  353. minipic = CharField()
  354. name = CharField()
  355. newcomments = IntegerField()
  356. password = CharField()
  357. picture = CharField()
  358. pluginsettings = TextField(null=True)
  359. postheader = TextField(null=True)
  360. postplusones = IntegerField()
  361. postplusonesgiven = IntegerField()
  362. posts = IntegerField()
  363. postsperpage = IntegerField()
  364. powerlevel = IntegerField()
  365. pss = CharField()
  366. rankset = CharField()
  367. realname = CharField()
  368. regdate = IntegerField()
  369. sex = IntegerField()
  370. showemail = IntegerField()
  371. signature = TextField(null=True)
  372. signsep = IntegerField()
  373. tempbanpl = IntegerField()
  374. tempbantime = BigIntegerField()
  375. theme = CharField()
  376. threadsperpage = IntegerField()
  377. timeformat = CharField()
  378. timezone = FloatField()
  379. title = CharField()
  380. usebanners = IntegerField()
  381. class Meta:
  382. db_table = 'users'
  383. class Uservotes(BaseModel):
  384. uid = IntegerField()
  385. up = IntegerField()
  386. voter = IntegerField()
  387. class Meta:
  388. db_table = 'uservotes'
  389. class WikiPages(BaseModel):
  390. flags = IntegerField()
  391. id = CharField()
  392. revision = IntegerField()
  393. class Meta:
  394. db_table = 'wiki_pages'
  395. class WikiPagesText(BaseModel):
  396. date = IntegerField()
  397. id = CharField()
  398. revision = IntegerField()
  399. text = TextField(null=True)
  400. user = IntegerField()
  401. class Meta:
  402. db_table = 'wiki_pages_text'