summaryrefslogtreecommitdiffstats
path: root/abs/core/mythinstall/MythVantage-app/mythinstall/fileshare.cpp
blob: d09efd77e20aed3849a21a6c141057e90cb1ae31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include <unistd.h>
#include "misc_settings.h"
#include "mv_common.h"

#include <QTextStream>
#include <unistd.h>
#include <stdio.h>
#include <QtNetwork>

#include <stdlib.h>
#include "mythprogressdialog.h"
#include "mythsystemlegacy.h"


#include "mythuihelper.h"

#include "fileshare.h"

extern  HostParms hostparm;
using namespace std;

//________________Client (NFS) Screen SETTINGS_________________________
static HostComboBox *HostHaveCentralNFS()
{
    HostComboBox *gc = new HostComboBox("HostHaveCentralNFS");
    gc->setLabel(QObject::tr("Central NFS Server"));
    gc->addSelection("no");
    gc->addSelection("yes") ;
    gc->setHelpText(QObject::tr("Select yes, if your media is stored on an NFS server different than the master backend. Select no if you are unsure."));

    return gc;
}

static  HostComboBox *HostCentralNFSIP()
{
    HostComboBox *gc = new HostComboBox("HostCentralNFSIP",true);
    gc->setLabel(QObject::tr("NFS Server"));
    gc->setHelpText(QObject::tr("Format should be IP:/SHARENAME, For example 192.168.1.6:/media. file:nfsmap will load shares from the nfsmap file."));
    gc->addSelection("example  ip:share") ;
    gc->addSelection("file:nfsmap_auto") ;
    gc->addSelection("file:nfsmap") ;
    gc->addSelection("silverraid:/raid0/data/media/");
    gc->addSelection("") ;
    return gc;
};

static HostComboBox *HostNFSmountpoint()
{
//     #ifdef __MVAPP__
//     HostComboBox *gc = new HostComboBox("HostNFSmountpoint");
//     gc->addSelection("/data/storage/central_nfs");
//     #else
//     HostComboBox *gc = new HostComboBox("HostNFSmountpoint",true);
//     gc->addSelection("/myth");
//     #endif

    HostComboBox *gc = new HostComboBox("HostNFSmountpoint",true);
    gc->addSelection("/data/storage/central_nfs");
    gc->setLabel(QObject::tr("Mount Point"));
    gc->setHelpText(QObject::tr(""));
    return gc;
}

static HostCheckBox *HostCentralNFSallhosts()
{
    HostCheckBox *gc = new HostCheckBox("HostCentralNFSallhosts");
    gc->setLabel(QObject::tr("All Hosts Use This Share"));
    gc->setValue(true);
    gc->setHelpText(QObject::tr("If checked then all new hosts added to the cluster will try to access the same share."));
    return gc;
};





ClientNFSSettings::ClientNFSSettings():
TriggeredConfigurationGroup(false,false,false,true,true,false,false,true)
{
    setLabel(QObject::tr("Client NFS configuration"));

    Setting* havenfs = HostHaveCentralNFS();
    addChild(havenfs);
    setTrigger(havenfs);

    ConfigurationGroup* settings = new VerticalConfigurationGroup();
    QString systemtype = gCoreContext->GetSetting("HostSystemType");

    if  ( systemtype == "Master_backend" )
    {
        settings->addChild(HostCentralNFSallhosts());
    }







    settings->addChild(HostCentralNFSIP());
    settings->addChild(HostNFSmountpoint());

    addTarget("no", new VerticalConfigurationGroup());
    addTarget("yes", settings);
};



//_______________Client NFS Frame
FileShareMainFrameClient::FileShareMainFrameClient():
VerticalConfigurationGroup(false,false,false,false)
{
    setLabel(QObject::tr("File Sharing Settings (1/2)"));
    VerticalConfigurationGroup* fileshareframeclientsettings =
    new VerticalConfigurationGroup(false, true,false,false);

   ClientNFSSettings *clientnfssettings = new ClientNFSSettings();
    fileshareframeclientsettings->addChild(clientnfssettings);
    addChild(fileshareframeclientsettings);
}


//--------------------------------------

static HostCheckBox *HostServiceNFS()
{
    HostCheckBox *gc = new HostCheckBox("HostServiceNFS");
    gc->setLabel(QObject::tr("File Sharing using NFS"));
    gc->setValue(true);
    gc->setHelpText(QObject::tr("If checked, any device on the network can access media via NFS."));
    return gc;
};
static HostCheckBox *HostServiceSamba()
{
    HostCheckBox *gc = new HostCheckBox("HostServiceSamba");
    gc->setLabel(QObject::tr("File Sharing using SMB (Windows Sharing)"));
    gc->setValue(false);
    gc->setHelpText(QObject::tr("If checked, any device on the network can access media via Windows SMB file sharing."));
    return gc;
};

static HostCheckBox *HostServiceSamba_write()
{
    HostCheckBox *gc = new HostCheckBox("HostServiceSamba_write");
    gc->setLabel(QObject::tr("ReadOnly"));
    gc->setValue(false);
    gc->setHelpText(QObject::tr("If checked, all remote connections will be read only. If not checked, remote clients will have write and delete abilities."));
    return gc;
};


static HostCheckBox *HostServiceSamba_writehome()
{
    HostCheckBox *gc = new HostCheckBox("HostServiceSamba_writehome");
    gc->setLabel(QObject::tr("ReadOnly"));
    gc->setValue(false);
    gc->setHelpText(QObject::tr("If checked, all remote connections will be read only. If not checked, remote clients will have write and delete abilities."));
    return gc;
};

static HostCheckBox *HostServiceSamba_media()
{
    HostCheckBox *gc = new HostCheckBox("HostServiceSamba_media");
    gc->setLabel(QObject::tr("Share media"));
    gc->setValue(true);
    gc->setHelpText(QObject::tr(" "));
    return gc;
};

static HostCheckBox *HostServiceSamba_home()
{
    HostCheckBox *gc = new HostCheckBox("HostServiceSamba_home");
    gc->setLabel(QObject::tr("Share home"));
    gc->setValue(true);
    gc->setHelpText(QObject::tr(" "));
    return gc;
};



static HostComboBox *HostServiceSamba_domain()
{
    HostComboBox *gc = new HostComboBox("HostServiceSamba_domain",true);
    gc->setLabel(QObject::tr("Workgroup"));
    gc->setHelpText(QObject::tr("Workgroup for Windows SMB shares."));
    gc->addSelection("WORKGROUP");
    QString currentitem;
    QString line;
    QFile file("/tmp/smbdomainlist");
    if ( file.open(QIODevice::ReadOnly | QIODevice::Text) )
    {
        QTextStream t( &file );        // use a text stream
        while ( !t.atEnd() )
        {
            line = t.readLine();
            if ( line.startsWith("domain"))
            {
                currentitem = line.section( " ", 1, 1 );
                if ( currentitem != "-" )
                    gc->addSelection(currentitem);
            }
        }
        file.close();
    }
    gc->addSelection("type_workgroup_here");
    return gc;
};

class SAMBAsettings: public TriggeredConfigurationGroup {
public:

    SAMBAsettings():
    TriggeredConfigurationGroup(false, true, true, true,false, false, true, true) {
        SetVertical(true);
        Setting* trigger =  HostServiceSamba() ;
        addChild(trigger);
        setTrigger(trigger);

        ConfigurationGroup* settings = new GridConfigurationGroup(2,false,false);
        //settings->addChild(HostServiceSamba());
        settings->addChild(HostServiceSamba_media());
        settings->addChild(HostServiceSamba_write());
        settings->addChild(HostServiceSamba_home());
        settings->addChild(HostServiceSamba_writehome());
        settings->addChild(HostServiceSamba_domain());

        addTarget("0", new GridConfigurationGroup(2,false, false));
        addTarget("1", settings);
    };
};

void smb_busy_box() {
    system ("nmbscan -d  > /tmp/smbdomainlist & ");
    QString msgtext="Searching for Windows Workgroups";
    int return_code;
    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
    MythUIBusyDialog *busyPopup = new MythUIBusyDialog(msgtext, popupStack,
                                                       "installbusy");
    if (busyPopup->Create())
    {
        popupStack->AddScreen(busyPopup, false);
    }
    else
    {
        delete busyPopup;
        busyPopup = NULL;
    }

    int progressbar=1;
    MythProgressDialog *popupProgress = NULL;
    popupProgress = new MythProgressDialog(msgtext, 50);
    if (popupProgress)
    {
        popupProgress->setProgress(progressbar);
    }



    while (  return_code == 0 )
    {

        progressbar++;
        popupProgress->setProgress(progressbar);
        if (progressbar > 50 )
            progressbar = 10;

        return_code = myth_system("ps -ef|grep nmbscan|grep -v grep > /dev/null");
        qApp->processEvents ();
        usleep(900);
    }

    if (busyPopup)
    {
        busyPopup->Close();
        busyPopup = NULL;
    }


    if (popupProgress)
    {
        popupProgress->Close();
        popupProgress->deleteLater();
    }
}


//_______________Server NFS Frame
FileShareMainFrameServer::FileShareMainFrameServer():
VerticalConfigurationGroup(false,false,false,false)
{
    setLabel(QObject::tr("File Sharing Settings (2/2)"));

    VerticalConfigurationGroup* denied =  new VerticalConfigurationGroup(false,false,true,true);
    TransLabelSetting *deniedlabel = new TransLabelSetting();
    deniedlabel->setValue("               File sharing is not available for frontend_only systems." );
    denied->addChild(deniedlabel);

    VerticalConfigurationGroup* fileshare_frame_serversettings =
        new VerticalConfigurationGroup(false,false,false,false);
        fileshare_frame_serversettings->addChild(HostServiceNFS());
        fileshare_frame_serversettings->addChild(new SAMBAsettings);

    hostparm.ThisSystemType     = gCoreContext->GetSetting("HostSystemType");
    if  (hostparm.ThisSystemType == "Frontend_only" )
    {
        addChild(denied);
    }
    else
    {
        smb_busy_box();
        addChild(fileshare_frame_serversettings);
    }

}