#!/usr/bin/env nodejs
try {
var package = require ( _ _dirname + '/../package.json' )
var program = require ( 'commander' )
var fs = require ( 'fs' )
program
. version ( package . version )
. description ( 'command line client for SafeChat, see https://safechat.ch' )
. option ( '-u, --url <url>' , 'url to safechat server [http://localhost:8888]' , 'http://localhost:8888' )
. option ( '-n, --name <name>' , 'username [test]' , 'test' )
. option ( '-H, --host <host>' , 'user\'s SafeChat host, mail is <name>@<host> [safechat.ch]' , 'safechat.ch' )
. option ( '-K, --keyserver <host>' , 'pgp key server [https://safechat.ch]' , 'https://safechat.ch' )
. option ( '-p, --password <pwd>' , 'password [ert456]' , 'ert456' )
. option ( '-k, --key <file>' , 'pgp key file [key.pgp]' , 'key.pgp' )
. parse ( process . argv )
var client = require ( _ _dirname + '/../safechat/client' ) ( program . url , program . keyserver )
fs . stat ( program . key , function ( err , stats ) {
if ( err ) {
console . log ( 'generate keys' )
client . create ( program . name , program . host , program . password ,
function ( user ) {
fs . writeFileSync ( program . key , JSON . stringify ( user ) )
console . log ( 'new user credentials created' )
} ,
function ( msg , e ) {
console . log ( "**** ERRROR:" , msg , e , e . stack )
} )
} else if ( stats . isFile ( ) ) {
client . login ( JSON . parse ( fs . readFileSync ( program . key ) ) ,
function ( user ) {
console . log ( 'user successfully restored:' , user . email )
} ,
function ( msg , e ) {
console . log ( "**** ERRROR:" , msg , e , e . stack )
} )
} else {
console . log ( '**** ERROR: cannot read file' , program . key )
}
} )
/ *
console . log ( 'connecting to:' , program . url )
var socket = io ( program . url )
socket
. on ( 'connect' , function ( ) {
console . log ( 'connect' )
socket . emit ( 'login' , { name : 'test' , } )
} )
. on ( "login" , function ( ) {
console . log ( 'loggedin' )
} )
. on ( "fail" , function ( ) {
console . log ( 'fail' )
} )
. on ( "user" , function ( ) {
console . log ( 'user' )
} )
. on ( "users" , function ( ) {
console . log ( 'users' )
} )
. on ( "message" , function ( ) {
console . log ( 'message' )
} )
. on ( "messages" , function ( ) {
console . log ( 'messages' )
} )
. io
. on ( "connect" , function ( ) {
console . log ( 'io.connect' )
} )
. on ( "reconnect" , function ( ) {
console . log ( 'io.reconnect' )
} )
. on ( "disconnect" , function ( ) {
console . log ( 'io.disconnect' )
} )
. on ( "error" , function ( ) {
console . log ( 'io.disconnect' )
} )
* /
} catch ( e ) {
console . log ( '**** ERROR:' , e . stack )
}