コード例 #1
0
ファイル: shutdown.js プロジェクト: andreasn/cockpit
 return calculate().then(function(when) {
     var arg = (operation == "shutdown") ? "--poweroff" : "--reboot";
     var message = $("#shutdown-dialog textarea").val();
     if (operation == "restart")
         cockpit.hint("restart");
     return cockpit.spawn(["shutdown", arg, when, message], { superuser: true, err: "message" });
 });
コード例 #2
0
ファイル: client.js プロジェクト: AmartC/cockpit
                    .done(function(result) {
                        var connect_args = {
                            "superuser" : true,
                            "address": result[0],
                            "bus": "none"
                        };

                        if (reboot)
                            cockpit.hint('restart');

                        transaction_client = cockpit.dbus(null, connect_args);
                        transaction_client.addEventListener("close", on_close);

                        subscription = transaction_client.subscribe({ 'path' : "/", },
                            function(path, iface, signal, args) {
                                if (signal == "DownloadProgress") {
                                    var line = build_progress_line(args);
                                    if (line)
                                        dp.notify(line);
                                } else if (signal == "Message") {
                                    dp.notify(args[0]);
                                } else if (signal == "Finished") {
                                    if (args) {
                                        if (args[0]) {
                                            dp.resolve(args[1]);
                                            cleanup();
                                        } else {
                                            fail(args[1]);
                                        }
                                    } else {
                                        console.warn("Unexpected transaction response", args);
                                        fail({ "problem": "protocol-error" });
                                    }
                                }
                            });
                        transaction_client.call("/", TRANSACTION, "Start");
                    });
コード例 #3
0
ファイル: base_index.js プロジェクト: arilivigni/cockpit
        function message_handler(event) {
            if (event.origin !== origin)
                return;

            var data = event.data;
            var child = event.source;
            if (!child || typeof data !== "string")
                return;

            var source = source_by_name[child.name];
            var control;

            /* Closing the transport */
            if (data.length === 0) {
                if (source)
                    unregister(source);
                return;
            }

            /* A control message */
            if (data[0] == '\n') {
                control = JSON.parse(data.substring(1));
                if (control.command === "init") {
                    if (source)
                        unregister(source);
                    source = register(child);
                    if (source) {
                        var reply = $.extend({ }, cockpit.transport.options,
                            { command: "init", "host": source.default_host, "channel-seed": source.channel_seed }
                        );
                        child.postMessage("\n" + JSON.stringify(reply), origin);
                        source.inited = true;

                        /* If this new frame is not the current one, tell it */
                        if (child.frameElement != index.current_frame())
                            self.hint(child.frameElement.contentWindow, { "hidden": true });
                    }

                } else if (control.command === "jump") {
                    perform_jump(child, control);
                    return;

                } else if (control.command === "hint") {
                    if (control.hint == "restart") {
                        /* watchdog handles current host for now */
                        if (control.host != cockpit.transport.host)
                            index.expect_restart(control.host);
                    } else
                        cockpit.hint(control.hint, control);
                    return;
                } else if (control.command == "oops") {
                    index.show_oops();
                    return;

                /* Only control messages with a channel are forwardable */
                } else if (control.channel === undefined) {
                    return;

                /* Add the child's group to all open channel messages */
                } else if (control.command == "open") {
                    control.group = child.name;
                    data = "\n" + JSON.stringify(control);
                }
            }

            if (!source) {
                console.warn("child frame " + child.name + " sending data without init");
                return;
            }

            /* Everything else gets forwarded */
            cockpit.transport.inject(data, true);
        }
コード例 #4
0
ファイル: base_index.js プロジェクト: mareklibra/cockpit
        function message_handler(event) {
            if (event.origin !== origin)
                return;

            var forward_command = false;
            var data = event.data;
            var child = event.source;
            if (!child)
                return;

            /* If it's binary data just send it.
             * TODO: Once we start restricting what frames can
             * talk to which hosts, we need to parse control
             * messages here, and cross check channels */
            if (data instanceof window.ArrayBuffer) {
                cockpit.transport.inject(data, true);
                return;
            }

            if (typeof data !== "string")
                return;

            var source, control;

            /*
             * On Internet Explorer we see Access Denied when non Cockpit
             * frames send messages (such as Javascript console). This also
             * happens when the window is closed.
             */
            try {
                source = source_by_name[child.name];
            } catch(ex) {
                console.log("received message from child with in accessible name: ", ex);
                return;
            }


            /* Closing the transport */
            if (data.length === 0) {
                if (source)
                    unregister(source);
                return;
            }

            /* A control message */
            if (data[0] == '\n') {
                control = JSON.parse(data.substring(1));
                if (control.command === "init") {
                    if (source)
                        unregister(source);
                    if (control.problem) {
                        console.warn("child frame failed to init: " + control.problem);
                        source = null;
                    } else {
                        source = register(child);
                    }
                    if (source) {
                        var reply = $.extend({ }, cockpit.transport.options,
                            { command: "init", "host": source.default_host, "channel-seed": source.channel_seed }
                        );
                        child.postMessage("\n" + JSON.stringify(reply), origin);
                        source.inited = true;

                        /* If this new frame is not the current one, tell it */
                        if (child.frameElement != index.current_frame())
                            self.hint(child.frameElement.contentWindow, { "hidden": true });
                    }

                } else if (control.command === "jump") {
                    perform_jump(child, control);
                    return;

                } else if (control.command == "logout" || control.command == "kill") {
                    forward_command = true;

                } else if (control.command === "hint") {
                    if (control.hint == "restart") {
                        /* watchdog handles current host for now */
                        if (control.host != cockpit.transport.host)
                            index.expect_restart(control.host);
                    } else
                        cockpit.hint(control.hint, control);
                    return;
                } else if (control.command == "oops") {
                    index.show_oops();
                    return;

                /* Only control messages with a channel are forwardable */
                } else if (control.channel === undefined && !forward_command) {
                    return;

                /* Add the child's group to all open channel messages */
                } else if (control.command == "open") {
                    control.group = child.name;
                    data = "\n" + JSON.stringify(control);
                }
            }

            if (!source) {
                console.warn("child frame " + child.name + " sending data without init");
                return;
            }

            /* Everything else gets forwarded */
            cockpit.transport.inject(data, true);
        }