2015-01-12 02:03:45 +01:00
class Wrapper
constructor: (ws_url) ->
@ log " Created! "
2018-02-22 23:34:18 +01:00
@loading = new Loading ( @ )
2015-01-12 02:03:45 +01:00
@notifications = new Notifications ( $ ( " .notifications " ) )
2019-02-02 00:12:50 +01:00
@infopanel = new Infopanel ( $ ( " .infopanel " ) )
2019-02-05 15:54:32 +01:00
@infopanel.onClosed = =>
@ ws . cmd ( " siteSetSettingsValue " , [ " modified_files_notification " , false ] )
@infopanel.onOpened = =>
@ ws . cmd ( " siteSetSettingsValue " , [ " modified_files_notification " , true ] )
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
2018-02-21 03:09:36 +01:00
@next_cmd_message_id = - 1
2015-01-12 02:03:45 +01:00
@site_info = null # Hold latest site info
2018-04-28 22:04:58 +02:00
@server_info = null # Hold latest server 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
2016-03-26 00:20:53 +01:00
@opener_tested = false
2018-04-28 22:04:58 +02:00
@announcer_line = null
2019-04-19 18:08:49 +02:00
@web_notifications = { }
2020-09-04 17:57:34 +02:00
@is_title_changed = false
2015-01-12 02:03:45 +01:00
2018-06-28 02:39:46 +02:00
@allowed_event_constructors = [ window . MouseEvent , window . KeyboardEvent , window . PointerEvent ] # Allowed event constructors
2018-02-21 03:08:52 +01:00
2018-02-21 03:05:02 +01:00
window . onload = @ onPageLoad # On iframe loaded
2016-02-27 21:39:36 +01:00
window . onhashchange = (e) => # On hash change
2015-01-27 22:37:13 +01:00
@ 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
2016-02-27 21:39:36 +01:00
window . onpopstate = (e) =>
2016-05-16 22:27:17 +02:00
@ sendInner { " cmd " : " wrapperPopState " , " params " : { " href " : document . location . href , " state " : e . state } }
2016-02-27 21:39:36 +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
$ ( " # inner-iframe " ) . focus ( )
2018-03-06 12:02:39 +01:00
2018-02-21 03:08:52 +01:00
verifyEvent: (allowed_target, e) =>
if not e . originalEvent . isTrusted
throw " Event not trusted "
if e . originalEvent . constructor not in @ allowed_event_constructors
2018-06-28 02:39:46 +02:00
throw " Invalid event constructor: #{ e . constructor } not in #{ JSON . stringify ( @ allowed_event_constructors ) } "
2018-02-21 03:08:52 +01:00
if e . originalEvent . currentTarget != allowed_target [ 0 ]
throw " Invalid event target: #{ e . originalEvent . currentTarget } != #{ allowed_target [ 0 ] } "
2015-01-12 02:03:45 +01:00
# Incoming message from UiServer websocket
onMessageWebsocket: (e) =>
message = JSON . parse ( e . data )
2019-07-01 16:26:37 +02:00
@ handleMessageWebsocket ( message )
handleMessageWebsocket: (message) =>
2015-01-12 02:03:45 +01:00
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 ]
2017-07-18 20:55:53 +02:00
id = " notification-ws- #{ message . id } "
2016-03-21 09:43:53 +01:00
if " - " in message . params [ 0 ] # - in first param: message id defined
2015-08-16 11:51:00 +02:00
[ id , type ] = message . params [ 0 ] . split ( " - " )
@ notifications . add ( id , type , message . params [ 1 ] , message . params [ 2 ] )
2017-01-16 13:41:11 +01:00
else if cmd == " progress " # Display notification
@ actionProgress ( 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 == " prompt " # Prompt input
2017-05-11 17:55:09 +02:00
@ displayPrompt message . params [ 0 ] , message . params [ 1 ] , message . params [ 2 ] , message . params [ 3 ] , (res) =>
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
@ ws . response message . id , res
2016-04-09 19:49:12 +02:00
else if cmd == " confirm " # Confirm action
@ displayConfirm message . params [ 0 ] , message . params [ 1 ] , (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
2016-08-10 12:27:24 +02:00
@ updateProgress message . params
2018-04-28 22:04:58 +02:00
else if cmd == " setAnnouncerInfo "
@ sendInner message # Pass to inner frame
if message . params . address == @ address # Current page
@ setAnnouncerInfo message . params
@ updateProgress 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
2019-04-09 15:06:27 +02:00
@ log " Updating: Closing websocket "
2015-02-20 01:37:12 +01:00
@ ws . ws . close ( )
@ ws . onCloseWebsocket ( null , 4000 )
2018-11-26 00:05:04 +01:00
else if cmd == " redirect "
window . top.location = message . params
2017-11-29 13:48:07 +01:00
else if cmd == " injectHtml "
$ ( " body " ) . append ( message . params )
2018-11-26 00:05:04 +01:00
else if cmd == " injectScript "
script_tag = $ ( " <script> " )
script_tag . attr ( " nonce " , @ script_nonce )
script_tag . html ( message . params )
document . head . appendChild ( script_tag [ 0 ] )
2015-01-12 02:03:45 +01:00
else
@ sendInner message # Pass message to inner frame
# Incoming message from inner frame
onMessageInner: (e) =>
2016-03-12 20:36:17 +01:00
# No nonce security enabled, test if window opener present
2016-03-26 00:20:53 +01:00
if not window . postmessage_nonce_security and @ opener_tested == false
if window . opener and window . opener != window
2016-02-23 01:36:47 +01:00
@ log " Opener present " , window . opener
@ displayOpenerDialog ( )
return false
else
2016-03-26 00:20:53 +01:00
@opener_tested = true
2016-02-23 01:36:47 +01:00
2015-01-12 02:03:45 +01:00
message = e . data
2016-03-12 20:36:17 +01:00
# Invalid message (probably not for us)
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
if not message . cmd
2017-08-09 14:20:20 +02:00
@ log " Invalid message: " , message
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return false
2016-03-12 20:36:17 +01:00
# Test nonce security to avoid third-party messages
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
return
2016-03-12 20:36:17 +01:00
2018-02-21 03:09:48 +01:00
@ handleMessage message
2018-02-21 03:09:36 +01:00
cmd: (cmd, params={}, cb=null) =>
message = { }
message.cmd = cmd
message.params = params
message.id = @ next_cmd_message_id
if cb
@ ws . waiting_cb [ message . id ] = cb
@ next_cmd_message_id -= 1
@ handleMessage ( message )
2018-02-21 03:09:48 +01:00
handleMessage: (message) =>
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
2017-02-16 19:04:00 +01:00
else if cmd == " innerLoaded " or cmd == " wrapperInnerLoaded "
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 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 )
2017-01-16 13:41:11 +01:00
else if cmd == " wrapperProgress " # Progress bar
@ actionProgress ( message )
2015-02-10 00:08:25 +01:00
else if cmd == " wrapperSetViewport " # Set the viewport
@ actionSetViewport ( message )
2016-11-22 02:06:32 +01:00
else if cmd == " wrapperSetTitle "
2020-09-04 17:57:34 +02:00
@ log " wrapperSetTitle " , message . params
2016-11-22 02:06:32 +01:00
$ ( " head title " ) . text ( message . params )
2020-09-04 17:57:34 +02:00
@is_title_changed = true
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 )
2016-02-27 21:39:36 +01:00
else if cmd == " wrapperGetState "
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : window . history . state }
2017-08-15 02:40:38 +02:00
else if cmd == " wrapperGetAjaxKey "
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : window . ajax_key }
2016-03-19 18:05:08 +01:00
else if cmd == " wrapperOpenWindow "
@ actionOpenWindow ( message . params )
2016-08-10 12:25:25 +02:00
else if cmd == " wrapperPermissionAdd "
@ actionPermissionAdd ( message )
2016-12-30 19:32:36 +01:00
else if cmd == " wrapperRequestFullscreen "
@ actionRequestFullscreen ( )
2019-04-19 18:08:49 +02:00
else if cmd == " wrapperWebNotification "
@ actionWebNotification ( message )
else if cmd == " wrapperCloseWebNotification "
@ actionCloseWebNotification ( message )
2015-01-12 02:03:45 +01:00
else # Send to websocket
2015-02-14 14:05:00 +01:00
if message . id < 1000000
2019-02-05 15:55:12 +01:00
if message . cmd == " fileWrite " and not @ modified_panel_updater_timer and site_info ? . settings ? . own
2019-02-02 00:12:50 +01:00
@modified_panel_updater_timer = setTimeout ( => @ updateModifiedPanel ( ) ; @modified_panel_updater_timer = null ) , 1000
2015-02-14 14:05:00 +01:00
@ ws . send ( message ) # Pass message to websocket
else
@ log " Invalid inner message id "
2015-01-12 02:03:45 +01:00
2016-02-27 21:39:36 +01:00
toRelativeQuery: (query=null) ->
if query == null
query = window . location . search
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 = window . location . pathname
2016-12-14 00:25:47 +01:00
if back . match / ^ \ / [ ^ \ / ] + $ / # Add / after site address if called without it
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 += " / "
2017-05-06 17:27:49 +02:00
if query . startsWith ( " # " )
back = query
else if query . replace ( " ? " , " " )
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 += " ? " + query . replace ( " ? " , " " )
return back
2015-01-12 02:03:45 +01:00
2016-02-23 01:36:47 +01:00
displayOpenerDialog: ->
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 )
2015-01-21 12:58:26 +01:00
# - Actions -
2016-03-19 18:05:08 +01:00
actionOpenWindow: (params) ->
if typeof ( params ) == " string "
w = window . open ( )
w.opener = null
w.location = params
else
2016-03-20 21:33:13 +01:00
w = window . open ( null , params [ 1 ] , params [ 2 ] )
2016-03-19 18:05:08 +01:00
w.opener = null
w.location = params [ 0 ]
2016-12-30 19:32:36 +01:00
actionRequestFullscreen: ->
2018-09-07 11:33:40 +02:00
elem = document . getElementById ( " inner-iframe " )
request_fullscreen = elem . requestFullScreen || elem . webkitRequestFullscreen || elem . mozRequestFullScreen || elem . msRequestFullScreen
request_fullscreen . call ( elem )
2016-03-19 18:05:08 +01:00
2019-04-19 18:08:49 +02:00
actionWebNotification: (message) ->
2019-04-17 11:39:00 +02:00
$ . when ( @ event_site_info ) . done =>
# Check that the wrapper may send notifications
if Notification . permission == " granted "
2019-04-19 18:08:49 +02:00
@ displayWebNotification message
2019-04-17 11:39:00 +02:00
else if Notification . permission == " denied "
2019-04-19 18:08:49 +02:00
res = { " error " : " Web notifications are disabled by the user " }
2019-04-17 11:39:00 +02:00
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : res }
else
Notification . requestPermission ( ) . then (permission) =>
if permission == " granted "
2019-04-19 18:08:49 +02:00
@ displayWebNotification message
2019-04-17 11:39:00 +02:00
2019-04-19 18:08:49 +02:00
actionCloseWebNotification: (message) ->
2019-04-17 18:56:19 +02:00
$ . when ( @ event_site_info ) . done =>
id = message . params [ 0 ]
2019-04-19 18:08:49 +02:00
@ web_notifications [ id ] . close ( )
2019-04-17 18:56:19 +02:00
2019-04-19 18:08:49 +02:00
displayWebNotification: (message) ->
2019-04-17 11:39:00 +02:00
title = message . params [ 0 ]
id = message . params [ 1 ]
options = message . params [ 2 ]
notification = new Notification ( title , options )
2019-04-19 18:08:49 +02:00
@ web_notifications [ id ] = notification
2019-04-17 11:39:00 +02:00
notification.onshow = () =>
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : " ok " }
notification.onclick = (e) =>
if not options . focus_tab
e . preventDefault ( )
2019-04-19 18:08:49 +02:00
@ sendInner { " cmd " : " webNotificationClick " , " params " : { " id " : id } }
2019-04-17 11:39:00 +02:00
notification.onclose = () =>
2019-04-19 18:08:49 +02:00
@ sendInner { " cmd " : " webNotificationClose " , " params " : { " id " : id } }
delete @ web_notifications [ id ]
2019-04-17 11:39:00 +02:00
2016-08-10 12:25:25 +02:00
actionPermissionAdd: (message) ->
permission = message . params
2018-02-21 03:10:23 +01:00
$ . when ( @ event_site_info ) . done =>
if permission in @ site_info . settings . permissions
return false
@ ws . cmd " permissionDetails " , permission , (permission_details) =>
@ displayConfirm " This site requests permission: " + " <b> #{ @ toHtmlSafe ( permission ) } </b> " + " <br><small style= ' color: # 4F4F4F ' > #{ permission_details } </small> " , " Grant " , =>
@ ws . cmd " permissionAdd " , permission , (res) =>
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : res }
2016-08-10 12:25:25 +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
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 ] )
2018-03-06 12:02:39 +01:00
displayConfirm: (body, captions, cb) ->
body = $ ( " <span class= ' message-outer ' ><span class= ' message ' > " + body + " </span></span> " )
2017-05-18 03:05:02 +02:00
buttons = $ ( " <span class= ' buttons ' ></span> " )
2017-05-11 17:54:48 +02:00
if captions not instanceof Array then captions = [ captions ] # Convert to list if necessary
for caption , i in captions
2018-03-06 12:02:39 +01:00
button = $ ( " <a></a> " , { href: " # " + caption , class : " button button-confirm button- #{ caption } button- #{ i + 1 } " , " data-value " : i + 1 } ) # Add confirm button
button . text ( caption )
2018-02-21 03:08:52 +01:00
( (button) =>
button . on " click " , (e) =>
@ verifyEvent button , e
cb ( parseInt ( e . currentTarget . dataset . value ) )
return false
) ( button )
2017-05-18 03:05:02 +02:00
buttons . append ( button )
body . append ( buttons )
2015-02-14 14:05:00 +01:00
@ notifications . add ( " notification- #{ caption } " , " ask " , body )
2015-01-21 12:58:26 +01:00
2017-05-18 03:05:02 +02:00
buttons . first ( ) . focus ( )
2015-09-16 00:01:23 +02:00
$ ( " .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 "
2017-05-11 17:54:48 +02:00
@ displayConfirm message . params [ 0 ] , caption , (res) =>
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : res } # Response to confirm
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
return false
2015-01-24 19:14:29 +01:00
2017-05-11 17:55:09 +02:00
displayPrompt: (message, type, caption, placeholder, cb) ->
2018-03-07 03:10:13 +01:00
body = $ ( " <span class= ' message ' ></span> " ) . html ( message )
2017-11-29 13:48:20 +01:00
placeholder ? = " "
2015-01-24 19:14:29 +01:00
2018-03-06 12:02:39 +01:00
input = $ ( " <input/> " , { type: type , class : " input button- #{ type } " , placeholder: placeholder } ) # Add input
2015-01-24 19:14:29 +01:00
input . on " keyup " , (e) => # Send on enter
2018-02-21 03:08:52 +01:00
@ verifyEvent input , e
2015-01-24 19:14:29 +01:00
if e . keyCode == 13
2018-02-21 03:08:52 +01:00
cb input . val ( ) # Response to confirm
2015-01-24 19:14:29 +01:00
body . append ( input )
2018-03-06 12:02:39 +01:00
button = $ ( " <a></a> " , { href: " # " + caption , class : " button button- #{ caption } " } ) . text ( caption ) # Add confirm button
2018-02-21 03:08:52 +01:00
button . on " click " , (e) => # Response on button click
@ verifyEvent button , e
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 "
2017-05-11 17:55:09 +02:00
caption = if message . params [ 2 ] then message . params [ 2 ] else " OK "
2017-05-23 12:42:02 +02:00
if message . params [ 3 ] ?
placeholder = message . params [ 3 ]
else
placeholder = " "
2015-07-31 23:34:53 +02:00
2017-05-11 17:55:09 +02:00
@ displayPrompt message . params [ 0 ] , type , caption , placeholder , (res) =>
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
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : res } # Response to confirm
2015-07-31 23:34:53 +02:00
2019-05-29 16:02:34 +02:00
displayProgress: (type, body, percent) ->
percent = Math . min ( 100 , percent ) / 100
2017-01-16 13:41:11 +01:00
offset = 75 - ( percent * 75 )
circle = """
< div class = " circle " > < svg class = " circle-svg " width = " 30 " height = " 30 " viewport = " 0 0 30 30 " version = " 1.1 " xmlns = " http://www.w3.org/2000/svg " >
< circle r = " 12 " cx = " 15 " cy = " 15 " fill = " transparent " class = " circle-bg " > < / circle >
< circle r = " 12 " cx = " 15 " cy = " 15 " fill = " transparent " class = " circle-fg " style = " stroke-dashoffset: #{ offset } " > < / circle >
< / svg > < / div >
"""
2019-05-29 16:02:34 +02:00
body = " <span class= ' message ' > " + body + " </span> " + circle
elem = $ ( " .notification- #{ type } " )
2017-01-16 13:41:11 +01:00
if elem . length
width = $ ( " .body .message " , elem ) . outerWidth ( )
2019-05-29 16:02:34 +02:00
$ ( " .body .message " , elem ) . html ( body )
2017-01-16 13:41:11 +01:00
if $ ( " .body .message " , elem ) . css ( " width " ) == " "
$ ( " .body .message " , elem ) . css ( " width " , width )
$ ( " .body .circle-fg " , elem ) . css ( " stroke-dashoffset " , offset )
else
2019-05-29 16:02:34 +02:00
elem = @ notifications . add ( type , " progress " , $ ( body ) )
2017-01-16 13:41:11 +01:00
if percent > 0
$ ( " .body .circle-bg " , elem ) . css { " animation-play-state " : " paused " , " stroke-dasharray " : " 180px " }
if $ ( " .notification-icon " , elem ) . data ( " done " )
return false
2019-06-04 16:18:02 +02:00
else if percent >= 1 # Done
2017-01-16 13:41:11 +01:00
$ ( " .circle-fg " , elem ) . css ( " transition " , " all 0.3s ease-in-out " )
setTimeout ( ->
$ ( " .notification-icon " , elem ) . css { transform: " scale(1) " , opacity: 1 }
$ ( " .notification-icon .icon-success " , elem ) . css { transform: " rotate(45deg) scale(1) " }
) , 300
setTimeout ( =>
@ notifications . close elem
) , 3000
$ ( " .notification-icon " , elem ) . data ( " done " , true )
2019-05-29 16:02:34 +02:00
else if percent < 0 # Error
2017-01-16 13:41:11 +01:00
$ ( " .body .circle-fg " , elem ) . css ( " stroke " , " # ec6f47 " ) . css ( " transition " , " transition: all 0.3s ease-in-out " )
setTimeout ( =>
$ ( " .notification-icon " , elem ) . css { transform: " scale(1) " , opacity: 1 }
elem . removeClass ( " notification-done " ) . addClass ( " notification-error " )
$ ( " .notification-icon .icon-success " , elem ) . removeClass ( " icon-success " ) . html ( " ! " )
) , 300
$ ( " .notification-icon " , elem ) . data ( " done " , true )
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
2019-05-29 16:02:34 +02:00
actionProgress: (message) ->
message.params = @ toHtmlSafe ( message . params ) # Escape html
@ displayProgress ( message . params [ 0 ] , message . params [ 1 ] , message . params [ 2 ] )
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 " )
2016-08-10 12:26:00 +02:00
actionReload: (message) ->
2018-02-21 03:06:21 +01:00
@ reload ( message . params [ 0 ] )
2015-02-10 00:08:25 +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
reload: (url_post="") ->
2020-01-04 16:52:51 +01:00
@ log " Reload "
2019-10-06 03:20:58 +02:00
current_url = window . location . toString ( ) . replace ( /#.*/g , " " )
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 url_post
2019-10-06 03:20:58 +02:00
if current_url . indexOf ( " ? " ) > 0
window . location = current_url + " & " + url_post
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
2019-10-06 03:20:58 +02:00
window . location = current_url + " ? " + url_post
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
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) ->
2018-11-21 03:32:12 +01:00
$ . when ( @ event_site_info ) . done =>
back = localStorage . setItem " site. #{ @ site_info . address } . #{ @ site_info . auth_address } " , JSON . stringify ( message . params )
@ sendInner { " cmd " : " response " , " to " : message . id , " result " : back }
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) =>
2018-04-28 22:04:58 +02:00
if window . show_loadingscreen # Get info on modifications
@ ws . cmd " channelJoin " , { " channels " : [ " siteChanged " , " serverChanged " , " announcerChanged " ] }
else
@ ws . cmd " channelJoin " , { " channels " : [ " siteChanged " , " serverChanged " ] }
2015-01-12 02:03:45 +01:00
if not @ wrapperWsInited and @ inner_ready
@ sendInner { " cmd " : " wrapperOpenedWebsocket " } # Send to inner frame
@wrapperWsInited = true
2018-04-28 22:04:58 +02:00
if window . show_loadingscreen
@ ws . cmd " serverInfo " , [ ] , (server_info) =>
@server_info = server_info
@ ws . cmd " announcerInfo " , [ ] , (announcer_info) =>
@ setAnnouncerInfo ( announcer_info )
2015-01-12 02:03:45 +01:00
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. " )
2016-08-27 11:52:44 +02:00
else if e and e . code == 1001 and e . wasClean == true # Navigating to other page
return
2015-01-12 02:03:45 +01:00
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
2018-02-21 03:05:02 +01:00
onPageLoad: (e) =>
2020-01-04 16:52:51 +01:00
@ log " onPageLoad "
2015-01-12 02:03:45 +01:00
@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 ( )
2020-09-04 17:57:34 +02:00
else if @ site_info and @ site_info . content ? . title ? and not @ is_title_changed
window . document . title = @ site_info . content . title + " - ZeroNet "
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
@ log " Setting title to " , window . document . title
2015-01-12 02:03:45 +01:00
2018-02-21 03:03:01 +01:00
onWrapperLoad: =>
2018-11-26 00:04:06 +01:00
@script_nonce = window . script_nonce
@wrapper_key = window . wrapper_key
2018-02-21 03:03:01 +01:00
# Cleanup secret variables
delete window . wrapper
delete window . wrapper_key
2018-11-26 00:04:06 +01:00
delete window . script_nonce
2018-02-21 03:03:01 +01:00
$ ( " # script_init " ) . remove ( )
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
2020-01-04 16:53:49 +01:00
if site_info . settings . size > site_info . size_limit * 1024 * 1024 and not @ loading . screen_visible # Site size too large and not displaying it yet
@ 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) =>
if res == " ok "
@ notifications . add ( " size_limit " , " done " , " Site storage limit modified! " , 5000 )
2015-04-03 14:31:15 +02:00
2020-09-04 17:57:34 +02:00
if site_info . content ? . title ? and not @ is_title_changed
2018-10-20 02:22:29 +02:00
window . document . title = site_info . content . title + " - ZeroNet "
2015-04-03 14:31:15 +02:00
@ 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 ( )
2020-09-04 17:57:34 +02:00
if site_info . content and not @ is_title_changed
2020-01-04 16:52:51 +01:00
window . document . title = site_info . content . title + " - ZeroNet "
@ log " Required file #{ window . file_inner_path } done, setting title to " , window . document . title
2017-01-27 12:09:23 +01:00
if not window . show_loadingscreen
2015-01-12 02:03:45 +01:00
@ 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) =>
2017-04-12 17:36:50 +02:00
if res == " ok "
@ notifications . add ( " size_limit " , " done " , " Site storage limit modified! " , 5000 )
2015-02-14 14:05:00 +01:00
return false
2015-02-25 03:22:10 +01:00
2020-01-04 16:53:49 +01: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
@ log " Loading screen visible, but inner loaded "
2015-02-25 03:22:10 +01:00
@ loading . hideScreen ( )
2019-02-02 00:12:50 +01:00
if site_info ? . settings ? . own and site_info ? . settings ? . modified != @ site_info ? . settings ? . modified
@ updateModifiedPanel ( )
2020-01-04 16:53:49 +01:00
if @ loading . screen_visible and site_info . settings . size > site_info . size_limit * 1024 * 1024
@ log " Site too large "
@ loading . showTooLarge ( site_info )
2016-08-10 12:27:24 +02:00
@site_info = site_info
@ event_site_info . resolve ( )
2019-02-02 00:12:50 +01:00
siteSign: (inner_path, cb) =>
if @ site_info . privatekey
# Privatekey stored in users.json
@ infopanel . elem . find ( " .button " ) . addClass ( " loading " )
@ ws . cmd " siteSign " , { privatekey: " stored " , inner_path: inner_path , update_changed_files: true } , (res) =>
if res == " ok "
cb ? ( true )
else
cb ? ( false )
@ infopanel . elem . find ( " .button " ) . removeClass ( " loading " )
else
# Ask the user for privatekey
@ displayPrompt " Enter your private key: " , " password " , " Sign " , " " , (privatekey) => # Prompt the private key
@ infopanel . elem . find ( " .button " ) . addClass ( " loading " )
@ ws . cmd " siteSign " , { privatekey: privatekey , inner_path: inner_path , update_changed_files: true } , (res) =>
if res == " ok "
cb ? ( true )
else
cb ? ( false )
@ infopanel . elem . find ( " .button " ) . removeClass ( " loading " )
sitePublish: (inner_path) =>
@ ws . cmd " sitePublish " , { " inner_path " : inner_path , " sign " : false }
updateModifiedPanel: =>
@ ws . cmd " siteListModifiedFiles " , [ ] , (res) =>
2020-04-11 13:34:18 +02:00
num = res . modified_files ? . length
2019-02-02 00:12:50 +01:00
if num > 0
2019-02-05 15:54:32 +01:00
closed = @ site_info . settings . modified_files_notification == false
@ infopanel . show ( closed )
2019-02-02 00:12:50 +01:00
else
@ infopanel . hide ( )
if num > 0
@ infopanel . setTitle (
" #{ res . modified_files . length } modified file #{ if num > 1 then ' s ' else ' ' } " ,
res . modified_files . join ( " , " )
)
2019-02-09 13:55:53 +01:00
@ infopanel . setClosedNum ( num )
2019-02-02 00:12:50 +01:00
@ infopanel . setAction " Sign & Publish " , =>
@ siteSign " content.json " , (res) =>
if ( res )
@ notifications . add " sign " , " done " , " content.json Signed! " , 5000
@ sitePublish ( " content.json " )
return false
2020-04-11 13:34:18 +02:00
@ log " siteListModifiedFiles " , num , res
2019-02-02 00:12:50 +01:00
2018-04-28 22:04:58 +02:00
setAnnouncerInfo: (announcer_info) ->
2018-04-29 13:06:07 +02:00
status_db = { announcing: [ ] , error: [ ] , announced: [ ] }
2018-04-28 22:04:58 +02:00
for key , val of announcer_info . stats
2018-10-08 15:34:40 +02:00
if val . status
status_db [ val . status ] . push ( val )
2018-04-29 13:06:07 +02:00
status_line = " Trackers announcing: #{ status_db . announcing . length } , error: #{ status_db . error . length } , done: #{ status_db . announced . length } "
2018-04-28 22:04:58 +02:00
if @ announcer_line
@ announcer_line . text ( status_line )
else
@announcer_line = @ loading . printLine ( status_line )
2020-12-03 20:02:48 +01:00
if status_db . error . length > ( status_db . announced . length + status_db . announcing . length ) and status_db . announced . length < 3
2018-04-28 22:05:38 +02:00
@ loading . showTrackerTorBridge ( @ server_info )
2016-08-10 12:27:24 +02:00
updateProgress: (site_info) ->
2015-02-26 01:32:27 +01:00
if site_info . tasks > 0 and site_info . started_task_num > 0
2016-09-04 18:01:48 +02:00
@ loading . setProgress 1 - ( Math . max ( site_info . tasks , site_info . bad_files ) / site_info . started_task_num )
2015-02-26 01:32:27 +01:00
else
@ loading . hideProgress ( )
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
2017-05-11 17:54:48 +02:00
if value instanceof Array
value = @ toHtmlSafe ( value )
else
2018-03-06 12:01:39 +01:00
value = String ( value ) . replace ( /&/g , ' & ' ) . replace ( /</g , ' < ' ) . replace ( />/g , ' > ' ) . replace ( /"/g , ' " ' ) . replace ( /'/g , ' ' ' ) # Escape dangerous characters
2018-02-21 03:05:11 +01:00
value = value . replace ( /<([\/]{0,1}(br|b|u|i|small))>/g , " <$1> " ) # Unescape b, i, u, br tags
2015-02-10 00:08:25 +01:00
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) =>
2020-01-04 16:52:51 +01:00
@ log " setSizeLimit: #{ size_limit } , reload: #{ reload } "
2020-01-04 16:54:13 +01:00
@inner_loaded = false # Inner frame not loaded, just a 404 page displayed
2015-02-14 14:05:00 +01:00
@ ws . cmd " siteSetLimit " , [ size_limit ] , (res) =>
2017-04-12 17:36:50 +02:00
if res != " ok "
return false
2015-02-14 14:05:00 +01:00
@ loading . printLine res
2020-01-04 16:54:13 +01:00
@inner_loaded = false
2018-04-28 22:01:12 +02:00
if reload then @ reloadIframe ( )
2015-02-14 14:05:00 +01:00
return false
2018-04-28 22:01:12 +02:00
reloadIframe: =>
src = $ ( " iframe " ) . attr ( " src " )
@ ws . cmd " serverGetWrapperNonce " , [ ] , (wrapper_nonce) =>
src = src . replace ( /wrapper_nonce=[A-Za-z0-9]+/ , " wrapper_nonce= " + wrapper_nonce )
@ log " Reloading iframe using url " , src
$ ( " iframe " ) . attr " src " , src
2015-01-12 02:03:45 +01:00
log: (args...) ->
console . log " [Wrapper] " , args . . .
2016-04-20 23:22:39 +02:00
origin = window . server_url or window . location . href . replace ( /(\:\/\/.*?)\/.*/ , " $1 " )
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 ' }
2019-04-15 15:42:24 +02:00
ws_url = proto . ws + " : " + origin . replace ( proto . http + " : " , " " ) + " /ZeroNet-Internal/Websocket?wrapper_key= " + window . wrapper_key
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
2016-02-23 01:36:47 +01:00
window . wrapper = new Wrapper ( ws_url )
2018-02-21 03:08:52 +01:00