aboutsummaryrefslogtreecommitdiff
path: root/onionshare
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-11-02 17:01:47 -0700
committerMicah Lee <micah@micahflee.com>2019-11-02 17:01:47 -0700
commit87918c5d89f26bce515879895ed0a4ae736dbd2a (patch)
treed700cc583b6afb626cf822ab01feaceb924f338a /onionshare
parent598db21dcdea4b98c4a4e5216ff2d80d7cbd4b26 (diff)
downloadonionshare-87918c5d89f26bce515879895ed0a4ae736dbd2a.tar.gz
onionshare-87918c5d89f26bce515879895ed0a4ae736dbd2a.zip
Fix CLI tests, and also fix bug related to autostop_sharing that the tests found
Diffstat (limited to 'onionshare')
-rw-r--r--onionshare/__init__.py6
-rw-r--r--onionshare/mode_settings.py22
-rw-r--r--onionshare/onionshare.py6
-rw-r--r--onionshare/settings.py20
-rw-r--r--onionshare/web/share_mode.py13
5 files changed, 34 insertions, 33 deletions
diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index e7c7158c..7bc18bff 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -282,7 +282,7 @@ def main(cwd=None):
)
sys.exit()
- app.start_onion_service(False, True)
+ app.start_onion_service(mode_settings, False, True)
url = build_url(mode_settings, app, web)
schedule = datetime.now() + timedelta(seconds=autostart_timer)
if mode == "receive":
@@ -318,9 +318,9 @@ def main(cwd=None):
print("Waiting for the scheduled time before starting...")
app.onion.cleanup(False)
time.sleep(autostart_timer)
- app.start_onion_service()
+ app.start_onion_service(mode_settings)
else:
- app.start_onion_service()
+ app.start_onion_service(mode_settings)
except KeyboardInterrupt:
print("")
sys.exit()
diff --git a/onionshare/mode_settings.py b/onionshare/mode_settings.py
index 9557abcd..dfc0b939 100644
--- a/onionshare/mode_settings.py
+++ b/onionshare/mode_settings.py
@@ -17,6 +17,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
+import os
+import pwd
class ModeSettings:
@@ -43,7 +45,7 @@ class ModeSettings:
"client_auth": False,
},
"share": {"autostop_sharing": True},
- "receive": {"data_dir": self.common.settings.build_default_data_dir()},
+ "receive": {"data_dir": self.build_default_data_dir()},
"website": {"disable_csp": False},
}
@@ -52,3 +54,21 @@ class ModeSettings:
def set(self, group, key, val):
self.settings[group][key] = val
+
+ def build_default_data_dir(self):
+ """
+ Returns the path of the default Downloads directory for receive mode.
+ """
+
+ if self.common.platform == "Darwin":
+ # We can't use os.path.expanduser() in macOS because in the sandbox it
+ # returns the path to the sandboxed homedir
+ real_homedir = pwd.getpwuid(os.getuid()).pw_dir
+ return os.path.join(real_homedir, "OnionShare")
+ elif self.common.platform == "Windows":
+ # On Windows, os.path.expanduser() needs to use backslash, or else it
+ # retains the forward slash, which breaks opening the folder in explorer.
+ return os.path.expanduser("~\OnionShare")
+ else:
+ # All other OSes
+ return os.path.expanduser("~/OnionShare")
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index a5c03ea3..f4828140 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -63,7 +63,9 @@ class OnionShare(object):
except:
raise OSError(strings._("no_available_port"))
- def start_onion_service(self, await_publication=True, save_scheduled_key=False):
+ def start_onion_service(
+ self, mode_settings, await_publication=True, save_scheduled_key=False
+ ):
"""
Start the onionshare onion service.
"""
@@ -83,7 +85,7 @@ class OnionShare(object):
self.port, await_publication, save_scheduled_key
)
- if self.stealth:
+ if mode_settings.get("general", "client_auth"):
self.auth_string = self.onion.auth_string
def cleanup(self):
diff --git a/onionshare/settings.py b/onionshare/settings.py
index 00854204..6d6528a4 100644
--- a/onionshare/settings.py
+++ b/onionshare/settings.py
@@ -122,7 +122,7 @@ class Settings(object):
"public_mode": False,
"password": "",
"hidservauth_string": "",
- "data_dir": self.build_default_data_dir(),
+ "data_dir": "",
"csp_header_disabled": False,
"locale": None, # this gets defined in fill_in_defaults()
}
@@ -163,24 +163,6 @@ class Settings(object):
"""
return os.path.join(self.common.build_data_dir(), "onionshare.json")
- def build_default_data_dir(self):
- """
- Returns the path of the default Downloads directory for receive mode.
- """
-
- if self.common.platform == "Darwin":
- # We can't use os.path.expanduser() in macOS because in the sandbox it
- # returns the path to the sandboxed homedir
- real_homedir = pwd.getpwuid(os.getuid()).pw_dir
- return os.path.join(real_homedir, "OnionShare")
- elif self.common.platform == "Windows":
- # On Windows, os.path.expanduser() needs to use backslash, or else it
- # retains the forward slash, which breaks opening the folder in explorer.
- return os.path.expanduser("~\OnionShare")
- else:
- # All other OSes
- return os.path.expanduser("~/OnionShare")
-
def load(self):
"""
Load the settings from file.
diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py
index 60c8eca0..16a16a0b 100644
--- a/onionshare/web/share_mode.py
+++ b/onionshare/web/share_mode.py
@@ -38,7 +38,7 @@ class ShareModeWeb(SendBaseModeWeb):
# Deny new downloads if "Stop sharing after files have been sent" is checked and there is
# currently a download
deny_download = (
- not self.web.settings.get("share", "autostop_sharing")
+ self.web.settings.get("share", "autostop_sharing")
and self.download_in_progress
)
if deny_download:
@@ -64,7 +64,7 @@ class ShareModeWeb(SendBaseModeWeb):
# Deny new downloads if "Stop After First Download" is checked and there is
# currently a download
deny_download = (
- not self.web.settings.get("share", "autostop_sharing")
+ self.web.settings.get("share", "autostop_sharing")
and self.download_in_progress
)
if deny_download:
@@ -102,7 +102,7 @@ class ShareModeWeb(SendBaseModeWeb):
def generate():
# Starting a new download
- if not self.web.settings.get("share", "autostop_sharing"):
+ if self.web.settings.get("share", "autostop_sharing"):
self.download_in_progress = True
chunk_size = 102400 # 100kb
@@ -167,14 +167,11 @@ class ShareModeWeb(SendBaseModeWeb):
sys.stdout.write("\n")
# Download is finished
- if not self.web.settings.get("share", "autostop_sharing"):
+ if self.web.settings.get("share", "autostop_sharing"):
self.download_in_progress = False
# Close the server, if necessary
- if (
- not self.web.settings.get("share", "autostop_sharing")
- and not canceled
- ):
+ if self.web.settings.get("share", "autostop_sharing") and not canceled:
print("Stopped because transfer is complete")
self.web.running = False
try: