2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									NodeBB  -  A  better  forum  platform  for  the  modern  web 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									https : //github.com/NodeBB/NodeBB/
 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-21 21:11:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Copyright  ( C )  2013 - 2017   NodeBB  Inc . 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									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/>.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* /  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-18 01:56:23 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								'use strict' ;  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-12 15:22:58 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( require . main  !==  module )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require . main . require  =  function  ( path )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  require ( path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  nconf  =  require ( 'nconf' ) ;  
						 
					
						
							
								
									
										
										
										
											2017-06-22 11:10:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								nconf . argv ( ) . env ( {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									separator :  '__' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									lowerCase :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-18 12:01:33 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  url  =  require ( 'url' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  async  =  require ( 'async' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  winston  =  require ( 'winston' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  path  =  require ( 'path' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  pkg  =  require ( './package.json' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var  file  =  require ( './src/file' ) ;  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								global . env  =  process . env . NODE _ENV  ||  'production' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . remove ( winston . transports . Console ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								winston . add ( winston . transports . Console ,  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									colorize :  true , 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-13 11:43:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									timestamp :  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  date  =  new  Date ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-18 12:51:13 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  nconf . get ( 'json-logging' )  ?  date . toJSON ( )  : 	date . getDate ( )  +  '/'  +  ( date . getMonth ( )  +  1 )  +  ' '  +  date . toTimeString ( ) . substr ( 0 ,  8 )  +  ' ['  +  global . process . pid  +  ']' ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-02 15:31:19 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									level :  nconf . get ( 'log-level' )  ||  ( global . env  ===  'production'  ?  'info'  :  'verbose' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 19:48:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									json :  ( ! ! nconf . get ( 'json-logging' ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-17 19:31:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									stringify :  ( ! ! nconf . get ( 'json-logging' ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-17 21:54:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Alternate configuration file support
  
						 
					
						
							
								
									
										
										
										
											2015-09-17 21:54:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var 	configFile  =  path . join ( _ _dirname ,  '/config.json' ) ;  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( nconf . get ( 'config' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									configFile  =  path . resolve ( _ _dirname ,  nconf . get ( 'config' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-09-17 21:54:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-05 11:37:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  configExists  =  file . existsSync ( configFile )  ||  ( nconf . get ( 'url' )  &&  nconf . get ( 'secret' )  &&  nconf . get ( 'database' ) ) ;  
						 
					
						
							
								
									
										
										
										
											2015-09-17 21:54:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								loadConfig ( ) ;  
						 
					
						
							
								
									
										
										
										
											2016-08-30 17:01:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								versionCheck ( ) ;  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-24 22:32:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( ! process . send )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If run using `node app`, log GNU copyright info along with server info
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-29 17:38:53 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston . info ( 'NodeBB v'  +  nconf . get ( 'version' )  +  ' Copyright (C) 2013-'  +  ( new  Date ( ) ) . getFullYear ( )  +  ' NodeBB Inc.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-24 22:32:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									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.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . info ( '' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-16 19:25:05 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( nconf . get ( 'setup' )  ||  nconf . get ( 'install' ) )  {  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									setup ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  else  if  ( ! configExists )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									require ( './install/web' ) . install ( nconf . get ( 'port' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'upgrade' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									upgrade ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'reset' ) )  {  
						 
					
						
							
								
									
										
										
										
											2016-12-05 10:23:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									async . waterfall ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . apply ( require ( './src/reset' ) . reset ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-17 19:31:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										async . apply ( require ( './src/meta/build' ) . buildAll ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-05 10:23:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									] ,  function  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										process . exit ( err  ?  1  :  0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-16 19:25:05 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'activate' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									activate ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-03 11:50:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'plugins' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									listPlugins ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 19:49:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'build' ) )  {  
						 
					
						
							
								
									
										
										
										
											2017-02-02 19:15:01 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									require ( './src/meta/build' ) . build ( nconf . get ( 'build' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 16:24:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  if  ( nconf . get ( 'events' ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									async . series ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . apply ( require ( './src/database' ) . init ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . apply ( require ( './src/events' ) . output ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-16 19:25:05 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  else  {  
						 
					
						
							
								
									
										
										
										
											2016-12-23 14:45:37 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									require ( './src/start' ) . start ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  loadConfig ( callback )  {  
						 
					
						
							
								
									
										
										
										
											2015-09-17 21:54:12 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston . verbose ( '* using configuration stored in: %s' ,  configFile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf . file ( { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-17 19:31:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										file :  configFile , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nconf . defaults ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										base _dir :  _ _dirname , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										themes _path :  path . join ( _ _dirname ,  'node_modules' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 11:41:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										upload _path :  'public/uploads' , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-14 22:36:10 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										views _dir :  path . join ( _ _dirname ,  'build/public/templates' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-17 19:31:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										version :  pkg . version , 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! nconf . get ( 'isCluster' ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nconf . set ( 'isPrimary' ,  'true' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nconf . set ( 'isCluster' ,  'false' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Ensure themes_path is a full filepath
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nconf . set ( 'themes_path' ,  path . resolve ( _ _dirname ,  nconf . get ( 'themes_path' ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nconf . set ( 'core_templates_path' ,  path . join ( _ _dirname ,  'src/views' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-19 14:57:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf . set ( 'base_templates_path' ,  path . join ( nconf . get ( 'themes_path' ) ,  'nodebb-theme-persona/templates' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-18 01:27:46 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 11:41:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf . set ( 'upload_path' ,  path . resolve ( nconf . get ( 'base_dir' ) ,  nconf . get ( 'upload_path' ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 16:24:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-22 18:16:09 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( nconf . get ( 'url' ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nconf . set ( 'url_parsed' ,  url . parse ( nconf . get ( 'url' ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 11:23:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Explicitly cast 'jobsDisabled' as Bool
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  castAsBool  =  [ 'jobsDisabled' ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nconf . stores . env . readOnly  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									castAsBool . forEach ( function  ( prop )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  value  =  nconf . get ( prop ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nconf . set ( prop ,  typeof  value  ===  'boolean'  ?  value  :  String ( value ) . toLowerCase ( )  ===  'true' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									nconf . stores . env . readOnly  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( typeof  callback  ===  'function' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										callback ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  setup ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . info ( 'NodeBB Setup Triggered via Command Line' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  install  =  require ( './src/install' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-02 19:15:01 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  build  =  require ( './src/meta/build' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									process . stdout . write ( '\nWelcome to NodeBB!\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									process . stdout . write ( '\nThis looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									process . stdout . write ( 'Press enter to accept the default setting (shown in brackets).\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									async . series ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . apply ( install . setup ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . apply ( loadConfig ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-17 19:31:21 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										async . apply ( build . buildAll ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:26:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									] ,  function  ( err ,  data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Disregard build step data
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										data  =  data [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  separator  =  '     ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( process . stdout . columns  >  10 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-18 01:52:56 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  ( var  x  =  0 ,  cols  =  process . stdout . columns  -  10 ;  x  <  cols ;  x  +=  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												separator  +=  '=' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										process . stdout . write ( '\n'  +  separator  +  '\n\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . error ( 'There was a problem completing NodeBB setup: ' ,  err . message ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( data . hasOwnProperty ( 'password' ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . stdout . write ( 'An administrative user was automatically created for you:\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . stdout . write ( '    Username: '  +  data . username  +  '\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . stdout . write ( '    Password: '  +  data . password  +  '\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . stdout . write ( '\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											process . stdout . write ( 'NodeBB Setup Completed. Run \'./nodebb start\' to manually start your NodeBB server.\n' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// If I am a child process, notify the parent of the returned data before exiting (useful for notifying
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// hosts of auto-generated username/password during headless setups)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( process . send )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . send ( data ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										process . exit ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-18 12:01:33 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2016-11-16 19:49:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:26:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  upgrade ( )  {  
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  db  =  require ( './src/database' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  meta  =  require ( './src/meta' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  upgrade  =  require ( './src/upgrade' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-02 19:15:01 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  build  =  require ( './src/meta/build' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 13:20:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  tasks  =  [ db . init ,  meta . configs . init ,  upgrade . run ,  build . buildAll ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 13:20:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( nconf . get ( 'upgrade' )  !==  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Likely an upgrade script name passed in
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										tasks [ 2 ]  =  async . apply ( upgrade . runSingle ,  nconf . get ( 'upgrade' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Skip build
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										tasks . pop ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 14:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// disable mongo timeouts during upgrade
 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-09 18:19:22 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf . set ( 'mongo:options:socketTimeoutMS' ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 13:20:47 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									async . series ( tasks ,  function  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . error ( err . stack ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-16 20:24:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											process . exit ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											process . exit ( 0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-18 12:01:33 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-07-21 11:23:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-16 19:25:05 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  activate ( )  {  
						 
					
						
							
								
									
										
										
										
											2016-11-09 10:25:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  db  =  require ( './src/database' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:53:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  plugins  =  require ( './src/plugins' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 16:24:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  events  =  require ( './src/events' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:53:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  plugin  =  nconf . get ( 'activate' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									async . waterfall ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											db . init ( next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:55:18 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( plugin . indexOf ( 'nodebb-' )  !==  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// Allow omission of `nodebb-plugin-`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												plugin  =  'nodebb-plugin-'  +  plugin ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:53:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											plugins . isInstalled ( plugin ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										function  ( isInstalled ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! isInstalled )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  next ( new  Error ( 'plugin not installed' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:46:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:53:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											winston . info ( 'Activating plugin `%s`' ,  plugin ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											db . sortedSetAdd ( 'plugins:active' ,  0 ,  plugin ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 16:24:40 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										function  ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											events . log ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												type :  'plugin-activate' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												text :  plugin , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:53:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									] ,  function  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . error ( err . message ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-09 10:25:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-18 13:53:43 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										process . exit ( err  ?  1  :  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-16 19:25:05 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-03 11:50:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  listPlugins ( )  {  
						 
					
						
							
								
									
										
										
										
											2016-10-13 11:43:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									require ( './src/database' ) . init ( function  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:46:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . error ( err . stack ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											process . exit ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-03 11:50:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  db  =  require ( './src/database' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-13 11:43:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										db . getSortedSetRange ( 'plugins:active' ,  0 ,  - 1 ,  function  ( err ,  plugins )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-16 19:46:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												winston . error ( err . stack ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												process . exit ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-03 11:50:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											winston . info ( 'Active plugins: \n\t - '  +  plugins . join ( '\n\t - ' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											process . exit ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-30 17:01:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  versionCheck ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  version  =  process . version . slice ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  range  =  pkg . engines . node ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  semver  =  require ( 'semver' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									var  compatible  =  semver . satisfies ( version ,  range ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! compatible )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-30 17:03:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										winston . warn ( 'Your version of Node.js is too outdated for NodeBB. Please update your version of Node.js.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										winston . warn ( 'Recommended '  +  range . green  +  ', ' . reset  +  version . yellow  +  ' provided\n' . reset ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-30 17:01:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-21 21:11:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}