2015-01-12 02:03:45 +01:00
class Wrapper
constructor: (ws_url) ->
@ log " Created! "
@loading = new Loading ( )
@notifications = new Notifications ( $ ( " .notifications " ) )
2015-07-31 23:34:53 +02:00
@fixbutton = new Fixbutton ( )
2015-01-12 02:03:45 +01:00
window . addEventListener ( " message " , @ onMessageInner , false )
@inner = document . getElementById ( " inner-iframe " ) . contentWindow
@ws = new ZeroWebsocket ( ws_url )
@ws.next_message_id = 1000000 # Avoid messageid collision :)
@ws.onOpen = @ onOpenWebsocket
@ws.onClose = @ onCloseWebsocket
@ws.onMessage = @ onMessageWebsocket
@ ws . connect ( )
@ws_error = null # Ws error message
@site_info = null # Hold latest site info
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
@event_site_info = $ . Deferred ( ) # Event when site_info received
2015-01-12 02:03:45 +01:00
@inner_loaded = false # If iframe loaded or not
@inner_ready = false # Inner frame ready to receive messages
@wrapperWsInited = false # Wrapper notified on websocket open
@site_error = null # Latest failed file download
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
@address = null
2015-01-12 02:03:45 +01:00
window . onload = @ onLoad # On iframe loaded
2015-01-27 22:37:13 +01:00
$ ( window ) . on " hashchange " , => # On hash change
@ log " Hashchange " , window . location . hash
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
if window . location . hash
src = $ ( " # inner-iframe " ) . attr ( " src " ) . replace ( /#.*/ , " " ) + window . location . hash
$ ( " # inner-iframe " ) . attr ( " src " , src )
version 0.3.0, rev187, Trusted authorization sites support, --publish option on signing, cryptSign command line option, OpenSSL enabled on OSX, Crypto verify allows list of valid addresses, Option for version 2 json DB tables, DbCursor SELECT parameters bugfix, Add peer to site on ListModified, Download blind includes when new site added, Publish command better messages, Multi-threaded announce, New http Torrent trackers, Wait for dbschema.json on query, Handle json import errors, More compact writeJson storage command, Testcase for signing and verifying, Workaround to make non target=_top links work, More clean UiWebsocket command route, Send cert_user_id on siteinfo, Notify other local clients on local file modify, Option to wait for file download before sql query, File rules websocket API command, Cert add and select, set websocket API command, Put focus on innerframe, innerloaded wrapper api command to add hashtag, Allow more file error on big sites, Keep worker running after stuked on done task, New more stable openSSL layer that works on OSX, Noparallel parameter bugfix, RateLimit allowed again interval bugfix, Updater skips non-writeable files, Try to close openssl dll before update
2015-05-25 01:26:33 +02:00
$ ( " # inner-iframe " ) . focus ( )
2015-01-12 02:03:45 +01:00
# Incoming message from UiServer websocket
onMessageWebsocket: (e) =>
message = JSON . parse ( e . data )
cmd = message . cmd
if cmd == " response "
if @ ws . waiting_cb [ message . to ] ? # We are waiting for response
@ ws . waiting_cb [ message . to ] ( message . result )
else
@ sendInner message # Pass message to inner frame
else if cmd == " notification " # Display notification
2015-08-16 11:51:00 +02:00
type = message . params [ 0 ]
id = " notification- #{ message . id } "
if " - " in message . params [ 0 ] # - in first param: message id definied
[ id , type ] = message . params [ 0 ] . split ( " - " )
@ notifications . add ( id , type , message . params [ 1 ] , message . params [ 2 ] )
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
else if cmd == " prompt " # Prompt input
@ displayPrompt message . params [ 0 ] , message . params [ 1 ] , message . params [ 2 ] , (res) =>
@ ws . response message . id , res
2015-01-12 02:03:45 +01:00
else if cmd == " setSiteInfo "
@ sendInner message # Pass to inner frame
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
if message . params . address == @ address # Current page
2015-01-12 02:03:45 +01:00
@ setSiteInfo message . params
2015-08-16 11:51:00 +02:00
else if cmd == " error "
@ notifications . add ( " notification- #{ message . id } " , " error " , message . params , 0 )
2015-02-20 01:37:12 +01:00
else if cmd == " updating " # Close connection
@ ws . ws . close ( )
@ ws . onCloseWebsocket ( null , 4000 )
2015-01-12 02:03:45 +01:00
else
@ sendInner message # Pass message to inner frame
# Incoming message from inner frame
onMessageInner: (e) =>
message = e . data
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
if window . postmessage_nonce_security and message . wrapper_nonce != window . wrapper_nonce
@ log " Message nonce error: " , message . wrapper_nonce , ' != ' , window . wrapper_nonce
@ actionNotification ( { " params " : [ " error " , " Message wrapper_nonce error, please report! " ] } )
window . removeEventListener ( " message " , @ onMessageInner )
return
2015-01-12 02:03:45 +01:00
cmd = message . cmd
if cmd == " innerReady "
@inner_ready = true
if @ ws . ws . readyState == 1 and not @ wrapperWsInited # If ws already opened
@ sendInner { " cmd " : " wrapperOpenedWebsocket " }
@wrapperWsInited = true
version 0.3.0, rev187, Trusted authorization sites support, --publish option on signing, cryptSign command line option, OpenSSL enabled on OSX, Crypto verify allows list of valid addresses, Option for version 2 json DB tables, DbCursor SELECT parameters bugfix, Add peer to site on ListModified, Download blind includes when new site added, Publish command better messages, Multi-threaded announce, New http Torrent trackers, Wait for dbschema.json on query, Handle json import errors, More compact writeJson storage command, Testcase for signing and verifying, Workaround to make non target=_top links work, More clean UiWebsocket command route, Send cert_user_id on siteinfo, Notify other local clients on local file modify, Option to wait for file download before sql query, File rules websocket API command, Cert add and select, set websocket API command, Put focus on innerframe, innerloaded wrapper api command to add hashtag, Allow more file error on big sites, Keep worker running after stuked on done task, New more stable openSSL layer that works on OSX, Noparallel parameter bugfix, RateLimit allowed again interval bugfix, Updater skips non-writeable files, Try to close openssl dll before update
2015-05-25 01:26:33 +02:00
else if cmd == " innerLoaded "
if window . location . hash
$ ( " # inner-iframe " ) [ 0 ] . src += window . location . hash # Hash tag
@ log " Added hash to location " , $ ( " # inner-iframe " ) [ 0 ] . src
2015-01-21 12:58:26 +01:00
else if cmd == " wrapperNotification " # Display notification
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
@ actionNotification ( message )
2015-01-21 12:58:26 +01:00
else if cmd == " wrapperConfirm " # Display confirm message
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
@ actionConfirm ( message )
2015-01-24 19:14:29 +01:00
else if cmd == " wrapperPrompt " # Prompt input
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
@ actionPrompt ( message )
2015-02-10 00:08:25 +01:00
else if cmd == " wrapperSetViewport " # Set the viewport
@ actionSetViewport ( message )
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
else if cmd == " wrapperReload " # Reload current page
@ actionReload ( message )
2015-02-17 01:48:15 +01:00
else if cmd == " wrapperGetLocalStorage "
@ actionGetLocalStorage ( message )
else if cmd == " wrapperSetLocalStorage "
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
@ actionSetLocalStorage ( message )
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
else if cmd == " wrapperPushState "
query = @ toRelativeQuery ( message . params [ 2 ] )
window . history . pushState ( message . params [ 0 ] , message . params [ 1 ] , query )
else if cmd == " wrapperReplaceState "
query = @ toRelativeQuery ( message . params [ 2 ] )
window . history . replaceState ( message . params [ 0 ] , message . params [ 1 ] , query )
2015-01-12 02:03:45 +01:00
else # Send to websocket
2015-02-14 14:05:00 +01:00
if message . id < 1000000
@ ws . send ( message ) # Pass message to websocket
else
@ log " Invalid inner message id "
2015-01-12 02:03:45 +01:00
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
toRelativeQuery: (query) ->
back = window . location . pathname
if back . slice ( - 1 ) != " / "
back += " / "
if query . replace ( " ? " , " " )
back += " ? " + query . replace ( " ? " , " " )
return back
2015-01-12 02:03:45 +01:00
2015-01-21 12:58:26 +01:00
# - Actions -
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
actionNotification: (message) ->
2015-01-21 12:58:26 +01:00
message.params = @ toHtmlSafe ( message . params ) # Escape html
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
body = $ ( " <span class= ' message ' > " + message . params [ 1 ] + " </span> " )
@ notifications . add ( " notification- #{ message . id } " , message . params [ 0 ] , body , message . params [ 2 ] )
2015-02-14 14:05:00 +01:00
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
displayConfirm: (message, caption, cb) ->
body = $ ( " <span class= ' message ' > " + message + " </span> " )
2015-02-14 14:05:00 +01:00
button = $ ( " <a href= ' # #{ caption } ' class= ' button button- #{ caption } ' > #{ caption } </a> " ) # Add confirm button
button . on " click " , cb
2015-01-21 12:58:26 +01:00
body . append ( button )
2015-02-14 14:05:00 +01:00
@ notifications . add ( " notification- #{ caption } " , " ask " , body )
2015-01-21 12:58:26 +01:00
2015-09-16 00:01:23 +02:00
button . focus ( )
$ ( " .notification " ) . scrollLeft ( 0 )
2015-09-13 12:52:11 +02:00
2015-01-21 12:58:26 +01:00
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
actionConfirm: (message, cb=false) ->
2015-01-24 19:14:29 +01:00
message.params = @ toHtmlSafe ( message . params ) # Escape html
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
if message . params [ 1 ] then caption = message . params [ 1 ] else caption = " ok "
@ displayConfirm message . params [ 0 ] , caption , =>
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : " boom " } # Response to confirm
return false
2015-01-24 19:14:29 +01:00
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
displayPrompt: (message, type, caption, cb) ->
body = $ ( " <span class= ' message ' > " + message + " </span> " )
2015-01-24 19:14:29 +01:00
input = $ ( " <input type= ' #{ type } ' class= ' input button- #{ type } ' /> " ) # Add input
input . on " keyup " , (e) => # Send on enter
if e . keyCode == 13
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
button . trigger " click " # Response to confirm
2015-01-24 19:14:29 +01:00
body . append ( input )
button = $ ( " <a href= ' # #{ caption } ' class= ' button button- #{ caption } ' > #{ caption } </a> " ) # Add confirm button
button . on " click " , => # Response on button click
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
cb input . val ( )
2015-01-24 19:14:29 +01:00
return false
body . append ( button )
@ notifications . add ( " notification- #{ message . id } " , " ask " , body )
2015-09-16 00:01:23 +02:00
input . focus ( )
$ ( " .notification " ) . scrollLeft ( 0 )
2015-09-13 12:52:11 +02:00
2015-01-24 19:14:29 +01:00
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
actionPrompt: (message) ->
message.params = @ toHtmlSafe ( message . params ) # Escape html
if message . params [ 1 ] then type = message . params [ 1 ] else type = " text "
caption = " OK "
2015-07-31 23:34:53 +02:00
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
@ displayPrompt message . params [ 0 ] , type , caption , (res) =>
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : res } # Response to confirm
2015-07-31 23:34:53 +02:00
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
2015-02-10 00:08:25 +01:00
actionSetViewport: (message) ->
@ log " actionSetViewport " , message
if $ ( " # viewport " ) . length > 0
$ ( " # viewport " ) . attr ( " content " , @ toHtmlSafe message . params )
else
$ ( ' <meta name= " viewport " id= " viewport " > ' ) . attr ( " content " , @ toHtmlSafe message . params ) . appendTo ( " head " )
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
reload: (url_post="") ->
if url_post
if window . location . toString ( ) . indexOf ( " ? " ) > 0
window . location += " & " + url_post
else
window . location += " ? " + url_post
else
window . location . reload ( )
2015-02-17 01:48:15 +01:00
actionGetLocalStorage: (message) ->
2015-07-31 23:34:53 +02:00
$ . when ( @ event_site_info ) . done =>
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
data = localStorage . getItem " site. #{ @ site_info . address } . #{ @ site_info . auth_address } "
if not data # Migrate from non auth_address based local storage
data = localStorage . getItem " site. #{ @ site_info . address } "
if data
localStorage . setItem " site. #{ @ site_info . address } . #{ @ site_info . auth_address } " , data
localStorage . removeItem " site. #{ @ site_info . address } "
@ log " Migrated LocalStorage from global to auth_address based "
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
if data then data = JSON . parse ( data )
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : data }
2015-02-17 01:48:15 +01:00
actionSetLocalStorage: (message) ->
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
back = localStorage . setItem " site. #{ @ site_info . address } . #{ @ site_info . auth_address } " , JSON . stringify ( message . params )
2015-02-17 01:48:15 +01:00
2015-02-10 00:08:25 +01:00
# EOF actions
2015-01-12 02:03:45 +01:00
onOpenWebsocket: (e) =>
@ ws . cmd " channelJoin " , { " channel " : " siteChanged " } # Get info on modifications
if not @ wrapperWsInited and @ inner_ready
@ sendInner { " cmd " : " wrapperOpenedWebsocket " } # Send to inner frame
@wrapperWsInited = true
if @ inner_loaded # Update site info
@ reloadSiteInfo ( )
# If inner frame not loaded for 2 sec show peer informations on loading screen by loading site info
setTimeout ( =>
if not @ site_info then @ reloadSiteInfo ( )
) , 2000
2015-07-31 23:34:53 +02:00
if @ ws_error
2015-01-12 02:03:45 +01:00
@ notifications . add ( " connection " , " done " , " Connection with <b>UiServer Websocket</b> recovered. " , 6000 )
@ws_error = null
onCloseWebsocket: (e) =>
@wrapperWsInited = false
setTimeout ( => # Wait a bit, maybe its page closing
@ sendInner { " cmd " : " wrapperClosedWebsocket " } # Send to inner frame
2015-02-20 01:37:12 +01:00
if e and e . code == 1000 and e . wasClean == false # Server error please reload page
2015-01-12 02:03:45 +01:00
@ws_error = @ notifications . add ( " connection " , " error " , " UiServer Websocket error, please reload the page. " )
else if not @ ws_error
@ws_error = @ notifications . add ( " connection " , " error " , " Connection with <b>UiServer Websocket</b> was lost. Reconnecting... " )
2015-02-14 14:05:00 +01:00
) , 1000
2015-01-12 02:03:45 +01:00
# Iframe loaded
onLoad: (e) =>
@inner_loaded = true
if not @ inner_ready then @ sendInner { " cmd " : " wrapperReady " } # Inner frame loaded before wrapper
2015-02-14 14:54:11 +01:00
#if not @site_error then @loading.hideScreen() # Hide loading screen
2015-01-12 02:03:45 +01:00
if @ ws . ws . readyState == 1 and not @ site_info # Ws opened
@ reloadSiteInfo ( )
2015-02-14 14:05:00 +01:00
else if @ site_info and @ site_info . content ? . title ?
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
window . document . title = @ site_info . content . title + " - ZeroNet "
@ log " Setting title to " , window . document . title
2015-01-12 02:03:45 +01:00
# Send message to innerframe
sendInner: (message) ->
@ inner . postMessage ( message , ' * ' )
# Get site info from UiServer
reloadSiteInfo: ->
2015-04-20 22:31:29 +02:00
if @ loading . screen_visible # Loading screen visible
params = { " file_status " : window . file_inner_path } # Query the current required file status
else
params = { }
2015-07-31 23:34:53 +02:00
2015-04-20 22:31:29 +02:00
@ ws . cmd " siteInfo " , params , (site_info) =>
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
@address = site_info . address
2015-01-12 02:03:45 +01:00
@ setSiteInfo site_info
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
2015-04-03 14:31:15 +02:00
if site_info . settings . size > site_info . size_limit * 1024 * 1024 # Site size too large and not displaying it yet
2015-06-25 20:09:41 +02:00
if @ loading . screen_visible
@ loading . showTooLarge ( site_info )
else
@ displayConfirm " Site is larger than allowed: #{ ( site_info . settings . size / 1024 / 1024 ) . toFixed ( 1 ) } MB/ #{ site_info . size_limit } MB " , " Set limit to #{ site_info . next_size_limit } MB " , =>
@ ws . cmd " siteSetLimit " , [ site_info . next_size_limit ] , (res) =>
@ notifications . add ( " size_limit " , " done " , res , 5000 )
2015-04-03 14:31:15 +02:00
if site_info . content
window . document . title = site_info . content . title + " - ZeroNet "
@ log " Setting title to " , window . document . title
2015-01-12 02:03:45 +01:00
# Got setSiteInfo from websocket UiServer
setSiteInfo: (site_info) ->
if site_info . event ? # If loading screen visible add event to it
# File started downloading
2015-01-18 22:52:19 +01:00
if site_info . event [ 0 ] == " file_added " and site_info . bad_files
@ loading . printLine ( " #{ site_info . bad_files } files needs to be downloaded " )
2015-01-12 02:03:45 +01:00
# File finished downloading
else if site_info . event [ 0 ] == " file_done "
@ loading . printLine ( " #{ site_info . event [ 1 ] } downloaded " )
2015-04-20 22:31:29 +02:00
if site_info . event [ 1 ] == window . file_inner_path # File downloaded we currently on
2015-01-12 02:03:45 +01:00
@ loading . hideScreen ( )
2015-01-21 12:58:26 +01:00
if not @ site_info then @ reloadSiteInfo ( )
2015-04-03 14:31:15 +02:00
if site_info . content
window . document . title = site_info . content . title + " - ZeroNet "
2015-04-20 22:31:29 +02:00
@ log " Required file done, setting title to " , window . document . title
2015-01-12 02:03:45 +01:00
if not $ ( " .loadingscreen " ) . length # Loading screen already removed (loaded +2sec)
@ notifications . add ( " modified " , " info " , " New version of this page has just released.<br>Reload to see the modified content. " )
# File failed downloading
2015-07-31 23:34:53 +02:00
else if site_info . event [ 0 ] == " file_failed "
2015-01-12 02:03:45 +01:00
@site_error = site_info . event [ 1 ]
2015-02-14 14:05:00 +01:00
if site_info . settings . size > site_info . size_limit * 1024 * 1024 # Site size too large and not displaying it yet
2015-04-03 14:31:15 +02:00
@ loading . showTooLarge ( site_info )
2015-02-14 14:05:00 +01:00
else
@ loading . printLine ( " #{ site_info . event [ 1 ] } download failed " , " error " )
2015-01-12 02:03:45 +01:00
# New peers found
2015-07-31 23:34:53 +02:00
else if site_info . event [ 0 ] == " peers_added "
2015-01-12 02:03:45 +01:00
@ loading . printLine ( " Peers found: #{ site_info . peers } " )
if @ loading . screen_visible and not @ site_info # First site info display current peers
if site_info . peers > 1
@ loading . printLine " Peers found: #{ site_info . peers } "
else
@site_error = " No peers found "
@ loading . printLine " No peers found "
2015-02-14 14:05:00 +01:00
2015-10-17 02:56:39 +02:00
if not @ site_info and not @ loading . screen_visible and $ ( " # inner-iframe " ) . attr ( " src " ) . replace ( " ?wrapper=False " , " " ) . replace ( /\?wrapper_nonce=[A-Za-z0-9]+/ , " " ) . indexOf ( " ? " ) == - 1 # First site info and we are on mainpage (does not have other parameter thatn wrapper)
2015-06-25 20:09:41 +02:00
if site_info . size_limit * 1.1 < site_info . next_size_limit # Need upgrade soon
2015-08-06 00:51:25 +02:00
@ displayConfirm " Running out of size limit ( #{ ( site_info . settings . size / 1024 / 1024 ) . toFixed ( 1 ) } MB/ #{ site_info . size_limit } MB) " , " Set limit to #{ site_info . next_size_limit } MB " , =>
2015-02-14 14:05:00 +01:00
@ ws . cmd " siteSetLimit " , [ site_info . next_size_limit ] , (res) =>
@ notifications . add ( " size_limit " , " done " , res , 5000 )
return false
2015-02-25 03:22:10 +01:00
2015-08-26 02:51:32 +02:00
if @ loading . screen_visible and @ inner_loaded and site_info . settings . size < site_info . size_limit * 1024 * 1024 and site_info . settings . size > 0 # Loading screen still visible, but inner loaded
2015-02-25 03:22:10 +01:00
@ loading . hideScreen ( )
2015-02-26 01:32:27 +01:00
if site_info . tasks > 0 and site_info . started_task_num > 0
@ loading . setProgress 1 - ( site_info . tasks / site_info . started_task_num )
else
@ loading . hideProgress ( )
2015-01-12 02:03:45 +01:00
@site_info = site_info
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
@ event_site_info . resolve ( )
2015-01-12 02:03:45 +01:00
2015-02-10 00:08:25 +01:00
toHtmlSafe: (values) ->
if values not instanceof Array then values = [ values ] # Convert to array if its not
for value , i in values
value = String ( value ) . replace ( /&/g , ' & ' ) . replace ( /</g , ' < ' ) . replace ( />/g , ' > ' ) . replace ( /"/g , ' " ' ) # Escape
value = value . replace ( /<([\/]{0,1}(br|b|u|i))>/g , " <$1> " ) # Unescape b, i, u, br tags
values [ i ] = value
return values
2015-01-21 12:58:26 +01:00
2015-02-14 14:05:00 +01:00
setSizeLimit: (size_limit, reload=true) =>
@ ws . cmd " siteSetLimit " , [ size_limit ] , (res) =>
@ loading . printLine res
2015-04-03 14:31:15 +02:00
@inner_loaded = false # Inner frame not loaded, just a 404 page displayed
2015-02-14 14:05:00 +01:00
if reload
2015-08-06 00:51:25 +02:00
src = $ ( " iframe " ) . attr ( " src " )
$ ( " iframe " ) . attr " src " , " "
$ ( " iframe " ) . attr " src " , src
2015-02-14 14:05:00 +01:00
return false
version 0.3.0, rev187, Trusted authorization sites support, --publish option on signing, cryptSign command line option, OpenSSL enabled on OSX, Crypto verify allows list of valid addresses, Option for version 2 json DB tables, DbCursor SELECT parameters bugfix, Add peer to site on ListModified, Download blind includes when new site added, Publish command better messages, Multi-threaded announce, New http Torrent trackers, Wait for dbschema.json on query, Handle json import errors, More compact writeJson storage command, Testcase for signing and verifying, Workaround to make non target=_top links work, More clean UiWebsocket command route, Send cert_user_id on siteinfo, Notify other local clients on local file modify, Option to wait for file download before sql query, File rules websocket API command, Cert add and select, set websocket API command, Put focus on innerframe, innerloaded wrapper api command to add hashtag, Allow more file error on big sites, Keep worker running after stuked on done task, New more stable openSSL layer that works on OSX, Noparallel parameter bugfix, RateLimit allowed again interval bugfix, Updater skips non-writeable files, Try to close openssl dll before update
2015-05-25 01:26:33 +02:00
isProxyRequest: ->
return window . location . pathname == " / "
gotoSite: (elem) =>
href = $ ( elem ) . attr ( " href " )
if @ isProxyRequest ( ) # Fix for proxy request
$ ( elem ) . attr ( " href " , " http://zero #{ href } " )
2015-01-21 12:58:26 +01:00
2015-01-12 02:03:45 +01:00
log: (args...) ->
console . log " [Wrapper] " , args . . .
version 0.3.0, rev187, Trusted authorization sites support, --publish option on signing, cryptSign command line option, OpenSSL enabled on OSX, Crypto verify allows list of valid addresses, Option for version 2 json DB tables, DbCursor SELECT parameters bugfix, Add peer to site on ListModified, Download blind includes when new site added, Publish command better messages, Multi-threaded announce, New http Torrent trackers, Wait for dbschema.json on query, Handle json import errors, More compact writeJson storage command, Testcase for signing and verifying, Workaround to make non target=_top links work, More clean UiWebsocket command route, Send cert_user_id on siteinfo, Notify other local clients on local file modify, Option to wait for file download before sql query, File rules websocket API command, Cert add and select, set websocket API command, Put focus on innerframe, innerloaded wrapper api command to add hashtag, Allow more file error on big sites, Keep worker running after stuked on done task, New more stable openSSL layer that works on OSX, Noparallel parameter bugfix, RateLimit allowed again interval bugfix, Updater skips non-writeable files, Try to close openssl dll before update
2015-05-25 01:26:33 +02:00
origin = window . server_url or window . location . origin
2015-01-12 02:03:45 +01:00
version 0.3.0, rev187, Trusted authorization sites support, --publish option on signing, cryptSign command line option, OpenSSL enabled on OSX, Crypto verify allows list of valid addresses, Option for version 2 json DB tables, DbCursor SELECT parameters bugfix, Add peer to site on ListModified, Download blind includes when new site added, Publish command better messages, Multi-threaded announce, New http Torrent trackers, Wait for dbschema.json on query, Handle json import errors, More compact writeJson storage command, Testcase for signing and verifying, Workaround to make non target=_top links work, More clean UiWebsocket command route, Send cert_user_id on siteinfo, Notify other local clients on local file modify, Option to wait for file download before sql query, File rules websocket API command, Cert add and select, set websocket API command, Put focus on innerframe, innerloaded wrapper api command to add hashtag, Allow more file error on big sites, Keep worker running after stuked on done task, New more stable openSSL layer that works on OSX, Noparallel parameter bugfix, RateLimit allowed again interval bugfix, Updater skips non-writeable files, Try to close openssl dll before update
2015-05-25 01:26:33 +02:00
if origin . indexOf ( " https: " ) == 0
proto = { ws: ' wss ' , http: ' https ' }
2015-04-20 02:56:33 +02:00
else
version 0.3.0, rev187, Trusted authorization sites support, --publish option on signing, cryptSign command line option, OpenSSL enabled on OSX, Crypto verify allows list of valid addresses, Option for version 2 json DB tables, DbCursor SELECT parameters bugfix, Add peer to site on ListModified, Download blind includes when new site added, Publish command better messages, Multi-threaded announce, New http Torrent trackers, Wait for dbschema.json on query, Handle json import errors, More compact writeJson storage command, Testcase for signing and verifying, Workaround to make non target=_top links work, More clean UiWebsocket command route, Send cert_user_id on siteinfo, Notify other local clients on local file modify, Option to wait for file download before sql query, File rules websocket API command, Cert add and select, set websocket API command, Put focus on innerframe, innerloaded wrapper api command to add hashtag, Allow more file error on big sites, Keep worker running after stuked on done task, New more stable openSSL layer that works on OSX, Noparallel parameter bugfix, RateLimit allowed again interval bugfix, Updater skips non-writeable files, Try to close openssl dll before update
2015-05-25 01:26:33 +02:00
proto = { ws: ' ws ' , http: ' http ' }
ws_url = proto . ws + " : " + origin . replace ( proto . http + " : " , " " ) + " /Websocket?wrapper_key= " + window . wrapper_key
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
Rev903, FeedQuery command only available for ADMIN sites, Show bad files in sidebar, Log unknown messages, Add and check inner_path and site address on sign/verify, Better peer cleanup limit, Log site load times, Testcase for address and inner_path verification, Re-sign testsite with new fields, Fix unnecessary loading screen display when browsing sub-folder with index.html, Fix safari notification width
2016-02-18 11:22:21 +01:00
if window . opener and window . postmessage_nonce_security == false
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
# Window opener security problem workaround: Open a new window, close this one
console . log " Opener present: " , window . opener
setTimeout ( -> # Wait 200ms to parent tab closing
2016-02-21 11:44:10 +01:00
console . log " Opener still present: " , window . opener
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
if window . opener
# Opener still present, display message
elem = $ ( " <div class= ' opener-overlay ' ><div class= ' dialog ' >You have opened this page by clicking on a link. Please, confirm if you want to load this site.<a href= ' ? ' target= ' _blank ' class= ' button ' >Open site</a></div></div> " )
elem . find ( ' a ' ) . on " click " , ->
window . open ( " ? " , " _blank " )
window . close ( )
return false
$ ( " body " ) . prepend ( elem )
else
window . location . reload ( )
# Opener gone, continue init
# window.wrapper = new Wrapper(ws_url)
2016-02-21 11:44:10 +01:00
# window.wrapper.reload()
) , 200
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
else
2016-02-21 11:44:10 +01:00
window . wrapper = new Wrapper ( ws_url )