321
327
self.checker_command = config[u"checker"]
322
328
self.current_checker_command = None
323
329
self.last_connect = None
330
self._approved = None
331
self.approved_by_default = config.get(u"approved_by_default",
324
333
self.approvals_pending = 0
325
self._approved = None
326
self.approved_by_default = config.get(u"approved_by_default",
328
self.approved_delay = string_to_delta(
329
config[u"approved_delay"])
330
self.approved_duration = string_to_delta(
331
config[u"approved_duration"])
334
self.approval_delay = string_to_delta(
335
config[u"approval_delay"])
336
self.approval_duration = string_to_delta(
337
config[u"approval_duration"])
332
338
self.changedstate = multiprocessing_manager.Condition(multiprocessing_manager.Lock())
334
340
def send_changedstate(self):
335
341
self.changedstate.acquire()
336
342
self.changedstate.notify_all()
709
716
+ self.name.replace(u".", u"_")))
710
717
DBusObjectWithProperties.__init__(self, self.bus,
711
718
self.dbus_object_path)
720
def _get_approvals_pending(self):
721
return self._approvals_pending
722
def _set_approvals_pending(self, value):
723
old_value = self._approvals_pending
724
self._approvals_pending = value
726
if (hasattr(self, "dbus_object_path")
727
and bval is not bool(old_value)):
728
dbus_bool = dbus.Boolean(bval, variant_level=1)
729
self.PropertyChanged(dbus.String(u"ApprovalPending"),
732
approvals_pending = property(_get_approvals_pending,
733
_set_approvals_pending)
734
del _get_approvals_pending, _set_approvals_pending
714
737
def _datetime_to_dbus(dt, variant_level=0):
898
# approved_pending - property
923
# ApprovalPending - property
899
924
@dbus_service_property(_interface, signature=u"b", access=u"read")
900
def approved_pending_dbus_property(self):
901
return dbus.Boolean(self.approved_pending())
925
def ApprovalPending_dbus_property(self):
926
return dbus.Boolean(bool(self.approvals_pending))
903
# approved_by_default - property
928
# ApprovedByDefault - property
904
929
@dbus_service_property(_interface, signature=u"b",
905
930
access=u"readwrite")
906
def approved_by_default_dbus_property(self):
907
return dbus.Boolean(self.approved_by_default)
909
# approved_delay - property
910
@dbus_service_property(_interface, signature=u"t",
912
def approved_delay_dbus_property(self):
913
return dbus.UInt64(self.approved_delay_milliseconds())
915
# approved_duration - property
916
@dbus_service_property(_interface, signature=u"t",
918
def approved_duration_dbus_property(self):
919
return dbus.UInt64(self._timedelta_to_milliseconds(
920
self.approved_duration))
931
def ApprovedByDefault_dbus_property(self, value=None):
932
if value is None: # get
933
return dbus.Boolean(self.approved_by_default)
934
self.approved_by_default = bool(value)
936
self.PropertyChanged(dbus.String(u"ApprovedByDefault"),
937
dbus.Boolean(value, variant_level=1))
939
# ApprovalDelay - property
940
@dbus_service_property(_interface, signature=u"t",
942
def ApprovalDelay_dbus_property(self, value=None):
943
if value is None: # get
944
return dbus.UInt64(self.approval_delay_milliseconds())
945
self.approval_delay = datetime.timedelta(0, 0, 0, value)
947
self.PropertyChanged(dbus.String(u"ApprovalDelay"),
948
dbus.UInt64(value, variant_level=1))
950
# ApprovalDuration - property
951
@dbus_service_property(_interface, signature=u"t",
953
def ApprovalDuration_dbus_property(self, value=None):
954
if value is None: # get
955
return dbus.UInt64(self._timedelta_to_milliseconds(
956
self.approval_duration))
957
self.approval_duration = datetime.timedelta(0, 0, 0, value)
959
self.PropertyChanged(dbus.String(u"ApprovalDuration"),
960
dbus.UInt64(value, variant_level=1))
923
963
@dbus_service_property(_interface, signature=u"s", access=u"read")
924
def name_dbus_property(self):
964
def Name_dbus_property(self):
925
965
return dbus.String(self.name)
927
# fingerprint - property
967
# Fingerprint - property
928
968
@dbus_service_property(_interface, signature=u"s", access=u"read")
929
def fingerprint_dbus_property(self):
969
def Fingerprint_dbus_property(self):
930
970
return dbus.String(self.fingerprint)
933
973
@dbus_service_property(_interface, signature=u"s",
934
974
access=u"readwrite")
935
def host_dbus_property(self, value=None):
975
def Host_dbus_property(self, value=None):
936
976
if value is None: # get
937
977
return dbus.String(self.host)
938
978
self.host = value
939
979
# Emit D-Bus signal
940
self.PropertyChanged(dbus.String(u"host"),
980
self.PropertyChanged(dbus.String(u"Host"),
941
981
dbus.String(value, variant_level=1))
944
984
@dbus_service_property(_interface, signature=u"s", access=u"read")
945
def created_dbus_property(self):
985
def Created_dbus_property(self):
946
986
return dbus.String(self._datetime_to_dbus(self.created))
948
# last_enabled - property
988
# LastEnabled - property
949
989
@dbus_service_property(_interface, signature=u"s", access=u"read")
950
def last_enabled_dbus_property(self):
990
def LastEnabled_dbus_property(self):
951
991
if self.last_enabled is None:
952
992
return dbus.String(u"")
953
993
return dbus.String(self._datetime_to_dbus(self.last_enabled))
956
996
@dbus_service_property(_interface, signature=u"b",
957
997
access=u"readwrite")
958
def enabled_dbus_property(self, value=None):
998
def Enabled_dbus_property(self, value=None):
959
999
if value is None: # get
960
1000
return dbus.Boolean(self.enabled)
975
1015
return dbus.String(self._datetime_to_dbus(self
976
1016
.last_checked_ok))
1018
# Timeout - property
979
1019
@dbus_service_property(_interface, signature=u"t",
980
1020
access=u"readwrite")
981
def timeout_dbus_property(self, value=None):
1021
def Timeout_dbus_property(self, value=None):
982
1022
if value is None: # get
983
1023
return dbus.UInt64(self.timeout_milliseconds())
984
1024
self.timeout = datetime.timedelta(0, 0, 0, value)
985
1025
# Emit D-Bus signal
986
self.PropertyChanged(dbus.String(u"timeout"),
1026
self.PropertyChanged(dbus.String(u"Timeout"),
987
1027
dbus.UInt64(value, variant_level=1))
988
1028
if getattr(self, u"disable_initiator_tag", None) is None:
1003
1043
self.disable_initiator_tag = (gobject.timeout_add
1004
1044
(time_to_die, self.disable))
1006
# interval - property
1046
# Interval - property
1007
1047
@dbus_service_property(_interface, signature=u"t",
1008
1048
access=u"readwrite")
1009
def interval_dbus_property(self, value=None):
1049
def Interval_dbus_property(self, value=None):
1010
1050
if value is None: # get
1011
1051
return dbus.UInt64(self.interval_milliseconds())
1012
1052
self.interval = datetime.timedelta(0, 0, 0, value)
1013
1053
# Emit D-Bus signal
1014
self.PropertyChanged(dbus.String(u"interval"),
1054
self.PropertyChanged(dbus.String(u"Interval"),
1015
1055
dbus.UInt64(value, variant_level=1))
1016
1056
if getattr(self, u"checker_initiator_tag", None) is None:
1021
1061
(value, self.start_checker))
1022
1062
self.start_checker() # Start one now, too
1024
# checker - property
1064
# Checker - property
1025
1065
@dbus_service_property(_interface, signature=u"s",
1026
1066
access=u"readwrite")
1027
def checker_dbus_property(self, value=None):
1067
def Checker_dbus_property(self, value=None):
1028
1068
if value is None: # get
1029
1069
return dbus.String(self.checker_command)
1030
1070
self.checker_command = value
1031
1071
# Emit D-Bus signal
1032
self.PropertyChanged(dbus.String(u"checker"),
1072
self.PropertyChanged(dbus.String(u"Checker"),
1033
1073
dbus.String(self.checker_command,
1034
1074
variant_level=1))
1036
# checker_running - property
1076
# CheckerRunning - property
1037
1077
@dbus_service_property(_interface, signature=u"b",
1038
1078
access=u"readwrite")
1039
def checker_running_dbus_property(self, value=None):
1079
def CheckerRunning_dbus_property(self, value=None):
1040
1080
if value is None: # get
1041
1081
return dbus.Boolean(self.checker is not None)
1170
1210
client.Rejected("Disabled")
1173
if client._approved or not client.approved_delay:
1213
if client._approved or not client.approval_delay:
1174
1214
#We are approved or approval is disabled
1176
1216
elif client._approved is None:
1177
logger.info(u"Client %s need approval",
1217
logger.info(u"Client %s needs approval",
1179
1219
if self.server.use_dbus:
1180
1220
# Emit D-Bus signal
1181
1221
client.NeedApproval(
1182
client.approved_delay_milliseconds(),
1222
client.approval_delay_milliseconds(),
1183
1223
client.approved_by_default)
1185
1225
logger.warning(u"Client %s was not approved",
1187
1227
if self.server.use_dbus:
1188
1228
# Emit D-Bus signal
1189
client.Rejected("Disapproved")
1229
client.Rejected("Denied")
1192
1232
#wait until timeout or approved