2013-07-11 12:14:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NodeBB  -  A  forum  powered  by  node  in  development  by  designcreateplay 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Copyright  ( C )  2013   DesignCreatePlay  Inc . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									This  program  is  free  software :  you  can  redistribute  it  and / or  modify 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									it  under  the  terms  of  the  GNU  General  Public  License  as  published  by 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									the  Free  Software  Foundation ,  either  version  3  of  the  License ,  or 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									( at  your  option )  any  later  version . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									This  program  is  distributed  in  the  hope  that  it  will  be  useful , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									but  WITHOUT  ANY  WARRANTY ;  without  even  the  implied  warranty  of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									MERCHANTABILITY  or  FITNESS  FOR  A  PARTICULAR  PURPOSE .   See  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									GNU  General  Public  License  for  more  details . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									You  should  have  received  a  copy  of  the  GNU  General  Public  License 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									along  with  this  program .   If  not ,  see  < http : //www.gnu.org/licenses/>.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* /  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 16:25:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Configuration setup
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								nconf  =  require ( 'nconf' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								nconf . argv ( ) . file ( {  file :  _ _dirname  +  '/config.json' } ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 14:02:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  fs  =  require ( 'fs' ) ,  
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston  =  require ( 'winston' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 13:30:48 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									pkg  =  require ( './package.json' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									url  =  require ( 'url' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									meta  =  require ( './src/meta.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-05 11:26:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-21 13:28:55 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Runtime environment
  
						 
					
						
							
								
									
										
										
										
											2013-09-04 12:13:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								global . env  =  process . env . NODE _ENV  ||  'production' ;  
						 
					
						
							
								
									
										
										
										
											2013-06-21 13:28:55 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 16:25:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 14:02:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								winston . remove ( winston . transports . Console ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . add ( winston . transports . Console ,  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									colorize : true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . add ( winston . transports . File ,  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									filename : 'error.log' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									level : 'error' 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-04 12:13:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// TODO: remove once https://github.com/flatiron/winston/issues/280 is fixed
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . err  =  function ( err )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . error ( err . stack ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-11 12:10:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Log GNU copyright info along with server info
  
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								winston . info ( 'NodeBB v'  +  pkg . version  +  ' Copyright (C) 2013 DesignCreatePlay Inc.' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . info ( 'This program comes with ABSOLUTELY NO WARRANTY.' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . info ( 'This is free software, and you are welcome to redistribute it under certain conditions.' ) ;  
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								winston . info ( '' ) ;  
						 
					
						
							
								
									
										
										
										
											2013-07-11 12:10:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( ! nconf . get ( 'setup' )  &&  ! nconf . get ( 'upgrade' )  &&  nconf . get ( 'base_url' ) )  {  
						 
					
						
							
								
									
										
										
										
											2013-07-19 23:56:30 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf . set ( 'url' ,  nconf . get ( 'base_url' )  +  ( nconf . get ( 'use_port' )  ?  ':'  +  nconf . get ( 'port' )  :  '' )  +  nconf . get ( 'relative_path' )  +  '/' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf . set ( 'upload_url' ,  nconf . get ( 'url' )  +  'uploads/' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-19 13:31:04 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston . info ( 'Initializing NodeBB v'  +  pkg . version  +  ', on port '  +  nconf . get ( 'port' )  +  ', using Redis store at '  +  nconf . get ( 'redis:host' )  +  ':'  +  nconf . get ( 'redis:port' )  +  '.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-04 14:08:24 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( process . env . NODE _ENV  ===  'development' )  winston . info ( 'Base Configuration OK.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									meta . configs . init ( function ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-26 17:10:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Initial setup for Redis & Reds
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var 	reds  =  require ( 'reds' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										RDB  =  require ( './src/redis.js' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										reds . createClient  =  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  reds . client  ||  ( reds . client  =  RDB ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 14:02:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  categories  =  require ( './src/categories.js' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											templates  =  require ( './public/src/templates.js' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											webserver  =  require ( './src/webserver.js' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											websockets  =  require ( './src/websockets.js' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											plugins  =  require ( './src/plugins' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											admin  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'categories' :  require ( './src/admin/categories.js' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 14:02:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										global . templates  =  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										templates . init ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											'header' ,  'footer' ,  'logout' ,  'outgoing' ,  'admin/header' ,  'admin/footer' ,  'admin/index' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											'emails/reset' ,  'emails/reset_plaintext' ,  'emails/email_confirm' ,  'emails/email_confirm_plaintext' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											'emails/header' ,  'emails/footer' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 14:02:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											'noscript/header' ,  'noscript/home' ,  'noscript/category' ,  'noscript/topic' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-27 14:02:57 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										templates . ready ( webserver . init ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'upgrade' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									meta . configs . init ( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										require ( './src/upgrade' ) . upgrade ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// New install, ask setup questions
 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( nconf . get ( 'setup' ) )  winston . info ( 'NodeBB Setup Triggered via Command Line' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-03 22:21:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									else  winston . warn ( 'Configuration not found, starting NodeBB setup' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									meta . config  =  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 16:12:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var 	install  =  require ( './src/install' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston . info ( 'Welcome to NodeBB!' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . info ( 'This looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . info ( 'Press enter to accept the default setting (shown in brackets).' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 16:12:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									install . setup ( function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											winston . error ( 'There was a problem completing NodeBB setup: ' ,  err . message ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 16:12:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-06 22:22:42 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											winston . info ( 'NodeBB Setup Completed.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 16:12:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 16:12:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										process . exit ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-16 15:22:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}