Exemplo n.º 1
0
def add():
    if "q" in request.args:
        words = extended_split(request.args.get("q"))
        key, url, search = (words + 3 * [""])[:3]
        print("=======q=", [request.args.get("q"), key, url, search])
        return redirect(url_for("search.add", key=key, url=url, search=search))

    elif "key" in request.args and request.args.get("url"):
        key = request.args.get("key")
        # why to control key?
        #if not key.replace(" ","").replace("_","").replace("-","").isalnum():
        #	return "Invalid key."

        url = request.args.get("url")

        engine = db.query(SearchEngine).filter_by(
            key=key, author=current_user).one_or_none()
        if engine:
            force = request.args.get("force")
            if not force == "True":
                return render_template(
                    "add.html",
                    caption="{key} already points at {url}".format(
                        key=key,
                        url=engine.search if engine.search else engine.url),
                    key=request.args.get("key", ""),
                    url=request.args.get("url", ""),
                    search=request.args.get("search", ""),
                    force="True",
                    button="Override")
            else:
                print("===========editing==to==", url)
                engine.url = url
                engine.search = request.args.get("search")
                db.commit()
        else:
            engine = SearchEngine(
                url=url,
                key=key,
                search=request.args.get("search"),
            )
            db.add(engine)
            db.commit()

        return """
				<b>{key}</b> -> {url}
				<br/> added <br/>
				<a href="{url}">back</a>
			   """.format(key=key, url=engine.url)
    else:
        return render_template(
            "add.html",
            caption="example search: https://www.google.com/search?q={query}",
            key=request.args.get("key", ""),
            url=request.args.get("url", ""),
            search=request.args.get("search", ""),
            force="",
            button="Submit")
Exemplo n.º 2
0
def load_or_write(key):
	item = db.query(Sensitive).get(key)
	if not item:
		value = input("Enter " + key + ":")
		db.add(Sensitive(key=key,value=value))
		db.commit()
	else:
		value = item.value
		
	return value
Exemplo n.º 3
0
Arquivo: auth.py Projeto: jarys/chuml
def add_user(name, pasw):
	salt = crypto.get_random_iid()
	pasw = hash(pasw + salt)

	user = User(
		name=name,
		pasw=pasw,
		salt=salt
		)
	db.add(user)
	db.commit()

	return user
Exemplo n.º 4
0
def internal_add(name, url, author, lbls=[], t=None):
    if t == None:
        t = int(time.time())

    bm = Bookmark(name=name,
                  url=url,
                  created_timestamp=t,
                  updated_timestamp=t,
                  author=author)

    for label in lbls:
        bm.labels.append(label)

    print("======", bm.to_dict())
    print("======", type(bm.labels))
    db.add(bm)
    db.commit()
    return bm
Exemplo n.º 5
0
def get_self_access_policy():
	ap = AccessPolicy(
		secret=crypto.get_random_secret(),
		with_secret_can=NOTHING,
		public_can=NOTHING
	)
	db.add(ap)
	db.commit()

	ua = UserAccess(
		user_id=current_user.id,
		access_policy_id=ap.id,
		user_can=ADMIN
	)
	ap.individuals.append(ua)
	db.add(ua)
	db.commit()
	return ap
Exemplo n.º 6
0
def internal_add(name, author, labels=[], t=None):
    if t == None:
        t = int(time.time())

    if db.query(Label).filter_by(name=name, author=author).all():
        label = db.query(Label).filter_by(name=name, author=author).first()
    else:
        label = Label(name=name,
                      author=author,
                      created_timestamp=t,
                      updated_timestamp=t)
        db.add(label)

    for l in labels:
        if not l in label.labels:
            label.labels.append(l)
    db.commit()

    return label
Exemplo n.º 7
0
def edit_post(id=0):
    node = db.query(Node).get(id)
    if not node:
        return "node {} not found".format(id)

    if access.access(node) < access.EDIT:
        return "access forbidden to node {}".format(id)
    try:
        action = get_arg("action")

        if action == "remove_label":
            label_name = get_arg("label_name")
            label = db.query(Label).filter_by(
                author=current_user,
                name=label_name,
            ).one_or_none()
            node.labels.remove(label)
            db.commit()
            return "success: label removed"
        elif action == "add_label":
            label_name = get_arg("label_name")
            label = db.query(Label).filter_by(
                author=current_user,
                name=label_name,
            ).one_or_none()
            if not label:
                label = Label(name=name)
                db.add(label)
                db.commit()
            node.labels.append(label)
            db.commit()
            return "success: label added"
        else:
            return "nothing done"
    except Exception as e:
        print("===== nodes =====")
        print(e)
        print("==================")
        db.rollback()
        return str(e)
import json
from chuml.auth import auth
from chuml.search import bookmarks
from chuml.search import labels
from chuml.utils import db
from chuml.search import search

#db.db_path = "../../db"
author = db.query(auth.User).filter_by(name="agi").first()

with open("/home/agi/backups/engines-2020-12-26.json") as file:
    engines = json.load(file)

for key, data in engines.items():
    e = search.SearchEngine(key=key, author=author)
    if "search" in data:
        e.search = data["search"]
    if "url" in data:
        e.url = data["url"]
    else:
        print("engine without url", key)

    db.add(e)
    db.commit()
    print(key)
Exemplo n.º 9
0
Arquivo: log.py Projeto: jarys/chuml
def log(text):
    db.add(Log(text=text, time=int(time.time())))
    db.commit()
Exemplo n.º 10
0
Arquivo: notes.py Projeto: jarys/chuml
def create():
    note = Note(text=request.args.get("text"), name=request.args.get("name"))
    db.add(note)
    db.commit()
    return redirect(url_for("notes.edit", id=note.id))