Skip to content

Commit ab431b6

Browse files
committed
fix regular service creation
1 parent 9a821a9 commit ab431b6

File tree

3 files changed

+57
-39
lines changed

3 files changed

+57
-39
lines changed

core/service.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func CreateService(service *model.Service) (*model.Service, error) {
108108
Updated: &u,
109109
CreatedBy: service.CreatedBy,
110110
UpdatedBy: service.CreatedBy,
111+
Default: &model.Settings{},
111112
}
112113
net.Default.Address = []string{service.DefaultSubnet}
113114
net.Default.Dns = service.Net.Default.Dns
@@ -157,7 +158,7 @@ func CreateService(service *model.Service) (*model.Service, error) {
157158
}
158159
} // otherwise it was created remotely
159160

160-
if service.VPN == nil {
161+
if service.VPN == nil || service.VPN.Id == "" {
161162

162163
// create a default vpn using the net
163164
var c time.Time = time.Now().UTC()

core/vpn.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,20 @@ func GetAllReservedNetIps(netId string) ([]string, error) {
200200
for _, client := range clients {
201201
if client.NetId == netId {
202202
for _, cidr := range client.Current.Address {
203-
ip, err := util.GetIpFromCidr(cidr)
204-
if err != nil {
203+
parts := strings.Split(cidr, "/")
204+
if len(parts) == 1 {
205205
reservedIps = append(reservedIps, cidr)
206-
log.WithFields(log.Fields{
207-
"err": err,
208-
"cidr": cidr,
209-
}).Error("failed to ip from cidr")
210206
} else {
211-
reservedIps = append(reservedIps, ip)
207+
ip, err := util.GetIpFromCidr(cidr)
208+
if err != nil {
209+
reservedIps = append(reservedIps, cidr)
210+
log.WithFields(log.Fields{
211+
"err": err,
212+
"cidr": cidr,
213+
}).Error("failed to ip from cidr")
214+
} else {
215+
reservedIps = append(reservedIps, ip)
216+
}
212217
}
213218
}
214219
}

ui/src/components/Services.vue

+43-31
Original file line numberDiff line numberDiff line change
@@ -715,50 +715,62 @@ export default {
715715
// switch to the wilderness
716716
ApiService.setWildServer();
717717
ApiService.setWildHeader();
718-
ApiService.post("/device", device)
719-
.then( d => {
720-
this.errorService(`Device created: ${d.name}`);
721-
console.log("device created: ", d);
722-
vpn.deviceid = d.id;
723-
724-
ApiService.setWildServer();
725-
ApiService.setWildHeader();
726-
ApiService.post("/vpn", vpn)
727-
.then( v => {
728-
console.log("vpn created: ", v);
729-
this.errorService(`VPN created: ${v.name}`);
730-
731-
this.service.device = d;
732-
this.service.vpn = v;
733-
734-
ApiService.setServer();
735-
ApiService.setHeader();
736-
ApiService.post("/service", this.service)
737-
.then( s => {
738-
console.log("service created: ", s);
739-
this.errorService(`Service created: ${s.name}`);
740-
this.Refreshing();
718+
719+
ApiService.get("/net/" + this.wildList.selected.value)
720+
.then( n => {
721+
console.log("net: ", n);
722+
service.net = n;
723+
724+
ApiService.post("/device", device)
725+
.then( d => {
726+
this.errorService(`Device created: ${d.name}`);
727+
console.log("device created: ", d);
728+
vpn.deviceid = d.id;
729+
730+
ApiService.post("/vpn", vpn)
731+
.then( v => {
732+
console.log("vpn created: ", v);
733+
this.errorService(`VPN created: ${v.name}`);
734+
735+
this.service.device = d;
736+
this.service.vpn = v;
737+
738+
ApiService.setServer();
739+
ApiService.setHeader();
740+
ApiService.post("/service", this.service)
741+
.then( s => {
742+
console.log("service created: ", s);
743+
this.errorService(`Service created: ${s.name}`);
744+
this.Refreshing();
745+
})
746+
.catch(error => {
747+
console.log("error: ", error)
748+
if (error.response) {
749+
this.errorService(error.response.data.error)
750+
}
751+
});
741752
})
742753
.catch(error => {
743754
console.log("error: ", error)
744755
if (error.response) {
745756
this.errorService(error.response.data.error)
746757
}
747758
});
748-
})
749-
.catch(error => {
750-
console.log("error: ", error)
751-
if (error.response) {
752-
this.errorService(error.response.data.error)
753-
}
754-
});
759+
})
760+
.catch(error => {
761+
console.log("error: ", error)
762+
if (error.response) {
763+
this.errorService(error.response.data.error)
764+
}
765+
});
755766
})
756767
.catch(error => {
757768
console.log("error: ", error)
758769
if (error.response) {
759-
this.errorService(error.response.data.error)
770+
this.errorService(error.response.data.error)
760771
}
761772
});
773+
762774
this.dialogWilderness = false;
763775
},
764776

0 commit comments

Comments
 (0)