File: srifreq

package info (click to toggle)
binkd 1.1a-115-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,500 kB
  • sloc: ansic: 22,989; makefile: 1,124; perl: 368; sh: 325
file content (130 lines) | stat: -rwxr-xr-x 3,705 bytes parent folder | download | duplicates (4)
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
#!/bin/bash

# Simple SRIF compatible FREQ processor
# © Copyleft Stas Degteff 2:5080/102@fidonet
version=1.0

##### Configuration
PUB=/ftp/pub
if [ ${BASH_VERSINFO[1]} -ge 4 ]
 then 
  ALIASES=( [FILES]=/ftp/pub/FILES )
fi
logfacilityinfo=local1.notice
logfacilityerror=local1.err
logstderr= #-s

##### Implementation

function usage ()
{
   echo "Simple SRIF compatible Fidonet File Request processor v.${version}"
   echo -e "@ copyleft Stas Degteff 2:5080/102\n"
   if [ ${BASH_VERSINFO[1]} -ge 4 ]
    then 
     Aliases are supported
   fi
   echo "Usage: `basename $0` <SRIF-file>"
}
if [ ${BASH_VERSINFO[1]} -ge 4 ]
 then 
  declare -A ALIASES
fi

function getSrifFile ( )
# read information from SRIF file
# Parameters: $1 = SRIF file name
{
 local token value error

 logger -p ${logfacilityinfo} ${logstderr} -t "srifreq[$$]" "parse SRIF file: ${1}"
 { while read -u 4 token value
   do 
    token=${token//[\'\"\`\$]/}
    value=${value//[\'\"\`\$]/}
    if [ ${BASH_VERSINFO[1]} -ge 4 ]
     then 
      token=${token,,}
    fi

#   case ${token,,} in
    case ${token} in
#    [Ss][yY][sS][oO][pP])
#             sysop=value
#             logger -p ${logfacilityinfo} ${logstderr} -t "srifreq[$$]" "sysop: ${sysop}"
#    ;;
#    [Aa][Kk][Aa])
#             aka=value
#             logger -p ${logfacilityinfo} ${logstderr} -t "srifreq[$$]" "aka: ${aka}"
#    ;;
    [Rr][eE][qQ][uU][eE][sS][tT][Ll][iI][sS][tT])
#     requestlist)
             requestlist=${value//\.\.\/}
             logger -p ${logfacilityinfo} ${logstderr} -t "srifreq[$$]" "requestlist: ${requestlist}"
             if [ ! -s ${requestlist} ]
              then
               error=1
               logger -p ${logfacilityerror} ${logstderr} -t "srifreq[$$]" "broken SRIF file: RequestList" ${requestlist} "is not exist or empty!"
              else
               if [ ! -r ${requestlist} ]
                then
                 error=1
                 logger -p ${logfacilityerror} ${logstderr} -t "srifreq[$$]" "Error: RequestList" ${requestlist} "is not readable!"
               fi
             fi
    ;;
    [Rr][eE][sS][pP][oO][nN][sS][eE][Ll][iI][sS][tT])
#     responselist)
             responselist=${value//\.\.\/}
             logger -p ${logfacilityinfo} ${logstderr} -t "srifreq[$$]" "responselist: ${responselist}"
             if [ ! -w `dirname ${responselist}` ]
              then
               error=1
               logger -p ${logfacilityerror} ${logstderr} -t "srifreq[$$]" "responselist ${responselist} is not writable"
             fi
    ;;
    esac 
   done
  }  4<$1
  if [ -z ${responselist} -o -z ${requestlist} ]
   then
    logger -p ${logfacilityerror} ${logstderr} -t "srifreq[$$]" "broken SRIF file: ResponseList or RequestList is not specified"
    error=1
  fi
  if [ ${error} ] ; then exit ${error} ; fi
}

function processrequest ()
# Process requested file list
# Parameters: $1 = request file (one requesting file in line)
#             $2 = responce file (found files prefixed with "+")
{ local fname
  while read -u4 fname
   do
    fname=${fname//[\'\"\`\$]}
    fname=${fname//$'\r'}
    fname=`basename ${fname}`
    logger -p ${logfacilityinfo} ${logstderr} -t "srifreq[$$]" "Find file ${fname}"
    if [ ${BASH_VERSINFO[1]} -ge 4 ]
     then 
      if [ -n ${ALIASES[${fname}]} ]
       then
        echo "+${ALIASES[${fname}]}" >>${2}
       else
        find ${PUB} -name ${fname} -printf "+%p\n" 2>/dev/null  >>${2}
      fi
     else
      find ${PUB} -name ${fname} -printf "+%p\n" 2>/dev/null  >>${2}
    fi
   done
} 4<${1}
#### main code
if [ $# != 1  -o ! -f "$1" ]
 then
   usage
   exit 1
fi

getSrifFile $1
processrequest ${requestlist} ${responselist}