From 867fb84ffacbb02e44e2b6a511e61612dd2af3b1 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Tue, 17 Jul 2018 20:59:04 +0200 Subject: web: fix shortname --- src/web/main.vala | 30 +++++++++++++++++++++++------- src/web/template.vala | 1 + src/web/web.vala | 35 ----------------------------------- 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/web/main.vala b/src/web/main.vala index 2043df0..761bba9 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -19,6 +19,7 @@ public PGP pgp; public Config cfg; public AudioPlayer audio; string templatedir; +string? shortname; public static int main(string[] args) { Intl.setlocale(LocaleCategory.ALL, ""); @@ -37,13 +38,6 @@ public static int main(string[] args) { var datapath = cfg.get_string("GENERAL", "datapath"); templatedir = Path.build_filename(datapath, "templates"); port = cfg.get_integer("WEB", "port"); - - try { - certificate = cfg.get_string("WEB", "cert"); - privatekey = cfg.get_string("WEB", "key"); - } catch(KeyFileError e) { - warning(_("KeyFile Error: %s\n"), e.message); - } } catch(IOError e) { error(_("IO Error: %s\n"), e.message); } catch(KeyFileError e) { @@ -52,6 +46,28 @@ public static int main(string[] args) { error(_("DBus Error: %s\n"), e.message); } + try { + certificate = cfg.get_string("WEB", "cert"); + privatekey = cfg.get_string("WEB", "key"); + } catch(KeyFileError e) { + warning(_("KeyFile Error: %s\n"), e.message); + } catch(IOError e) { + error(_("IO Error: %s\n"), e.message); + } catch(DBusError e) { + error(_("DBus Error: %s\n"), e.message); + } + + try { + shortname = cfg.get_string("GENERAL", "shortname"); + } catch(KeyFileError e) { + shortname = ""; + warning(_("KeyFile Error: %s\n"), e.message); + } catch(IOError e) { + error(_("IO Error: %s\n"), e.message); + } catch(DBusError e) { + error(_("DBus Error: %s\n"), e.message); + } + stdout.printf(_("Web Server Port: %u\n"), port); stdout.printf(_("TLS certificate: %s\n"), certificate); stdout.printf(_("TLS private key: %s\n"), privatekey); diff --git a/src/web/template.vala b/src/web/template.vala index 4dcda38..009ebcf 100644 --- a/src/web/template.vala +++ b/src/web/template.vala @@ -65,6 +65,7 @@ public class WebTemplate { } this.template = ((string) basis).replace("{{{NAVBAR}}}", ((string) menu)); + this.template = this.template.replace("{{{SHORTNAME}}}", shortname); this.template = this.template.replace("{{{AUTH}}}", ((string) auth)); this.template = this.template.replace("{{{CONTENT}}}", ((string) template)); this.template = this.template.replace("{{{USERNAME}}}", login.name); diff --git a/src/web/web.vala b/src/web/web.vala index 5f82cec..8934763 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -16,8 +16,6 @@ public class WebServer { private Soup.Server srv; - private string longname; - private string shortname; void handler_default(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) { try { @@ -46,7 +44,6 @@ public class WebServer { l.logout(); var t = new WebTemplate("logout.html", l); t.replace("TITLE", shortname + " Shop System"); - t.replace("SHORTNAME", shortname); t.menu_set_active("home"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -106,7 +103,6 @@ public class WebServer { var t = new WebTemplate("users/index.html", session); t.replace("TITLE", shortname + " Shop System: User"); - t.replace("SHORTNAME", shortname); t.menu_set_active("users"); var data = ""; foreach(var m in db.get_member_ids()) { @@ -143,7 +139,6 @@ public class WebServer { var t = new WebTemplate("users/import-pgp.html", session); t.replace("TITLE", shortname + " Shop System: PGP Key Import"); - t.replace("SHORTNAME", shortname); t.menu_set_active("users"); Soup.Buffer filedata; @@ -198,7 +193,6 @@ public class WebServer { } var t = new WebTemplate("users/import.html", session); t.replace("TITLE", shortname + " Shop System: User Import"); - t.replace("SHORTNAME", shortname); t.menu_set_active("users"); Soup.Buffer filedata; @@ -348,7 +342,6 @@ public class WebServer { } var t = new WebTemplate("users/entry.html", session); t.replace("TITLE", shortname + " Shop System: User Info %llu".printf(id)); - t.replace("SHORTNAME", shortname); t.menu_set_active("users"); var userinfo = db.get_user_info(id); @@ -456,7 +449,6 @@ public class WebServer { } var t = new WebTemplate("users/invoice.html", l); t.replace("TITLE", shortname + " Shop System: User Invoice %llu".printf(id)); - t.replace("SHORTNAME", shortname); t.menu_set_active("users"); /* years, in which something has been purchased by the user */ @@ -581,7 +573,6 @@ public class WebServer { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("products/index.html", l); t.replace("TITLE", shortname + " Shop System: Product List"); - t.replace("SHORTNAME", shortname); t.menu_set_active("products"); string table = ""; @@ -621,7 +612,6 @@ public class WebServer { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("products/bestbefore.html", l); t.replace("TITLE", shortname + " Shop System: Best Before List"); - t.replace("SHORTNAME", shortname); t.menu_set_active("products"); string table = ""; @@ -681,7 +671,6 @@ public class WebServer { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("products/entry.html", l); t.replace("TITLE", shortname + " Shop System: Product %llu".printf(id)); - t.replace("SHORTNAME", shortname); t.menu_set_active("products"); /* ean */ @@ -764,7 +753,6 @@ public class WebServer { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("products/new.html", session); template.replace("TITLE", shortname + " Shop System: New Product"); - template.replace("SHORTNAME", shortname); template.menu_set_active("products"); if(!session.superuser && !session.auth_products) { @@ -823,7 +811,6 @@ public class WebServer { var template = new WebTemplate("products/restock.html", session); template.replace("TITLE", shortname + " Shop System: Restock Product %llu".printf(id)); - template.replace("SHORTNAME", shortname); template.replace("NAME", db.get_product_name(id)); template.menu_set_active("products"); @@ -925,7 +912,6 @@ public class WebServer { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("aliases/index.html", l); t.replace("TITLE", shortname + " Shop System: Alias List"); - t.replace("SHORTNAME", shortname); t.menu_set_active("aliases"); string table = ""; @@ -960,7 +946,6 @@ public class WebServer { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("aliases/new.html", session); template.replace("TITLE", shortname + " Shop System: New Alias"); - template.replace("SHORTNAME", shortname); template.menu_set_active("aliases"); if(!session.superuser && !session.auth_products) { @@ -1011,7 +996,6 @@ public class WebServer { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("stats/index.html", l); t.replace("TITLE", shortname + " Shop System: Statistics"); - t.replace("SHORTNAME", shortname); t.menu_set_active("stats"); var stats = db.get_stats_info(); @@ -1044,7 +1028,6 @@ public class WebServer { var t = new WebTemplate("stats/stock.html", l); string data = db.get_stats_stock().json; t.replace("DATA", data); - t.replace("SHORTNAME", shortname); t.replace("TITLE", shortname + " Shop System: Statistics: Stock"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); @@ -1061,7 +1044,6 @@ public class WebServer { var t = new WebTemplate("stats/profit_per_day.html", l); string data = db.get_stats_profit_per_day().json; t.replace("DATA", data); - t.replace("SHORTNAME", shortname); t.replace("TITLE", shortname + " Shop System: Statistics: Profit"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); @@ -1078,7 +1060,6 @@ public class WebServer { var t = new WebTemplate("stats/profit_per_weekday.html", l); string data = db.get_stats_profit_per_weekday().json; t.replace("DATA", data); - t.replace("SHORTNAME", shortname); t.replace("TITLE", shortname + " Shop System: Statistics: Profit/Weekday"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); @@ -1095,7 +1076,6 @@ public class WebServer { var t = new WebTemplate("stats/profit_per_product.html", l); string data = db.get_stats_profit_per_products().json; t.replace("DATA", data); - t.replace("SHORTNAME", shortname); t.replace("TITLE", shortname + " Shop System: Statistics: Profit/Product"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); @@ -1228,7 +1208,6 @@ public class WebServer { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("errors/todo.html", session); template.replace("TITLE", shortname + " Shop System: ToDo"); - template.replace("SHORTNAME", shortname); template.menu_set_active(""); msg.set_response("text/html", Soup.MemoryUse.COPY, template.data); msg.set_status(200); @@ -1276,7 +1255,6 @@ public class WebServer { } template.replace("TITLE", shortname + " Shop System: Cashbox"); - template.replace("SHORTNAME", shortname); template.replace("CASHBOX_STATUS", status); template.replace("CASHBOX_HISTORY", hist); template.menu_set_active("cashbox"); @@ -1305,7 +1283,6 @@ public class WebServer { var template = new WebTemplate("cashbox/add.html", session); template.replace("TITLE", shortname + " Shop System: Cashbox Balance"); - template.replace("SHORTNAME", shortname); template.menu_set_active("cashbox"); bool error = false; @@ -1380,7 +1357,6 @@ public class WebServer { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("cashbox/selection.html", session); template.replace("TITLE", shortname + " Shop System: Cashbox Detail"); - template.replace("SHORTNAME", shortname); template.menu_set_active("cashbox"); msg.set_response("text/html", Soup.MemoryUse.COPY, template.data); msg.set_status(200); @@ -1454,7 +1430,6 @@ public class WebServer { var template = new WebTemplate("cashbox/detail.html", session); template.replace("TITLE", shortname + " Shop System: Cashbox Detail"); template.menu_set_active("cashbox"); - template.replace("SHORTNAME", shortname); template.replace("DATE", start.format("%B %Y")); template.replace("DEBIT", debit.to_string()); template.replace("LOSS", loss.to_string()); @@ -1480,16 +1455,6 @@ public class WebServer { } public WebServer(uint port = 8080, TlsCertificate? cert = null) throws Error { - /* get configuration */ - Config config = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - try { - longname = config.get_string("GENERAL", "longname"); - shortname = config.get_string("GENERAL", "shortname"); - } catch(KeyFileError e) { - longname = "Logname Missing in Config"; - shortname = "Shortname Missing in Config"; - } - srv = new Soup.Server("tls-certificate", cert); Soup.ServerListenOptions options = 0; -- cgit v1.2.3