unit osconf;

// This code is part of the opsi.org project

// Copyright (c) uib gmbh (www.uib.de)
// This sourcecode is owned by the uib gmbh, D55118 Mainz, Germany
// and published under the Terms of the GNU Affero General Public License.
// Text of the AGPL: http://www.gnu.org/licenses/agpl-3.0-standalone.html
// author: Rupert Roeder, detlef oertel
// credits: http://www.opsi.org/credits/


{$MODE DELPHI}
//{$RANGECHECKS ON}
{$OVERFLOWCHECKS ON}
{$IOCHECKS ON}
{$OBJECTCHECKS ON}
{$VARSTRINGCHECKS ON}
{$LONGSTRINGS ON}


interface
uses
  Classes
  , SysUtils
{$IFDEF GUI}
  , Forms
{$ENDIF GUI}
{$IFDEF WINDOWS}
 , VersionInfoX
  , Windows
  , registry
{$ENDIF WINDOWS} ;


function readConfig: boolean;

const
{$IFDEF WINDOWS}
selfProductName = 'opsi-winst';
{$ELSE}
selfProductName = 'opsi-script';
{$ENDIF WINDOWS}
ParamFilename = 'winst_p.ini';

valueEnvVarNotFound = '/-!!- not found -!!-/';


opsiorgKey = '\SOFTWARE\opsi.org';
opsiorgShareInfoKey = opsiorgKey + '\shareinfo';
opsiorgGeneralKey = opsiorgKey + '\general';


//deprecated stuff start:
opsiorgSyslogDKey = opsiorgKey + '\syslogd';
Profildateienverzeichnis: string = 'p:\pcpatch';
PathNamsInfoFilename: string = 'p:\pcpatch\pathnams.ini';
ProdukteInfoFilename: string = 'p:\utils\produkte.txt';
SaveddeWithProgmanFilename = 'ProgGrps.ins';
veryOldWinstRegKey = 'SOFTWARE\Hupsi\winst';

//deprecated stuff end


opsiservicePORThttps = 4447;


  debug: boolean = False;
  maxvisualmemostrings = 1000;
  {$IFDEF WINDOWS}
  ParamDelim = '/';
  opsiscriptconf = '';
  {$ENDIF WINDOWS}
  {$IFDEF LINUX}
  ParamDelim = '-';
  opsiscriptconf = '/etc/opsi-client-agent/opsi-script.conf';
  {$ENDIF LINUX}

  WinstRegHive = 'HKLM';
  WinstRegKey: string = 'SOFTWARE\opsi.org\winst';

  WinstRegFinalShutdownVar = 'ShutdownRequested';
  WinstRegRebootVar = 'RebootRequested';
  WinstRegContinueVar = 'ContinueLogFile';
  WinstRegLastLogfile = 'LastLogFilename';
  WinstRegNumberOfErrors = 'NumberOfErrors';

  WinstSendToLog = 'SendLogToService';

  RegNoCallLogout = 0;
  RegCallLogout = 2;
  RegCallReboot = 4;
  RegNoCallShutdown = 0;
  RegCallShutdown = 1;

  var
  computername: string;
  opsiserviceURL: string;
  opsiserviceUser: string;
  opsiservicePassword: string;
  opsiserviceSessionId: string;
  depoturl: string;
  depotshare, depotdir: string;
  depotdrive: string;
  TempPath: string;
  LogPath: string;
  TmpPathFromLogdatei: string;
  {$IFDEF WINDOWS}
  vi: TVersionInfo;
  regist : TRegistry;
  {$ENDIF WINDOWS}
  WinstVersion: string;
  WinstVersionName: string;

  //deprecated stuff start:
  configurl: string;
  configshare, configdir: string;
  utilsurl: string;
  utilsshare, utilsdir: string;
  utilsdrive: string;
  configdrive: string;
  //deprecated stuff end


implementation
uses
{$IFDEF WINDOWS}osfunc {$ENDIF}
{$IFDEF LINUX}osfunclin {$ENDIF};

function readConfig: boolean;

const
  shareDelim = '\\';

var
  part1, part2: string;

  ///XProperties :   TStringList;

begin

//{$IFDEF LINUX} computername := getHostnameLin; {$ENDIF LINUX}
{$IFDEF LINUX} computername := ''; {$ENDIF LINUX}
  Result := True;
  depoturl := '';
  //configurl := '';
  //utilsurl := '';

  depotshare := '';
  //configshare := '';
  //utilsshare := '';

  //depotdir := PathDelim + 'install';
  depotdir := PathDelim;
  //configdir := PathDelim + 'pcpatch';
  //utilsdir := PathDelim + 'utils';

  //utilsdrive := 'p:';
  //configdrive := 'p:';

  {$IFDEF WINDOWS} depotdrive := 'p:'; {$ENDIF WINDOWS}
  {$IFDEF LINUX} depotdrive := '/mnt'; {$ENDIF LINUX}

{$IFDEF WINDOWS}
  try
    regist := TRegistry.Create;
    regist.RootKey := HKEY_LOCAL_MACHINE;

    Result := regist.openKey(opsiorgshareinfokey, False);

    if Result then
    begin
      depoturl := regist.ReadString('depoturl');
      //configurl := regist.ReadString('configurl');
      //utilsurl := regist.ReadString('utilsurl');


      //If (depoturl = '') Or (configurl = '') Or (utilsurl = '')
      if (depoturl = '') then
        Result := False
      else
      begin
        depoturl := StringReplace(depoturl, '/', '\');
        //configurl := StringReplace (configurl, '/', '\');
        //utilsurl := StringReplace (utilsurl, '/', '\');

        depotdrive := regist.ReadString('depotdrive');
        //configdrive := regist.ReadString('configdrive');
        //utilsdrive := regist.ReadString('utilsdrive');

        DivideAtFirst('\\', depoturl, part1, part2);
        DivideAtFirst('\', part2, part1, part2);
        depotshare := '\\' + part1;
        DivideAtFirst('\', part2, part1, part2);
        depotshare := depotshare + '\' + part1;
        depotdir := '\' + part2;
(*
            DivideAtFirst ('\\', configurl, part1, part2);
            DivideAtFirst ('\', part2, part1, part2);
            configshare := '\\' + part1;
            DivideAtFirst ('\', part2, part1, part2);
            configshare := configshare + '\' + part1;
            configdir := '\' + part2;

            DivideAtFirst ('\\', utilsurl, part1, part2);
            DivideAtFirst ('\', part2, part1, part2);
            utilsshare := '\\' + part1;
            DivideAtFirst ('\', part2, part1, part2);
            utilsshare := utilsshare + '\' + part1;
            utilsdir := '\' + part2;
*)
      end;
    end;

    regist.CloseKey;
    regist.Free;

  except
    Result := False
  end;
{$ENDIF}
end;




initialization
{$IFDEF WINDOWS}vi := TVersionInfo.Create(Application.ExeName);
WinstVersion := vi.getString('FileVersion');
vi.Free;
{$ELSE}
WinstVersion := '4.11.4.18';
{$ENDIF WINDOWS}

WinstVersionName := 'Version ' + winstVersion ;



end.

