mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] base_report_to_printer: allow connect to protected server
This commit is contained in:
committed by
trisdoan
parent
ea8cb069f9
commit
06cf9a6660
@@ -24,6 +24,17 @@ class PrintingServer(models.Model):
|
||||
default="localhost", required=True, help="IP address or hostname of the server"
|
||||
)
|
||||
port = fields.Integer(default=631, required=True, help="Port of the server.")
|
||||
user = fields.Char(help="User name to connect to the server. Empty by default.")
|
||||
password = fields.Char(help="Password to connect to the server. Empty by default.")
|
||||
encryption_policy = fields.Selection(
|
||||
[
|
||||
("0", "HTTP_ENCRYPT_IF_REQUESTED"),
|
||||
("1", "HTTP_ENCRYPT_NEVER"),
|
||||
("2", "HTTP_ENCRYPT_REQUIRED"),
|
||||
("3", "HTTP_ENCRYPT_ALWAYS"),
|
||||
],
|
||||
help="Encryption Policy to connect to the server. Empty by default.",
|
||||
)
|
||||
active = fields.Boolean(default=True, help="If checked, this server is useable.")
|
||||
printer_ids = fields.One2many(
|
||||
comodel_name="printing.printer",
|
||||
@@ -35,6 +46,13 @@ class PrintingServer(models.Model):
|
||||
def _open_connection(self, raise_on_error=False):
|
||||
self.ensure_one()
|
||||
connection = False
|
||||
|
||||
# Password callback
|
||||
password = self.password
|
||||
|
||||
def pw_callback(prompt):
|
||||
return password
|
||||
|
||||
try:
|
||||
# Sometimes connecting to printer servers outside of the local network
|
||||
# can result in a weird error "cups.IPPError: (1030, 'The printer
|
||||
@@ -43,6 +61,13 @@ class PrintingServer(models.Model):
|
||||
# (see https://github.com/OpenPrinting/pycups/issues/30)
|
||||
cups.setServer(self.address)
|
||||
cups.setPort(self.port)
|
||||
if self.user:
|
||||
cups.setUser(self.user)
|
||||
if self.encryption_policy:
|
||||
cups.setEncryption(int(self.encryption_policy))
|
||||
if self.password:
|
||||
cups.setPasswordCB(pw_callback)
|
||||
|
||||
connection = cups.Connection(host=self.address, port=self.port)
|
||||
except Exception:
|
||||
message = _(
|
||||
@@ -57,7 +82,7 @@ class PrintingServer(models.Model):
|
||||
return connection
|
||||
|
||||
def action_update_printers(self):
|
||||
return self.update_printers()
|
||||
return self.update_printers(raise_on_error=True)
|
||||
|
||||
def update_printers(self, domain=None, raise_on_error=False):
|
||||
if domain is None:
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
<field name="address" />
|
||||
<field name="port" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="user" />
|
||||
<field name="password" />
|
||||
<field name="encryption_policy" />
|
||||
</group>
|
||||
<group>
|
||||
<separator string="Printers" colspan="2" />
|
||||
<field name="printer_ids" nolabel="1" />
|
||||
|
||||
Reference in New Issue
Block a user