![](https://seccdn.libravatar.org/avatar/e76779f0629280df6d2dfce07e4e1600.jpg?s=120&d=mm&r=g)
Hello, Am Donnerstag, 8. Juni 2017, 10:06:52 CEST schrieb Josef Reidinger:
On Wed, 7 Jun 2017 15:38:47 -0500 Goldwyn Rodrigues
wrote: From: Goldwyn Rodrigues
The apparmor_ui_dialog communicates with aa-logprof in JSON. Each dialog is converted to a yast dialog for input from the user and returns the actions performed in yast in the form of JSON response.
An extra opendialog has been used to indicate the end of the logprof execution.
Signed-off-by: Goldwyn Rodrigues
...
+module AppArmor + class YesNoDialog + include Yast::UIShortcuts + include Yast::I18n + def initialize(hm) + @data = hm["text"] + @map = Hash.new + @map["dialog"] = "yesno" + end + + def run() + Yast::UI.OpenDialog( + Opt(:decorated, :defaultsize), + VBox( + Label(@data), + VSpacing(1), + HBox( + HStretch(), + HWeight(1, PushButton(Id(:y), _("Yes"))), + HSpacing(2), + HWeight(1, PushButton(Id(:n), _("No"))), + ) + ) + ) + case Yast::UI.UserInput + when :y + @map["response"] = "yes" + @map["response_key"] = "y" + when :n + @map["response"] = "no" + @map["response_key"] = "n" + end + Yast::UI.CloseDialog + return @map + end + end
how big data you expect? In general maybe easier way is to simply use Yast::Popup.YesNo http://www.rubydoc.info/github/yast/yast-yast2/Yast/PopupClass#YesNo-> instance_method
Indeed, there's no need to re-invent the wheel ;-)
+ class YesNoCancelDialog + include Yast::UIShortcuts + include Yast::I18n + include Yast::Logger + def initialize(hm) + @data = hm["data"] + @map = Hash.new + @map["dialog"] = "yesnocancel" + end + + def run() + Yast::UI.OpenDialog( + Opt(:decorate, :defaultsize), + VBox( + Label(@data), + VSpacing(0.3), + HBox( + HWeight(1, PushButton(Id(:y), _("Yes"))), + HStretch(), + HWeight(1, PushButton(Id(:n), _("No"))), + HStretch(), + HWeight(1, PushButton(Id(:c), Label.CancelButton)) + ) + ) + ) + case Yast::UI.UserInput + when :y + @map["response"] = "yes" + @map["response_key"] = "y" + when :n + @map["response"] = "no" + @map["response_key"] = "n" + when :c + @map["response"] = "cancel" + @map["response_key"] = "c" + end + Yast::UI.CloseDialog + return @map + end + end
Here I would reuse Popup.AnyQuestion3 http://www.rubydoc.info/github/yast/yast-yast2/Yast%2FPopupClass:AnyQu estion3
Another wheel that doesn't need re-invention.
+ class InfoDialog + include Yast::UIShortcuts + include Yast::I18n + include Yast::Logger + def initialize(hm) + log.info "Hash map #{hm}" + end + def run() + return nil + end + end
Ugh, what? what is purpose of this dialog? It do nothing.
I see a "log.info" call there, so I'd guess (without knowing what log.info does exactly) it writes #{hm} to the YaST log. FYI: messages on the info level are something like - "/foo/* r," added to the profile - Deleted 2 previous matching profile entries. While the text version of aa-logprof displays those messages, they are not too important - and especially not important enough for displaying a popup dialog. Writing them to the log and hiding them in the user interface looks like a valid option to me. ...
+ class AAJSONVersion + include Yast::I18n + include Yast::Logger + AA_JSON = 2.12
I expect this will break often in future. Is there any plans to have json somehow backward compatible?
I don't really expect changes ;-) The json is constructed in a way that allows lots of flexibilty - for example, adding support for new rule types in the AppArmor tools will _not_ require any changes on the YaST side and things will just work. Basically the json describes the dialog layout (header, available options, available buttons etc.) and YaST will "just" be the frontend. The only case that will require changes in the json layout is adding a new dialog type - for example a new variant of the yes/no dialog. I tried to come up with a possible example, but didn't find one, so it's unlikely that this happens in the near future. That said - I'll happily accept some tests in the upstream AppArmor test suite that ensure we don't accidently break the json interface. Such a test would talk to aa-logprof --json (like YaST will do) and could include - some example profiles (or just use the profiles we ship anyway) - 20 lines of audit.log events - a json "script" describing which messages/questions to expect from aa-logprof and how to answer them (one per line, prefixed by IN or OUT or something like that) - the expected profiles after the aa-logprof run Regards, Christian Boltz -- <mancha> who forgot to load the troll profile? [from #apparmor] -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org