예제 #1
0
def main():
  uid = get_uid_from_cookie()
  uid_dir = os.path.join(app_dir, 'storage', 'users', uid['uid'])

  form = cgi.FieldStorage()
  fileId = int(form.getvalue('fileId'))

  if form.has_key('settings'):
    settings = form.getvalue('settings')
    userconfig = set_user_config_from_json(uid, settings)
  else:
    userconfig = read_user_config(uid)

  if len(userconfig['tp_files']) >= fileId: 
    os.remove(os.path.join(uid_dir, 'turnpoints_' + str(fileId) + '.cup'))
    userconfig['tp_files'].pop(fileId-1)

  for f_id in range(fileId+1, (len(userconfig['tp_files'])+2)):
    os.rename(os.path.join(uid_dir, 'turnpoints_' + str(f_id) + '.cup'),
              os.path.join(uid_dir, 'turnpoints_' + str(f_id-1) + '.cup'))

  write_user_config(uid, userconfig)

  print "Content-type: text/html"
  print
#  print '{"success":true}'
  print get_user_config_as_json(uid)
예제 #2
0
def reply_success(uid, taskname):
  print "Content-type: text/html"
  print
  print '{"success":true,"settings":'
  print get_user_config_as_json(uid)
  print ',"download":{'
  print '"xcsoar":{"url":"tasks/'+uid['uid']+'/temp/'+taskname+'/xcsoar",'
  print '"qrcode":"tasks/'+uid['uid']+'/temp/'+taskname+'/xcsoar/qr",'
  print '"name":"XCSoar (*.tsk)"},'
  print '"seeyou":{"url":"tasks/'+uid['uid']+'/temp/'+taskname+'/seeyou",'
  print '"qrcode":"tasks/'+uid['uid']+'/temp/'+taskname+'/seeyou/qr",'
  print '"name":"SeeYou (*.cup)"}'
  print '}}'
예제 #3
0
def delete(taskname):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    userconfig = read_user_config(uid)

    success = False

    for key, d in enumerate(userconfig['task_files']):
        if d.get('name') == taskname:
            taskfile = os.path.join(uid_dir,
                                    'task_' + str(d.get('id')) + '.tsk')
            os.unlink(taskfile)
            userconfig['task_files'].pop(key)
            success = True
            break

    for key, d in enumerate(userconfig['task_files']):
        if (key + 1) != int(d.get('id')):
            taskfile_old = os.path.join(uid_dir,
                                        'task_' + str(d.get('id')) + '.tsk')
            taskfile_new = os.path.join(uid_dir,
                                        'task_' + str(key + 1) + '.tsk')
            os.rename(taskfile_old, taskfile_new)
            d['id'] = str(key + 1)

    write_user_config(uid, userconfig)

    return jsonify({
        'success': success,
        'settings': get_user_config_as_json(uid, encoded=False),
    })
예제 #4
0
파일: tasks.py 프로젝트: Turbo87/proSoar
def delete(taskname):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config["USERS_FOLDER"], uid["uid"])

    userconfig = read_user_config(uid)

    success = False

    for key, d in enumerate(userconfig["task_files"]):
        if d.get("name") == taskname:
            taskfile = os.path.join(uid_dir, "task_" + str(d.get("id")) + ".tsk")
            os.unlink(taskfile)
            userconfig["task_files"].pop(key)
            success = True
            break

    for key, d in enumerate(userconfig["task_files"]):
        if (key + 1) != int(d.get("id")):
            taskfile_old = os.path.join(uid_dir, "task_" + str(d.get("id")) + ".tsk")
            taskfile_new = os.path.join(uid_dir, "task_" + str(key + 1) + ".tsk")
            os.rename(taskfile_old, taskfile_new)
            d["id"] = str(key + 1)

    write_user_config(uid, userconfig)

    return jsonify({"success": success, "settings": get_user_config_as_json(uid, encoded=False)})
예제 #5
0
def upload():
    uid = get_uid_from_cookie()

    if 'settings' in request.values:
        settings = request.values['settings']
        write_user_config(uid, set_user_config_from_json(uid, settings))

    uploaded_file = save_uploaded_file()

    if not uploaded_file:
        return jsonify({'success': False})

    process = subprocess.Popen([
        os.path.join(current_app.config['APP_FOLDER'],
        'bin', 'private', 'add_waypoint_file_to_user'),
        '-u', uid['uid'], '-k', uid['key'], '-f', uploaded_file["tempname"],
        '-n', uploaded_file["filename"]
    ], stdout=subprocess.PIPE)
    stdout, stderr = process.communicate()

    os.remove(uploaded_file["tempname"])

    if stdout:
        return jsonify({'success': False})

    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False)
    })
예제 #6
0
파일: tasks.py 프로젝트: GliderGeek/proSoar
def delete(taskname):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    userconfig = read_user_config(uid)

    success = False

    for key, d in enumerate(userconfig['task_files']):
        if d.get('name') == taskname:
            taskfile = os.path.join(
                uid_dir, 'task_' + str(d.get('id')) + '.tsk')
            os.unlink(taskfile)
            userconfig['task_files'].pop(key)
            success = True
            break

    for key, d in enumerate(userconfig['task_files']):
        if (key + 1) != int(d.get('id')):
            taskfile_old = os.path.join(
                uid_dir, 'task_' + str(d.get('id')) + '.tsk')
            taskfile_new = os.path.join(
                uid_dir, 'task_' + str(key + 1) + '.tsk')
            os.rename(taskfile_old, taskfile_new)
            d['id'] = str(key + 1)

    write_user_config(uid, userconfig)

    return jsonify({
        'success': success,
        'settings': get_user_config_as_json(uid, encoded=False),
    })
예제 #7
0
def load(type="json"):
    uid = get_uid_from_cookie()

    type = request.values.get("as", type)

    if type == "js":
        match = geolite2.lookup(request.remote_addr)

        settings = "var initialSettings = " + get_user_config_as_json(uid) + ";"

        if match and match.location:
            location = (
                "var initialLocation = {lon: " + str(match.location[1]) + ", lat: " + str(match.location[0]) + "};"
            )
        else:
            location = "var initialLocation = {lon: 10, lat: 50};"

        return settings + location

    elif type == "json":
        return jsonify(get_user_config_as_json(uid), encoded=False)
예제 #8
0
def main():
  uid = get_uid_from_cookie()

  form = cgi.FieldStorage();

  if form.getvalue('as') == 'js':
    geoip = GeoIP.open(os.path.join(app_dir, 'storage', 'GeoLiteCity.dat'), GeoIP.GEOIP_STANDARD)
    location = geoip.record_by_addr(os.environ['REMOTE_ADDR'])

    print "Content-type: text/html"
    print
    print 'var initialSettings = '+get_user_config_as_json(uid)+';'
    
    if location:
      print 'var initialLocation = {lon: '+str(location['longitude'])+', lat: '+str(location['latitude'])+'};'
    else:
      print 'var initialLocation = {lon: 10, lat: 50};'

  elif form.getvalue('as') == 'json':
    print "Content-type: text/html"
    print
    print get_user_config_as_json(uid)
예제 #9
0
파일: settings.py 프로젝트: matejuh/proSoar
def load(type='json'):
    uid = get_uid_from_cookie()

    type = request.values.get('as', type)

    if type == 'js':
        match = geolite2.lookup(request.remote_addr)

        settings = \
            'var initialSettings = ' + get_user_config_as_json(uid) + ';'

        if match and match.location:
            location = 'var initialLocation = {lon: ' + \
                str(match.location[1]) + ', lat: ' + \
                str(match.location[0]) + '};'
        else:
            location = 'var initialLocation = {lon: 10, lat: 50};'

        return settings + location

    elif type == 'json':
        return jsonify(get_user_config_as_json(uid), encoded=False)
예제 #10
0
파일: tasks.py 프로젝트: Turbo87/proSoar
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config["USERS_FOLDER"], uid["uid"])

    if "task" in request.values:
        taskstring = request.values["task"]
        task = parse_json_task(taskstring)

    else:
        return jsonify({"success": False, "reason": "No task."})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    d = datetime.now()
    taskname = d.strftime("%w") + str(d.hour * 3600 + d.minute * 60 + d.second)
    filename = "tasktemp_" + taskname + ".tsk"

    with open(os.path.join(uid_dir, filename), "w") as f:
        f.write(create_xcsoar_task(task))

        base_url = "tasks/" + uid["uid"] + "/temp/" + taskname
        return jsonify(
            {
                "success": True,
                "settings": get_user_config_as_json(uid, encoded=False),
                "download": {
                    "xcsoar": {
                        "name": "XCSoar (*.tsk)",
                        "url": base_url + "/xcsoar",
                        "qrcode": base_url + "/xcsoar/qr",
                    },
                    "seeyou": {
                        "name": "SeeYou (*.cup)",
                        "url": base_url + "/seeyou",
                        "qrcode": base_url + "/seeyou/qr",
                    },
                },
            }
        )

    return jsonify({"success": False, "reason": "Unknown failure."})
예제 #11
0
파일: tasks.py 프로젝트: Turbo87/proSoar
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' in request.values:
        taskstring = request.values['task']
        task = parse_json_task(taskstring)

    else:
        return jsonify({'success': False, 'reason': 'No task.'})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    d = datetime.now()
    taskname = d.strftime('%w') + str(d.hour * 3600 + d.minute * 60 + d.second)
    filename = 'tasktemp_' + taskname + '.tsk'

    with open(os.path.join(uid_dir, filename), 'w') as f:
        f.write(create_xcsoar_task(task))

        base_url = 'tasks/' + uid['uid'] + '/temp/' + taskname
        return jsonify({
            'success': True,
            'settings': get_user_config_as_json(uid, encoded=False),
            'download': {
                'xcsoar': {
                    'name': 'XCSoar (*.tsk)',
                    'url': base_url + '/xcsoar',
                    'qrcode': base_url + '/xcsoar/qr',
                },
                'seeyou': {
                    'name': 'SeeYou (*.cup)',
                    'url': base_url + '/seeyou',
                    'qrcode': base_url + '/seeyou/qr',
                },
            }
        })

    return jsonify({'success': False, 'reason': 'Unknown failure.'})
예제 #12
0
파일: remove_task.py 프로젝트: ubx/proSoar
def main():
  uid = get_uid_from_cookie()
  uid_dir = os.path.join(app_dir, 'storage', 'users', uid['uid'])

  form = cgi.FieldStorage()
  m = re.compile('([^&+/;]*)').match(form.getvalue('task_name'))
  taskname = m.group(1)

  userconfig = read_user_config(uid)

  success = False

  for key, d in enumerate(userconfig['task_files']):
    if d.get('name') == taskname:
      taskfile = os.path.join(uid_dir, 'task_' + str(d.get('id')) + '.tsk')
      os.unlink(taskfile)
      userconfig['task_files'].pop(key)
      success = True
      break

  for key, d in enumerate(userconfig['task_files']):
    if (key+1) != int(d.get('id')):
      taskfile_old = os.path.join(uid_dir, 'task_' + str(d.get('id')) + '.tsk')
      taskfile_new = os.path.join(uid_dir, 'task_' + str(key+1) + '.tsk')
      os.rename(taskfile_old, taskfile_new)
      d['id'] = str(key+1)

  write_user_config(uid, userconfig)

  print "Content-type: text/html"
  print
  print '{'

  if success:
    print '"success":true,'
  else:
    print '"success":false,'

  print '"settings":' + get_user_config_as_json(uid)
  print '}'
예제 #13
0
파일: tasks.py 프로젝트: GliderGeek/proSoar
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    d = datetime.now()
    taskname = d.strftime('%w') + str(d.hour * 3600 + d.minute * 60 + d.second)
    filename = 'tasktemp_' + taskname + '.tsk'

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    base_url = 'tasks/' + uid['uid'] + '/temp/' + taskname
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False),
        'download': {
            'xcsoar': {
                'name': 'XCSoar (*.tsk)',
                'url': base_url + '/xcsoar',
                'qrcode': base_url + '/xcsoar/qr',
            },
            'seeyou': {
                'name': 'SeeYou (*.cup)',
                'url': base_url + '/seeyou',
                'qrcode': base_url + '/seeyou/qr',
            },
        }
    })
예제 #14
0
def remove(fileId):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'settings' in request.values:
        settings = request.values['settings']
        userconfig = set_user_config_from_json(uid, settings)
    else:
        userconfig = read_user_config(uid)

    if len(userconfig['tp_files']) >= fileId:
        os.remove(os.path.join(uid_dir, 'turnpoints_' + str(fileId) + '.cup'))
        userconfig['tp_files'].pop(fileId - 1)

    for f_id in range(fileId + 1, (len(userconfig['tp_files']) + 2)):
        os.rename(
            os.path.join(uid_dir, 'turnpoints_' + str(f_id) + '.cup'),
            os.path.join(uid_dir, 'turnpoints_' + str(f_id - 1) + '.cup')
        )

    write_user_config(uid, userconfig)

    return jsonify(get_user_config_as_json(uid, encoded=False))
예제 #15
0
def reply_success(uid):
  print "Content-type: text/html"
  print
  print '{"success":true,"settings":'
  print get_user_config_as_json(uid)
  print '}'
예제 #16
0
파일: tasks.py 프로젝트: GliderGeek/proSoar
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    m = re.compile('([^&+/;]*)').match(task_name)
    task_name = m.group(1)

    if task_name == '':
        return jsonify({'success': False, 'reason': 'Invalid task name.'})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    replace = False

    taskid = len(userconfig['task_files'])

    for key, value in enumerate(userconfig['task_files']):

        if value['name'] == task_name:
            replace = True
            taskid = key
            break

    if taskid >= 20:
        return jsonify({
            'success': False,
            'reason': 'Too much tasks saved already (maximum of 20 reached).'
        })

    filename = 'task_' + str(taskid + 1) + '.tsk'
    d = datetime.today()

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    taskinfo = {
        'id': taskid + 1,
        'name': task_name,
        'distance': task.distance,
        'type': task.type,
        'turnpoints': len(task),
        'date': d.isoformat()
    }

    if not replace:
        userconfig['task_files'].append(taskinfo)
    else:
        userconfig['task_files'][taskid] = taskinfo

    write_user_config(uid, userconfig)
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False)
    })
예제 #17
0
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    m = re.compile('([^&+/;]*)').match(task_name)
    task_name = m.group(1)

    if task_name == '':
        return jsonify({'success': False, 'reason': 'Invalid task name.'})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    replace = False

    taskid = len(userconfig['task_files'])

    for key, value in enumerate(userconfig['task_files']):

        if value['name'] == task_name:
            replace = True
            taskid = key
            break

    if taskid >= 20:
        return jsonify({
            'success':
            False,
            'reason':
            'Too much tasks saved already (maximum of 20 reached).'
        })

    filename = 'task_' + str(taskid + 1) + '.tsk'
    d = datetime.today()

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    taskinfo = {
        'id': taskid + 1,
        'name': task_name,
        'distance': task.distance,
        'type': task.type,
        'turnpoints': len(task),
        'date': d.isoformat()
    }

    if not replace:
        userconfig['task_files'].append(taskinfo)
    else:
        userconfig['task_files'][taskid] = taskinfo

    write_user_config(uid, userconfig)
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False)
    })
예제 #18
0
파일: tasks.py 프로젝트: Turbo87/proSoar
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config["USERS_FOLDER"], uid["uid"])

    if "task" in request.values:
        taskstring = request.values["task"]
        task = parse_json_task(taskstring)

    else:
        return jsonify({"success": False, "reason": "No task."})

    m = re.compile("([^&+/;]*)").match(task_name)
    task_name = m.group(1)

    if task_name == "":
        return jsonify({"success": False, "reason": "Invalid task name."})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    replace = False

    taskid = len(userconfig["task_files"])

    for key, value in enumerate(userconfig["task_files"]):

        if value["name"] == task_name:
            replace = True
            taskid = key
            break

    if taskid >= 20:
        return jsonify({"success": False, "reason": "Too much tasks saved already (maximum of 20 reached)."})

    filename = "task_" + str(taskid + 1) + ".tsk"
    d = datetime.today()

    with open(os.path.join(uid_dir, filename), "w") as f:
        f.write(create_xcsoar_task(task))

        if not replace:
            userconfig["task_files"].append(
                {
                    "id": taskid + 1,
                    "name": task_name,
                    "distance": task.distance,
                    "type": task.type,
                    "turnpoints": len(task),
                    "date": d.isoformat(),
                }
            )
        else:
            userconfig["task_files"][taskid] = {
                "id": taskid + 1,
                "name": task_name,
                "distance": task.distance,
                "type": task.type,
                "turnpoints": len(task),
                "date": d.isoformat(),
            }

        write_user_config(uid, userconfig)
        return jsonify({"success": True, "settings": get_user_config_as_json(uid, encoded=False)})

    return jsonify({"success": False, "reason": "Unknown failure."})