Skip to content

Commit 80eef8f

Browse files
KT-lczlichangze
andauthored
fix: 移除硬编码的公网 url (#191)
移除硬编码的公网 url Log: 移除硬编码的公网 url Bug: https://pms.uniontech.com/bug-view-321337.html Influence: 安全基线 Co-authored-by: lichangze <lichangze@uniontech.com>
1 parent f5d69ef commit 80eef8f

13 files changed

Lines changed: 26 additions & 174 deletions

File tree

src/internal/config/config.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ func NewConfig(configPath string) *Config {
137137
if dc.CheckInterval < MinCheckInterval {
138138
_ = dc.SetCheckInterval(MinCheckInterval)
139139
}
140-
if dc.Repository == "" || dc.MirrorSource == "" {
141-
info := system.DetectDefaultRepoInfo(system.RepoInfos)
142-
_ = dc.SetRepository(info.Name)
143-
_ = dc.SetMirrorSource("default") // info.Mirror
144-
}
145140
if dc.Version == "" {
146141
_ = dc.SetVersion(ConfigVersion)
147142
_ = dc.SetCheckInterval(time.Hour * 24 * 7)
@@ -499,11 +494,7 @@ func getConfigFromDSettings() *Config {
499494
} else {
500495
url = v.Value().(string)
501496
}
502-
if len(url) == 0 {
503-
c.PlatformUrl = "https://update-platform.uniontech.com"
504-
} else {
505-
c.PlatformUrl = url
506-
}
497+
c.PlatformUrl = url
507498

508499
v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformRepoComponents)
509500
if err != nil {

src/internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestConfig(t *testing.T) {
2626
require.NoError(t, err)
2727
defer tmpfile.Close()
2828

29-
data := []byte(`{"Version":"0.1","AutoCheckUpdates":true,"DisableUpdateMetadata":false,"AutoDownloadUpdates":false,"AutoClean":true,"MirrorSource":"default","UpdateNotify":true,"CheckInterval":604800000000000,"CleanInterval":604800000000000,"UpdateMode":3,"CleanIntervalCacheOverLimit":86400000000000,"AppstoreRegion":"","LastCheckTime":"2021-06-17T14:10:21.896021304+08:00","LastCleanTime":"2021-06-17T09:18:31.515019638+08:00","LastCheckCacheSizeTime":"2021-06-17T09:18:31.5151104+08:00","Repository":"desktop","MirrorsUrl":"http://packages.deepin.com/mirrors/community.json","AllowInstallRemovePkgExecPaths":null}`)
29+
data := []byte(`{"Version":"0.1","AutoCheckUpdates":true,"DisableUpdateMetadata":false,"AutoDownloadUpdates":false,"AutoClean":true,"MirrorSource":"default","UpdateNotify":true,"CheckInterval":604800000000000,"CleanInterval":604800000000000,"UpdateMode":3,"CleanIntervalCacheOverLimit":86400000000000,"AppstoreRegion":"","LastCheckTime":"2021-06-17T14:10:21.896021304+08:00","LastCleanTime":"2021-06-17T09:18:31.515019638+08:00","LastCheckCacheSizeTime":"2021-06-17T09:18:31.5151104+08:00","Repository":"desktop","MirrorsUrl":"","AllowInstallRemovePkgExecPaths":null}`)
3030
err = os.WriteFile(tmpfile.Name(), data, 0777)
3131
require.NoError(t, err)
3232

src/internal/dstore/dstore.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package dstore
66

77
import (
8+
"errors"
89
"strings"
910
"time"
1011

@@ -38,15 +39,15 @@ func NewStore() *Store {
3839
return s
3940
}
4041

41-
func (s *Store) GetMetadataServer() string {
42+
func (s *Store) GetMetadataServer() (string, error) {
4243
var metadataServer string
4344
if s.sysCfg != nil {
4445
metadataServer = s.sysCfg.Section("General").Key("Server").String()
4546
}
4647
if metadataServer == "" {
47-
metadataServer = "https://store.chinauos.com"
48+
return "", errors.New("no metadata server")
4849
}
49-
return metadataServer
50+
return metadataServer, nil
5051
}
5152

5253
type AppInfo struct {
@@ -77,11 +78,17 @@ type packageApps map[string]*PackageInfo
7778
func (s *Store) GetPackageApplication(path string) (v []*PackageInfo, err error) {
7879
// cachePath := filepath.Join(system.VarLibDir, "packages.cache.json")
7980
cachePath := path + ".cache.json"
80-
apiAppURL := s.GetMetadataServer() + "/api/public/packages"
81+
server, err := s.GetMetadataServer()
82+
if err != nil {
83+
return nil, err
84+
}
85+
apiAppURL := server + "/api/public/packages"
8186

8287
packages := make(packageApps)
8388
err = cacheFetchJSON(&packages, apiAppURL, cachePath, expireDelay)
84-
89+
if err != nil {
90+
return nil, err
91+
}
8592
for dpk, app := range packages {
8693
app.PackageURI = dpk
8794
app.PackageName = strings.Replace(dpk, "dpk://deb/", "", -1)

src/internal/mirrors/mirrors.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"fmt"
1010
"net/http"
1111
"os"
12+
"path"
1213
"path/filepath"
1314
"sort"
1415

16+
"github.com/linuxdeepin/lastore-daemon/src/internal/config"
1517
"github.com/linuxdeepin/lastore-daemon/src/internal/system"
1618
"github.com/linuxdeepin/lastore-daemon/src/internal/utils"
1719
)
@@ -92,6 +94,7 @@ func getUnpublishedMirrorSources(url string) ([]system.MirrorSource, error) {
9294

9395
// LoadMirrorSources return supported MirrorSource from remote server
9496
func LoadMirrorSources(url string) ([]system.MirrorSource, error) {
97+
config := config.NewConfig(path.Join("/var/lib/lastore", "config.json"))
9598
var mirrorsUrl string
9699
if url != "" {
97100
mirrorsUrl = url
@@ -100,14 +103,14 @@ func LoadMirrorSources(url string) ([]system.MirrorSource, error) {
100103
data, err := os.ReadFile(filepath.Join(system.VarLibDir, "config.json"))
101104
if err != nil {
102105
if os.IsNotExist(err) {
103-
mirrorsUrl = system.DefaultMirrorsUrl
106+
mirrorsUrl = config.MirrorsUrl
104107
} else {
105108
return nil, err
106109
}
107110
} else {
108111
cfg := struct {
109112
MirrorsUrl string
110-
}{system.DefaultMirrorsUrl}
113+
}{config.MirrorsUrl}
111114

112115
err = json.Unmarshal(data, &cfg)
113116
if err != nil {

src/internal/system/system.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
)
1212

1313
const VarLibDir = "/var/lib/lastore"
14-
const DefaultMirrorsUrl = "http://packages.deepin.com/mirrors/community.json"
1514

1615
type Status string
1716

src/internal/system/system_apt.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ lastore-daemon
99
package system
1010

1111
import (
12-
"bufio"
1312
"bytes"
1413
"errors"
1514
"fmt"
@@ -358,52 +357,17 @@ func SystemArchitectures() ([]Architecture, error) {
358357
return r, nil
359358
}
360359

361-
var defaultRepoInfo = RepositoryInfo{
362-
Name: "desktop",
363-
Url: "http://packages.deepin.com/deepin",
364-
Mirror: "http://cdn.packages.deepin.com/deepin",
365-
}
366-
367360
func init() {
368361
err := DecodeJson(path.Join(VarLibDir, "repository_info.json"), &RepoInfos)
369362
if err != nil {
370-
RepoInfos = []RepositoryInfo{defaultRepoInfo}
363+
RepoInfos = []RepositoryInfo{}
371364
}
372365
_ = os.Setenv("DEBIAN_FRONTEND", "noninteractive")
373366
_ = os.Setenv("DEBIAN_PRIORITY", "critical")
374367
_ = os.Setenv("DEBCONF_NONINTERACTIVE_SEEN", "true")
375368
_ = os.Setenv("IMMUTABLE_DISABLE_REMOUNT", "true")
376369
}
377370

378-
func DetectDefaultRepoInfo(rInfos []RepositoryInfo) RepositoryInfo {
379-
f, err := os.Open("/etc/apt/sources.list")
380-
if err != nil {
381-
return defaultRepoInfo
382-
}
383-
defer func() {
384-
_ = f.Close()
385-
}()
386-
387-
r := bufio.NewReader(f)
388-
for {
389-
bs, _, err := r.ReadLine()
390-
if err != nil {
391-
break
392-
}
393-
line := strings.TrimLeft(string(bs), " ")
394-
if strings.IndexByte(line, '#') == 0 {
395-
continue
396-
}
397-
398-
for _, repo := range rInfos {
399-
if strings.Contains(line, " "+repo.Url+" ") {
400-
return repo
401-
}
402-
}
403-
}
404-
return defaultRepoInfo
405-
}
406-
407371
func guestBasePackageName(pkgId string) string {
408372
for _, sep := range []string{"-", ":", "_"} {
409373
index := strings.LastIndex(pkgId, sep)

src/internal/updateplatform/message_report.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ func NewUpdatePlatformManager(c *Config, updateToken bool) *UpdatePlatformManage
106106
platformUrl := c.PlatformUrl
107107
if len(platformUrl) == 0 {
108108
platformUrl = os.Getenv("UPDATE_PLATFORM_URL")
109-
if len(platformUrl) == 0 {
110-
platformUrl = "https://update-platform.uniontech.com"
111-
}
112109
}
113110

114111
if !utils.IsFileExist(CacheVersion) {

src/lastore-daemon/manager_unit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const (
6464

6565
type lastoreUnitMap map[UnitName][]string
6666

67-
// 定时任务和文件监听
67+
// 定时任务和文件监听map
6868
func (m *Manager) getLastoreSystemUnitMap() lastoreUnitMap {
6969
unitMap := make(lastoreUnitMap)
7070
if (m.config.GetLastoreDaemonStatus()&config.DisableUpdate) == 0 && !m.ImmutableAutoRecovery { // 更新禁用未开启且无忧还原未开启时

src/lastore-smartmirror-daemon/lastore_smartmirror_daemon_test.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/lastore-tools/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func main() {
112112
cli.StringFlag{
113113
Name: "dstoreapi",
114114
Usage: "the dstore api server url. There has many jobs would use the to fetch data",
115-
Value: "http://api.appstore.deepin.org",
115+
Value: "",
116116
},
117117
}
118118
app.Commands = []cli.Command{CMDUpdater, CMDTester, CMDSmartMirror, CMDMetadata, CMDQueryDesktop, CMDCheckPolicy, CMDPostUpgrade}

0 commit comments

Comments
 (0)