persistent sessions #486
This commit is contained in:
parent
5457cdcd80
commit
c67bfe74a7
|
@ -173,7 +173,7 @@ class Core(
|
||||||
# Load the GeoIP DB for country look-ups
|
# Load the GeoIP DB for country look-ups
|
||||||
self.session.load_country_db(
|
self.session.load_country_db(
|
||||||
pkg_resources.resource_filename("deluge", os.path.join("data", "GeoIP.dat")))
|
pkg_resources.resource_filename("deluge", os.path.join("data", "GeoIP.dat")))
|
||||||
|
|
||||||
# Set the user agent
|
# Set the user agent
|
||||||
self.settings = lt.session_settings()
|
self.settings = lt.session_settings()
|
||||||
self.settings.user_agent = "Deluge %s" % deluge.common.get_version()
|
self.settings.user_agent = "Deluge %s" % deluge.common.get_version()
|
||||||
|
@ -186,7 +186,7 @@ class Core(
|
||||||
# Load metadata extension
|
# Load metadata extension
|
||||||
self.session.add_extension(lt.create_metadata_plugin)
|
self.session.add_extension(lt.create_metadata_plugin)
|
||||||
self.session.add_extension(lt.create_ut_metadata_plugin)
|
self.session.add_extension(lt.create_ut_metadata_plugin)
|
||||||
|
|
||||||
# Start the AlertManager
|
# Start the AlertManager
|
||||||
self.alerts = AlertManager(self.session)
|
self.alerts = AlertManager(self.session)
|
||||||
|
|
||||||
|
@ -363,6 +363,7 @@ class Core(
|
||||||
'upload_rate':float(),
|
'upload_rate':float(),
|
||||||
'num_connections':int(),
|
'num_connections':int(),
|
||||||
'dht_nodes',int(),
|
'dht_nodes',int(),
|
||||||
|
'free_space':float()
|
||||||
'max_num_connections':int(),
|
'max_num_connections':int(),
|
||||||
'max_download':float(),
|
'max_download':float(),
|
||||||
'max_upload':float()
|
'max_upload':float()
|
||||||
|
@ -374,6 +375,7 @@ class Core(
|
||||||
"upload_rate":self.session.status().payload_upload_rate,
|
"upload_rate":self.session.status().payload_upload_rate,
|
||||||
"num_connections":self.session.num_connections(),
|
"num_connections":self.session.num_connections(),
|
||||||
"dht_nodes":self.session.status().dht_nodes,
|
"dht_nodes":self.session.status().dht_nodes,
|
||||||
|
"free_space":deluge.common.free_space(self.config["download_location"]),
|
||||||
#max config values:
|
#max config values:
|
||||||
"max_download":self.config["max_download_speed"],
|
"max_download":self.config["max_download_speed"],
|
||||||
"max_upload":self.config["max_upload_speed"],
|
"max_upload":self.config["max_upload_speed"],
|
||||||
|
@ -415,7 +417,7 @@ class Core(
|
||||||
|
|
||||||
# Run the plugin hooks for 'post_torrent_add'
|
# Run the plugin hooks for 'post_torrent_add'
|
||||||
self.plugins.run_post_torrent_add(torrent_id)
|
self.plugins.run_post_torrent_add(torrent_id)
|
||||||
|
|
||||||
def export_remove_torrent(self, torrent_ids, remove_torrent, remove_data):
|
def export_remove_torrent(self, torrent_ids, remove_torrent, remove_data):
|
||||||
log.debug("Removing torrent %s from the core.", torrent_ids)
|
log.debug("Removing torrent %s from the core.", torrent_ids)
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
|
@ -645,11 +647,11 @@ class Core(
|
||||||
"""Returns the size of the file or folder 'path' and -1 if the path is
|
"""Returns the size of the file or folder 'path' and -1 if the path is
|
||||||
unaccessible (non-existent or insufficient privs)"""
|
unaccessible (non-existent or insufficient privs)"""
|
||||||
return deluge.common.get_path_size(path)
|
return deluge.common.get_path_size(path)
|
||||||
|
|
||||||
def export_create_torrent(self, path, tracker, piece_length, comment, target,
|
def export_create_torrent(self, path, tracker, piece_length, comment, target,
|
||||||
url_list, private, created_by, httpseeds, add_to_session):
|
url_list, private, created_by, httpseeds, add_to_session):
|
||||||
|
|
||||||
log.debug("creating torrent..")
|
log.debug("creating torrent..")
|
||||||
threading.Thread(target=_create_torrent_thread,
|
threading.Thread(target=_create_torrent_thread,
|
||||||
args=(
|
args=(
|
||||||
path,
|
path,
|
||||||
|
@ -662,7 +664,7 @@ class Core(
|
||||||
created_by,
|
created_by,
|
||||||
httpseeds,
|
httpseeds,
|
||||||
add_to_session)).start()
|
add_to_session)).start()
|
||||||
|
|
||||||
def _create_torrent_thread(self, path, tracker, piece_length, comment, target,
|
def _create_torrent_thread(self, path, tracker, piece_length, comment, target,
|
||||||
url_list, private, created_by, httpseeds, add_to_session):
|
url_list, private, created_by, httpseeds, add_to_session):
|
||||||
import deluge.metafile
|
import deluge.metafile
|
||||||
|
@ -685,16 +687,16 @@ class Core(
|
||||||
when connecting to the daemon remotely and installing a new plugin on
|
when connecting to the daemon remotely and installing a new plugin on
|
||||||
the client side. 'plugin_data' is a xmlrpc.Binary object of the file data,
|
the client side. 'plugin_data' is a xmlrpc.Binary object of the file data,
|
||||||
ie, plugin_file.read()"""
|
ie, plugin_file.read()"""
|
||||||
|
|
||||||
f = open(os.path.join(self.config["config_location"], "plugins", filename), "wb")
|
f = open(os.path.join(self.config["config_location"], "plugins", filename), "wb")
|
||||||
f.write(plugin_data.data)
|
f.write(plugin_data.data)
|
||||||
f.close()
|
f.close()
|
||||||
component.get("PluginManager").scan_for_plugins()
|
component.get("PluginManager").scan_for_plugins()
|
||||||
|
|
||||||
def export_rescan_plugins(self):
|
def export_rescan_plugins(self):
|
||||||
"""Rescans the plugin folders for new plugins"""
|
"""Rescans the plugin folders for new plugins"""
|
||||||
component.get("PluginManager").scan_for_plugins()
|
component.get("PluginManager").scan_for_plugins()
|
||||||
|
|
||||||
## Queueing functions ##
|
## Queueing functions ##
|
||||||
def export_queue_top(self, torrent_ids):
|
def export_queue_top(self, torrent_ids):
|
||||||
log.debug("Attempting to queue %s to top", torrent_ids)
|
log.debug("Attempting to queue %s to top", torrent_ids)
|
||||||
|
|
|
@ -48,7 +48,7 @@ def check_session(func):
|
||||||
#check session:
|
#check session:
|
||||||
vars = web.input(redir_after_login = None)
|
vars = web.input(redir_after_login = None)
|
||||||
ck = cookies()
|
ck = cookies()
|
||||||
if ck.has_key("session_id") and ck["session_id"] in utils.SESSIONS:
|
if ck.has_key("session_id") and ck["session_id"] in utils.config.get("sessions"):
|
||||||
return func(self, name) #check_session:ok
|
return func(self, name) #check_session:ok
|
||||||
elif vars.redir_after_login:
|
elif vars.redir_after_login:
|
||||||
utils.seeother(url("/login",redir=self_url()))
|
utils.seeother(url("/login",redir=self_url()))
|
||||||
|
|
|
@ -68,15 +68,19 @@ def setcookie(key, val):
|
||||||
return w_setcookie(key, val , expires=2592000)
|
return w_setcookie(key, val , expires=2592000)
|
||||||
|
|
||||||
#really simple sessions, to bad i had to implement them myself.
|
#really simple sessions, to bad i had to implement them myself.
|
||||||
SESSIONS = []
|
|
||||||
def start_session():
|
def start_session():
|
||||||
session_id = str(random.random())
|
session_id = str(random.random())
|
||||||
SESSIONS.append(session_id)
|
config.set("sessions", config.get("sessions") + [session_id])
|
||||||
|
if len(config.get("sessions")) > 30: #store a max of 20 sessions.
|
||||||
|
config.set("sessions",config["sessions"][:-20])
|
||||||
setcookie("session_id", session_id)
|
setcookie("session_id", session_id)
|
||||||
|
config.save()
|
||||||
|
|
||||||
def end_session():
|
def end_session():
|
||||||
session_id = getcookie("session_id")
|
session_id = getcookie("session_id")
|
||||||
setcookie("session_id","")
|
setcookie("session_id","")
|
||||||
|
if session_id in config.get("sessions"):
|
||||||
|
config.set("sessions", config.get("sessions").append(session_id))
|
||||||
#/sessions
|
#/sessions
|
||||||
|
|
||||||
def seeother(url, *args, **kwargs):
|
def seeother(url, *args, **kwargs):
|
||||||
|
|
|
@ -60,5 +60,6 @@ CONFIG_DEFAULTS = {
|
||||||
"cache_templates":True,
|
"cache_templates":True,
|
||||||
"daemon":"http://localhost:58846",
|
"daemon":"http://localhost:58846",
|
||||||
"base":"",
|
"base":"",
|
||||||
"disallow":{}
|
"disallow":{},
|
||||||
|
"sessions":[]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue