Esempio n. 1
0
    def post(self):
        try:
            if self.request.POST.get("login", None): #depois logo me preocupo com a seguranca
                if hasattr(self, "session"):
                    session = self.session
                    user = session.get("user", None)
                    if user:
                        self.redirect("/")
                    else:
                        username = str(self.request.POST.get("username", None))
                        password = str(self.request.POST.get("password", None))
                        if username:
                            r = requests.get("http://localhost:7000/users/" + username)
                            user = json.loads(r.text)
                            print user
                            if password:
                                if user:
                                    if user.get("password", None) == password:
                                        self.session["user"] = username
                                        self.redirect("/")
                                    else:
                                        context_dict = {"register": True,
                                                        "username": username,
                                                        "error": "Invalid Password"}
                                        self.response.write(template("login.html", context_dict))
                                else:
                                    context_dict = {"register": True,
                                                    "username": username,
                                                    "error": "Invalid Username"}
                                    self.response.write(template("login.html", context_dict))
                            else:
                                context_dict = {"register": True,
                                                "error": "Please insert a password"}
                                self.response.write(template("login.html", context_dict))
                        else:
                            context_dict = {"register": True,
                                            "error": "Please insert username"}
                            self.response.write(template("login.html", context_dict))
                else:
                    print "Login PUT"
            else:
                self.redirect("/")

        except (InvalidAuthIdError, InvalidPasswordError), e:
            print "Login POST"
            print e
Esempio n. 2
0
 def get(self, RestaurantName = None, RestaurantID = None):
     if hasattr(self, "session"):
         user = self.session.get("user", None)
         context_dict = {}
         if user:
             context_dict["user"] = user
         self.response.write(template("new_restaurant.html", context_dict))
     else:
         print "NewRestaurant GET"
Esempio n. 3
0
 def get(self):
     if hasattr(self, "session"):
         session = self.session
         user = session.get('user', None)
         context_dict = {}
         if user:
             context_dict["user"] = user
         self.response.write(template("index.html", context_dict))
     else:
         print "Index GET"
Esempio n. 4
0
    def post(self):
        try:
            if hasattr(self, "session"):
                username = self.request.POST.get("username", None)
                password = self.request.POST.get("password", None)

                if username:
                    r = requests.get("http://localhost:7000/users/" + username)
                    user = json.loads(r.text)
                    if password:
                        if user:
                            context_dict = {"register": True,
                                            "error": "user already exists"}
                            self.response.write(template("register.html", context_dict))
                        else:
                            if hasattr(self, "session"):
                                data = {
                                    "Username": username,
                                    "Password": password
                                }
                                r = requests.post("http://localhost:7000/users", data = data)
                                print r.text
                                self.session["user"] = username
                            else:
                                print "Register POST"
                                print "no session"
                            self.redirect("/")
                    else:
                        context_dict = {"register": True,
                                        "error": "please insert a password"}
                        self.response.write(template("register.html", context_dict))
                else:
                    print "Register POST"
                    context_dict = {"register": True,
                                    "error": "please insert a username and a password"}
                    self.response.write(template("register.html", context_dict))
        except (InvalidAuthIdError, InvalidPasswordError), e:
            print "Register POST"
            print e
            self.redirect("/")
Esempio n. 5
0
    def post(self):
        try:
            if hasattr(self, "session"):
                session = self.session
                user = self.session.get("user", None)
                context_dict = {}
                if user:
                    context_dict["user"] = user
                    name = self.request.POST.get("name", None)
                    address = self.request.POST.get("address", None)
                    if name:
                        if address:
                            data = {
                                "Name": name,
                                "Address": address
                            }
                            r = requests.post("http://localhost:7000/restaurants", data=data)
                            print r.text
                            self.redirect("/html/restaurants")
                        else:
                            context_dict["error"] = "Please insert an address"
                            self.response.write(template("new_restaurant.html", context_dict))
                    else:
                        if address:
                            context_dict["error"] = "Please insert a name"
                            self.response.write(template("new_restaurant.html", context_dict))
                        else:
                            context_dict["error"] = "Please insert a name and an address"
                            self.response.write(template("new_restaurant.html", context_dict))

                else:
                    context_dict["error"] = "you have to be loged in to add a new restaurant"
                    self.response.write(template("new_restaurant.html", context_dict))
            else:
                print "Login GET"
        except Exception as e:
            print "Login GET"
            print e
Esempio n. 6
0
 def get(self):
     try:
         if hasattr(self, "session"):
             session = self.session
             if session.get("user", None):
                 self.redirect("/")
             else:
                 context_dict = {"register": True}
                 self.response.write(template("login.html", context_dict))
         else:
             print "Login GET"
     except Exception as e:
         print "Login GET"
         print e
Esempio n. 7
0
 def get(self, RestaurantName = None, RestaurantID = None):
     if hasattr(self, "session"):
         user = self.session.get("user", None)
         context_dict = {}
         if user:
             context_dict["user"] = user
         if RestaurantID:
             r = requests.get("http://localhost:7000/restaurants/" + RestaurantID)
         elif RestaurantName:
             r = requests.get("http://localhost:7000/restaurants/search/" + RestaurantName)
         else:
             r = requests.get("http://localhost:7000/restaurants" )
         try:
             restaurants = json.loads(r.text)
             context_dict["restaurants"] = restaurants
             print context_dict
             self.response.write(template("restaurants.html", context_dict))
         except Exception as e:
             print "Restaurant Http GET"
             print e
     else:
         print "Restaurant Http GET"
Esempio n. 8
0
        if server.get('summarize', True):
            logging.debug("Checking server: %s..." % server_name)
            try:
                server = Server(server_name, server)
                servers.append(server.getSummary())
            except Exception, e:
                logging.warning("Unable to add server summary for %s: %s" %
                                (server_name, e))

    data = {
        "ctime": time.ctime(),
        "servers": servers,
        "meta": config.get('meta', {})
    }

    print template(templateName, data)


def parseArgs(args):
    p = argparse.ArgumentParser(
        description="Run monitoring against servers defined in config")

    p.add_argument('command',
                   help="Command to execute",
                   choices=['check', 'summary'])
    p.add_argument('configs', metavar='cfg', nargs='+', help="YML config file")

    p.add_argument('-v',
                   '--verbose',
                   action='store_true',
                   help="Enable verbose logging")
Esempio n. 9
0
def draw_form(form_type, f, method, dynamic_options={}):
    form_content = ""
    required_fields = []
    groups = get_form_groups(form_type)
    if not groups or len(groups) == 0:
        fields = {}
        if form_type == "lists":
            import lists
            fields = lists.fields()
        elif form_type == "templates":
            import templates
            fields = templates.template()
        elif form_type == "template_categories":
            import templates
            fields = templates.template_category()
        elif form_type == 'emails':
            import emails
            fields = emails.email()
        elif form_type == 'segments':
            import segments
            fields = segments.segment()
        elif form_type == 'campaigns':
            import campaigns
            fields = campaigns.campaign()
        elif form_type == "ab_tests":
            import campaigns
            fields = campaigns.variate_campaign()
            
        if len(fields) > 0:
            init_form(fields, form_type)
            groups = get_form_groups(form_type)
    
    for group in groups:
        if method == "new":
            fields = group.fields.filter(FormField.create == True).order_by(FormField.rank.asc()).all()
        elif method == "update":
            fields = group.fields.filter(FormField.update == True).order_by(FormField.rank.asc()).all()
        else:
            return ""
        if len(fields) > 0:
            if group.fieldset_on_form:
                form_content = """%s
                <fieldset id="%s">
                    <legend>%s</legend>""" % (form_content, group.id, group.name)
            for field in group.fields:
                #print field.rank
                field_value = ""
                alt_field_name = '%s_%s' % (form_type, field.name)
                if field.name in f:
                    field_value = f[field.name]
                elif alt_field_name in f:
                    field_value = f[alt_field_name]
                elif field.default_value != None:
                    field_value = field.default_value
                input_field = ""
                required = ""
                field_name = '%s_%s' % (form_type, field.name)
                if field.required:
                    required = "required"
                    required_fields.append(field_name)
                if field.tag == "input":
                    classes = ""
                    maxlength = ""
                    if field.field_type == "checkbox":
                        classes = " sw-checkbox"
                        if field_value != False:
                            maxlength = " checked "
                            field_value == "1"
                        else:
                            field_value == "0"
                    elif field.field_type == "text":
                        maxlength = " maxlength='%s' " % field.max_length
                    input_field = '<input type="%s" name="%s" id="%s" class="form-control %s" value="%s" %s %s />' % (field.field_type, field_name, field_name, classes, field_value, maxlength, required)
                elif field.tag == "textarea":
                    input_field = '<textarea name="%s" id="%s" class="form-control" style="height:100px;" %s>%s</textarea' % (field_name, field_name, field_value, required)
                elif field.tag == "select":
                    input_field = '<select name="%s" id="%s" class="form-control" %s>' % (field_name, field_name, required)
                    if field.options.count() > 0:
                        for option in field.options.order_by(FormFieldOption.label.asc()).all():
                            selected = ""
                            if (option.value == field_value) or (field_value == "None" and option.value == '0'):
                                selected = " selected"
                            input_field = '%s<option value="%s" %s>%s</option>' % (input_field, option.value, selected, option.label)
                    elif field_name in dynamic_options:
                        #print dynamic_options
                        sorted_options = sorted(dynamic_options[field_name].items(), key=(operator.itemgetter(0)))
                        for value, label in sorted_options:
                            selected = ""
                            if (str(value) == str(field_value)) or (field_value == "None" and str(value) == '0'):
                                selected = ' selected="selected"'
                            input_field = '%s<option value="%s" %s>%s</option>' % (input_field, value, selected, label)
                    input_field = '%s\n</select>' % input_field
                if input_field != "":
                    form_content = """%s
                        <div class="form-group">
                            <label for="%s" class="control-label col-lg-2">%s</label>
                            <div class="col-lg-10">
                                %s
                            </div>
                        </div>""" % (form_content, field.name, field.label, input_field)
            if group.fieldset_on_form:
                form_content = '%s</fieldset>' % form_content
    return form_content, required_fields
Esempio n. 10
0
	for server_name, server in config["servers"].iteritems():
		if server.get('summarize', True):
			logging.debug("Checking server: %s..." % server_name)
			try:
				server = Server(server_name, server)
				servers.append(server.getSummary())
			except Exception, e:
				logging.warning("Unable to add server summary for %s: %s" % (server_name, e))

	data = {
		"ctime" : time.ctime(),
		"servers" : servers,
		"meta" : config.get('meta', {})
	}

	print template(templateName, data)



def parseArgs(args):
	p = argparse.ArgumentParser(description = "Run monitoring against servers defined in config")

	p.add_argument('command', help="Command to execute", choices=['check', 'summary'])
	p.add_argument('configs', metavar='cfg', nargs='+', help="YML config file")

	p.add_argument('-v', '--verbose', action='store_true', help="Enable verbose logging")
	p.add_argument('-m', '--merge', help="Update-merge multiple configs from left to right", action='store_true')
	p.add_argument('-f', '--format', help="Specify template format to output summary (markdown)", default="md")

	return p.parse_args(args)