agent_conf.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. #!/bin/bash
  2. #
  3. # OGP - Open Game Panel
  4. # Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  5. #
  6. # http://www.opengamepanel.org/
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. if [ $EUID -ne 0 -a "$(uname -o)" != "Cygwin" ]; then
  23. echo "This script must be run as root" 1>&2
  24. exit 1
  25. fi
  26. usage()
  27. {
  28. cat << EOF
  29. Usage: $0 option
  30. OPTIONS:
  31. -s password Set the password for the agent's user (Linux)
  32. -p password Set the password for cyg_server user (Windows)
  33. EOF
  34. }
  35. while getopts "hs:p:" OPTION
  36. do
  37. case $OPTION in
  38. s)
  39. sudo_password=$OPTARG
  40. ;;
  41. p)
  42. cs_psw=$OPTARG
  43. ;;
  44. ?)
  45. exit
  46. ;;
  47. esac
  48. done
  49. if [ -z $1 ]
  50. then
  51. usage
  52. exit
  53. fi
  54. if [ "$(uname -o)" == "Cygwin" ]; then
  55. if [ -z $cs_psw ]
  56. then
  57. echo "Must use -p argument instead of -s."
  58. exit
  59. fi
  60. else
  61. if [ -z $sudo_password ]
  62. then
  63. echo "Must use -s argument instead of -p."
  64. exit
  65. fi
  66. fi
  67. readonly DEFAULT_PORT=12679
  68. readonly DEFAULT_IP=0.0.0.0
  69. readonly DEFAULT_FTP_PORT=21
  70. readonly DEFAULT_FTP_PASV_RANGE=40000:50000
  71. readonly AGENT_VERSION='v1.4'
  72. failed()
  73. {
  74. echo "ERROR: ${1}"
  75. exit 1
  76. }
  77. agent_home="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  78. cfgfile=${agent_home}/Cfg/Config.pm
  79. prefsfile=${agent_home}/Cfg/Preferences.pm
  80. bashprefsfile=${agent_home}/Cfg/bash_prefs.cfg
  81. overwrite_config=1
  82. if [ -e ${cfgfile} ]; then
  83. while [ 1 ]
  84. do
  85. echo "Overwrite old configuration?"
  86. echo -n "(yes/no) [Default yes]: "
  87. read octmp
  88. if [ "$octmp" == "yes" -o -z "$octmp" ]
  89. then
  90. break
  91. elif [ "$octmp" == "no" ]
  92. then
  93. overwrite_config=0
  94. break
  95. else
  96. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  97. fi
  98. done
  99. fi
  100. if [ "X${overwrite_config}" == "X1" ]
  101. then
  102. if [ -z "$sudo_password" ]; then
  103. if [ -f "$cfgfile" ]; then
  104. sudo_password=`awk '/sudo_password/{print $3}' $cfgfile|sed -e "s#\('\)\(.*\)\(',\)#\2#"`
  105. fi
  106. fi
  107. echo "#######################################################################"
  108. echo ""
  109. echo "OGP agent uses basic encryption to prevent unauthorized users from connecting"
  110. echo "Enter a string of alpha-numeric characters for example 'abcd12345'"
  111. echo "**** NOTE - Use the same key in your Open Game Panel webpage config file - they must match *****"
  112. echo ""
  113. while [ -z "${key}" ]
  114. do
  115. echo -n "Set encryption key: "
  116. read key
  117. done
  118. echo
  119. echo "Set the listen port for the agent. The default should be fine for everyone."
  120. echo "However, if you want to change it that can be done here, otherwise just press Enter."
  121. echo -n "Set listen port [Default ${DEFAULT_PORT}]: "
  122. read port
  123. if [ -z "${port}" ]
  124. then
  125. port=$DEFAULT_PORT
  126. fi
  127. echo
  128. echo "Set the listen IP for the agent."
  129. echo "Use ${DEFAULT_IP} to bind on all interfaces."
  130. echo -n "Set listen IP [Default ${DEFAULT_IP}]: "
  131. read ip
  132. if [ -z "${ip}" ]
  133. then
  134. ip=$DEFAULT_IP
  135. fi
  136. while [ 1 ]
  137. do
  138. echo
  139. echo "For some games the OGP panel is using Steam client."
  140. echo "This client has its own license that you need to agree before continuing."
  141. echo "This agreement is available at http://store.steampowered.com/subscriber_agreement/"
  142. echo;
  143. echo "Do you accept the terms of Steam(tm) Subscriber Agreement?"
  144. echo -n "(Accept|Reject): "
  145. read steam_license
  146. if [ "$steam_license" == "Accept" -o "$steam_license" == "Reject" ]
  147. then
  148. break;
  149. fi
  150. echo "You need to type either 'Accept' or 'Reject'."
  151. done
  152. echo "Writing Config file - $cfgfile"
  153. echo "%Cfg::Config = (
  154. logfile => '${agent_home}/ogp_agent.log',
  155. listen_port => '${port}',
  156. listen_ip => '${ip}',
  157. version => '${AGENT_VERSION}',
  158. key => '${key}',
  159. steam_license => '${steam_license}',
  160. sudo_password => '${sudo_password}',
  161. );" > $cfgfile
  162. if [ $? != 0 ]
  163. then
  164. failed "Failed to write config file."
  165. else
  166. chmod 600 ${cfgfile} || failed "Failed to chmod ${cfgfile} to 600."
  167. fi
  168. echo;
  169. while [ 1 ]
  170. do
  171. echo "The agent should be updated when the service is restarted or started?"
  172. echo -n "(yes|no) [Default yes]: "
  173. read auto_update
  174. if [ "${auto_update}" == "yes" -o "${auto_update}" == "no" -o -z "${auto_update}" ]
  175. then
  176. if [ "${auto_update}" == "yes" ]
  177. then
  178. autoUpdate=1
  179. elif [ -z "${auto_update}" ]
  180. then
  181. autoUpdate=1
  182. else
  183. autoUpdate=0
  184. fi
  185. break;
  186. fi
  187. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  188. done
  189. echo;
  190. while [ 1 ]
  191. do
  192. echo "The agent should backup the server log files in the game server directory?"
  193. echo -n "(yes|no) [Default yes]: "
  194. read log_local_copy
  195. if [ "${log_local_copy}" == "yes" -o "${log_local_copy}" == "no" -o -z "${log_local_copy}" ]
  196. then
  197. if [ "${log_local_copy}" == "yes" ]
  198. then
  199. logLocalCopy=1
  200. elif [ -z "${log_local_copy}" ]
  201. then
  202. logLocalCopy=1
  203. else
  204. logLocalCopy=0
  205. fi
  206. break;
  207. fi
  208. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  209. done
  210. echo;
  211. echo "After how many days should be deleted the old backups of server's logs?"
  212. echo -n "[Default 30]: "
  213. read delete_logs_after
  214. case ${delete_logs_after} in
  215. ''|*[!0-9]*) deleteLogsAfter=30 ;;
  216. *) deleteLogsAfter=${delete_logs_after} ;;
  217. esac
  218. echo;
  219. while [ 1 ]
  220. do
  221. echo "The agent should automatically restart game servers if they crash?"
  222. echo -n "(yes|no) [Default yes]: "
  223. read auto_restart
  224. if [ "${auto_restart}" == "yes" -o "${auto_restart}" == "no" -o -z "${auto_restart}" ]
  225. then
  226. if [ "${auto_restart}" == "yes" ]
  227. then
  228. autoRestart=1
  229. elif [ -z "${auto_restart}" ]
  230. then
  231. autoRestart=1
  232. else
  233. autoRestart=0
  234. fi
  235. break;
  236. fi
  237. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  238. done
  239. echo;
  240. echo "What mirror you want to use for updating the agent?: "
  241. echo;
  242. echo "1 - SourceForge, Inc. (Chicago, Illinois, US)"
  243. echo "2 - AARNet (Melbourne, Australia, AU)"
  244. echo "3 - CityLan (Moscow, Russian Federation, RU)"
  245. echo "4 - Free France (Paris, France, FR)"
  246. echo "5 - garr.it (Ancona, Italy, IT)"
  247. echo "6 - HEAnet (Ireland, IE)"
  248. echo "7 - HiVelocity (Tampa, FL, US)"
  249. echo "8 - Internode (Adelaide, Australia, AU)"
  250. echo "9 - Japan Advanced Institute of Science and Technology (Nomi, Japan, JP)"
  251. echo "10 - kaz.kz (Almaty, Kazakhstan, KZ)"
  252. echo "11 - University of Kent (Canterbury, United Kingdom, GB)"
  253. echo "12 - NetCologne (K&ouml;ln, Germany, DE)"
  254. echo "13 - Optimate-Server (Germany, DE)"
  255. echo "14 - Softlayer (Dallas, TX, US)"
  256. echo "15 - SURFnet (Zurich, Switzerland, CH)"
  257. echo "16 - SWITCH (Zurich, Switzerland, CH)"
  258. echo "17 - Centro de Computacao Cientifica e Software Livre (Curitiba, Brazil, BR)"
  259. read setmirror
  260. case ${setmirror} in
  261. 1) mirror="master"
  262. ;;
  263. 2) mirror="aarnet"
  264. ;;
  265. 3) mirror="citylan"
  266. ;;
  267. 4) mirror="freefr"
  268. ;;
  269. 5) mirror="garr"
  270. ;;
  271. 6) mirror="heanet"
  272. ;;
  273. 7) mirror="hivelocity"
  274. ;;
  275. 8) mirror="internode"
  276. ;;
  277. 9) mirror="jaist"
  278. ;;
  279. 10) mirror="kaz"
  280. ;;
  281. 11) mirror="kent"
  282. ;;
  283. 12) mirror="netcologne"
  284. ;;
  285. 13) mirror="optimate"
  286. ;;
  287. 14) mirror="softlayer-dal"
  288. ;;
  289. 15) mirror="surfnet"
  290. ;;
  291. 16) mirror="switch"
  292. ;;
  293. 17) mirror="ufpr"
  294. ;;
  295. *) mirror="master"
  296. ;;
  297. esac
  298. echo;
  299. while [ 1 ]
  300. do
  301. echo "Should Open Game Panel create and manage FTP accounts?"
  302. echo -n "(yes|no) [Default yes]: "
  303. read manage_ftp
  304. if [ "${manage_ftp}" == "yes" -o "${manage_ftp}" == "no" -o -z "${manage_ftp}" ]
  305. then
  306. if [ "${manage_ftp}" == "yes" ]
  307. then
  308. ogpManagesFTP=1
  309. elif [ -z "${manage_ftp}" ]
  310. then
  311. ogpManagesFTP=1
  312. else
  313. ogpManagesFTP=0
  314. fi
  315. break;
  316. fi
  317. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  318. done
  319. echo;
  320. # Only ask these install questions if users want OGP to manage FTP accounts
  321. if [ "$ogpManagesFTP" == "1" ]
  322. then
  323. if [ "$(uname -o)" != "Cygwin" ]; then
  324. while [ 1 ]
  325. do
  326. echo "If you are running ISPConfig 3 in this machine the agent"
  327. echo "can use it to create FTP accounts instead of using Pure-FTPd."
  328. echo "Would you like to configure this agent to use the API of ISPConfig 3?"
  329. echo -n "(yes|no) [Default no]: "
  330. read IspConfig
  331. if [ "${IspConfig}" == "yes" -o "${IspConfig}" == "no" -o -z "${IspConfig}" ]
  332. then
  333. if [ "${IspConfig}" == "yes" ]
  334. then
  335. ftpMethod="IspConfig"
  336. else
  337. IspConfig="no"
  338. fi
  339. break;
  340. fi
  341. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  342. done
  343. if [ "${IspConfig}" == "yes" ]
  344. then
  345. while [ 1 ]
  346. do
  347. echo "Do you use HTTPS to access to your ISPConfig 3 Panel?"
  348. echo -n "(yes|no) [Default no]: "
  349. read https
  350. if [ "${https}" == "yes" -o "${https}" == "no" -o -z "${https}" ]
  351. then
  352. if [ "${https}" == "yes" ]
  353. then
  354. secure="s"
  355. else
  356. secure=""
  357. fi
  358. break;
  359. fi
  360. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  361. done
  362. echo -n "What port do you use to connect to your ISPConfig 3 Panel? [Default 8080]: "
  363. read setport
  364. case ${setport} in
  365. ''|*[!0-9]*) port=8080 ;;
  366. *) port=${setport} ;;
  367. esac
  368. echo -n "Enter an user name to sing in remotelly (Remote user): "
  369. read remote_login_username
  370. echo -n "Enter password (Remote user): "
  371. read remote_login_password
  372. echo -e "<?php\n\$username = '${remote_login_username}';" > ${agent_home}/IspConfig/soap_config.php
  373. echo "\$password = '${remote_login_password}';" >> ${agent_home}/IspConfig/soap_config.php
  374. echo "\$soap_location = 'http${secure}://127.0.0.1:${port}/remote/index.php';" >> ${agent_home}/IspConfig/soap_config.php
  375. echo -e "\$soap_uri = 'http${secure}://127.0.0.1:${port}/remote/';\n?>" >> ${agent_home}/IspConfig/soap_config.php
  376. else
  377. while [ 1 ]
  378. do
  379. echo;
  380. echo "If you have installed the Easy Hosting Control Panel (EHCP - www.ehcp.net),"
  381. echo "the agent can use it to create FTP accounts instead of using Pure-FTPd."
  382. echo "Would you like to configure this agent to use the API of EHCP?"
  383. echo -n "(yes|no) [Default no]: "
  384. read ehcp
  385. if [ "${ehcp}" == "yes" -o "${ehcp}" == "no" -o -z "${ehcp}" ]
  386. then
  387. if [ "${ehcp}" == "yes" ]
  388. then
  389. ftpMethod="EHCP"
  390. fi
  391. break;
  392. fi
  393. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  394. done
  395. if [ "${ehcp}" == "yes" ]
  396. then
  397. echo "Please enter the MySQL database password for the ehcp user"
  398. echo -n "(created during the install of EHCP): "
  399. read ehcpDB
  400. ehcpConf=${agent_home}/EHCP/config.php
  401. sed -i "s/changeme/${ehcpDB}/" $ehcpConf
  402. else
  403. while [ 1 ]
  404. do
  405. echo;
  406. echo "The agent can use ProFTPd to create FTP accounts."
  407. echo "Would you like to configure this agent to use the ProFTPd?"
  408. echo -n "(yes|no) [Default no]: "
  409. read proftpd
  410. if [ "${proftpd}" == "yes" -o "${proftpd}" == "no" -o -z "${proftpd}" ]
  411. then
  412. if [ "${proftpd}" == "yes" ]
  413. then
  414. ftpMethod="proftpd"
  415. fi
  416. break;
  417. fi
  418. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  419. done
  420. if [ "${proftpd}" == "yes" ]
  421. then
  422. echo "Please enter the path for proFTPd configuration file"
  423. echo -n "[Default /etc/proftpd/proftpd.conf]: "
  424. read proFTPdConfFile
  425. if [ -z $proFTPdConfFile ]
  426. then
  427. proFTPdConfFile="/etc/proftpd/proftpd.conf"
  428. fi
  429. proFTPdConfPath=$(dirname ${proFTPdConfFile})
  430. while [ 1 ]
  431. do
  432. if [ ! -e $proFTPdConfFile ]
  433. then
  434. echo "The file ${proFTPdConfFile} does not exists,"
  435. echo "what you want to do, reenter it or ignore and continue?"
  436. echo "If your answer is 'ignore' is meant that you will install proFTPd later."
  437. echo -n "(reenter|ignore): "
  438. read answer
  439. if [ "${answer}" == "reenter" -o "${answer}" == "ignore" ]
  440. then
  441. if [ "${answer}" == "reenter" ]
  442. then
  443. echo "Reenter proFTPd's configuration file path:"
  444. read proFTPdConfFile
  445. continue
  446. elif [ "${answer}" == "ignore" ]
  447. then
  448. echo "You will need to append this to ${proFTPdConfFile} once you've installed proftpd:"
  449. bold=`tput bold`
  450. normal=`tput sgr0`
  451. echo -e "\n\n${bold}RequireValidShell off\nAuthUserFile ${proFTPdConfPath}/ftpd.passwd\nAuthGroupFile ${proFTPdConfPath}/ftpd.group${normal}\n\n"
  452. break
  453. fi
  454. fi
  455. echo "You need to type 'reenter' or 'ignore'."
  456. else
  457. if egrep -iq "LoadModule\s*mod_auth_file.c" ${proFTPdConfFile}
  458. then
  459. sed -i "s/\s*#\s*LoadModule\s*mod_auth_file.c/LoadModule mod_auth_file.c/g" ${proFTPdConfFile}
  460. else
  461. echo -e "LoadModule mod_auth_file.c" >> ${proFTPdConfFile}
  462. fi
  463. if egrep -iq "^\s*AuthOrder.*" ${proFTPdConfFile}
  464. then
  465. if egrep -iq "^\s*AuthOrder.*mod_auth_file.c" ${proFTPdConfFile}
  466. then
  467. false
  468. else
  469. sed -ri "s/(^\s*AuthOrder.*)/\1 mod_auth_file.c/g" ${proFTPdConfFile}
  470. fi
  471. else
  472. echo -e "AuthOrder mod_auth_file.c" >> ${proFTPdConfFile}
  473. fi
  474. if egrep -iq "RequireValidShell.*" ${proFTPdConfFile}
  475. then
  476. sed -i "s#RequireValidShell.*#RequireValidShell off#g" ${proFTPdConfFile}
  477. else
  478. echo -e "RequireValidShell off" >> ${proFTPdConfFile}
  479. fi
  480. if egrep -iq "AuthUserFile.*" ${proFTPdConfFile}
  481. then
  482. sed -i "s#AuthUserFile.*#AuthUserFile ${proFTPdConfPath}/ftpd.passwd#g" ${proFTPdConfFile}
  483. else
  484. echo -e "AuthUserFile "${proFTPdConfPath}"/ftpd.passwd" >> ${proFTPdConfFile}
  485. fi
  486. if egrep -iq "AuthGroupFile.*" ${proFTPdConfFile}
  487. then
  488. sed -i "s#AuthGroupFile.*#AuthGroupFile ${proFTPdConfPath}/ftpd.group#g" ${proFTPdConfFile}
  489. else
  490. echo -e "AuthGroupFile "${proFTPdConfPath}"/ftpd.group" >> ${proFTPdConfFile}
  491. fi
  492. if [ ! -e "${proFTPdConfPath}/ftpd.group" ]
  493. then
  494. touch ${proFTPdConfPath}/ftpd.group
  495. fi
  496. if [ ! -e "${proFTPdConfPath}/ftpd.passwd" ]
  497. then
  498. touch ${proFTPdConfPath}/ftpd.passwd
  499. fi
  500. ftpd_user=$(grep -oP '^User\s+\K.+' ${proFTPdConfFile})
  501. ftpd_group=$(grep -oP '^Group\s+\K.+' ${proFTPdConfFile})
  502. agent_user=$(grep -oP 'agent_user=\K.+' /etc/init.d/ogp_agent)
  503. if [ ! -z "$ftpd_user" ] && [ ! -z "$ftpd_group" ] && [ ! -z "$agent_user" ]
  504. then
  505. if [ "$(groups $agent_user|grep $ftpd_group)" == "" ]
  506. then
  507. usermod -aG $ftpd_group $agent_user
  508. fi
  509. if [ -e "${proFTPdConfPath}/ftpd.passwd" -a -e "${proFTPdConfPath}/ftpd.group" ]
  510. then
  511. chmod 640 ${proFTPdConfPath}/ftpd.*
  512. chown -f $ftpd_user:$ftpd_group ${proFTPdConfPath}/ftpd.*
  513. fi
  514. fi
  515. break
  516. fi
  517. done
  518. if [ -e "/etc/init.d/proftpd" ]
  519. then
  520. /etc/init.d/proftpd restart
  521. else
  522. echo "If proftpd is running, to apply the changes, you must restart the service."
  523. fi
  524. else
  525. ftpMethod="PureFTPd"
  526. fi
  527. fi
  528. fi
  529. else
  530. if uname -a|grep -q "x86_64"
  531. then
  532. FZ="yes"
  533. else
  534. while [ 1 ]
  535. do
  536. echo;
  537. echo "If you have installed the FileZilla Server,"
  538. echo "the agent can use it to create FTP accounts instead of using Pure-FTPd."
  539. echo "Would you like to configure this agent to use it?"
  540. echo -n "(yes|no) [Default no]: "
  541. read FZ
  542. if [ "${FZ}" == "yes" -o "${FZ}" == "no" -o -z "${FZ}" ]
  543. then
  544. break;
  545. fi
  546. echo "You need to type 'yes', 'no' or leave empty for default value [no].";
  547. done
  548. fi
  549. if [ "${FZ}" == "yes" ]; then
  550. ftpMethod="FZ"
  551. PF=$(cmd /Q /C echo %PROGRAMFILES\(X86\)% | sed 's/\r$//')
  552. if [ "X${PF}" == "X" ];then PF=$(cmd /Q /C echo %PROGRAMFILES% | sed 's/\r$//'); fi
  553. echo;
  554. echo "Please enter the path for FileZilla server executable file"
  555. echo -n "[Default ${PF}\\FileZilla Server\\FileZilla server.exe]: "
  556. read -r FZ_EXE
  557. if [ -z "${FZ_EXE}" ]
  558. then
  559. FZ_EXE="${PF}\\FileZilla Server\\FileZilla server.exe"
  560. fi
  561. echo;
  562. echo "Please enter the path for FileZilla server xml file"
  563. echo -n "[Default ${PF}\\FileZilla Server\\FileZilla Server.xml]: "
  564. read -r FZ_XML
  565. if [ -z "${FZ_XML}" ]
  566. then
  567. FZ_XML="${PF}\\FileZilla Server\\FileZilla server.xml"
  568. fi
  569. FZ_EXE=$(cygpath -u "$FZ_EXE")
  570. FZ_XML=$(cygpath -u "$FZ_XML")
  571. FZconf=${agent_home}/Cfg/FileZilla.pm
  572. echo -e "%Cfg::FileZilla = (\n\tfz_exe => '${FZ_EXE}',\n\tfz_xml => '${FZ_XML}'\n);" > ${FZconf}
  573. if [ $? != 0 ]
  574. then
  575. failed "Failed to write FileZilla configuration file."
  576. fi
  577. if [ ! -z "$cs_psw" ]; then
  578. UD=$(cmd /Q /C echo %USERDOMAIN% | sed 's/\r$//')
  579. net stop "FileZilla Server"
  580. sc config "FileZilla Server" obj= "${UD}\cyg_server" password= "$cs_psw" type= own
  581. net start "FileZilla Server"
  582. fi
  583. else
  584. if uname -a|grep -qv "x86_64"
  585. then
  586. ftpMethod="PureFTPd"
  587. echo;
  588. echo "Set the listen IP for the PureFTPd."
  589. echo "Default is (${DEFAULT_IP}) to bind on all interfaces."
  590. echo -n "Set listen IP [Default ${DEFAULT_IP}]: "
  591. read ftp_ip
  592. if [ -z "${ftp_ip}" ]
  593. then
  594. ftp_ip=$DEFAULT_IP
  595. fi
  596. echo
  597. echo "Set the listen port for PureFTPd. The default should be fine for everyone."
  598. echo "However, if you want to change it that can be done here, otherwise just press Enter."
  599. echo -n "Set listen port [Default ${DEFAULT_FTP_PORT}]: "
  600. read port
  601. if [ -z "${ftp_port}" ]
  602. then
  603. ftp_port=$DEFAULT_FTP_PORT
  604. fi
  605. echo
  606. echo "Passive-mode downloads."
  607. echo "This is especially useful if the server is behind a firewall."
  608. echo -n "Use only ports in the range?(yes|no)[Default no]: "
  609. read passive_ftp
  610. if [ -z "${passive_ftp}" -o "${passive_ftp}" != "yes" ]
  611. then
  612. ftp_pasv_range=""
  613. else
  614. echo "Enter passive ports range separated by colon (<first port>:<last port>)."
  615. echo -n "[Default ${DEFAULT_FTP_PASV_RANGE}]: "
  616. read ftp_pasv_range
  617. if [ -z "${ftp_pasv_range}" ]
  618. then
  619. ftp_pasv_range=$DEFAULT_FTP_PASV_RANGE
  620. fi
  621. fi
  622. fi
  623. fi
  624. fi
  625. fi
  626. if [ "${ftpMethod}" == "PureFTPd" ]
  627. then
  628. run_pureftpd=1
  629. else
  630. run_pureftpd=0
  631. fi
  632. echo "Writing Preferences file - $prefsfile"
  633. prefs="%Cfg::Preferences = (\n"
  634. prefs="${prefs}\tscreen_log_local => '${logLocalCopy}',\n"
  635. prefs="${prefs}\tdelete_logs_after => '${deleteLogsAfter}',\n"
  636. prefs="${prefs}\togp_manages_ftp => '${ogpManagesFTP}',\n"
  637. prefs="${prefs}\tftp_method => '${ftpMethod}',\n"
  638. prefs="${prefs}\togp_autorestart_server => '${autoRestart}',\n"
  639. if [ "X${proftpd}" == "Xyes" ]
  640. then
  641. prefs="${prefs}\tproftpd_conf_path => '${proFTPdConfPath}'\n"
  642. fi
  643. prefs="${prefs});"
  644. echo -e $prefs > $prefsfile
  645. if [ $? != 0 ]
  646. then
  647. failed "Failed to write preferences file."
  648. fi
  649. echo "Writing bash script preferences file - $bashprefsfile"
  650. echo -e "agent_auto_update=${autoUpdate}\nsf_update_mirror=${mirror}\nrun_pureftpd=${run_pureftpd}\nftp_port=${ftp_port}\nftp_ip=${ftp_ip}\nftp_pasv_range=${ftp_pasv_range}" > $bashprefsfile
  651. if [ $? != 0 ]
  652. then
  653. failed "Failed to write MISC configuration file used by bash scripts."
  654. fi
  655. fi