forked from coolaj86/telebit.js
		
	update access token
This commit is contained in:
		
							parent
							
								
									536afb2ad5
								
							
						
					
					
						commit
						388e2f7a58
					
				| @ -50,7 +50,14 @@ if (-1 !== argv.indexOf('-h') || -1 !== argv.indexOf('--help')) { | |||||||
| if (!confpath || /^--/.test(confpath)) { | if (!confpath || /^--/.test(confpath)) { | ||||||
|   help(); |   help(); | ||||||
| } | } | ||||||
| 
 | var tokenfile = 'access_token.txt'; | ||||||
|  | var tokenpath = path.join(path.dirname(confpath), tokenfile); | ||||||
|  | var token; | ||||||
|  | try { | ||||||
|  |   token = require('fs').readFileSync(tokenpath, 'ascii').trim(); | ||||||
|  | } catch(e) { | ||||||
|  |   // ignore
 | ||||||
|  | } | ||||||
| require('fs').readFile(confpath, 'utf8', function (err, text) { | require('fs').readFile(confpath, 'utf8', function (err, text) { | ||||||
|   var config; |   var config; | ||||||
| 
 | 
 | ||||||
| @ -78,6 +85,17 @@ require('fs').readFile(confpath, 'utf8', function (err, text) { | |||||||
| 
 | 
 | ||||||
|   state._confpath = confpath; |   state._confpath = confpath; | ||||||
|   state.config = camelCopy(config); |   state.config = camelCopy(config); | ||||||
|  |   if (state.config.token && token) { | ||||||
|  |     console.warn(); | ||||||
|  |     console.warn("Found two tokens:"); | ||||||
|  |     console.warn(); | ||||||
|  |     console.warn("\t1. " + tokenpath); | ||||||
|  |     console.warn("\n2. " + confpath); | ||||||
|  |     console.warn(); | ||||||
|  |     console.warn("Choosing the first."); | ||||||
|  |     console.warn(); | ||||||
|  |   } | ||||||
|  |   state.config.token = token; | ||||||
|   rawTunnel(); |   rawTunnel(); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| @ -135,8 +153,14 @@ function connectTunnel() { | |||||||
|           } |           } | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
|     , access_token: function (jwt) { |     , access_token: function (opts) { | ||||||
|         console.info("Received updated access_token:", jwt); |         console.info("Updating '" + tokenpath + "' with new token:"); | ||||||
|  |         try { | ||||||
|  |           require('fs').writeFileSync(tokenpath, opts.jwt); | ||||||
|  |         } catch (e) { | ||||||
|  |           console.error("Token not saved:"); | ||||||
|  |           console.error(e); | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   , greenlockConfig: { |   , greenlockConfig: { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user