Exemplo n.º 1
0
Arquivo: main.py Projeto: whs/OvzCP
	def post(self, veid):
		sql = models.VM.select(models.VM.q.veid == int(veid))[0]
		if sql.user != self.current_user and sql.user:
			self.redirect(self.reverse_url("containers")+"?error=1")
			return
		vm = sql.vz
		if vm.running:
			self.redirect(self.reverse_url("containers")+"?error=5")
			return
		proc = vm.destroy()
		for i in sql.varnishBackend:
			for i2 in i.cond:
				i2.destroySelf()
			i.destroySelf()
		for i in sql.portForward:
			i.destroySelf()
		if sql.munin:
			sql.munin.destroySelf()
		import munin, vmfw
		munin.update(models.Munin.select(), models.User.select())
		vmfw.update(models.PortForward.select())
		vmfw.restart()
		varnish.updateBackend(models.VarnishBackend.select())
		varnish.updateRecv(models.VarnishCond.select())
		varnish.restart()
		sql.destroySelf()
		time.sleep(1) # wait for dusts to settle
		self.redirect(self.get_argument("return", self.reverse_url("containers")+"?msg=3"))
Exemplo n.º 2
0
Arquivo: main.py Projeto: whs/OvzCP
	def get(self, veid):
		if not _config.getboolean("iface", "enabled"): return
		try:
			d=models.PortForward.select(models.PortForward.q.id == int(self.get_argument("delete")))[0]
		except IndexError:
			self.redirect(self.reverse_url("vminfo", veid)+"#portedit")
		if d.vm.user != self.current_user or not d.vm.user:
			self.redirect(self.reverse_url("containers")+"?error=1")
			return
		d.destroySelf()
		import vmfw
		vmfw.update(models.PortForward.select())
		vmfw.restart()
		self.redirect(self.reverse_url("vminfo", veid)+"#portedit")
Exemplo n.º 3
0
Arquivo: main.py Projeto: whs/OvzCP
	def post(self, veid):
		if not _config.getboolean("iface", "enabled"): return
		sql = models.VM.select(models.VM.q.veid == int(veid))[0]
		if sql.user != self.current_user or not sql.user:
			self.redirect(self.reverse_url("containers")+"?error=1")
			return
		if not re.match(_config.get("iface", "allowed"), self.get_argument("iface")):
			self.redirect(self.reverse_url("vminfo", veid)+"?error=4")
			return
		try:
			if _config.get("ifaceuser", self.get_argument("iface").replace(":", "-")) != self.current_user.email:
				self.redirect(self.reverse_url("vminfo", veid)+"?error=4")
				return
		except ConfigParser.NoOptionError:
			pass
		inport = self.get_argument("port", None)
		outport = self.get_argument("outport", None)
		if inport and not outport:
			outport = inport
		elif outport and not inport:
			inport = outport
		elif not inport and not outport:
			self.redirect(self.reverse_url("vminfo", veid)+"?error=4")
			return
		if outport.lower() == "dmz":
			outport = -1
			inport = -1
			if models.PortForward.select(models.PortForward.q.iface==self.get_argument("iface")).count():
				self.redirect(self.reverse_url("vminfo", veid)+"?error=1")
				return
		else:
			outport = int(outport) 
			inport = int(inport)
		if outport == 80 and _config.get("varnish", "enabled"):
			self.redirect(self.reverse_url("vminfo", veid)+"?error=6")
			return
		if models.PortForward.select(models.AND(models.PortForward.q.iface==self.get_argument("iface"), 
				models.OR(models.PortForward.q.outport==outport, models.PortForward.q.outport==-1))).count():
			self.redirect(self.reverse_url("vminfo", veid)+"?error=1")
			return
		models.PortForward(vm=sql, iface=self.get_argument("iface"), port=inport, outport=outport)
		import vmfw
		vmfw.update(models.PortForward.select())
		vmfw.restart()
		self.redirect(self.reverse_url("vminfo", veid)+"#portedit")