Example #1
0
long FBTestPluginAPI::countArrayLength(const FB::JSObjectPtr &jso) 
{
    if (!jso->HasProperty("getArray"))
        throw FB::invalid_arguments();
    FB::VariantList array = jso->GetProperty("getArray").cast<FB::VariantList>();
    long len = array.size();// array->GetProperty("length").convert_cast<long>();
    return len;
}
bool ProfileManager::has_user_ack(std::string profilename, FB::DOM::WindowPtr window) {
    
    try {
        if (window && window->getJSObject()->HasProperty("location")) {
            // Create a reference to the browswer console object
            FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("location");
            
            std::string origin = obj->GetProperty("origin").convert_cast<std::string>();
            std::string href = obj->GetProperty("href").convert_cast<std::string>();
            
            // Return the result of authorized domain entry, if found
            std::map<std::string, bool>::iterator it = authorized_domains.find(origin);
            if (it != authorized_domains.end())
                return it->second;
            
            // Ask user
            FB::variant ack_result;
            std::stringstream ss;
            ss << "The following page requests access to the BroadMask profile ";
            ss << "'" << profilename << "' :" << endl;
            ss << href << endl << endl;
            ss << "Do you want to authorize the domain?";
            ack_result = window->getJSObject()->Invoke("confirm", FB::variant_list_of(ss.str()));
            
            bool ack = ack_result.convert_cast<bool>();
            
            if (ack == true) {
                authorized_domains.insert(std::pair<std::string, bool>(origin, true));
                return true;
            } else {
                return false;
            }
            
        }
    } catch (exception& e) {
        cerr << "[BroadMask ProfileManager] Error getting user ack: " << e.what() << endl;
        return false;
    }
    
    return false;
}
Example #3
0
/**
 * Asynchronous function to open a new session
 */
void CVMWebAPISession::thread_open( const FB::variant& oConfigHash  ){
    CRASH_REPORT_BEGIN;
    int cpus = this->session->cpus;
    int ram = this->session->memory;
    int disk = this->session->disk;
    int flags = this->session->flags;
    std::string ver = this->session->version;
    int ans = 0;
    
    // If the user has provided an object, process overridable parameters
    if (oConfigHash.is_of_type<FB::JSObjectPtr>()) {
        FB::JSObjectPtr o = oConfigHash.cast<FB::JSObjectPtr>();
        
        // Check basic overridable: options
        if (o->HasProperty("cpus")  && __canOverride("cpus", this->session)) cpus = o->GetProperty("cpus").convert_cast<int>();
        if (o->HasProperty("ram")   && __canOverride("ram", this->session))  ram = o->GetProperty("ram").convert_cast<int>();
        if (o->HasProperty("disk")  && __canOverride("disk", this->session)) disk = o->GetProperty("disk").convert_cast<int>();
        
        // Check for overridable: flags
        if (o->HasProperty("flags") && __canOverride("flags", this->session)) {
            try {
                flags = o->GetProperty("flags").convert_cast<int>();
            } catch ( const FB::bad_variant_cast &) {
            }
        }
        
        // Check for overridable: diskURL
        if (o->HasProperty("diskURL") && __canOverride("diskURL", this->session)) {
            ver = o->GetProperty("diskURL").convert_cast<std::string>();
            flags |= HVF_DEPLOYMENT_HDD;
            
            // Check for 64bit image
            bool is64bit = false;
            if (o->HasProperty("cpu64bit")) {
                try {
                    is64bit = o->GetProperty("cpu64bit").convert_cast<bool>();
                } catch ( const FB::bad_variant_cast &) {
                    is64bit = false;
                }
            }
            if (is64bit)
                flags |= HVF_SYSTEM_64BIT;
            
        // Check for overridable: version
        } else if (o->HasProperty("version") && __canOverride("version", this->session)) {
            ver = o->GetProperty("version").convert_cast<std::string>();
            if (!isSanitized(&ver, "01234567890.-")) ver=DEFAULT_CERNVM_VERSION;
            flags |= HVF_SYSTEM_64BIT; // Micro is currently only 64-bit

        }
    }
    
    // Open session with the given flags
    ans = this->session->open( cpus, ram, disk, ver, flags );
    if (ans == 0) {
        WHEN_SAFE this->fire_open();
        
    } else {
        
        // Close session in case of a problem
        this->session->close( true );
        
        // Then fire errors
        WHEN_SAFE this->fire_openError(hypervisorErrorStr(ans), ans);
        WHEN_SAFE this->fire_error(hypervisorErrorStr(ans), ans, "open");
    }
    
    // The requirements of having a daemon might have changed
    try {
        CVMWebPtr p = this->getPlugin();
        if (p->hv != NULL) p->hv->checkDaemonNeed();
    } catch (...) {
        // InvalidPlugin might occur if the user unloads
        // the page while downloading the VM.
    }
    
    /* Start probing timer */
    this->probeTimer->start();

    CRASH_REPORT_END;
}