Пример #1
0
PaintPanel::PaintPanel(axWindow* parent,
                     const axRect& rect):
// Parent.
axPanel(parent, rect)
{
    std::string app_path(axApp::GetInstance()->GetAppDirectory());
    
	//std::string app_path("C:/Users/Alexandre Arsenault/Desktop/axLib/axExamples/Demo/VisualStudio2013/axGL/");
    dog_cat_img = new axImage(app_path + std::string("whiskers-wags-dog-cat.png"));
}
Пример #2
0
SoundEditorAudio::SoundEditorAudio():
    axAudio()
{
    std::string app_path(axApp::GetInstance()->GetAppDirectory());
    //std::string app_path("/Users/alexarse/Project/axLib/axProjects/SoundEditor/");
//	std::string app_path("C:/Users/Alexandre Arsenault/Desktop/axLib/axProjects/SoundEditor/");
    std::string snd_path = app_path + ("808 Samples/bass (8).wav");
    
    _sndBuffer = new axAudioBuffer(snd_path);
    _bufferPlayer = new axAudioBufferPlayer(_sndBuffer);
    _secToSendPlayingEvt = PLAYING_POSITION_TIME_INTERVAL;
    
    _filter = new axAudioFilter();
    _filter->SetFreq(40.0);
    _filter->SetQ(5.0);
}
Пример #3
0
FlatDialog::FlatDialog(
    gdi::GraphicApi & drawable, int16_t left, int16_t top, int16_t width, int16_t height,
    Widget & parent, NotifyApi* notifier,
    const char* caption, const char * text,
    WidgetFlatButton * extra_button,
    Theme const & theme, Font const & font, const char * ok_text,
    const char * cancel_text, ChallengeOpt has_challenge
)
    : WidgetParent(drawable, parent, notifier)
    , title(drawable, *this, nullptr, caption, -9,
            theme.global.fgcolor, theme.global.bgcolor, font, 5)
    , separator(drawable, *this, this, -12,
                theme.global.separator_color)
    , dialog(drawable, *this, nullptr, text, -10,
                theme.global.fgcolor, theme.global.bgcolor, font, 10, 2)
    , challenge(nullptr)
    , ok(drawable, *this, this, ok_text ? ok_text : "Ok", -12,
            theme.global.fgcolor, theme.global.bgcolor,
            theme.global.focus_color, 2, font, 6, 2)
    , cancel(cancel_text
        ? new WidgetFlatButton(
            drawable, *this, this, cancel_text, -11,
            theme.global.fgcolor, theme.global.bgcolor,
            theme.global.focus_color, 2, font, 6, 2)
        : nullptr)
    , img(drawable,
          theme.global.logo ? theme.global.logo_path.c_str() :
          app_path(AppPath::LoginWabBlue), *this, nullptr, -8)
    , extra_button(extra_button)
    , font(font)
    , bg_color(theme.global.bgcolor)
{
    this->impl = &composite_array;

    this->add_widget(&this->img);

    this->add_widget(&this->title);
    this->add_widget(&this->separator);
    this->add_widget(&this->dialog);

    if (has_challenge) {
        if (CHALLENGE_ECHO == has_challenge) {
            this->challenge = new WidgetEdit(
                this->drawable, *this, this, nullptr, -13,
                theme.edit.fgcolor, theme.edit.bgcolor,
                theme.edit.focus_color, font, -1u, 1, 1
            );
        }
        else {
            this->challenge = new WidgetPassword(
                this->drawable, *this, this, nullptr, -13,
                theme.edit.fgcolor, theme.edit.bgcolor,
                theme.edit.focus_color, font, -1u, 1, 1
            );
        }
        this->add_widget(this->challenge);

        this->set_widget_focus(this->challenge, focus_reason_tabkey);
    }


    this->add_widget(&this->ok);

    if (this->cancel) {
        this->add_widget(this->cancel);
    }

    if (has_challenge) {
        if (extra_button) {
            this->add_widget(extra_button);
        }
    }

    this->move_size_widget(left, top, width, height);

    if (!has_challenge)
        this->set_widget_focus(&this->ok, focus_reason_tabkey);
}
Пример #4
0
MenuPanel::MenuPanel(axWindow* parent,
                         const axRect& rect):
// Parent.
axPanel(parent, rect)
{
    std::string app_path(axApp::GetInstance()->GetAppDirectory());
	//std::string app_path("C:/Users/Alexandre Arsenault/Desktop/axLib/axExamples/Demo/VisualStudio2013/axGL/");
    
    axButtonInfo btn1_info;
    btn1_info.normal = axColor(0.8, 0.8, 0.8);
    btn1_info.hover = axColor(0.9, 0.9, 0.9);
    btn1_info.clicking = axColor(0.7, 0.7, 0.7);
    btn1_info.contour = axColor(0.0, 0.0, 0.0);
    btn1_info.selected = btn1_info.normal;
    
    axButtonEvents btn1_evts;
    btn1_evts.button_click = GetOnPopupMenu();
    
    _btnPopMenu = new axButton(this,
                               axRect(40, 40, 100, 20),
                               btn1_evts,
                               btn1_info,
                               "", "Test1");
    

  
    
    axPopupMenuInfo menu_info(axColor(1.0, 0.0, 0.0),
                              axColor(0.2, 0.8, 0.8),
                              axColor(0.2, 0.8, 0.8),
                              axColor(0.2, 0.8, 0.8),
                              axColor(0.2, 0.8, 0.8),
                              axColor(0.0, 0.0, 0.0));
    
    axPopupMenuEvents menu_evts;
    menu_evts.selection_change = GetOnPopupMenuChoice();
    
    std::vector<std::string> menu_str = {"None", "Test1",
                                         "Test2", "Test3",
                                         "Test4"};
    
    axPoint menu_pos = _btnPopMenu->GetAbsoluteRect().position;
    menu_pos.y += _btnPopMenu->GetSize().y;
    _popMenu = new axPopupMenu(this,
                               axRect(menu_pos, axSize(100, 30)),
                               menu_evts, menu_info, menu_str);
    
    _popMenu->Hide();
    _popMenu->SetSelectedIndex(0);
    
    std::cout << "MenuPanel::_popMenu (id) = " << _popMenu->GetId() << std::endl;
    
    axDropMenuInfo drop_info;
    drop_info.normal = axColor(0.8, 0.8, 0.8);
    drop_info.hover = axColor(0.9, 0.9, 0.9);
    drop_info.clicking = axColor(0.7, 0.7, 0.7);
    drop_info.contour = axColor(0.0, 0.0, 0.0);
    drop_info.selected = drop_info.normal;
    
    axDropMenuEvents drop_evts;
    drop_evts.selection_change = GetOnDropMenuChoice();
    
    _dropMenu = new axDropMenu(this, axRect(250, 40, 100, 20),
                               drop_evts,
                               drop_info,
                               app_path + std::string("DropMenuArrow.png"),
                               app_path + std::string("button.png"),
                               axDROP_MENU_SINGLE_IMG);
    
    
    axButtonEvents btn2_evts;
    btn2_evts.button_click = GetOnTestBtnUnder();
    
    axButton* btn2 = new axButton(this,
                                  axRect(_btnPopMenu->GetBottomLeftPosition() + axPoint(0, 10),
                                         axSize(70, 25)),
                                  btn2_evts,
                                  btn1_info,
                                  "", "BTN");
    
    //--------------------------------------------------------------------------
    axTextBoxEvents txtEvents;
    axTextBoxInfo txtInfo;
    txtInfo.normal = axColor(0.9, 0.9, 0.9);
    txtInfo.hover = axColor(0.9, 0.9, 0.9);
    txtInfo.selected = axColor(1.0, 1.0, 1.0);
    txtInfo.hightlight = axColor(0.4, 0.4, 0.6, 0.4);
    txtInfo.contour = axColor(0.0, 0.0, 0.0);
    txtInfo.cursor = axColor(1.0, 0.0, 0.0);
    txtInfo.selected_shadow = axColor(0.8, 0.8, 0.8, 0.3);
    
    _txtCtrl = new axTextBox(this,
                             axRect(110, 225, 180, 25),
                             txtEvents,
                             txtInfo,
                             "",
                             "Alexandre",
                             axTEXT_BOX_CONTOUR_HIGHLIGHT);
    
    //--------------------------------------------------------------------------


}
Пример #5
0
SliderPanel::SliderPanel(axWindow* parent,
                         const axRect& rect):
// Parent.
axPanel(parent, rect)
{
    std::string app_path(axApp::GetInstance()->GetAppDirectory());
	//std::string app_path("C:/Users/Alexandre Arsenault/Desktop/axLib/axExamples/Demo/VisualStudio2013/axGL/");

    axSliderInfo sld_info;
    sld_info.img_path = app_path + std::string("sliderPlain.png");
    sld_info.btn_size = axSize(12, 12);
    sld_info.slider_width = 4;
    
    // Doesn't seem to work for now.
    sld_info.bgColorNormal = axColor(0.7, 0.7, 0.7);
    sld_info.bgColorHover = axColor(0.9, 0.9, 0.9);
    sld_info.bgColorClicked = axColor(0.6, 0.6, 0.6);
    sld_info.contourColor = axColor(0.0, 0.0, 0.0);
    
    sld_info.sliderColorNormal = axColor(0.2, 0.2, 0.9);
    sld_info.sliderColorHover = axColor(0.2, 0.2, 1.0);
    sld_info.sliderColorClicked = axColor(0.2, 0.2, 0.6);
    sld_info.sliderContourColor = axColor(0.2, 0.2, 0.2);
    
    sld_info.backSliderColor = axColor(0.7, 0.7, 0.7);
    sld_info.backSliderContourColor = axColor(0.2, 0.2, 0.2);
    
    axSliderEvents sld_evts;
    sld_evts.slider_value_change = GetOnSlider1();
    
    axSlider* sld1 = new axSlider(this, axRect(40, 80, 300, 15),
                                  sld_evts, sld_info);
    
    sld1->SetBackgroundAlpha(0.3);
    sld_info.sliderColorNormal = axColor(0.8, 0.2, 0.9);

    axSlider* sld2 = new axSlider(this, axRect(40, 100, 300, 15),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_BACK_SLIDER);
    
    
    sld2->SetBackgroundAlpha(0.3);
    sld_info.sliderColorNormal = axColor(0.2, 0.8, 0.2);
    
    axSlider* sld3 = new axSlider(this, axRect(40, 120, 300, 15),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_NO_SLIDER_LINE);
    
    sld3->SetBackgroundAlpha(0.3);
    
    
    axSlider* sld4 = new axSlider(this, axRect(40, 140, 300, 15),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_CLICK_ANYWHERE);
    
    sld4->SetBackgroundAlpha(0.3);
    
    axSlider* sld5 = new axSlider(this, axRect(40, 160, 300, 15),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_CLICK_ANYWHERE |
                                  axSLIDER_FLAG_RIGHT_ALIGN);
    
    sld5->SetBackgroundAlpha(0.3);
    
    sld_info.img_path = "";
    sld_info.btn_size = axSize(12, 12);
    sld_info.slider_width = 13;
    axSlider* sld6 = new axSlider(this, axRect(40, 180, 300, 15),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_CLICK_ANYWHERE);
    
    sld6->SetBackgroundAlpha(0.3);
    
    
    sld_info.img_path = "";
    sld_info.btn_size = axSize(12, 12);
    sld_info.slider_width = 6;
    axSlider* sld7 = new axSlider(this, axRect(40, 200, 300, 15),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_CLICK_ANYWHERE|
                                  axSLIDER_FLAG_MIDDLE_ALIGN);
    
    sld7->SetBackgroundAlpha(0.3);
    
    
    axSlider* sld8 = new axSlider(this, axRect(40, 240, 15, 100),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_CLICK_ANYWHERE|
                                  axSLIDER_FLAG_VERTICAL |
                                  axSLIDER_FLAG_RIGHT_ALIGN);
    
    sld8->SetBackgroundAlpha(0.3);
    
    axSlider* sld9 = new axSlider(this, axRect(60, 240, 15, 100),
                                  sld_evts, sld_info,
                                  axSLIDER_FLAG_CLICK_ANYWHERE |
                                  axSLIDER_FLAG_VERTICAL |
                                  axSLIDER_FLAG_RELEASE_ON_LEAVE);
    
    sld9->SetBackgroundAlpha(0.3);
    
    
    sld_info.img_path = app_path + std::string("sliderCtrl.png");
    sld_info.btn_size = axSize(12, 12);
    sld_info.slider_width = 5;
    int x = 80;
    for(int i = 0; i < 5; i++, x+= 15)
    {
        axSlider* sld = new axSlider(this, axRect(x, 240, 15, 100),
                                     sld_evts, sld_info,
                                     axSLIDER_FLAG_CLICK_ANYWHERE |
                                     axSLIDER_FLAG_VERTICAL |
                                     axSLIDER_FLAG_RIGHT_ALIGN);
        
        sld->SetBackgroundAlpha(0.3);
    }
    
    
    _scrollPanel = new MyScrollPanel(this, axRect(200, 250, 150, 600),
                                     axSize(150, 200));
//    _scrollPanel->SetShownRect(axRect(0, 0, 150, 200));
    
    
    
}
Пример #6
0
    Server_status start(int incoming_sck) override
    {
        union
        {
            struct sockaddr s;
            struct sockaddr_storage ss;
            struct sockaddr_in s4;
            struct sockaddr_in6 s6;
        } u;
        unsigned int sin_size = sizeof(u);
        memset(&u, 0, sin_size);

        int sck = accept(incoming_sck, &u.s, &sin_size);
        if (-1 == sck) {
            LOG(LOG_INFO, "Accept failed on socket %d (%s)", incoming_sck, strerror(errno));
            _exit(1);
        }

        char source_ip[256];
        strcpy(source_ip, inet_ntoa(u.s4.sin_addr));
        REDEMPTION_DIAGNOSTIC_PUSH
        REDEMPTION_DIAGNOSTIC_GCC_IGNORE("-Wold-style-cast") // only to release
        const int source_port = ntohs(u.s4.sin_port);
        REDEMPTION_DIAGNOSTIC_POP
        /* start new process */
        const pid_t pid = fork();
        switch (pid) {
        case 0: /* child */
        // TODO: see exit status of child, we could use it to diagnose session behaviours
        // TODO: we could probably use some session launcher object here. Something like
        // an abstraction layer that would manage either forking of threading behavior
        // this would also likely have some effect on network ressources management
        // (that means the select() on ressources could be managed by that layer)
            {
                close(incoming_sck);

                Inifile ini;
                ini.set<cfg::font>(Font(app_path(AppPath::DefaultFontFile)));
                ini.set<cfg::debug::config>(this->debug_config);
                configuration_load(ini.configuration_holder(), this->config_filename);

                if (ini.get<cfg::debug::session>()){
                    LOG(LOG_INFO, "Setting new session socket to %d\n", sck);
                }

                union
                {
                    struct sockaddr s;
                    struct sockaddr_storage ss;
                    struct sockaddr_in s4;
                    struct sockaddr_in6 s6;
                } localAddress;
                socklen_t addressLength = sizeof(localAddress);


                if (-1 == getsockname(sck, &localAddress.s, &addressLength)){
                    LOG(LOG_INFO, "getsockname failed error=%s", strerror(errno));
                    _exit(1);
                }

                char target_ip[256];
                REDEMPTION_DIAGNOSTIC_PUSH
                REDEMPTION_DIAGNOSTIC_GCC_IGNORE("-Wold-style-cast") // only to release
                const int target_port = ntohs(localAddress.s4.sin_port);
                REDEMPTION_DIAGNOSTIC_POP
//                strcpy(real_target_ip, inet_ntoa(localAddress.s4.sin_addr));
                strcpy(target_ip, inet_ntoa(localAddress.s4.sin_addr));

                if (0 != strcmp(source_ip, "127.0.0.1")){
                    // do not log early messages for localhost (to avoid tracing in watchdog)
                    LOG(LOG_INFO, "Redemption " VERSION);
                    LOG(LOG_INFO, "src=%s sport=%d dst=%s dport=%d", source_ip, source_port, target_ip, target_port);
                }

                char real_target_ip[256];
                if (ini.get<cfg::globals::enable_transparent_mode>() &&
                    (0 != strcmp(source_ip, "127.0.0.1"))) {
                    int fd = open("/proc/net/ip_conntrack", O_RDONLY);
                    // source and dest are inverted because we get the information we want from reply path rule
                    int res = parse_ip_conntrack(fd, target_ip, source_ip, target_port, source_port, real_target_ip, sizeof(real_target_ip), 1);
                    if (res){
                        LOG(LOG_WARNING, "Failed to get transparent proxy target from ip_conntrack: %d", fd);
                    }
                    close(fd);

                    if (setgid(this->gid) != 0){
                        LOG(LOG_ERR, "Changing process group to %u failed with error: %s\n", this->gid, strerror(errno));
                        _exit(1);
                    }
                    if (setuid(this->uid) != 0){
                        LOG(LOG_ERR, "Changing process user to %u failed with error: %s\n", this->uid, strerror(errno));
                        _exit(1);
                    }

                    LOG(LOG_INFO, "src=%s sport=%d dst=%s dport=%d", source_ip, source_port, real_target_ip, target_port);
                }
                else {
                    ::memset(real_target_ip, 0, sizeof(real_target_ip));
                }

                int nodelay = 1;
                if (0 == setsockopt(sck, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay))){
                    // Create session file
                    int child_pid = getpid();
                    char session_file[256];
                    sprintf(session_file, "%s/redemption/session_%d.pid", app_path(AppPath::Pid), child_pid);
                    int fd = open(session_file, O_WRONLY | O_CREAT, S_IRWXU);
                    if (fd == -1) {
                        LOG(LOG_ERR, "Writing process id to SESSION ID FILE failed. Maybe no rights ?:%d:%s\n", errno, strerror(errno));
                        _exit(1);
                    }
                    char text[256];
                    const size_t lg = snprintf(text, 255, "%d", child_pid);
                    if (write(fd, text, lg) == -1) {
                        LOG(LOG_ERR, "Couldn't write pid to %s/redemption/session_<pid>.pid: %s", app_path(AppPath::Pid), strerror(errno));
                        _exit(1);
                    }
                    close(fd);

                    // Launch session
                    if (0 != strcmp(source_ip, "127.0.0.1")){
                        // do not log early messages for localhost (to avoid tracing in watchdog)
                        LOG(LOG_INFO,
                            "New session on %d (pid=%d) from %s to %s",
                            sck, child_pid, source_ip, (real_target_ip[0] ? real_target_ip : target_ip));
                    }
                    ini.set_acl<cfg::globals::host>(source_ip);
//                    ini.context_set_value(AUTHID_TARGET, real_target_ip);
                    ini.set_acl<cfg::globals::target>(target_ip);
                    if (ini.get<cfg::globals::enable_transparent_mode>()
                        &&  strncmp(target_ip, real_target_ip, strlen(real_target_ip))) {
                        ini.set_acl<cfg::context::real_target_device>(real_target_ip);
                    }
                    Session session(sck, ini, this->cctx, this->rnd, this->fstat);

                    // Suppress session file
                    unlink(session_file);

                    if (ini.get<cfg::debug::session>()){
                        LOG(LOG_INFO, "Session::end of Session(%d)", sck);
                    }

                    shutdown(sck, 2);
                    close(sck);
                }
                else {
                    LOG(LOG_ERR, "Failed to set socket TCP_NODELAY option on client socket");
                }
                _exit(0);
            }
            break;
        default: /* father */
            {
                close(sck);
            }
            break;
        case -1:
            // error forking
            LOG(LOG_ERR, "Error creating process for new session : %s\n", strerror(errno));
            break;
        }
        return START_FAILED;
    }