def next_button_clicked(self): """ """ if self.currentId() == self.steps.index('connection_main_page'): self.resize(580, 400) self.button(QtGui.QWizard.CancelButton).setVisible(True) self.button(QtGui.QWizard.FinishButton).setVisible(False) #self.center() if self.currentId() == self.steps.index('tor_status_page'): self.button(QtGui.QWizard.BackButton).setVisible(True) self.button(QtGui.QWizard.CancelButton).setVisible(True) self.button(QtGui.QWizard.FinishButton).setVisible(False) ## Get a fresh torrc shutil.copy('/etc/tor/torrc.orig', '/etc/tor/torrc') if Common.use_bridges: bridges = json.loads(open(Common.bridges_default_path).read()) with open('/etc/tor/torrc', 'a') as f: f.write('UseBridges 1\n') if Common.bridge_type == 'obfs3': f.write('ClientTransportPlugin obfs2,obfs3 exec /usr/bin/obfsproxy managed\n') elif Common.bridge_type == 'scramblesuit': f.write('ClientTransportPlugin obfs2,obfs3,scramblesuit exec /usr/bin/obfsproxy managed\n') elif Common.bridge_type == 'obfs4': f.write('ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy managed\n') for bridge in bridges['bridges'][Common.bridge_type]: f.write('Bridge %s\n' % bridge) if Common.use_proxy: pass if not Common.disable_tor: self.tor_status = tor_status.set_enabled() if self.tor_status == 'tor_enabled' or self.tor_status == 'tor_already_enabled': self.tor_status_page.bootstrap_progress.setVisible(True) self.bootstrap_thread = TorBootstrap(self) self.connect(self.bootstrap_thread, self.bootstrap_thread.signal, self.update_bootstrap) self.bootstrap_thread.finished.connect(self.show_finish_button) self.bootstrap_thread.start() else: pass else: self.tor_status = tor_status.set_disabled() self.tor_status_page.bootstrap_progress.setVisible(False) self.tor_status_page.text.setText('<b>Tor is disabled.</b> You will not be able to use any \ network facing application.<p> If you shut down the gateway \ now, this wizard will be run automatically next time you boot. \ </p><p>You can run it at any moment using <i>Anon Connection Wizard</i> \ from your application launcher, or from a terminal:<blockquote> \ <code>kdesudo anon-connection-wizard</code></blockquote> \ or press the Back button and select another option.') self.show_finish_button()
def next_button_clicked(self): """ Next button slot. The commands cannot be implemented in the wizard's nextId() function, as it is polled by the event handler on the creation of the page. Depending on the checkbox states, the commands would be run when the page is loaded. Those button_clicked functions are called once, when the user clicks the corresponding button. Options (like button states, window size changes...) are set here. """ if Common.argument == 'setup': if self.env == 'workstation': if (self.currentId() == self.steps.index('whonix_repo_page') or self.currentId() == self.steps.index('finish_page')): self.resize(470, 310) self.center() if self.env == 'gateway': # Set Next button state if self.currentId() == self.steps.index('connection_page'): self.resize(580, 390) self.center() if (self.connection_page.censored.isChecked() or self.connection_page.use_proxy.isChecked()): self.button(QtGui.QWizard.NextButton).setEnabled(False) else: self.button(QtGui.QWizard.NextButton).setEnabled(True) if self.currentId() == self.steps.index('tor_status_page'): if self.connection_page.enable.isChecked(): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) Common.tor_status = tor_status.set_enabled() QApplication.restoreOverrideCursor() if Common.tor_status == 'tor_enabled': if Common.exit_after_tor_enabled: sys.exit(0) self.tor_status_page.text.setText(self._('tor_enabled')) torrc_text = open('/etc/tor/torrc').read() self.tor_status_page.torrc.setPlainText(torrc_text) self.tor_status_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-complete.png')) elif Common.tor_status == 'tor_already_enabled': self.tor_status_page.text.setText(self._('tor_already_enabled')) torrc_text = open('/etc/tor/torrc').read() self.tor_status_page.torrc.setPlainText(torrc_text) self.tor_status_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-complete.png')) else: self.tor_status_page.torrc.setFrameShape(QtGui.QFrame.NoFrame) self.tor_status_page.text.setText(self._('something_wrong')) self.tor_status_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-reject.png')) elif self.connection_page.disable.isChecked(): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) Common.tor_status = tor_status.set_disabled() QApplication.restoreOverrideCursor() if Common.tor_status == 'tor_disabled': self.tor_status_page.text.setText(self._('tor_disabled')) torrc_text = open('/etc/tor/torrc').read() self.tor_status_page.torrc.setPlainText(torrc_text) self.tor_status_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-attention.png')) elif Common.tor_status == 'tor_already_disabled': self.tor_status_page.text.setText(self._('tor_already_disabled')) torrc_text = open('/etc/tor/torrc').read() self.tor_status_page.torrc.setPlainText(torrc_text) self.tor_status_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-attention.png')) else: self.tor_status_page.torrc.setFrameShape(QtGui.QFrame.NoFrame) self.tor_status_page.text.setText(self._('something_wrong')) self.tor_status_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-reject.png')) if self.currentId() == self.steps.index('whonix_repo_page'): self.whonix_repo_page.text.setText(self._('whonix_repository_page')) if Common.argument == 'setup' or Common.argument == 'repository': if self.currentId() == self.steps.index('repository_wizard_finish'): if Common.disable_repo: command = 'whonix_repository --disable' QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) exit_code = call(command, shell=True) QApplication.restoreOverrideCursor() mypath = inspect.getfile(inspect.currentframe()) if exit_code == 0: self.repository_wizard_finish.text.setText(self._('repo_finish_disabled')) message = 'INFO %s: Ok, exit code of "%s" was %s.' % ( mypath, command, exit_code ) else: error = '<p>ERROR %s: exit code of \"%s\" was %s.</p>' % ( mypath, command, exit_code ) finish_text_failed = error + self.finish_text_failed self.repository_wizard_finish.text.setText(self._('repo_finish_failed')) message = error command = 'echo ' + message call(command, shell=True) self.one_shot = False else: if self.repository_wizard_page_2.stable_repo.isChecked(): codename = ' --repository stable' elif self.repository_wizard_page_2.testers_repo.isChecked(): codename = ' --repository testers' elif self.repository_wizard_page_2.devs_repo.isChecked(): codename = ' --repository developers' command = 'whonix_repository --enable' + codename QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) exit_code = call(command, shell=True) QApplication.restoreOverrideCursor() mypath = inspect.getfile(inspect.currentframe()) if exit_code == 0: self.repository_wizard_finish.text.setText(self._('repo_finish_enabled')) message = 'INFO %s: Ok, exit code of "%s" was %s.' % ( mypath, command, exit_code ) else: error = '<p>ERROR %s: exit code of \"%s\" was %s.</p>' % ( mypath, command, exit_code ) finish_text_failed = error + self.finish_text_failed self.repository_wizard_finish.text.setText(self._('repo_finish_failed')) message = error command = 'echo ' + message call(command, shell=True) self.one_shot = False if Common.argument == 'setup': if self.currentId() == self.steps.index('finish_page'): # for whonixcheck. Common.is_complete = True if self.env == 'gateway': if (Common.tor_status == 'tor_enabled' or Common.tor_status == 'tor_already_enabled'): self.finish_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-complete.png')) self.finish_page.text.setText(self._('finish_page_ok')) else: Common.is_complete = False if (Common.tor_status == 'tor_disabled' or Common.tor_status == 'tor_already_disabled'): self.finish_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-attention.png')) self.finish_page.text.setText(self._('finish_disabled')) # ERROR pages. elif Common.tor_status == 'no_torrc': self.finish_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-reject.png')) self.button(QtGui.QWizard.BackButton).setEnabled(False) self.finish_page.text.setText(self._('no_torrc')) elif Common.tor_status == 'bad_torrc': self.finish_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-reject.png')) self.button(QtGui.QWizard.BackButton).setEnabled(False) self.finish_page.text.setText(self._('bad_torrc')) elif Common.tor_status == 'cannot_connect': # #DisableNetwork 0 was uncommented. re-comment. QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) Common.tor_status = tor_status.set_disabled() QApplication.restoreOverrideCursor() self.finish_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-reject.png')) self.button(QtGui.QWizard.BackButton).setEnabled(False) self.finish_page.text.setText(self._('cannot_connect')) if Common.show_disclaimer: # Disclaimer page 1 not understood -> leave if self.disclaimer_1.no_button.isChecked(): self.hide() command = '/sbin/poweroff' call(command, shell=True) # Disclaimer page 2 not understood -> leave if self.disclaimer_2.no_button.isChecked(): self.hide() command = '/sbin/poweroff' call(command, shell=True) if self.env == 'workstation': self.finish_page.icon.setPixmap(QtGui.QPixmap( \ '/usr/share/icons/oxygen/48x48/status/task-complete.png')) self.finish_page.text.setText(self._('finish_page_ok')) if Common.argument == 'locale_settings': if self.currentId() == self.steps.index('locale_settings_finish'): if self.locale_settings.other_button.isChecked(): kcmshell = distutils.spawn.find_executable("kcmshell4") if self.locale_settings.lang_checkbox.isChecked(): command = command = '%s language' % (kcmshell) call(command, shell=True) if self.locale_settings.kbd_checkbox.isChecked(): command = command = '%s kcm_keyboard' % (kcmshell) call(command, shell=True) self.button(QtGui.QWizard.BackButton).setEnabled(False) self.locale_settings_finish.text.setText(self._('locale_finish'))
def next_button_clicked(self): """ """ if self.currentId() == self.steps.index('connection_main_page'): self.resize(580, 400) self.button(QtWidgets.QWizard.CancelButton).setVisible(True) self.button(QtWidgets.QWizard.FinishButton).setVisible(False) #self.center() if self.currentId() == self.steps.index('tor_status_page'): self.button(QtWidgets.QWizard.BackButton).setVisible(True) self.button(QtWidgets.QWizard.CancelButton).setVisible(True) self.button(QtWidgets.QWizard.FinishButton).setVisible(False) ## Get a fresh torrc shutil.copy('/etc/tor/torrc.orig', '/etc/tor/torrc') if Common.use_bridges: with open('/etc/tor/torrc', 'a') as f: f.write('UseBridges 1\n') if Common.use_default_bridge: # Q: Why there is no those lines in torrc after using Torlauncher to configure that? # Do we really need these? # If so, can we just input them as default and manage them only use UseBridges 0/1 to control it? if Common.bridge_type == 'obfs3': f.write('ClientTransportPlugin obfs2,obfs3 exec /usr/bin/obfsproxy managed\n') elif Common.bridge_type == 'scramblesuit': f.write('ClientTransportPlugin obfs2,obfs3,scramblesuit exec /usr/bin/obfsproxy managed\n') elif Common.bridge_type == 'obfs4': f.write('ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy managed\n') ''' More types of bridges will be availble once Whonix support them: meek, flashproxy''' #elif Common.bridge_type == '': bridges = json.loads(open(Common.bridges_default_path).read()) # default bridges will be loaded, however, what does the variable bridges do? A: for bridge in bridges # Q: What does json.load do? for bridge in bridges['bridges'][Common.bridge_type]: # What does this line mean? A: The bridges are more like a multilayer-dictionary f.write('Bridge {0}\n'.format(bridge)) # This is the format to configure a bridge in torrc else: # Use custom bridges # TODO: we should preserve the custom bridge setting for the next time use. # TODO: Unfinished for different types of bridges: if Common.bridge_custom.startswith('obfs4'): f.write('ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy managed\n') elif Common.bridge_custom.startswith('obfs3'): f.write('ClientTransportPlugin obfs2,obfs3 exec /usr/bin/obfsproxy managed\n') elif Common.bridge_custom.startswith('fte'): f.write('ClientTransportPlugin fte exec /usr/bin/fteproxy --managed\n') elif Common.bridge_custom.startswith('meek-amazon'): pass # Wait to be implemented in Whonix. elif Common.bridge_custom.startswith('meek-azure'): pass # Write the specific bridge address, port, cert etc. bridge_custom_list = Common.bridge_custom.split('\n') for bridge in bridge_custom_list: f.write('Bridge {0}\n'.format(bridge)) ''' The part is the IO to torrc for proxy settings. Related official docs: https://www.torproject.org/docs/tor-manual.html.en ''' if Common.use_proxy: #pass with open('/etc/tor/torrc', 'a') as f: # TODO: Notice that if SOCKS4 is selected, the proxy username and password inputLine should be disabled # This is because SOCKS4 does not support that. if Common.proxy_type == 'HTTP/HTTPS': f.write('HTTPSProxy {0}:{1}\n'.format(Common.proxy_ip, Common.proxy_port)) if (Common.proxy_username != ''): # Q: It seems there is no need to check password because username is essential, not password, right? f.write('HTTPSProxyAuthenticator {0}:{1}\n'.format(Common.proxy_username, Common.proxy_password)) elif Common.proxy_type == 'SOCKS4': f.write('Socks4Proxy {0}:{1}\n'.format(Common.proxy_ip, Common.proxy_port)) elif Common.proxy_type == 'SOCKS5': f.write('Socks5Proxy {0}:{1}\n'.format(Common.proxy_ip, Common.proxy_port)) if (Common.proxy_username != ''): f.write('Socks5ProxyUsername {0}\n'.format(Common.proxy_username)) f.write('Socks5ProxyPassword {0}\n'.format(Common.proxy_password)) ''' TODO: Another feature can be implemented in the future is auto-configure for well-known third party proxy-based censorship circumvention tools, like Lantern. Uncomment all the fragments to enable it. ''' # proxies = json.loads(open(Common.well_known_proxy_setting_default_path).read()) # default bridges will be loaded, however, what does the variable bridges do? A: for bridge in bridges # for proxy in proxies['proxies'][Common.well_known_proxy_setting]: # f.write('{0}\n'.format(proxy)) '''Arranging different tor_status_page according to the value of disable_tor.''' if not Common.disable_tor: self.tor_status = tor_status.set_enabled() if self.tor_status == 'tor_enabled' or self.tor_status == 'tor_already_enabled': self.tor_status_page.bootstrap_progress.setVisible(True) self.bootstrap_thread = TorBootstrap(self) self.bootstrap_thread.signal.connect(self.update_bootstrap) self.bootstrap_thread.finished.connect(self.show_finish_button) self.bootstrap_thread.start() else: pass else: self.tor_status = tor_status.set_disabled() self.tor_status_page.bootstrap_progress.setVisible(False) self.tor_status_page.text.setText('<b>Tor is disabled.</b> You will not be able to use any \ network facing application.<p> If you shut down the gateway \ now, this wizard will be run automatically next time you boot. \ </p><p>You can run it at any moment using <i>Anon Connection Wizard</i> \ from your application launcher, or from a terminal:<blockquote> \ <code>kdesudo anon-connection-wizard</code></blockquote> \ or press the Back button and select another option.') self.show_finish_button()