示例#1
0
function handle_list_command($list_name, $cmd_name)
{
    switch ($cmd_name) {
        case 'list':
            $res = mmc_array_values($list_name);
            if (count($res) === 0) {
                update_sched_tasks($list_name);
                $res = mmc_array_values($list_name);
            }
            return jsonp($res);
        case 'create':
        case 'update':
            $key_name = @$_POST['name'];
            if ($key_name) {
                return result_ok(mmc_array_set($list_name, md5($key_name), $_POST));
            } else {
                return '{"res": false}';
            }
        case 'delete':
            mmc_array_del($list_name, md5($_POST['name']));
            if (mmc_array_length($list_name) === 0) {
                del_cached_file($list_name);
            }
            return result_ok(true);
        case 'flush':
            sched_changed();
            return '{"res": false}';
        case 'names':
            return jsonp(mmc_array_keys($list_name));
        case 'tags':
            $items = mmc_array_values($list_name);
            $output_tags = [];
            foreach ($items as $item) {
                $tags = @$item['tags'];
                if ($tags) {
                    $tag_list = explode(' ', $tags);
                    foreach ($tag_list as $tag) {
                        $output_tags[] = $tag;
                    }
                }
            }
            return jsonp($output_tags);
        default:
            die('{"res": false}');
    }
}
示例#2
0
function handle_reset()
{
    $device = @$_GET['device'];
    if (empty($device)) {
        $device = get_device();
    }
    if (empty($device)) {
        return 'no device';
    }
    //删除保存了的在线列表
    mmc_array_del(NS_DEVICE_LIST, $device);
    //删除保存了的账户信息
    $mem = api_open_mmc();
    $mem->ns_delete(NS_BINDED_LIST, $device);
    $mem->ns_delete(NS_BINDED_CAPTION, $device);
    foreach (mmc_array_keys(NS_BINDING_LIST) as $platform) {
        $ns_bind_list = NS_BINDING_LIST . $platform;
        mmc_array_del($ns_bind_list, $device);
    }
    //删除保存了的计划任务消息记录
    $mem->ns_delete(NS_SCHED_DEVICE, $device);
    $mem->ns_delete(NS_PLANS_DEVICE, $device);
    new_user($device, time() + COOKIE_TIMEOUT_NEW);
    //清空cookie
    unset($_COOKIE[COOKIE_DEVICE_SAVED]);
    setcookie(COOKIE_DEVICE_SAVED, '', time() - 3600, '/', COOKIE_DOMAIN);
    return 'succeed';
}
示例#3
0
function mmc_array_all_cache($name)
{
    $list = mmc_array_all($name);
    //清理异常记录
    foreach ($list as $key => &$value) {
        if (@$value['name'] === '') {
            mmc_array_del($name, $key);
            loglocal('del ' . $key);
            loglocal($value);
            unset($list[$key]);
        }
        if (array_key_exists('finish_time', $value)) {
            $finish_time = trans_time($value['finish_time']);
            if (time() >= $finish_time) {
                $value['status'] = 'timeout';
                mmc_array_set($name, $key, $value);
            }
        }
    }
    $file_name = get_cached_filename($name);
    if (count($list) === 0) {
        if (file_exists($file_name)) {
            $list = unserialize(file_get_contents($file_name));
            if (empty($list)) {
                return array();
            }
        } else {
            return array();
        }
        mmc_array_clear($name);
        foreach ($list as $key => $value) {
            $res = mmc_array_set($name, $key, $value);
        }
    } else {
        file_put_contents($file_name, serialize($list));
    }
    return $list;
}