2023-09-16 15:25:25 +00:00
|
|
|
//
|
|
|
|
// Copyright ⓒ 2023 Chakib Ben Ziane <contact@blob42.xyz> and [`GoSuki` contributors]
|
|
|
|
// (https://github.com/blob42/gosuki/graphs/contributors).
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// This file is part of GoSuki.
|
|
|
|
//
|
|
|
|
// GoSuki is free software: you can redistribute it and/or modify it under the terms of
|
|
|
|
// the GNU Affero General Public License as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License along with
|
|
|
|
// gosuki. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-10-23 13:08:06 +00:00
|
|
|
// TODO: add cli options to set/get options
|
|
|
|
// TODO: move browser module commands to their own module packag
|
2022-11-07 20:58:35 +00:00
|
|
|
package firefox
|
2019-02-26 10:23:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-08-12 19:11:48 +00:00
|
|
|
|
2023-02-18 23:13:23 +00:00
|
|
|
"git.blob42.xyz/gomark/gosuki/cmd"
|
2023-09-09 23:14:13 +00:00
|
|
|
"git.blob42.xyz/gomark/gosuki/internal/logging"
|
|
|
|
"git.blob42.xyz/gomark/gosuki/pkg/browsers/mozilla"
|
|
|
|
"git.blob42.xyz/gomark/gosuki/internal/utils"
|
2019-02-26 10:23:00 +00:00
|
|
|
|
2020-08-12 18:13:01 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-02-26 10:23:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var fflog = logging.GetLogger("FF")
|
|
|
|
|
|
|
|
var ffUnlockVFSCmd = cli.Command{
|
|
|
|
Name: "unlock",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Action: ffUnlockVFS,
|
|
|
|
}
|
|
|
|
|
|
|
|
var ffCheckVFSCmd = cli.Command{
|
|
|
|
Name: "check",
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Action: ffCheckVFS,
|
|
|
|
}
|
|
|
|
|
|
|
|
var ffVFSCommands = cli.Command{
|
|
|
|
Name: "vfs",
|
|
|
|
Usage: "VFS locking commands",
|
2020-08-12 19:11:48 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
&ffUnlockVFSCmd,
|
|
|
|
&ffCheckVFSCmd,
|
2019-02-26 10:23:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var ffListProfilesCmd = cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"l"},
|
|
|
|
Action: ffListProfiles,
|
|
|
|
}
|
|
|
|
|
|
|
|
var ffProfilesCmds = cli.Command{
|
|
|
|
Name: "profiles",
|
|
|
|
Aliases: []string{"p"},
|
|
|
|
Usage: "Profiles commands",
|
2020-08-12 19:11:48 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
&ffListProfilesCmd,
|
2019-02-26 10:23:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-08-12 19:11:48 +00:00
|
|
|
var FirefoxCmds = &cli.Command{
|
2019-02-26 10:23:00 +00:00
|
|
|
Name: "firefox",
|
|
|
|
Aliases: []string{"ff"},
|
|
|
|
Usage: "firefox related commands",
|
2020-08-12 19:11:48 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
&ffVFSCommands,
|
|
|
|
&ffProfilesCmds,
|
2019-02-26 10:23:00 +00:00
|
|
|
},
|
|
|
|
//Action: unlockFirefox,
|
|
|
|
}
|
|
|
|
|
2022-11-07 20:58:35 +00:00
|
|
|
func init() {
|
|
|
|
cmd.RegisterModCommand(BrowserName, FirefoxCmds)
|
|
|
|
}
|
|
|
|
|
2023-01-31 21:21:39 +00:00
|
|
|
//TODO: #54 define interface for modules to handle and list profiles
|
2023-02-18 22:08:12 +00:00
|
|
|
//FIX: Remove since profile listing is implemented at the main module level
|
2023-01-31 21:21:39 +00:00
|
|
|
func ffListProfiles(_ *cli.Context) error {
|
2022-11-07 20:58:35 +00:00
|
|
|
profs, err := FirefoxProfileManager.GetProfiles()
|
2019-02-26 10:23:00 +00:00
|
|
|
if err != nil {
|
2020-08-12 19:11:48 +00:00
|
|
|
return err
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range profs {
|
2022-12-11 22:06:07 +00:00
|
|
|
fmt.Printf("%-10s \t %s\n", p.Name, utils.ExpandPath(FirefoxProfileManager.ConfigDir, p.Path))
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|
2019-02-26 18:41:02 +00:00
|
|
|
|
2020-08-12 19:11:48 +00:00
|
|
|
return nil
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 21:21:39 +00:00
|
|
|
func ffCheckVFS(_ *cli.Context) error {
|
2022-11-07 20:58:35 +00:00
|
|
|
err := mozilla.CheckVFSLock("path to profile")
|
2019-02-26 10:23:00 +00:00
|
|
|
if err != nil {
|
2020-08-12 19:11:48 +00:00
|
|
|
return err
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|
2020-08-12 19:11:48 +00:00
|
|
|
|
|
|
|
return nil
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 21:21:39 +00:00
|
|
|
func ffUnlockVFS(_ *cli.Context) error {
|
2022-11-07 20:58:35 +00:00
|
|
|
err := mozilla.UnlockPlaces("path to profile")
|
2019-02-26 10:23:00 +00:00
|
|
|
if err != nil {
|
2020-08-12 19:11:48 +00:00
|
|
|
return err
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|
2020-08-12 19:11:48 +00:00
|
|
|
|
|
|
|
return nil
|
2019-02-26 10:23:00 +00:00
|
|
|
}
|